Market Account Info Deserialization #115
-
I'm writing a user-friendly .NET wrapper for the MonacoProtocol- I have extensive experience developing for other sports betting APIs but I am new to web3. I've used the Solana JSON RPC API to get the data from one of your on-chain accounts for a particular market and received this response:
I am assuming what I am after is somewhere in that Base64 encoded string, which I have converted to bytes? But I am not sure where to go from there. I am assuming the protocol is based on the Anchor framework, which from what I have read, uses Borsh serialization. Also, according to this page in the Anchor docs "The first 8 bytes are reserved for a unique account discriminator, self-described by the first 8 bytes of the SHA256 of the account’s Rust ident.". I am not sure if this is relevant in this case. Regardless, what do I do for the rest of the data? Is there some kind of schema? If so, what order are the properties in? Am I correct in saying I need to know the order for Borsh serialization? For reference, the corresponding type in your TypeScript client looks like this (again, I'm assuming data to populate these fields is somewhere in that Base64 encoded string):
I may be doing this completely wrong, please forgive my ignorance- I'm very new to web3 development. Thank you for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey. You are definitely on the right track.
Yes. The Rust code of the account is the schema. It dictates types, sizes and order in which everything is serialised/deserialised. Here is the one for the market. You can find others in the same folder. I would probably ignore TypeScript client (or treat it as a guide only) as source of truth as not all types map 1-1 with Rust. Here's some useful code for the data type sizes that we use to initiate accounts.
You can use those 8bytes to validate if you are deserilising the right thing. I could imagine a smart wrapper in .NET that returns type depending on that signature. However considering that you usually know the type of the account you are dealing with anyway (as public keys of accounts owned by the program are quite intentional) most time you will be simply chopping it off. Hope that helps. |
Beta Was this translation helpful? Give feedback.
Hey. You are definitely on the right track.
Yes. The Rust code of the account is the schema. It dictates types, sizes and order in which everything is serialised/deserialised. Here is the one for the market. You can find others in the same folder. I would probably ignore TypeScript client (or treat it as a guide only) as source of truth as not all types map 1-1 with Rust. Here's some useful code for the data type sizes that we use to initiate accounts.