Skip to content

Commit

Permalink
feat!: unconditionally use muxed accounts in tx builder (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-wasp authored Feb 6, 2022
1 parent f7413e2 commit 8537fa7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
20 changes: 3 additions & 17 deletions base/lib/stellar/transaction_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def method_missing(method_name, *args, **kwargs)
op = Operation.send(
method_name,
**kwargs.except(
:source_account, :sequence_number, :base_fee, :time_bounds, :memo, :enable_muxed_accounts
:source_account, :sequence_number, :base_fee, :time_bounds, :memo
)
)

Expand All @@ -34,7 +34,6 @@ def initialize(
base_fee: 100,
time_bounds: nil,
memo: nil,
enable_muxed_accounts: false,
**_ # ignore any additional parameters without errors
)
raise ArgumentError, "Bad :sequence_number" unless sequence_number.is_a?(Integer) && sequence_number >= 0
Expand All @@ -45,7 +44,6 @@ def initialize(
@sequence_number = sequence_number
@base_fee = base_fee
@time_bounds = time_bounds
@enable_muxed_accounts = enable_muxed_accounts

set_timeout(0) if time_bounds.nil?

Expand All @@ -63,7 +61,7 @@ def build
end

attrs = {
source_account: source_muxed_account,
source_account: @source_account.muxed_account,
fee: @base_fee * @operations.length,
seq_num: @sequence_number,
time_bounds: @time_bounds,
Expand Down Expand Up @@ -94,7 +92,7 @@ def build_fee_bump(inner_txe:)
end

Stellar::FeeBumpTransaction.new(
fee_source: source_muxed_account,
fee_source: @source_account.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)
Expand Down Expand Up @@ -166,17 +164,5 @@ def make_memo(memo)
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
21 changes: 9 additions & 12 deletions base/spec/lib/stellar/transaction_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
let(:base_fee) { 100 }
let(:key_pair) { Stellar::KeyPair.random }
let(:source_account) { key_pair }
let(:enable_muxed_accounts) { false }

subject(:builder) do
described_class.new(
source_account: source_account,
sequence_number: 1,
enable_muxed_accounts: enable_muxed_accounts
)
described_class.new(source_account: source_account, sequence_number: 1)
end

describe ".initialize" do
Expand Down Expand Up @@ -45,6 +40,7 @@
ArgumentError, "Bad :base_fee"
)
end

it "bad memo" do
expect {
described_class.new(
Expand Down Expand Up @@ -317,15 +313,16 @@
])
end

it "sets tx's source account to muxed account without id" do
tx = builder.build
context "when source account does not have id" do
it "sets tx's source account to muxed account without id" do
tx = builder.build

expect(tx.source_account.switch.name).to eq("key_type_ed25519")
expect(tx.source_account.ed25519).to eq(key_pair.raw_public_key)
expect(tx.source_account.switch.name).to eq("key_type_ed25519")
expect(tx.source_account.ed25519).to eq(key_pair.raw_public_key)
end
end

context "when muxed accounts are enabled" do
let(:enable_muxed_accounts) { true }
context "when source account has id" do
let(:account_id) { 15 }
let(:source_account) { Stellar::Account.new(key_pair, account_id) }

Expand Down

0 comments on commit 8537fa7

Please sign in to comment.