Skip to content

Commit

Permalink
Update dependencies and get things compiling/passing CI again. (parit…
Browse files Browse the repository at this point in the history
…ytech#115)

* update deps and cargo check --all-targets working

* Get compiling with scale-value and scale-decode

* fix desub-current tests

* clippy and fmt

* workspace-ify all library deps. clap instead of structopt

* fmt

* doc
  • Loading branch information
jsdw committed Nov 1, 2023
1 parent 276c57e commit 6594d16
Show file tree
Hide file tree
Showing 41 changed files with 2,802 additions and 4,818 deletions.
3,961 changes: 2,463 additions & 1,498 deletions Cargo.lock

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,50 @@ members = [
"desub-common",
"integration-tests",
]

resolver = "2"

[workspace.package]
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0"
repository = "https://github.com/paritytech/desub"
homepage = "https://github.com/paritytech/desub"
description = "Decode Substrate with Backwards-Compatible Metadata"
rust-version = "1.70.0"
edition = "2021"

[workspace.dependencies]
anyhow = "1"
parity-scale-codec = "3.6.5"
scale-info = "2.10.0"
scale-value = "0.12.0"
scale-decode = "0.9"
frame-metadata = "16"
bitvec = "1"
serde = "1"
serde_json = "1"
derive_more = "0.99"
thiserror = "1"
hex = "0.4"
log = "0.4"
pretty_env_logger = "0.4"
paste = "1.0.3"
dyn-clone = "1.0"
onig = { version = "6", default-features = false }
phf = "0.11"
syn = "2"
clap = "4.4.7"

sp-core = "24.0.0"
sp-runtime = "27.0.0"
sp-version = "25.0.0"
sp-keyring = "27.0.0"
pallet-balances = "24.0.0"
frame-system = "24.0.0"

desub = { version = "0.1.0", default-features = false, path = "./desub" }
desub-common = { version = "0.1.0", default-features = false, path = "./desub-common" }
desub-current = { version = "0.1.0", default-features = false, path = "./desub-current" }
desub-json-resolver = { version = "0.1.0", default-features = false, path = "./desub-json-resolver" }
desub-legacy = { version = "0.1.0", default-features = false, path = "./desub-legacy" }
24 changes: 16 additions & 8 deletions bin/tx-decoder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
[package]
name = "tx-decoder"
version = "0.1.0"
edition = "2021"
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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
desub = { path = "../../desub", features = [ "polkadot-js" ] }
desub = { workspace = true, features = [ "polkadot-js" ] }
anyhow = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
log = { workspace = true }

# These are only used here, so aren't part of the workspace deps (this binary might go away):
async-std = { version = "1.10.0", features = [ "attributes" ] }
async-stream = "0.3.2"
sqlx = { version = "0.5", features = [ "runtime-async-std-rustls", "postgres", "offline" ]}
anyhow = "1.0.43"
futures = "0.3.17"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
log = "0.4.14"
argh = "0.1.6"
fern = {version = "0.6.0", features = [ "colored" ] }
fern = { version = "0.6.0", features = [ "colored" ] }
colored = "2.0.0"
indicatif = { version = "0.16.2", features = [ "rayon" ] }
rayon = "1.5.1"
Expand Down
11 changes: 5 additions & 6 deletions bin/tx-decoder/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ impl<'a> AppState<'a> {
let upgrade_block = get_upgrade_block(&self.app.network, version.try_into()?);
let mut len = 0;
let mut error_count = 0;
let decoder = self.decoder.read();
while let Some(Ok(block)) = blocks.next().await {
let version = if upgrade_block == Some(block.block_num.try_into()?) && upgrade_block != Some(0) {
previous.expect("Upgrade block must have previous version; qed")
} else {
version
};
let decoder = self.decoder.read();
if Self::decode(&decoder, block, version.try_into()?, errors).is_err() {
error_count += 1;
}
Expand Down Expand Up @@ -142,16 +142,15 @@ impl<'a> AppState<'a> {
/// returns the previous spec version.
async fn register_metadata(&self, conn: &mut PgConnection, version: SpecVersion) -> Result<Option<u32>, Error> {
let (past, present) = past_and_present_version(conn, version.try_into()?).await?;
let mut decoder = self.decoder.write();
if !decoder.has_version(&present) {
if !self.decoder.read().has_version(&present) {
let meta = metadata(conn, present.try_into()?).await?;
decoder.register_version(present, &meta)?;
self.decoder.write().register_version(present, &meta)?;
}

if let Some(p) = past {
if !decoder.has_version(&p) {
if !self.decoder.read().has_version(&p) {
let meta = metadata(conn, p.try_into()?).await?;
decoder.register_version(p, &meta)?;
self.decoder.write().register_version(p, &meta)?;
}
}
Ok(past)
Expand Down
20 changes: 13 additions & 7 deletions bin/v14-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[package]
name = "v14-test"
version = "0.1.0"
edition = "2021"
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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
structopt = "0.3.23"
desub-current = { path = "../../desub-current" }
anyhow = "1.0.44"
hex = "0.4.3"
pretty_env_logger = "0.4.0"
clap = { workspace = true, features = ["derive"] }
desub-current = { workspace = true }
anyhow = { workspace = true }
hex = { workspace = true }
pretty_env_logger = { workspace = true }
7 changes: 3 additions & 4 deletions bin/v14-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use clap::Parser;
use desub_current::{decoder, Metadata};
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Opts {
/// SCALE encoded V14 metadata blob
#[structopt(parse(from_os_str))]
metadata: PathBuf,
/// Extrinsic hash in the form 0x1a2b3c
extrinsic: String,
}

fn main() -> Result<(), anyhow::Error> {
let opts = Opts::from_args();
let opts = Opts::parse();
pretty_env_logger::init();

let metadata_bytes = std::fs::read(opts.metadata)?;
Expand Down
22 changes: 11 additions & 11 deletions desub-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "desub-common"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "GPL-3.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/desub/"
description = "Decode Substrate with Backwards-Compatible Metadata"
readme = "README.md"
edition = "2021"
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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1", features = [ "derive" ] }
serde = { workspace = true, features = [ "derive" ] }

sp-runtime = "4.0.0"
sp-core = "4.0.0"
sp-runtime = { workspace = true }
sp-core = { workspace = true }
46 changes: 24 additions & 22 deletions desub-current/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
[package]
name = "desub-current"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "GPL-3.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/desub/"
description = "Decode Substrate with Backwards-Compatible Metadata"
edition = "2021"
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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
thiserror = "1.0.30"
frame-metadata = { version = "14.2", features = ["v14", "std", "scale-info"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
codec = { version = "2", package = "parity-scale-codec", features = ["bit-vec"] }
hex = "0.4.3"
derive_more = "0.99.16"
scale-info = { version = "1.0.0", features = ["bit-vec", "derive"] }
bitvec = { version = "0.20.2", features = ["serde", "alloc"] }
desub-common = { version = "0.1.0", path = "../desub-common" }
log = { workspace = true }
thiserror = { workspace = true }
frame-metadata = { workspace = true, features = ["std", "scale-info"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["preserve_order"] }
parity-scale-codec = { workspace = true, features = ["bit-vec"] }
hex = { workspace = true }
derive_more = { workspace = true }
scale-info = { workspace = true, features = ["bit-vec", "derive"] }
bitvec = { workspace = true, features = ["serde", "alloc"] }
desub-common = { workspace = true }
scale-value = { workspace = true }
scale-decode = { workspace = true }

sp-core = "4.0.0"
sp-runtime = "4.0.0"
sp-core = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
serde_json = "1"
sp_keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", tag = "monthly-2021-12" }
sp-keyring = { workspace = true }
19 changes: 10 additions & 9 deletions desub-current/src/decoder/decode_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct StorageEntries {
entry_by_hashed_name: HashMap<[u8; 16], usize>,
}

#[derive(thiserror::Error, Debug, Clone, PartialEq)]
#[derive(thiserror::Error, Debug)]
pub enum StorageDecodeError {
#[error("Not enough bytes in the input data to decode the storage prefix and name; got {0} bytes but expected 32")]
NotEnoughBytesForPrefixAndName(usize),
Expand Down Expand Up @@ -87,7 +87,7 @@ impl StorageDecoder {
Ok(StorageEntry {
prefix: prefix_str.into(),
name: name_str.into(),
ty: ty.into(),
ty: ty.id,
details: StorageEntryType::Plain,
})
}
Expand Down Expand Up @@ -155,7 +155,7 @@ impl StorageDecoder {
Ok(StorageEntry {
prefix: prefix_str.into(),
name: name_str.into(),
ty: value.into(),
ty: value.id,
details: StorageEntryType::Map(storage_keys),
})
}
Expand Down Expand Up @@ -190,16 +190,17 @@ impl StorageDecoder {
// See https://github.com/paritytech/subxt/blob/793c945fbd2de022f523c39a84ee02609ba423a9/codegen/src/api/storage.rs#L105
// for another example of this being handled in code.
fn storage_map_key_to_type_id_vec(metadata: &Metadata, key: &ScaleInfoTypeId) -> Vec<TypeId> {
let ty = match metadata.resolve(key) {
let ty_id = key.id;
let ty = match metadata.resolve(ty_id) {
Some(ty) => ty,
None => panic!("Metadata inconsistency: type #{} not found", key.id()),
None => panic!("Metadata inconsistency: type #{} not found", ty_id),
};

match ty.type_def() {
match &ty.type_def {
// Multiple keys:
scale_info::TypeDef::Tuple(vals) => vals.fields().iter().map(|f| TypeId::from_u32(f.id())).collect(),
scale_info::TypeDef::Tuple(vals) => vals.fields.iter().map(|f| f.id).collect(),
// Single key:
_ => vec![key.into()],
_ => vec![ty_id],
}
}

Expand Down Expand Up @@ -267,7 +268,7 @@ pub struct StorageMapKey<'b> {
pub hasher: StorageHasher,
}

impl<'m, 'b> StorageMapKey<'b> {
impl<'b> StorageMapKey<'b> {
pub fn into_owned(self) -> StorageMapKey<'static> {
StorageMapKey { bytes: Cow::Owned(self.bytes.into_owned()), ty: self.ty, hasher: self.hasher }
}
Expand Down
Loading

0 comments on commit 6594d16

Please sign in to comment.