lib/stellar/transaction_builder.rb in stellar-base-0.23.0 vs lib/stellar/transaction_builder.rb in stellar-base-0.23.1
- old
+ new
@@ -5,12 +5,11 @@
def initialize(
source_account:,
sequence_number:,
base_fee: 100,
time_bounds: nil,
- memo: nil,
- v1: false
+ memo: nil
)
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
@@ -19,11 +18,10 @@
@sequence_number = sequence_number
@base_fee = base_fee
@time_bounds = time_bounds
@memo = make_memo(memo)
@operations = []
- @v1 = v1
end
def build
if @time_bounds.nil?
raise "TransactionBuilder.time_bounds must be set during initialization or by calling set_timeout"
@@ -32,33 +30,30 @@
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,
fee: @base_fee * @operations.length,
seq_num: @sequence_number,
time_bounds: @time_bounds,
memo: @memo,
operations: @operations,
ext: Stellar::Transaction::Ext.new(0)
}
- tx = if @v1
- attrs[:source_account] = @source_account.muxed_account
- Stellar::Transaction.new(attrs)
- else
- attrs[:source_account_ed25519] = @source_account.raw_public_key
- Stellar::TransactionV0.new(attrs)
- end
-
@sequence_number += 1
- tx
+
+ Stellar::Transaction.new(attrs)
end
def build_fee_bump(inner_txe:)
- if inner_txe.switch != Stellar::EnvelopeType.envelope_type_tx
- raise "Invalid inner transaction type, it should be a `envelope_type_tx` but received a #{inner_tx.to_envelope.switch}."
+ p inner_txe.switch
+ if inner_txe.switch == Stellar::EnvelopeType.envelope_type_tx_v0
+ inner_txe = Stellar::TransactionEnvelope.v1(tx: inner_txe.tx.to_v1, signatures: inner_txe.signatures)
+ elsif inner_txe.switch != Stellar::EnvelopeType.envelope_type_tx
+ raise ArgumentError, "Invalid inner transaction type #{inner_txe.switch}"
end
inner_tx = inner_txe.tx
inner_ops = inner_tx.operations
inner_base_fee_rate = inner_tx.fee.fdiv(inner_ops.length)
@@ -106,14 +101,10 @@
if @time_bounds.nil?
@time_bounds = Stellar::TimeBounds.new(min_time: 0, max_time: nil)
end
- @time_bounds.max_time = if timeout == 0
- timeout
- else
- Time.now.to_i + timeout
- end
+ @time_bounds.max_time = timeout == 0 ? timeout : Time.now.to_i + timeout
self
end
def set_memo(memo)