@@ -31,13 +31,17 @@ use utils::ensure;
3131use ledger_lib:: { Device , Exchange } ;
3232use ledger_proto:: StatusCode ;
3333use 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
4246const TIMEOUT_DUR : Duration = Duration :: from_secs ( 100 ) ;
4347const 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
301305fn 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
327356pub 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