substrate-ibc icon indicating copy to clipboard operation
substrate-ibc copied to clipboard

Converting data structure between protobuf and substrate’s SCALE

Open livelybug opened this issue 3 years ago • 0 comments

Something tedious in engineering may occur when converting data structure between protobuf and substrate’s SCALE.

Here's an example, which converting ibc-rs' ClientState to substrate's ClientState.

  • Define substrate's ClientState: https://github.com/cdot-network/substrate-ibc/commit/aa0e1b60bd56408bba34e52e910a3730f0cdb330#diff-bf7b01306aff35bb8c429e9d0b60028c041e7e93ab3453a60ec009420eebd53cL1-L39

  • Serialize fields for substrate's ClientState, before writing it to storage: https://github.com/cdot-network/substrate-ibc/commit/aa0e1b60bd56408bba34e52e910a3730f0cdb330#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R489-R509

  • Corresponding deserialization is needed when reading substrate's ClientState.

livelybug avatar Dec 10 '20 14:12 livelybug