Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ chrono = { version = "0.4", default-features = false }
const-hex = { version = "1.19", default-features = false }
derive_more = { version = "2.1", default-features = false }
itertools = { version = "0.15", default-features = false }
ledger_device_sdk = "1.35"
ledger_secure_sdk_sys = "1.16"
ledger_device_sdk = "1.36.1"
ledger_secure_sdk_sys = "1.16.3"
num_enum = { version = "0.7", default-features = false }
num-traits = { version = "0.2", default-features = false }
strum = { version = "0.27", default-features = false }
Expand Down
35 changes: 27 additions & 8 deletions crates/app-core/src/handlers/sign_tx/summary_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl TxSummaryCollector {
self.tx_type = merge_tx_type(self.tx_type, TxType::CreateOrder);
let (coin_or_token_id, amount) =
into_coin_or_token_id_and_amount(&order_data.give)?;
// Add the give amount as a "pseudo-output" (it goes into the order account).
self.increase_output_totals(coin_or_token_id, amount)?;
}
}
Expand Down Expand Up @@ -293,13 +294,26 @@ impl TxSummaryCollector {
self.tx_type = merge_tx_type(self.tx_type, TxType::FillOrder);
}
OrderAccountCommand::ConcludeOrder(_) => {
let (coin_or_token_id, _) =
let (asked_coin_or_token_id, initially_asked) =
into_coin_or_token_id_and_amount(&additional_info.initially_asked)?;
self.increase_input_totals(coin_or_token_id, additional_info.ask_balance)?;

let (coin_or_token_id, _) =
let (given_coin_or_token_id, _) =
into_coin_or_token_id_and_amount(&additional_info.initially_given)?;
self.increase_input_totals(coin_or_token_id, additional_info.give_balance)?;

let filled_atoms = initially_asked
.into_atoms()
.checked_sub(additional_info.ask_balance.into_atoms())
.ok_or(StatusWord::TxNumericOperationFail)?;
let filled_amount = Amount::from_atoms(filled_atoms);
// Add the filled amount as a "pseudo-input", so that actual transfer outputs
// can consume it.
self.increase_input_totals(asked_coin_or_token_id, filled_amount)?;

// Add the unspent given amount as a "pseudo-input", so that actual transfer outputs
// can consume it.
self.increase_input_totals(
given_coin_or_token_id,
additional_info.give_balance,
)?;

self.tx_type = merge_tx_type(self.tx_type, TxType::ConcludeOrder);
}
Expand Down Expand Up @@ -938,8 +952,9 @@ mod tests {
let ask_balance = mlcp::Amount::from_atoms(30);
let give_balance = mlcp::Amount::from_atoms(60);
let token_id = mlcp::Id::new(mlcp::H256::zero());
let initially_asked_amount = mlcp::Amount::from_atoms(100);
let additional_info = AdditionalOrderInfo {
initially_asked: mlcp::OutputValue::Coin(mlcp::Amount::from_atoms(100)),
initially_asked: mlcp::OutputValue::Coin(initially_asked_amount),
initially_given: mlcp::OutputValue::TokenV1(token_id, mlcp::Amount::from_atoms(200)),
ask_balance,
give_balance,
Expand All @@ -950,10 +965,14 @@ mod tests {
);
collector.process_input(&inp).unwrap();
assert_eq!(collector.tx_type(), Some(TxType::ConcludeOrder));
// Conclude order increases inputs by ask_balance and give_balance

let filled_amount = mlcp::Amount::from_atoms(
initially_asked_amount.into_atoms() - ask_balance.into_atoms(),
);
// Conclude order increases inputs by filled_amount and give_balance
assert_eq!(
collector.total_inputs().get(&CoinOrTokenId::Coin),
Some(&ask_balance)
Some(&filled_amount)
);
assert_eq!(
collector
Expand Down
7 changes: 4 additions & 3 deletions tests/test_sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,8 @@ def test_sign_tx_order_conclude(backend, scenario_navigator, device, navigator):
Test signing a transaction with two inputs:
1. A standard UTXO input to pay for tx fees.
2. An OrderAccountCommand input to conclude an order.
And one output to transfer the change coins + ask balance and another output for the give balance.
And one output to transfer the change coins plus the filled amount (where the latter
is initial_ask minus ask_balance) and another output for the give balance.
"""
client = MintlayerCommandSender(backend)
bip44_path = make_path(0, KeyPurpose.Receive, 0)
Expand Down Expand Up @@ -1332,7 +1333,7 @@ def test_sign_tx_order_conclude(backend, scenario_navigator, device, navigator):

initial_ask = 100
initial_give = 1000
ask_balance = 10
ask_balance = 90
give_balance = 900

token_id = bytes([1] * 32)
Expand Down Expand Up @@ -1367,7 +1368,7 @@ def test_sign_tx_order_conclude(backend, scenario_navigator, device, navigator):
}

change_output = _make_transfer_output(
100 - 1 + ask_balance,
100 - 1 + initial_ask - ask_balance,
fetch_public_key_as_pk_destination(client, MAINNET, bip44_change_path),
bip44_change_path,
)
Expand Down
Loading