Skip to content

Commit 6301aa6

Browse files
authored
Merge pull request #1921 from mintlayer/trezor-common-orders-v1
add orders v1 to trezor common
2 parents 5e8c20a + 0baa1ab commit 6301aa6

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

trezor-common/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,24 @@ pub enum AccountCommand {
355355
ChangeTokenMetadataUri(TokenId, parity_scale_codec::alloc::vec::Vec<u8>),
356356
}
357357

358+
#[derive(Encode, EnumDiscriminants)]
359+
#[strum_discriminants(name(OrderCommandTag), derive(EnumIter, FromPrimitive))]
360+
pub enum OrderAccountCommand {
361+
// Satisfy an order completely or partially.
362+
// Second parameter is an amount provided to fill an order which corresponds to order's ask currency.
363+
#[codec(index = 0)]
364+
FillOrder(OrderId, Amount, Destination),
365+
// Freeze an order which effectively forbids any fill operations.
366+
// Frozen order can only be concluded.
367+
// Only the address specified as `conclude_key` can authorize this command.
368+
#[codec(index = 1)]
369+
FreezeOrder(OrderId),
370+
// Close an order and withdraw all remaining funds from both give and ask balances.
371+
// Only the address specified as `conclude_key` can authorize this command.
372+
#[codec(index = 2)]
373+
ConcludeOrder(OrderId),
374+
}
375+
358376
#[derive(Encode)]
359377
pub enum TxInput {
360378
#[codec(index = 0)]
@@ -363,6 +381,8 @@ pub enum TxInput {
363381
Account(AccountOutPoint),
364382
#[codec(index = 2)]
365383
AccountCommand(#[codec(compact)] u64, AccountCommand),
384+
#[codec(index = 3)]
385+
OrderAccountCommand(OrderAccountCommand),
366386
}
367387

368388
#[cfg(test)]

trezor-common/src/tests/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ impl From<chain::AccountCommand> for crate::AccountCommand {
138138
}
139139
}
140140

141+
impl From<chain::OrderAccountCommand> for crate::OrderAccountCommand {
142+
fn from(value: chain::OrderAccountCommand) -> Self {
143+
match value {
144+
chain::OrderAccountCommand::FillOrder(order_id, amount, destination) => {
145+
Self::FillOrder(order_id.to_hash().into(), amount.into(), destination.into())
146+
}
147+
chain::OrderAccountCommand::FreezeOrder(order_id) => {
148+
Self::FreezeOrder(order_id.to_hash().into())
149+
}
150+
chain::OrderAccountCommand::ConcludeOrder(order_id) => {
151+
Self::ConcludeOrder(order_id.to_hash().into())
152+
}
153+
}
154+
}
155+
}
156+
141157
impl From<chain::TxInput> for crate::TxInput {
142158
fn from(value: chain::TxInput) -> Self {
143159
match value {
@@ -146,10 +162,8 @@ impl From<chain::TxInput> for crate::TxInput {
146162
chain::TxInput::AccountCommand(nonce, command) => {
147163
Self::AccountCommand(nonce.value(), command.into())
148164
}
149-
chain::TxInput::OrderAccountCommand(_) => {
150-
//TODO: support OrdersVersion::V1
151-
// https://github.com/mintlayer/mintlayer-core/issues/1902
152-
unimplemented!();
165+
chain::TxInput::OrderAccountCommand(command) => {
166+
Self::OrderAccountCommand(command.into())
153167
}
154168
}
155169
}

0 commit comments

Comments
 (0)