Skip to content

Commit

Permalink
change ZkLinkTxType to c-style enum type (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
zksemi authored Jun 6, 2024
1 parent 527c332 commit 1a6973e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
12 changes: 7 additions & 5 deletions types/src/tx_type/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ pub use liquidation::Liquidation;
pub use prices::{ContractPrice, OraclePrices, SpotPriceInfo};
pub use update_global_var::{Parameter, UpdateGlobalVar};

use super::zklink_tx::ZkLinkTxType;

impl Contract {
pub const MSG_TYPE: u8 = 0xfe;
}

impl ContractMatching {
pub const TX_TYPE: u8 = 0x09;
pub const TX_TYPE: u8 = ZkLinkTxType::ContractMatching as u8;
}
impl Liquidation {
pub const TX_TYPE: u8 = 0x0a;
pub const TX_TYPE: u8 = ZkLinkTxType::Liquidation as u8;
}
impl AutoDeleveraging {
pub const TX_TYPE: u8 = 0x0b;
pub const TX_TYPE: u8 = ZkLinkTxType::AutoDeleveraging as u8;
}
impl UpdateGlobalVar {
pub const TX_TYPE: u8 = 0x0c;
pub const TX_TYPE: u8 = ZkLinkTxType::UpdateGlobalVar as u8;
}
impl Funding {
pub const TX_TYPE: u8 = 0x0d;
pub const TX_TYPE: u8 = ZkLinkTxType::Funding as u8;
}
15 changes: 8 additions & 7 deletions types/src/tx_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use zklink_sdk_signers::zklink_signer::error::ZkSignerError;
use zklink_sdk_signers::zklink_signer::pk_signer::{sha256_bytes, ZkLinkSigner};
use zklink_sdk_signers::zklink_signer::signature::ZkLinkSignature;
use zklink_sdk_signers::zklink_signer::PubKeyHash;
use zklink_tx::ZkLinkTxType;

pub mod validator;

Expand All @@ -34,25 +35,25 @@ pub mod withdraw;
pub mod zklink_tx;

impl Deposit {
pub const TX_TYPE: u8 = 0x01;
pub const TX_TYPE: u8 = ZkLinkTxType::Deposit as u8;
}
impl Withdraw {
pub const TX_TYPE: u8 = 0x03;
pub const TX_TYPE: u8 = ZkLinkTxType::Withdraw as u8;
}
impl Transfer {
pub const TX_TYPE: u8 = 0x04;
pub const TX_TYPE: u8 = ZkLinkTxType::Transfer as u8;
}
impl FullExit {
pub const TX_TYPE: u8 = 0x05;
pub const TX_TYPE: u8 = ZkLinkTxType::FullExit as u8;
}
impl ChangePubKey {
pub const TX_TYPE: u8 = 0x06;
pub const TX_TYPE: u8 = ZkLinkTxType::ChangePubKey as u8;
}
impl ForcedExit {
pub const TX_TYPE: u8 = 0x07;
pub const TX_TYPE: u8 = ZkLinkTxType::ForcedExit as u8;
}
impl OrderMatching {
pub const TX_TYPE: u8 = 0x08;
pub const TX_TYPE: u8 = ZkLinkTxType::OrderMatching as u8;
}

/// Construct the first part of the message that should be signed by Ethereum key.
Expand Down
24 changes: 12 additions & 12 deletions types/src/tx_type/zklink_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub enum ZkLinkTxType {
Deposit,
FullExit,
ChangePubKey,
Transfer,
Withdraw,
ForcedExit,
OrderMatching,
AutoDeleveraging,
ContractMatching,
Funding,
Liquidation,
UpdateGlobalVar,
Deposit = 0x01,
FullExit = 0x05,
ChangePubKey = 0x06,
Transfer = 0x04,
Withdraw = 0x03,
ForcedExit = 0x07,
OrderMatching = 0x08,
AutoDeleveraging = 0x0b,
ContractMatching = 0x09,
Funding = 0x0d,
Liquidation = 0x0a,
UpdateGlobalVar = 0x0c,
}

/// A set of L2 transaction supported by the zklink network.
Expand Down

0 comments on commit 1a6973e

Please sign in to comment.