Skip to content

Commit a7d86d1

Browse files
committed
Use new ledger messages
1 parent 1a33b70 commit a7d86d1

File tree

9 files changed

+184
-112
lines changed

9 files changed

+184
-112
lines changed

Cargo.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ rev = "510bb3ca30639af4bdb12a918b6bbbdb75fa5f52"
291291

292292
[workspace.dependencies.mintlayer-ledger-messages]
293293
git = "https://github.com/mintlayer/mintlayer-ledger-app"
294-
# The commit "Remove App name and version instructions"
295-
rev = "d65b5200a4499c5ebdcf95903cc3a5579f611c6f"
294+
# The commit "fix tests"
295+
rev = "b87b78a330a7e2a80d30154e11c5065562ee9d0f"
296296
package = "messages"
297297

298298
[workspace.dependencies.trezor-client]

common/src/chain/transaction/account_outpoint.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,22 @@ impl From<&AccountCommand> for AccountType {
6161
}
6262
}
6363

64-
impl From<OrderAccountCommand> for AccountType {
65-
fn from(cmd: OrderAccountCommand) -> Self {
66-
match cmd {
64+
impl OrderAccountCommand {
65+
pub fn order_id(&self) -> OrderId {
66+
match self {
6767
OrderAccountCommand::FillOrder(order_id, _)
6868
| OrderAccountCommand::FreezeOrder(order_id)
69-
| OrderAccountCommand::ConcludeOrder(order_id) => AccountType::Order(order_id),
69+
| OrderAccountCommand::ConcludeOrder(order_id) => *order_id,
7070
}
7171
}
7272
}
7373

74+
impl From<OrderAccountCommand> for AccountType {
75+
fn from(cmd: OrderAccountCommand) -> Self {
76+
AccountType::Order(cmd.order_id())
77+
}
78+
}
79+
7480
/// The type represents the amount to withdraw from a particular account.
7581
/// Otherwise it's unclear how much should be deducted from an account balance.
7682
/// It also helps solving 2 additional problems: calculating fees and providing ability to sign input balance with the witness.

wallet/src/signer/ledger_signer/ledger_messages.rs

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ use utils::ensure;
3131
use ledger_lib::{Device, Exchange};
3232
use ledger_proto::StatusCode;
3333
use mintlayer_ledger_messages::{
34-
decode_all as ledger_decode_all, encode as ledger_encode, AddrType, Amount as LAmount, Apdu,
35-
Bip32Path as LedgerBip32Path, CoinType, GetPublicKeyRespones, InputAdditionalInfoReq, Ins,
36-
MsgSignature, OutputValue as LOutputValue, P1SignTx, PubKeyP1, PublicKeyReq, SignMessageReq,
37-
SignTxReq, Signature as LedgerSignature, TxInput as LTxInput, TxInputReq, TxMetadataReq,
38-
TxOutput as LTxOutput, TxOutputReq, APDU_CLASS, H256 as LH256, P1_SIGN_NEXT, P1_SIGN_START,
39-
P2_DONE, P2_SIGN_MORE,
34+
decode_all as ledger_decode_all, encode as ledger_encode, AccountCommand as LAccountCommand,
35+
AccountNonce as LAccountNonce, AccountOutPoint as LAccountOutPoint, AdditionalOrderInfo,
36+
AddrType, Amount as LAmount, Apdu, Bip32Path as LedgerBip32Path, CoinType,
37+
GetPublicKeyRespones, Id as LId, Ins, MsgSignature,
38+
OrderAccountCommand as LOrderAccountCommand, OutputValue as LOutputValue, P1SignTx, PubKeyP1,
39+
PublicKeyReq, SighashInputCommitment as LSighashInputCommitment, SignMessageReq, SignTxReq,
40+
Signature as LedgerSignature, TxInputReq, TxMetadataReq, TxOutput as LTxOutput, TxOutputReq,
41+
UtxoOutPoint as LUtxoOutPoint, APDU_CLASS, H256 as LH256, P1_SIGN_NEXT, P1_SIGN_START, P2_DONE,
42+
P2_MORE,
4043
};
44+
use wallet_types::partially_signed_transaction::OrderAdditionalInfo;
4145

4246
const TIMEOUT_DUR: Duration = Duration::from_secs(100);
4347
const TX_VERSION: u8 = 1;
@@ -213,7 +217,7 @@ pub async fn sign_tx<L: Exchange>(
213217
ledger: &mut L,
214218
chain_type: CoinType,
215219
inputs: Vec<TxInputReq>,
216-
input_additional_infos: Vec<InputAdditionalInfoReq>,
220+
input_commitments: Vec<LSighashInputCommitment>,
217221
outputs: Vec<TxOutputReq>,
218222
) -> SignerResult<BTreeMap<usize, Vec<LedgerSignature>>> {
219223
let metadata = ledger_encode(TxMetadataReq {
@@ -240,12 +244,12 @@ pub async fn sign_tx<L: Exchange>(
240244
.await?;
241245
}
242246

243-
for info in input_additional_infos {
247+
for commitment in input_commitments {
244248
send_chunked_expect_empty_ok_response(
245249
ledger,
246250
Ins::SIGN_TX,
247-
P1SignTx::InputAdditionalInfo.into(),
248-
&ledger_encode(SignTxReq::InputAdditionalInfo(info)),
251+
P1SignTx::InputCommitment.into(),
252+
&ledger_encode(SignTxReq::InputCommitment(commitment)),
249253
)
250254
.await?;
251255
}
@@ -300,7 +304,7 @@ pub async fn sign_tx<L: Exchange>(
300304

301305
fn decode_signature_response(resp: &[u8]) -> Result<SignatureResult, LedgerError> {
302306
let input_idx = *resp.first().ok_or(LedgerError::InvalidResponse)? as usize;
303-
let has_more_signatures = *resp.last().ok_or(LedgerError::InvalidResponse)? == P2_SIGN_MORE;
307+
let has_more_signatures = *resp.last().ok_or(LedgerError::InvalidResponse)? == P2_MORE;
304308

305309
let sig: LedgerSignature =
306310
ledger_decode_all(&resp[..resp.len() - 1][1..]).ok_or(LedgerError::InvalidResponse)?;
@@ -316,12 +320,37 @@ pub fn to_ledger_tx_output(value: &chain::TxOutput) -> LTxOutput {
316320
ledger_decode_all(value.encode().as_slice()).expect("ok")
317321
}
318322

319-
pub fn to_ledger_tx_input(value: &chain::TxInput) -> LTxInput {
323+
pub fn to_ledger_amount(value: &primitives::Amount) -> LAmount {
324+
LAmount::from_atoms(value.into_atoms())
325+
}
326+
327+
pub fn to_ledger_outpoint(value: &chain::UtxoOutPoint) -> LUtxoOutPoint {
320328
ledger_decode_all(value.encode().as_slice()).expect("ok")
321329
}
322330

323-
pub fn to_ledger_amount(value: &primitives::Amount) -> LAmount {
324-
LAmount::from_atoms(value.into_atoms())
331+
pub fn to_ledger_account_outpoint(value: &chain::AccountOutPoint) -> LAccountOutPoint {
332+
ledger_decode_all(value.encode().as_slice()).expect("ok")
333+
}
334+
335+
pub fn to_ledger_account_nonce(value: &chain::AccountNonce) -> LAccountNonce {
336+
ledger_decode_all(value.encode().as_slice()).expect("ok")
337+
}
338+
339+
pub fn to_ledger_account_command(value: &chain::AccountCommand) -> LAccountCommand {
340+
ledger_decode_all(value.encode().as_slice()).expect("ok")
341+
}
342+
343+
pub fn to_ledger_order_account_command(value: &chain::OrderAccountCommand) -> LOrderAccountCommand {
344+
ledger_decode_all(value.encode().as_slice()).expect("ok")
345+
}
346+
347+
pub fn to_ledger_additional_order_info(info: &OrderAdditionalInfo) -> AdditionalOrderInfo {
348+
AdditionalOrderInfo {
349+
initially_asked: to_ledger_output_value(&info.initially_asked),
350+
initially_given: to_ledger_output_value(&info.initially_given),
351+
ask_balance: to_ledger_amount(&info.ask_balance),
352+
give_balance: to_ledger_amount(&info.give_balance),
353+
}
325354
}
326355

327356
pub fn to_ledger_output_value(value: &chain::output_value::OutputValue) -> LOutputValue {
@@ -330,8 +359,9 @@ pub fn to_ledger_output_value(value: &chain::output_value::OutputValue) -> LOutp
330359
LOutputValue::Coin(to_ledger_amount(amount))
331360
}
332361
chain::output_value::OutputValue::TokenV0(_) => panic!("unsupported V0"),
333-
chain::output_value::OutputValue::TokenV1(token_id, amount) => {
334-
LOutputValue::TokenV1(LH256(token_id.to_hash().into()), to_ledger_amount(amount))
335-
}
362+
chain::output_value::OutputValue::TokenV1(token_id, amount) => LOutputValue::TokenV1(
363+
LId::new(LH256(token_id.to_hash().into())),
364+
to_ledger_amount(amount),
365+
),
336366
}
337367
}

0 commit comments

Comments
 (0)