@@ -22,10 +22,7 @@ use crate::{
2222 signer:: {
2323 ledger_signer:: ledger_messages:: {
2424 check_current_app, get_extended_public_key, get_extended_public_key_raw,
25- sign_challenge, sign_tx, to_ledger_account_command, to_ledger_account_nonce,
26- to_ledger_account_outpoint, to_ledger_additional_order_info, to_ledger_amount,
27- to_ledger_order_account_command, to_ledger_outpoint, to_ledger_output_value,
28- to_ledger_tx_output,
25+ sign_challenge, sign_tx,
2926 } ,
3027 utils:: { is_htlc_utxo, produce_uniparty_signature_for_input} ,
3128 Signer , SignerError , SignerProvider , SignerResult ,
@@ -58,6 +55,7 @@ use common::{
5855 Transaction , TxInput , TxOutput ,
5956 } ,
6057 primitives:: { BlockHeight , Idable , H256 } ,
58+ primitives_converters:: TryConvertInto as _,
6159} ;
6260use crypto:: key:: {
6361 extended:: ExtendedPublicKey ,
@@ -84,7 +82,7 @@ use async_trait::async_trait;
8482use itertools:: { izip, Itertools } ;
8583use ledger_lib:: { info:: Model , Exchange , Filters , LedgerHandle , LedgerProvider , Transport } ;
8684use mintlayer_ledger_messages:: {
87- AdditionalUtxoInfo , AddrType , Bip32Path as LedgerBip32Path , CoinType ,
85+ AdditionalOrderInfo , AdditionalUtxoInfo , AddrType , Bip32Path as LedgerBip32Path , CoinType ,
8886 InputAddressPath as LedgerInputAddressPath , SighashInputCommitment as LSighashInputCommitment ,
8987 Signature as LedgerSignature , TxInputReq , TxInputWithAdditionalInfo , TxOutputReq ,
9088} ;
@@ -378,12 +376,17 @@ where
378376 }
379377 }
380378
381- fn to_ledger_output_msgs ( & self , ptx : & PartiallySignedTransaction ) -> Vec < TxOutputReq > {
379+ fn to_ledger_output_msgs (
380+ & self ,
381+ ptx : & PartiallySignedTransaction ,
382+ ) -> SignerResult < Vec < TxOutputReq > > {
382383 ptx. tx ( )
383384 . outputs ( )
384385 . iter ( )
385- . map ( |out| TxOutputReq {
386- out : to_ledger_tx_output ( out) ,
386+ . map ( |out| {
387+ Ok ( TxOutputReq {
388+ out : out. clone ( ) . try_convert_into ( ) ?,
389+ } )
387390 } )
388391 . collect ( )
389392 }
@@ -504,7 +507,7 @@ where
504507 ) > {
505508 let ( inputs, standalone_inputs) = to_ledger_input_msgs ( & ptx, key_chain, & db_tx) ?;
506509 let input_commitments = to_ledger_input_commitments_reqs ( & ptx) ?;
507- let outputs = self . to_ledger_output_msgs ( & ptx) ;
510+ let outputs = self . to_ledger_output_msgs ( & ptx) ? ;
508511 let coin_type = to_ledger_chain_type ( & self . chain_config ) ;
509512
510513 let input_commitment_version = self
@@ -898,29 +901,34 @@ fn to_ledger_tx_input_with_additional_info(
898901 . get_pool_info ( pool_id)
899902 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
900903 AdditionalUtxoInfo :: PoolData {
901- utxo : to_ledger_tx_output ( utxo) ,
902- staker_balance : to_ledger_amount ( & pool_info. staker_balance ) ,
904+ utxo : utxo. clone ( ) . try_convert_into ( ) ? ,
905+ staker_balance : pool_info. staker_balance . try_convert_into ( ) ? ,
903906 }
904907 }
905- _ => AdditionalUtxoInfo :: Utxo ( to_ledger_tx_output ( utxo) ) ,
908+ _ => AdditionalUtxoInfo :: Utxo ( utxo. clone ( ) . try_convert_into ( ) ? ) ,
906909 } ;
907- TxInputWithAdditionalInfo :: Utxo ( to_ledger_outpoint ( outpoint) , info)
910+ TxInputWithAdditionalInfo :: Utxo ( outpoint. clone ( ) . try_convert_into ( ) ? , info)
908911 }
909912 TxInput :: Account ( acc) => {
910- TxInputWithAdditionalInfo :: Account ( to_ledger_account_outpoint ( acc) )
913+ TxInputWithAdditionalInfo :: Account ( acc. clone ( ) . try_convert_into ( ) ? )
911914 }
912915 TxInput :: AccountCommand ( nonce, cmd) => TxInputWithAdditionalInfo :: AccountCommand (
913- to_ledger_account_nonce ( nonce) ,
914- to_ledger_account_command ( cmd) ,
916+ ( * nonce) . try_convert_into ( ) ? ,
917+ cmd. clone ( ) . try_convert_into ( ) ? ,
915918 ) ,
916919 TxInput :: OrderAccountCommand ( cmd) => {
917920 let info = additional_info
918921 . get_order_info ( cmd. order_id ( ) )
919922 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
920923
921924 TxInputWithAdditionalInfo :: OrderAccountCommand (
922- to_ledger_order_account_command ( cmd) ,
923- to_ledger_additional_order_info ( info) ?,
925+ cmd. clone ( ) . try_convert_into ( ) ?,
926+ AdditionalOrderInfo {
927+ initially_asked : info. initially_asked . clone ( ) . try_convert_into ( ) ?,
928+ initially_given : info. initially_given . clone ( ) . try_convert_into ( ) ?,
929+ ask_balance : info. ask_balance . try_convert_into ( ) ?,
930+ give_balance : info. give_balance . try_convert_into ( ) ?,
931+ } ,
924932 )
925933 }
926934 } ;
@@ -1011,11 +1019,11 @@ fn to_ledger_input_commitments_reqs(
10111019 . get_pool_info ( pool_id)
10121020 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
10131021 LSighashInputCommitment :: ProduceBlockFromStakeUtxo {
1014- utxo : to_ledger_tx_output ( utxo) ,
1015- staker_balance : to_ledger_amount ( & pool_info. staker_balance ) ,
1022+ utxo : utxo. clone ( ) . try_convert_into ( ) ? ,
1023+ staker_balance : pool_info. staker_balance . try_convert_into ( ) ? ,
10161024 }
10171025 }
1018- _ => LSighashInputCommitment :: Utxo ( to_ledger_tx_output ( utxo) ) ,
1026+ _ => LSighashInputCommitment :: Utxo ( utxo. clone ( ) . try_convert_into ( ) ? ) ,
10191027 }
10201028 }
10211029 TxInput :: Account ( _) => LSighashInputCommitment :: None ,
@@ -1033,8 +1041,14 @@ fn to_ledger_input_commitments_reqs(
10331041 . get_order_info ( order_id)
10341042 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
10351043 LSighashInputCommitment :: FillOrderAccountCommand {
1036- initially_asked : to_ledger_output_value ( & order_info. initially_asked ) ?,
1037- initially_given : to_ledger_output_value ( & order_info. initially_given ) ?,
1044+ initially_asked : order_info
1045+ . initially_asked
1046+ . clone ( )
1047+ . try_convert_into ( ) ?,
1048+ initially_given : order_info
1049+ . initially_given
1050+ . clone ( )
1051+ . try_convert_into ( ) ?,
10381052 }
10391053 }
10401054 AccountCommand :: ConcludeOrder ( order_id) => {
@@ -1043,10 +1057,16 @@ fn to_ledger_input_commitments_reqs(
10431057 . get_order_info ( order_id)
10441058 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
10451059 LSighashInputCommitment :: ConcludeOrderAccountCommand {
1046- initially_asked : to_ledger_output_value ( & order_info. initially_asked ) ?,
1047- initially_given : to_ledger_output_value ( & order_info. initially_given ) ?,
1048- ask_balance : to_ledger_amount ( & order_info. ask_balance ) ,
1049- give_balance : to_ledger_amount ( & order_info. give_balance ) ,
1060+ initially_asked : order_info
1061+ . initially_asked
1062+ . clone ( )
1063+ . try_convert_into ( ) ?,
1064+ initially_given : order_info
1065+ . initially_given
1066+ . clone ( )
1067+ . try_convert_into ( ) ?,
1068+ ask_balance : order_info. ask_balance . try_convert_into ( ) ?,
1069+ give_balance : order_info. give_balance . try_convert_into ( ) ?,
10501070 }
10511071 }
10521072 } ,
@@ -1057,8 +1077,14 @@ fn to_ledger_input_commitments_reqs(
10571077 . get_order_info ( order_id)
10581078 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
10591079 LSighashInputCommitment :: FillOrderAccountCommand {
1060- initially_asked : to_ledger_output_value ( & order_info. initially_asked ) ?,
1061- initially_given : to_ledger_output_value ( & order_info. initially_given ) ?,
1080+ initially_asked : order_info
1081+ . initially_asked
1082+ . clone ( )
1083+ . try_convert_into ( ) ?,
1084+ initially_given : order_info
1085+ . initially_given
1086+ . clone ( )
1087+ . try_convert_into ( ) ?,
10621088 }
10631089 }
10641090 OrderAccountCommand :: ConcludeOrder ( order_id) => {
@@ -1067,10 +1093,16 @@ fn to_ledger_input_commitments_reqs(
10671093 . get_order_info ( order_id)
10681094 . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
10691095 LSighashInputCommitment :: ConcludeOrderAccountCommand {
1070- initially_asked : to_ledger_output_value ( & order_info. initially_asked ) ?,
1071- initially_given : to_ledger_output_value ( & order_info. initially_given ) ?,
1072- ask_balance : to_ledger_amount ( & order_info. ask_balance ) ,
1073- give_balance : to_ledger_amount ( & order_info. give_balance ) ,
1096+ initially_asked : order_info
1097+ . initially_asked
1098+ . clone ( )
1099+ . try_convert_into ( ) ?,
1100+ initially_given : order_info
1101+ . initially_given
1102+ . clone ( )
1103+ . try_convert_into ( ) ?,
1104+ ask_balance : order_info. ask_balance . try_convert_into ( ) ?,
1105+ give_balance : order_info. give_balance . try_convert_into ( ) ?,
10741106 }
10751107 }
10761108 OrderAccountCommand :: FreezeOrder ( _) => LSighashInputCommitment :: None ,
0 commit comments