Skip to content

Commit 5faeaaf

Browse files
committed
Use new TxInfoWithAdditionalInfo
1 parent 2a03f21 commit 5faeaaf

4 files changed

Lines changed: 285 additions & 291 deletions

File tree

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ build-std-features = ["compiler-builtins-mem"]
1212
# Authorized values are [2048, 4096, 8192, 16384, 24576]
1313
# Uncomment the following lines to set the heap size to 4096 bytes for instance
1414
[env]
15-
HEAP_SIZE = "24576"
15+
HEAP_SIZE = "16384"

messages/src/lib.rs

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ extern crate alloc;
2323
use alloc::vec::Vec;
2424

2525
pub use mintlayer_core_primitives::{
26-
AccountCommand, AccountOutPoint, AccountSpending, Amount, CoinType as PCoinType, Destination,
27-
H256, HashedTimelockContract, HtlcSecretHash, Id, IsTokenFreezable, IsTokenUnfreezable,
28-
NftIssuance, OrderAccountCommand, OrderData, OutPointSourceId, OutputTimeLock, OutputValue,
29-
PublicKey, PublicKeyHash, SchnorrkelPublicKey, Secp256k1PublicKey, SighashInputCommitment,
30-
StakePoolData, TokenIssuance, TokenTotalSupply, TxInput, TxOutput, UtxoOutPoint, VrfPublicKey,
26+
AccountCommand, AccountNonce, AccountOutPoint, AccountSpending, Amount, CoinType as PCoinType,
27+
Destination, H256, HashedTimelockContract, HtlcSecretHash, Id, IsTokenFreezable,
28+
IsTokenUnfreezable, NftIssuance, OrderAccountCommand, OrderData, OutPointSourceId,
29+
OutputTimeLock, OutputValue, PublicKey, PublicKeyHash, SchnorrkelPublicKey, Secp256k1PublicKey,
30+
SighashInputCommitment, StakePoolData, TokenIssuance, TokenTotalSupply, TxInput, TxOutput,
31+
UtxoOutPoint, VrfPublicKey,
3132
};
3233
use num_enum::{IntoPrimitive, TryFromPrimitive};
3334
pub use parity_scale_codec::Encode;
@@ -82,8 +83,9 @@ fn wrong_p1p2(_: u8) -> WrongP1P2 {
8283
pub enum P1SignTx {
8384
Metadata = 0,
8485
Input = 1,
85-
Output = 2,
86-
NextSignature = 3,
86+
InputAdditionalInfo = 2,
87+
Output = 3,
88+
NextSignature = 4,
8789
}
8890

8991
#[derive(Encode, Decode)]
@@ -102,6 +104,7 @@ pub struct SignMessageReq {
102104
#[derive(Encode, Decode)]
103105
pub enum SignTxReq {
104106
Input(TxInputReq),
107+
InputCommitment(SighashInputCommitment),
105108
Output(TxOutputReq),
106109
NextSignature,
107110
}
@@ -117,26 +120,89 @@ pub struct TxMetadataReq {
117120
#[derive(Encode, Decode)]
118121
pub struct TxInputReq {
119122
pub addresses: Vec<InputAddressPath>,
120-
pub inp: TxInput,
121-
pub additional_info: InputAdditionalInfo,
123+
pub inp: TxInputWithAdditionalInfo,
122124
}
123125

124-
#[derive(Encode, Decode)]
125-
pub enum InputAdditionalInfo {
126-
None,
127-
Utxo {
128-
utxo: TxOutput,
129-
},
130-
PoolInfo {
126+
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
127+
pub struct AdditionalOrderInfo {
128+
pub initially_asked: OutputValue,
129+
pub initially_given: OutputValue,
130+
pub ask_balance: Amount,
131+
pub give_balance: Amount,
132+
}
133+
134+
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
135+
pub enum AdditionalUtxoInfo {
136+
Utxo(TxOutput),
137+
PoolData {
131138
utxo: TxOutput,
132139
staker_balance: Amount,
133140
},
134-
OrderInfo {
135-
initially_asked: OutputValue,
136-
initially_given: OutputValue,
137-
ask_balance: Amount,
138-
give_balance: Amount,
139-
},
141+
}
142+
143+
impl From<AdditionalUtxoInfo> for SighashInputCommitment {
144+
fn from(value: AdditionalUtxoInfo) -> Self {
145+
match value {
146+
AdditionalUtxoInfo::Utxo(output) => SighashInputCommitment::Utxo(output),
147+
AdditionalUtxoInfo::PoolData {
148+
utxo,
149+
staker_balance,
150+
} => SighashInputCommitment::ProduceBlockFromStakeUtxo {
151+
utxo,
152+
staker_balance,
153+
},
154+
}
155+
}
156+
}
157+
158+
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
159+
pub enum TxInputWithAdditionalInfo {
160+
#[codec(index = 0)]
161+
Utxo(UtxoOutPoint, AdditionalUtxoInfo),
162+
163+
#[codec(index = 1)]
164+
Account(AccountOutPoint),
165+
166+
#[codec(index = 2)]
167+
AccountCommand(AccountNonce, AccountCommand),
168+
169+
#[codec(index = 3)]
170+
OrderAccountCommand(OrderAccountCommand, AdditionalOrderInfo),
171+
}
172+
173+
impl TxInputWithAdditionalInfo {
174+
pub fn into_input_and_commitment(self) -> (TxInput, SighashInputCommitment) {
175+
match self {
176+
TxInputWithAdditionalInfo::Utxo(utxo, info) => (TxInput::Utxo(utxo), info.into()),
177+
TxInputWithAdditionalInfo::Account(acc) => {
178+
(TxInput::Account(acc), SighashInputCommitment::None)
179+
}
180+
TxInputWithAdditionalInfo::AccountCommand(nonce, cmd) => (
181+
TxInput::AccountCommand(nonce, cmd),
182+
SighashInputCommitment::None,
183+
),
184+
TxInputWithAdditionalInfo::OrderAccountCommand(cmd, info) => {
185+
let commitment = match &cmd {
186+
OrderAccountCommand::FillOrder(_, _) => {
187+
SighashInputCommitment::FillOrderAccountCommand {
188+
initially_asked: info.initially_asked,
189+
initially_given: info.initially_given,
190+
}
191+
}
192+
OrderAccountCommand::ConcludeOrder(_) => {
193+
SighashInputCommitment::ConcludeOrderAccountCommand {
194+
initially_asked: info.initially_asked,
195+
initially_given: info.initially_given,
196+
ask_balance: info.ask_balance,
197+
give_balance: info.give_balance,
198+
}
199+
}
200+
OrderAccountCommand::FreezeOrder(_) => SighashInputCommitment::None,
201+
};
202+
(TxInput::OrderAccountCommand(cmd), commitment)
203+
}
204+
}
205+
}
140206
}
141207

142208
#[derive(Encode, Decode)]

0 commit comments

Comments
 (0)