starkware-libs / blockifier

Blockifier is a Rust implementation for the transaction-executing component in the StarkNet sequencer, in charge of creating state diffs and blocks.
Apache License 2.0
169 stars 107 forks source link

add common getters for all tx types #1703

Open tdelabro opened 7 months ago

tdelabro commented 7 months ago

https://github.com/keep-starknet-strange/madara/blob/main/crates/primitives/transactions/src/getters.rs#L51

In madara we added a set of common getters for all our tx types. You should do that for the one defined in blockifier too. It would avoid lib users having to write this type of bad boilerplate code all the time:

            let sender_address = match &transaction.tx {
                starknet_api::transaction::InvokeTransaction::V0(tx) => tx.contract_address,
                starknet_api::transaction::InvokeTransaction::V1(tx) => tx.sender_address,
                starknet_api::transaction::InvokeTransaction::V3(tx) => tx.sender_address,
            };

This should be a trait.

raizo07 commented 7 months ago

Hello, can this task be assigned to me?

tdelabro commented 7 months ago

@raizo07 I would love it if you could implement it, sadly I'm not the manager of this repo. @noaov1 is more likely to give you the green light

tdelabro commented 7 months ago

also I had to create those methods:

pub fn get_transaction_hash(tx: &Transaction) -> &TransactionHash {
    match tx {
        Transaction::AccountTransaction(tx) => get_account_transaction_hash(tx),
        Transaction::L1HandlerTransaction(tx) => &tx.tx_hash,
    }
}

pub fn get_account_transaction_hash(tx: &AccountTransaction) -> &TransactionHash {
    match tx {
        AccountTransaction::Invoke(tx) => &tx.tx_hash,
        AccountTransaction::Declare(tx) => &tx.tx_hash,
        AccountTransaction::DeployAccount(tx) => &tx.tx_hash,
    }
}

Just add some getters please :)