Skip to main content
added 72 characters in body
Source Link
Squirrel
  • 3.9k
  • 1
  • 8
  • 35

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically every runtime has a concrete Event type and that's what you're decoding into.

let event_bytes = hex::decode("0x1000000000000000585f8f090000000002000000010000000508ba6ef6480a2c4173bbbf0c27355c0e3c6d7a874a21cc2464e97d3fd5d92e245b1b5a7307000000000000000000000000000001000000080380eb30ca364f5c349d573b62cfadadba95af2e94f62fd8af4e15b90b971a4da633803b0648373051a1e2158c547112dcf63802d0d52b301a33dae8b9c6114e90f012b8516d57525358775a7476385956586574346e43424a396776646d4a6e3564364b34385a6a6148704763515a75676300000100000000001027000000000000000000").unwrap();
let event = <polkadot::Event as Decode>::decode(&mut event_bytes.as_slice()).unwrap();

and I have polkadot defined as:

#[subxt::subxt(runtime_metadata_path = "polkadot_metadata.scale")]
pub mod polkadot {}

(rather than pointing it at a metadata file you can download it by giving it a url #[subxt::subxt(runtime_metadata_path = "wss://kusama-rpc.polkadot.io:443")]. If you point that at your node's url then it should decode your event.)

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically every runtime has a concrete Event type and that's what you're decoding into.

let event_bytes = hex::decode("0x1000000000000000585f8f090000000002000000010000000508ba6ef6480a2c4173bbbf0c27355c0e3c6d7a874a21cc2464e97d3fd5d92e245b1b5a7307000000000000000000000000000001000000080380eb30ca364f5c349d573b62cfadadba95af2e94f62fd8af4e15b90b971a4da633803b0648373051a1e2158c547112dcf63802d0d52b301a33dae8b9c6114e90f012b8516d57525358775a7476385956586574346e43424a396776646d4a6e3564364b34385a6a6148704763515a75676300000100000000001027000000000000000000").unwrap();
let event = <polkadot::Event as Decode>::decode(&mut event_bytes.as_slice()).unwrap();

and I have polkadot defined as:

#[subxt::subxt(runtime_metadata_path = "polkadot_metadata.scale")]
pub mod polkadot {}

(rather than pointing it at a metadata file you can download it by giving it a url #[subxt::subxt(runtime_metadata_path = "wss://kusama-rpc.polkadot.io:443")])

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically every runtime has a concrete Event type and that's what you're decoding into.

let event_bytes = hex::decode("0x1000000000000000585f8f090000000002000000010000000508ba6ef6480a2c4173bbbf0c27355c0e3c6d7a874a21cc2464e97d3fd5d92e245b1b5a7307000000000000000000000000000001000000080380eb30ca364f5c349d573b62cfadadba95af2e94f62fd8af4e15b90b971a4da633803b0648373051a1e2158c547112dcf63802d0d52b301a33dae8b9c6114e90f012b8516d57525358775a7476385956586574346e43424a396776646d4a6e3564364b34385a6a6148704763515a75676300000100000000001027000000000000000000").unwrap();
let event = <polkadot::Event as Decode>::decode(&mut event_bytes.as_slice()).unwrap();

and I have polkadot defined as:

#[subxt::subxt(runtime_metadata_path = "polkadot_metadata.scale")]
pub mod polkadot {}

(rather than pointing it at a metadata file you can download it by giving it a url #[subxt::subxt(runtime_metadata_path = "wss://kusama-rpc.polkadot.io:443")]. If you point that at your node's url then it should decode your event.)

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.

added code snippits
Source Link
Squirrel
  • 3.9k
  • 1
  • 8
  • 35

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically every runtime has a concrete Event type and that's what you're decoding into.

let event_bytes = hex::decode("0x1000000000000000585f8f090000000002000000010000000508ba6ef6480a2c4173bbbf0c27355c0e3c6d7a874a21cc2464e97d3fd5d92e245b1b5a7307000000000000000000000000000001000000080380eb30ca364f5c349d573b62cfadadba95af2e94f62fd8af4e15b90b971a4da633803b0648373051a1e2158c547112dcf63802d0d52b301a33dae8b9c6114e90f012b8516d57525358775a7476385956586574346e43424a396776646d4a6e3564364b34385a6a6148704763515a75676300000100000000001027000000000000000000").unwrap();
let event = <polkadot::Event as Decode>::decode(&mut event_bytes.as_slice()).unwrap();

and I have polkadot defined as:

#[subxt::subxt(runtime_metadata_path = "polkadot_metadata.scale")]
pub mod polkadot {}

(rather than pointing it at a metadata file you can download it by giving it a url #[subxt::subxt(runtime_metadata_path = "wss://kusama-rpc.polkadot.io:443")])

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example.

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically every runtime has a concrete Event type and that's what you're decoding into.

let event_bytes = hex::decode("0x1000000000000000585f8f090000000002000000010000000508ba6ef6480a2c4173bbbf0c27355c0e3c6d7a874a21cc2464e97d3fd5d92e245b1b5a7307000000000000000000000000000001000000080380eb30ca364f5c349d573b62cfadadba95af2e94f62fd8af4e15b90b971a4da633803b0648373051a1e2158c547112dcf63802d0d52b301a33dae8b9c6114e90f012b8516d57525358775a7476385956586574346e43424a396776646d4a6e3564364b34385a6a6148704763515a75676300000100000000001027000000000000000000").unwrap();
let event = <polkadot::Event as Decode>::decode(&mut event_bytes.as_slice()).unwrap();

and I have polkadot defined as:

#[subxt::subxt(runtime_metadata_path = "polkadot_metadata.scale")]
pub mod polkadot {}

(rather than pointing it at a metadata file you can download it by giving it a url #[subxt::subxt(runtime_metadata_path = "wss://kusama-rpc.polkadot.io:443")])

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.

Source Link
Squirrel
  • 3.9k
  • 1
  • 8
  • 35

There's two ways of decoding events in rust: statically typed and dynamically typed.

Statically you can use subxt to decode events from this SCALE encoding - it's done here for example.

Dynamically the tooling needs generalising, but it is possible and has been done by cargo-contract.

If you need to interpret all events across all parachains then go dynamic. If you are focused on a few particular parachains then static typing is a lot safer and easier.