@@ -45,8 +45,8 @@ use common::{
4545 } ,
4646 timelock:: OutputTimeLock ,
4747 tokens:: { NftIssuance , TokenId , TokenIssuance , TokenTotalSupply } ,
48- AccountCommand , AccountSpending , ChainConfig , Destination , OutPointSourceId ,
49- SignedTransactionIntent , Transaction , TxInput , TxOutput ,
48+ AccountCommand , AccountSpending , ChainConfig , Destination , OrderAccountCommand ,
49+ OutPointSourceId , SignedTransactionIntent , Transaction , TxInput , TxOutput ,
5050 } ,
5151 primitives:: { Amount , Idable , H256 } ,
5252} ;
@@ -69,14 +69,15 @@ use trezor_client::{
6969 MintlayerAccountCommandTxInput , MintlayerAccountSpendingDelegationBalance ,
7070 MintlayerAccountTxInput , MintlayerAddressPath , MintlayerAddressType , MintlayerBurnTxOutput ,
7171 MintlayerChainType , MintlayerChangeTokenAuthority , MintlayerChangeTokenMetadataUri ,
72- MintlayerConcludeOrder , MintlayerCreateDelegationIdTxOutput , MintlayerCreateOrderTxOutput ,
73- MintlayerCreateStakePoolTxOutput , MintlayerDataDepositTxOutput ,
74- MintlayerDelegateStakingTxOutput , MintlayerFillOrder , MintlayerFreezeToken ,
75- MintlayerHtlcTxOutput , MintlayerIssueFungibleTokenTxOutput , MintlayerIssueNftTxOutput ,
72+ MintlayerConcludeOrder , MintlayerConcludeOrderV1 , MintlayerCreateDelegationIdTxOutput ,
73+ MintlayerCreateOrderTxOutput , MintlayerCreateStakePoolTxOutput ,
74+ MintlayerDataDepositTxOutput , MintlayerDelegateStakingTxOutput , MintlayerFillOrder ,
75+ MintlayerFillOrderV1 , MintlayerFreezeOrder , MintlayerFreezeToken , MintlayerHtlcTxOutput ,
76+ MintlayerIssueFungibleTokenTxOutput , MintlayerIssueNftTxOutput ,
7677 MintlayerLockThenTransferTxOutput , MintlayerLockTokenSupply , MintlayerMintTokens ,
77- MintlayerOutputValue , MintlayerProduceBlockFromStakeTxOutput , MintlayerTokenOutputValue ,
78- MintlayerTokenTotalSupply , MintlayerTokenTotalSupplyType , MintlayerUnfreezeToken ,
79- MintlayerUnmintTokens , MintlayerUtxoType ,
78+ MintlayerOrderCommandTxInput , MintlayerOutputValue , MintlayerProduceBlockFromStakeTxOutput ,
79+ MintlayerTokenOutputValue , MintlayerTokenTotalSupply , MintlayerTokenTotalSupplyType ,
80+ MintlayerUnfreezeToken , MintlayerUnmintTokens , MintlayerUtxoType ,
8081 } ,
8182 Model ,
8283} ;
@@ -837,10 +838,12 @@ fn to_trezor_input_msgs(
837838 command,
838839 ptx. additional_info ( ) ,
839840 ) ,
840- TxInput :: OrderAccountCommand ( _) => {
841- //TODO: support OrdersVersion::V1
842- unimplemented ! ( ) ;
843- }
841+ TxInput :: OrderAccountCommand ( command) => to_trezor_order_command_input (
842+ chain_config,
843+ address_paths,
844+ command,
845+ ptx. additional_info ( ) ,
846+ ) ,
844847 } ?;
845848
846849 Ok ( ( input, ( idx as u32 , standalone_inputs) ) )
@@ -990,6 +993,99 @@ fn to_trezor_account_command_input(
990993 Ok ( inp)
991994}
992995
996+ fn to_trezor_order_command_input (
997+ chain_config : & ChainConfig ,
998+ address_paths : Vec < MintlayerAddressPath > ,
999+ command : & OrderAccountCommand ,
1000+ additional_info : & TxAdditionalInfo ,
1001+ ) -> SignerResult < MintlayerTxInput > {
1002+ let mut inp_req = MintlayerOrderCommandTxInput :: new ( ) ;
1003+ inp_req. addresses = address_paths;
1004+ match command {
1005+ OrderAccountCommand :: FreezeOrder ( order_id) => {
1006+ let mut req = MintlayerFreezeOrder :: new ( ) ;
1007+ req. set_order_id ( Address :: new ( chain_config, * order_id) ?. into_string ( ) ) ;
1008+
1009+ inp_req. freeze = Some ( req) . into ( ) ;
1010+ }
1011+ OrderAccountCommand :: ConcludeOrder ( order_id) => {
1012+ let mut req = MintlayerConcludeOrderV1 :: new ( ) ;
1013+ req. set_order_id ( Address :: new ( chain_config, * order_id) ?. into_string ( ) ) ;
1014+
1015+ let OrderAdditionalInfo {
1016+ initially_asked,
1017+ initially_given,
1018+ ask_balance,
1019+ give_balance,
1020+ } = additional_info
1021+ . get_order_info ( order_id)
1022+ . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
1023+
1024+ let filled_value = match initially_asked {
1025+ OutputValue :: Coin ( amount) => OutputValue :: Coin (
1026+ ( * amount - * ask_balance) . ok_or ( SignerError :: OrderFillUnderflow ) ?,
1027+ ) ,
1028+ OutputValue :: TokenV1 ( id, amount) => OutputValue :: TokenV1 (
1029+ * id,
1030+ ( * amount - * ask_balance) . ok_or ( SignerError :: OrderFillUnderflow ) ?,
1031+ ) ,
1032+ OutputValue :: TokenV0 ( _) => return Err ( SignerError :: UnsupportedTokensV0 ) ,
1033+ } ;
1034+ let give_value = value_with_new_amount ( initially_given, give_balance) ?;
1035+
1036+ req. filled_ask_amount = Some ( to_trezor_output_value (
1037+ & filled_value,
1038+ additional_info,
1039+ chain_config,
1040+ ) ?)
1041+ . into ( ) ;
1042+
1043+ req. give_balance = Some ( to_trezor_output_value (
1044+ & give_value,
1045+ additional_info,
1046+ chain_config,
1047+ ) ?)
1048+ . into ( ) ;
1049+
1050+ inp_req. conclude = Some ( req) . into ( ) ;
1051+ }
1052+ OrderAccountCommand :: FillOrder ( order_id, amount, dest) => {
1053+ let mut req = MintlayerFillOrderV1 :: new ( ) ;
1054+ req. set_order_id ( Address :: new ( chain_config, * order_id) ?. into_string ( ) ) ;
1055+ req. set_amount ( amount. into_atoms ( ) . to_be_bytes ( ) . to_vec ( ) ) ;
1056+ req. set_destination ( Address :: new ( chain_config, dest. clone ( ) ) ?. into_string ( ) ) ;
1057+
1058+ let OrderAdditionalInfo {
1059+ initially_asked,
1060+ initially_given,
1061+ ask_balance : _,
1062+ give_balance : _,
1063+ } = additional_info
1064+ . get_order_info ( order_id)
1065+ . ok_or ( SignerError :: MissingTxExtraInfo ) ?;
1066+
1067+ req. ask_balance = Some ( to_trezor_output_value (
1068+ initially_asked,
1069+ additional_info,
1070+ chain_config,
1071+ ) ?)
1072+ . into ( ) ;
1073+
1074+ req. give_balance = Some ( to_trezor_output_value (
1075+ initially_given,
1076+ additional_info,
1077+ chain_config,
1078+ ) ?)
1079+ . into ( ) ;
1080+
1081+ inp_req. fill = Some ( req) . into ( ) ;
1082+ }
1083+ }
1084+ let mut inp = MintlayerTxInput :: new ( ) ;
1085+ inp. order_command = Some ( inp_req) . into ( ) ;
1086+ Ok ( inp)
1087+ }
1088+
9931089/// Construct a new OutputValue with a new amount
9941090fn value_with_new_amount (
9951091 initial_value : & OutputValue ,
0 commit comments