1515
1616use parity_scale_codec:: { Decode , Encode } ;
1717
18- use crate :: { AccountCommand , AccountNonce , AccountOutPoint , OrderAccountCommand , UtxoOutPoint } ;
18+ use crate :: {
19+ AccountCommand , AccountNonce , AccountOutPoint , Amount , OrderAccountCommand , OutputValue ,
20+ SighashInputCommitment , TxOutput , UtxoOutPoint ,
21+ } ;
1922
2023#[ derive( Debug , Clone , PartialEq , Eq , Encode , Decode , strum:: EnumDiscriminants ) ]
2124#[ strum_discriminants( name( TxInputTag ) , derive( strum:: EnumIter ) ) ]
@@ -32,3 +35,86 @@ pub enum TxInput {
3235 #[ codec( index = 3 ) ]
3336 OrderAccountCommand ( OrderAccountCommand ) ,
3437}
38+
39+ #[ derive( Debug , Clone , PartialEq , Eq , Encode , Decode ) ]
40+ pub struct AdditionalOrderInfo {
41+ pub initially_asked : OutputValue ,
42+ pub initially_given : OutputValue ,
43+ pub ask_balance : Amount ,
44+ pub give_balance : Amount ,
45+ }
46+
47+ #[ derive( Debug , Clone , PartialEq , Eq , Encode , Decode ) ]
48+ pub enum AdditionalUtxoInfo {
49+ Utxo ( TxOutput ) ,
50+ PoolData {
51+ utxo : TxOutput ,
52+ staker_balance : Amount ,
53+ } ,
54+ }
55+
56+ impl From < AdditionalUtxoInfo > for SighashInputCommitment {
57+ fn from ( value : AdditionalUtxoInfo ) -> Self {
58+ match value {
59+ AdditionalUtxoInfo :: Utxo ( output) => SighashInputCommitment :: Utxo ( output) ,
60+ AdditionalUtxoInfo :: PoolData {
61+ utxo,
62+ staker_balance,
63+ } => SighashInputCommitment :: ProduceBlockFromStakeUtxo {
64+ utxo,
65+ staker_balance,
66+ } ,
67+ }
68+ }
69+ }
70+
71+ #[ derive( Debug , Clone , PartialEq , Eq , Encode , Decode , strum:: EnumDiscriminants ) ]
72+ #[ strum_discriminants( name( TxInputWithAdditionalDataTag ) , derive( strum:: EnumIter ) ) ]
73+ pub enum TxInputWithAdditionalInfo {
74+ #[ codec( index = 0 ) ]
75+ Utxo ( UtxoOutPoint , AdditionalUtxoInfo ) ,
76+
77+ #[ codec( index = 1 ) ]
78+ Account ( AccountOutPoint ) ,
79+
80+ #[ codec( index = 2 ) ]
81+ AccountCommand ( AccountNonce , AccountCommand ) ,
82+
83+ #[ codec( index = 3 ) ]
84+ OrderAccountCommand ( OrderAccountCommand , AdditionalOrderInfo ) ,
85+ }
86+
87+ impl TxInputWithAdditionalInfo {
88+ pub fn into_input_and_commitment ( self ) -> ( TxInput , SighashInputCommitment ) {
89+ match self {
90+ TxInputWithAdditionalInfo :: Utxo ( utxo, info) => ( TxInput :: Utxo ( utxo) , info. into ( ) ) ,
91+ TxInputWithAdditionalInfo :: Account ( acc) => {
92+ ( TxInput :: Account ( acc) , SighashInputCommitment :: None )
93+ }
94+ TxInputWithAdditionalInfo :: AccountCommand ( nonce, cmd) => (
95+ TxInput :: AccountCommand ( nonce, cmd) ,
96+ SighashInputCommitment :: None ,
97+ ) ,
98+ TxInputWithAdditionalInfo :: OrderAccountCommand ( cmd, info) => {
99+ let commitment = match & cmd {
100+ OrderAccountCommand :: FillOrder ( _, _) => {
101+ SighashInputCommitment :: FillOrderAccountCommand {
102+ initially_asked : info. initially_asked ,
103+ initially_given : info. initially_given ,
104+ }
105+ }
106+ OrderAccountCommand :: ConcludeOrder ( _) => {
107+ SighashInputCommitment :: ConcludeOrderAccountCommand {
108+ initially_asked : info. initially_asked ,
109+ initially_given : info. initially_given ,
110+ ask_balance : info. ask_balance ,
111+ give_balance : info. give_balance ,
112+ }
113+ }
114+ OrderAccountCommand :: FreezeOrder ( _) => SighashInputCommitment :: None ,
115+ } ;
116+ ( TxInput :: OrderAccountCommand ( cmd) , commitment)
117+ }
118+ }
119+ }
120+ }
0 commit comments