Decode transaction blob

The hex of the transaction is

0a20000000000000000000000000000000000000000000000000000000000000000010a38f1028904e38f0e6b7e9051af4010abf014c49425241564d0a010007014a000000060000000350000000060000000c56000000050000000d5b00000004000000055f0000003300000004920000002000000007b20000000d000000000000010002000300010400020002040203020402063c53454c463e0c4c696272614163636f756e74094c69627261436f696e046d61696e0f6d696e745f746f5f6164647265737300000000000000000000000000000000000000000000000000000000000000000001020004000c000c01110102122408011220a09b14ddb32fcfa195d71a3360227c52e81c29331da7abae9b3fc5e8173737bf120a1208c0cd95d4e8000000

This is for version number 267361.

https://libexplorer.com/version/267361

Where can I get the schema to be able to decode the transaction bytes?

1 Like

I’m assuming you are referring to the raw_txn_bytes field of a SignedTransaction? This is a representation of the proto serialized bytes of a RawTransaction object, so you need to use deserialize the proto bytes into a RawTransaction object

2 Likes

Yes that is correct. I will look into the RawTransaction object.

I am wondering the design decision for using raw bytes. It makes developing a lot more more difficult for consumers of the API. It also took me a while to deserialize AccountStateBlob to get something as simple as the account balance.

It’s actually something that we will possibly be changing soon. The reasoning for doing it this way is because the wallet needs to sign the transactions. Since proto isn’t canonical, the server cannot know the exact format that the client signed, so it needs the raw bytes to verify the signatures

I found an easy way to decode the transaction blob.
Create a new RawTransaction protobuf message object.
Deserialize using the helper from the protobuf Message subclass.

In PHP it’s ->mergeFromString($bytes). This function is named differently in different languages. In javascipt protobuf library it is .deserializeBinary()

@kph any idea to which codec are you going to switch? we use protobuf as well at IOV so far:

and yes protobuf is not canonical…

It’s likely that we will use the same canonical serialization that we use during consensus

could you pin point to the code?
What kind of serialization is it?
thank you @kph!

I’ll connect you with the people who are actively maintaining it and can give you better details

1 Like

Hi @antoineherzog,
About you question:
CanonicalSerialize for AccountResource

.encode_struct(&self.authentication_key)?
.encode_u64(self.balance)?
.encode_bool(self.delegated_withdrawal_capability)?
.encode_u64(self.received_events_count)?
.encode_u64(self.sent_events_count)?
.encode_u64(self.sequence_number)?;

link: