rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

How parse hex of raw transaction?

Open eatruffle opened this issue 3 years ago • 4 comments

Hi, Is possible to deserialize a hex of a raw transaction ? I checked the web3-rust's source code and did not find function where I can put hex of raw_transaction and as return will be the RawTransaction object.

Best regards,

eatruffle avatar Jan 17 '22 14:01 eatruffle

The closes we have is crate::api::accounts::Transaction, but currently it only implements RLP encoding and is not exposed (see code) . A decoding counterpart implementation would be required for this. Happy to accept a PR.

tomusdrw avatar Feb 02 '22 15:02 tomusdrw

Hi, thank you. Maybe it will be helpful

impl<'a> rlp::Decodable for NewSignedTransaction { fn decode(d: &rlp::Rlp) -> Result<Self, rlp::DecoderError> {

    Ok(NewSignedTransaction {
        transaction: NewTransaction {
            chainId: d.val_at(0)?,//.map_err(|e| debug("nonce", e))?,
            nonce: d.val_at(1)?,//.map_err(|e| debug("nonce", e))?,
            maxPriorityFeePerGas: d.val_at(2)?,//.map_err(|e| debug("gas_price", e))?,
            maxFeePerGas: d.val_at(3)?,//.map_err(|e| debug("gas", e))?,
            gas_price: d.val_at(4)?,
            gas_limit: d.val_at(4)?,
            to: d.val_at(5)?,
            value: d.val_at(6)?,//.map_err(|e| debug("value", e))?,
            data: d.val_at::<Vec<u8>>(7)?.into(),//.map_err(|e| debug("data", e))?.into(),
        },
        v: Default::default(),//.map_err(|e| debug("v", e))?,
        r: Default::default(),//.map_err(|e| debug("r", e))?,
        s: Default::default(),//.map_err(|e| debug("s", e))?,
    })
}

}

pub struct NewTransaction { pub chainId: U256, pub nonce: U256, pub maxPriorityFeePerGas: U256, pub maxFeePerGas: U256, pub gas_price: U256, pub gas_limit: U256, pub to: Address, pub value: U256, pub data: Bytes, // pub accessList: Vec }

And in pleace of the NewTransaction object, sugested Transaction will be OK.

eatruffle avatar Mar 10 '22 09:03 eatruffle

Hi, if I put up a PR that includes this, how quickly can this get merged and released? Need it for prod asap or I need to switch to ethers

jakehemmerle avatar Feb 13 '23 20:02 jakehemmerle

@jakehemmerle I'd recommend switching to ethers, this package is barely maintained.

tomusdrw avatar Feb 16 '23 22:02 tomusdrw