avalanchejs
avalanchejs copied to clipboard
Deserialize P Chain block
Detailed Description
Add the possibility to deserialize PVM block's bytes coming out of the IPC socket .
Context
I was working on my rust pet project and while working on the PChain deserialization (with bytes coming out of the IPC socket) I noticed that I could not use avalancheJs PVM Tx.fromBuffer() . It would always fail .
It is because avalanchejs only deserialize bytes of a transaction , but on the pchain the bytes coming out of the socket are composed like this :
- Bytes of a Block
- Bytes of a Tx
So someone trying to use avalanchejs with the bytes coming out of the socket would only see errors .
It was rather confusing for me at first because even in the documentation there are no mentions of the structure of a PVM Block ( Added few issues in the repo as well) , and I had to dig in avalanchego code in order to understand how to deserialize it .
Possible Implementation
Follow same approach as for the PVM Tx .
Your Environment
- Version used: 3.1.0
Am up to implement it if it's something you want to add in avalanchejs ;)
So someone trying to use avalanchejs with the bytes coming out of the socket would only see errors .
That's news to me. Happened after I left, I guess? I guess a simple block parser in the PlatformVM makes sense @cgcardona .
Let me look into this and get back to you.
If you want to have a look, I did an implementation in Rust here : https://github.com/tbrunain/avalanche-rs/blob/master/src/pvm/parser/block_parser.rs .
I'm waiting on the platform team to get back to me w/ the serialization spec of blocks/vertices. Will get back ASAP w/ a code snippet once I have that serialization spec.
Do I need to do the same for C-chain blocks ? Or is there a mean provided by this SDK ?