lib/stellar/transaction_builder.rb in stellar-base-0.27.0 vs lib/stellar/transaction_builder.rb in stellar-base-0.28.0
- old
+ new
@@ -1,7 +1,9 @@
module Stellar
class TransactionBuilder
+ include Stellar::DSL
+
attr_reader :source_account, :sequence_number, :base_fee, :time_bounds, :memo, :operations
class << self
# This enable user to call shortcut methods, like
# TransactionBuilder.payment(...),
@@ -27,25 +29,24 @@
source_account:,
sequence_number:,
base_fee: 100,
time_bounds: nil,
memo: nil,
+ enable_muxed_accounts: false,
**_ # ignore any additional parameters without errors
)
- raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Stellar::KeyPair)
raise ArgumentError, "Bad :sequence_number" unless sequence_number.is_a?(Integer) && sequence_number >= 0
raise ArgumentError, "Bad :time_bounds" unless time_bounds.is_a?(Stellar::TimeBounds) || time_bounds.nil?
raise ArgumentError, "Bad :base_fee" unless base_fee.is_a?(Integer) && base_fee >= 100
- @source_account = source_account
+ @source_account = Account(source_account)
@sequence_number = sequence_number
@base_fee = base_fee
@time_bounds = time_bounds
+ @enable_muxed_accounts = enable_muxed_accounts
- if time_bounds.nil?
- set_timeout(0)
- end
+ set_timeout(0) if time_bounds.nil?
@memo = make_memo(memo)
@operations = []
end
@@ -57,11 +58,11 @@
elsif @time_bounds.max_time != 0 && @time_bounds.min_time > @time_bounds.max_time
raise "Timebounds.max_time must be greater than min_time"
end
attrs = {
- source_account: @source_account.muxed_account,
+ source_account: source_muxed_account,
fee: @base_fee * @operations.length,
seq_num: @sequence_number,
time_bounds: @time_bounds,
memo: @memo,
operations: @operations,
@@ -88,11 +89,11 @@
if @base_fee < inner_base_fee_rate
raise "Insufficient base_fee, it should be at least #{inner_base_fee_rate} stroops."
end
Stellar::FeeBumpTransaction.new(
- fee_source: @source_account.muxed_account,
+ fee_source: source_muxed_account,
fee: @base_fee * (inner_ops.length + 1),
inner_tx: Stellar::FeeBumpTransaction::InnerTx.new(:envelope_type_tx, inner_txe.v1!),
ext: Stellar::FeeBumpTransaction::Ext.new(0)
)
end
@@ -159,8 +160,20 @@
t, val = *memo
Memo.new(:"memo_#{t}", val)
else
raise ArgumentError, "Bad :memo"
end
+ end
+
+ def source_muxed_account
+ if with_muxed_accounts?
+ @source_account.muxed_account
+ else
+ @source_account.base_account
+ end
+ end
+
+ def with_muxed_accounts?
+ @enable_muxed_accounts
end
end
end