lib/stellar/transaction.rb in stellar-base-0.9.0 vs lib/stellar/transaction.rb in stellar-base-0.10.0
- old
+ new
@@ -99,10 +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.memo = make_memo(attributes[:memo])
result.source_account = account.account_id
result.apply_defaults
end
end
@@ -163,8 +164,27 @@
def apply_defaults
self.operations ||= []
self.fee ||= 100
self.memo ||= Memo.new(:memo_none)
self.ext ||= Stellar::Transaction::Ext.new 0
+ end
+
+ private
+ def self.make_memo(memo)
+ case memo
+ when Stellar::Memo ;
+ memo
+ when nil ;
+ nil
+ when Integer ;
+ Memo.new(:memo_id, memo)
+ when String ;
+ Memo.new(:memo_text, memo)
+ when Array ;
+ t, val = *memo
+ Memo.new(:"memo_#{t}", val)
+ else
+ raise ArgumentError, "Bad :memo"
+ end
end
end
end