alloy-rs / rlp

Fast implementation of Ethereum RLP serialization
Apache License 2.0
86 stars 17 forks source link

Porting from ethers_core RlpStream #13

Closed dospore closed 1 month ago

dospore commented 7 months ago

Hey, was looking to port some ethers_core RlpStream code to use Encode.

The struct uses some ethers_core primitives so I was looking for some guidance on how I could write a custom impl or modify the derive to work. A basic example of the struct im using.

pub struct ExecutionBlockHeader {
    // remaining items
    pub beneficiary: Address, // ethers Address which is more or less the same as Address from alloy_primitives
    // remaining items
}

The existing code uses an RlpStream from ethers_core. I am fairly close to getting the custom impl with something like

// encode individual elements
// get length of encoded buffer
// prepend Header

but the output is slightly off. I was trying to look through the derive macros but I'm fairly new to rust and thought I'd just ask as its something I could contribute to this project by writing a how to although I know you are recommending to just use the macros.

Was just asking if there are any extra steps that I might be missing which might be causing the output to differ.

It is feasible to change the ethers::Address to an alloy_primitive but this is a contribution to lighthouse and would require a lot more changes out of scope.

edit: Realised I can just do a new struct and impl From for NewStrcut and derive on the NewStruct