Skip to content

Refactor duplication in get_account, get_receipt, get_transaction, get_header #4

@jialinli98

Description

@jialinli98
pub fn get_account(chain_id: u32, block_no: u64, address: Address) -> AccountWithinBlock {
    // Safety: verification done separately
    let (account, state_proof) =
        unsafe { get_account_unconstrained_M(chain_id, block_no, address) };
    let header = get_header(chain_id, block_no);
    verify_account(address, account, state_proof, header.state_root);
    AccountWithinBlock { account, block_hash: header.hash }
}

pub fn get_transaction<let MAX_DATA_LEN: u32>(
    chain_id: u32,
    block_number: u64,
    tx_idx: Field,
) -> TransactionWithinBlock<MAX_DATA_LEN> {
    let (tx_type, transaction, proof_input) =
        unsafe { get_transaction_unconstrained_M(chain_id, block_number, tx_idx) };
    let header = get_header(chain_id, block_number);
    verify_tx(
        tx_idx,
        tx_type,
        transaction,
        proof_input,
        header.transactions_root,
    );

    TransactionWithinBlock { transaction, block_hash: header.hash }
}

These functions all share the same pattern: oracle call, deserialization, get_header, erification, return *WithinBlock. Maybe we can extract the common pattern into a macro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions