lib/stellar/transaction.rb in stellar-base-0.0.18 vs lib/stellar/transaction.rb in stellar-base-0.0.19

- old
+ new

@@ -28,11 +28,11 @@ # # @see Stellar::Operation.create_offer def self.manage_offer(attributes={}) make :manage_offer, attributes end - + # # @see Stellar::Operation.create_passive_offer def self.create_passive_offer(attributes={}) make :create_passive_offer, attributes end @@ -99,11 +99,11 @@ raise ArgumentError, "Bad :fee #{sequence}" if fee.present? && !fee.is_a?(Integer) new.tap do |result| result.seq_num = sequence result.fee = fee - result.source_account = account.public_key + result.source_account = account.account_id result.apply_defaults end end def sign(key_pair) @@ -113,13 +113,24 @@ def sign_decorated(key_pair) key_pair.sign_decorated(hash) end def hash - Digest::SHA256.digest(to_xdr) + Digest::SHA256.digest(signature_base) end + # Returns the string of bytes that, when hashed, provide the value which + # should be signed to create a valid stellar transaciton signature + def signature_base + signature_base_prefix + to_xdr + end + + def signature_base_prefix + val = Stellar::EnvelopeType.envelope_type_tx + Stellar::EnvelopeType.to_xdr(val) + end + def to_envelope(*key_pairs) signatures = key_pairs.map(&method(:sign_decorated)) TransactionEnvelope.new({ :signatures => signatures, @@ -150,8 +161,9 @@ def apply_defaults self.operations ||= [] self.fee ||= 10 self.memo ||= Memo.new(:memo_none) + self.ext ||= Stellar::Transaction::Ext.new 0 end end end