forked from paritytech/desub
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix V1 feature flags (paritytech#117)
* add toy example and fix some feature flags * fmt * bn => block_number * add a couple of comments
- Loading branch information
Showing
12 changed files
with
1,357 additions
and
91 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"bin/tx-decoder", | ||
"bin/archive-demo", | ||
"bin/v14-test", | ||
"desub", | ||
"desub-current", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "archive-demo" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
description.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
clap = { workspace = true, features = ["derive"] } | ||
desub = { workspace = true, features = ["polkadot-js"] } | ||
anyhow = { workspace = true } | ||
hex = { workspace = true } | ||
subxt = "0.32.1" | ||
tokio = { version = "1.33.0", features = ["full"] } | ||
pretty_env_logger = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use desub::{Chain, Decoder}; | ||
use subxt::{ | ||
backend::{ | ||
legacy::{ | ||
rpc_methods::{Bytes, NumberOrHex}, | ||
LegacyRpcMethods, | ||
}, | ||
rpc::{rpc_params, RpcClient}, | ||
}, | ||
config::PolkadotConfig, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
pretty_env_logger::init(); | ||
|
||
// Connect to a node with an RPC client: | ||
let rpc_client = RpcClient::from_url("wss://rpc.polkadot.io").await?; | ||
let methods = LegacyRpcMethods::<PolkadotConfig>::new(rpc_client.clone()); | ||
|
||
let mut block_number = 1; | ||
let mut decoder = Decoder::new(Chain::Polkadot); | ||
|
||
loop { | ||
// Fetch the extrinsics and spec version, which we need for decoding: | ||
let hash = methods.chain_get_block_hash(Some(NumberOrHex::Number(block_number))).await?.unwrap(); | ||
let runtime_version = methods.state_get_runtime_version(Some(hash)).await?; | ||
let spec_version = runtime_version.spec_version; | ||
let block = methods.chain_get_block(Some(hash)).await?.unwrap(); | ||
|
||
// Mangle the extrinsics into the correct byte format from the RPC call which returns a Vec: | ||
let ext_bytes = make_extrinsic_bytes(block.block.extrinsics); | ||
|
||
if !decoder.has_version(spec_version) { | ||
// download the relevant metadata bytes, since the decoder doesn't have it yet. | ||
println!("# Downloading metadata for spec version {spec_version}"); | ||
let md: Bytes = rpc_client.request("state_getMetadata", rpc_params![hash]).await?; | ||
decoder.register_version(spec_version, &md.0)?; | ||
} | ||
|
||
println!("# Decoding exts for block {block_number}"); | ||
let decoded_exts = decoder.decode_extrinsics(spec_version, &ext_bytes)?; | ||
|
||
println!("{decoded_exts}"); | ||
|
||
// We'll decode every 10_000th block, just to make sure we span some spec versions. | ||
block_number += 10_000; | ||
} | ||
} | ||
|
||
// A hack because we get the exts back as a vec of bytes and | ||
// desub wants the whole block body as bytes. | ||
fn make_extrinsic_bytes(exts: Vec<Bytes>) -> Vec<u8> { | ||
use subxt::ext::codec::Encode; | ||
use subxt::utils::Encoded; | ||
// The inner `Bytes` are already encoded and contain the compact length etc, | ||
// so don't encode them again by wrapping them in `Encoded`. | ||
let e: Vec<Encoded> = exts.into_iter().map(|ext| Encoded(ext.0)).collect(); | ||
e.encode() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters