Skip to content

Commit

Permalink
Get compiling with scale-value and scale-decode
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdw committed Oct 31, 2023
1 parent b1a31ec commit 26a6018
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 3,092 deletions.
162 changes: 156 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ edition = "2021"
[workspace.dependencies]
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"

Expand Down
2 changes: 2 additions & 0 deletions desub-current/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ derive_more = "0.99.16"
scale-info = { workspace = true, features = ["bit-vec", "derive"] }
bitvec = { workspace = true, features = ["serde", "alloc"] }
desub-common = { version = "0.1.0", path = "../desub-common" }
scale-value = { workspace = true }
scale-decode = { workspace = true }

sp-core = { workspace = true }
sp-runtime = { workspace = true }
Expand Down
15 changes: 8 additions & 7 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 {
// 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
Loading

0 comments on commit 26a6018

Please sign in to comment.