fluidex / rollup-state-manager

5 stars 6 forks source link

feat: decode tx #132

Closed 0xmountaintop closed 3 years ago

0xmountaintop commented 3 years ago

we can get encoded_tx from db.

when showing tx detail for https://github.com/Fluidex/rollup-state-manager/issues/105

we need to implement decode_tx

lispc commented 3 years ago

ref https://github.com/Fluidex/circuits/blob/master/tools/inspect_l2_block.ts

0xmountaintop commented 3 years ago

example API: http://18.180.248.43:8763/rollupapi/l2_block/1

we have 5 kinds of txs (depending on https://github.com/fluidex/rollup-state-manager/issues/201)

pub enum TxType {
    Nop,
    Deposit,
    Transfer,
    SpotTradeTx,
    Withdraw,
}

index meaning: https://github.com/fluidex/circuits/blob/master/test/codec/tx_data.ts

For Deposit we need to show

pub struct DepositTx {
    pub account_id: u32, // TODO: use u32 first, query from DB to get l2_pubkey in the future
    pub token_id: u32, // TODO: use u32 first, query from DB to get token_info in the future
    pub amount: AmountType,
}
in rust struct in tx_data.ts
account_id AccountID1 == AccountID2
token_id TokenID1 == TokenID2
amount amount

For Transfer we need to show

pub struct TransferTx {
    pub from: u32,
    pub to: u32,
    pub token_id: u32,
    pub amount: AmountType,
}
in rust struct in tx_data.ts
from AccountID1
to AccountID2
token_id TokenID1 == TokenID2
amount amount

For SpotTradeTx we need to show

// TODO: more detail: ask/bid
pub struct SpotTradeTx {
    pub order1_account_id: u32,
    pub order2_account_id: u32,
    pub token_id_1to2: u32, // TODO: better naming?
    pub token_id_2to1: u32, // TODO: better naming?
    pub amount_1to2: AmountType,
    pub amount_2to1: AmountType,
    // pub order1_id: u32,
    // pub order2_id: u32,
}
in rust struct in tx_data.ts
order1_account_id AccountID1
order2_account_id AccountID12
token_id_1to2 TokenID1
token_id_2to1 TokenID2
amount_1to2 amount
amount_2to1 amount2

For Withdraw we need to show

pub struct WithdrawTx {
    pub account_id: u32,
    pub token_id: u32,
    pub amount: AmountType,
    pub old_balance: Fr,
    // TODO: should we remove old_balance? or should we keep new_balance, and add old/new_balance in TransferTx?
}
in rust struct in tx_data.ts
account_id AccountID1
token_id TokenID1 == TokenID2
amount amount
old_balance Balance1

seems we need to store user account info & token info in the db.