Skip to content

Commit

Permalink
Update parity scale dependencies (#687)
Browse files Browse the repository at this point in the history
* update scale

* taplo fmt
  • Loading branch information
haerdib authored Dec 7, 2023
1 parent 22f9f51 commit ff4e3d0
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 1,344 deletions.
54 changes: 42 additions & 12 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ frame-metadata = { version = "16.0", default-features = false, features = ["curr
hex = { version = "0.4.3", default-features = false }
log = { version = "0.4.14", default-features = false }
scale-bits = { version = "0.4.0", default-features = false, features = ["scale-info", "serde"] }
scale-decode = { version = "0.8.0", default-features = false, features = ["primitive-types", "derive"] }
scale-encode = { version = "0.4.0", default-features = false, features = ["bits", "primitive-types", "derive"] }
scale-decode = { version = "0.10.0", default-features = false, features = ["primitive-types", "derive"] }
scale-encode = { version = "0.5.0", default-features = false, features = ["bits", "primitive-types", "derive"] }
scale-info = { version = "2.0.1", features = ["derive", "decode", "bitvec"], default-features = false }
scale-value = { version = "0.13.0", default-features = false }
serde = { version = "1.0.136", features = ["derive"], default-features = false }
serde_json = { version = "1.0.79", default-features = false, features = ["alloc"] }

Expand Down
2 changes: 1 addition & 1 deletion node-api/src/events/event_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use crate::{
error::{DispatchError, Error},
metadata::{MetadataError, PalletMetadata},
scale_value::{Composite, TypeId},
Metadata, Phase, StaticEvent,
};
use alloc::{sync::Arc, vec::Vec};
use codec::Decode;
use log::*;
use scale_decode::DecodeAsFields;
use scale_value::{scale::TypeId, Composite};

/// The event details.
/// Based on subxt EventDetails.
Expand Down
39 changes: 9 additions & 30 deletions node-api/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ impl<Hash: Copy + Decode> Events<Hash> {
self.find::<Ev>().next().transpose()
}

/// Iterate through the events using metadata to dynamically decode and skip
/// them, and return the last event found which decodes to the provided `Ev` type.
pub fn find_last<Ev: StaticEvent>(&self) -> Result<Option<Ev>, Error> {
self.find::<Ev>().last().transpose()
}

/// Find an event that decodes to the type provided. Returns true if it was found.
pub fn has<Ev: StaticEvent>(&self) -> Result<bool, Error> {
Ok(self.find::<Ev>().next().transpose()?.is_some())
Expand All @@ -144,14 +150,14 @@ impl<Hash: Copy + Decode> Events<Hash> {
mod tests {
use super::*;
use crate::{
scale_value::Value,
test_utils::{
event_record, events, events_raw, metadata_with_version, SupportedMetadataVersions,
},
Phase,
};
use codec::Encode;
use scale_info::TypeInfo;
use scale_value::Value;
use sp_core::H256;
use test_case::test_case;

Expand All @@ -171,25 +177,7 @@ mod tests {

/// Compare some actual [`RawEventDetails`] with a hand-constructed
/// (probably) [`TestRawEventDetails`].
pub fn assert_raw_events_match(
// Just for convenience, pass in the metadata type constructed
// by the `metadata` function above to simplify caller code.
metadata: &Metadata,
actual: EventDetails<H256>,
expected: TestRawEventDetails,
) {
let types = &metadata.runtime_metadata().types;

// Make sure that the bytes handed back line up with the fields handed back;
// encode the fields back into bytes and they should be equal.
let actual_fields = actual.field_values().expect("can decode field values (1)");
let mut actual_bytes = vec![];
for field in actual_fields.into_values() {
crate::scale_value::encode_as_type(&field, field.context, types, &mut actual_bytes)
.expect("should be able to encode properly");
}
assert_eq!(actual_bytes, actual.field_bytes());

pub fn assert_raw_events_match(actual: EventDetails<H256>, expected: TestRawEventDetails) {
let actual_fields_no_context: Vec<_> = actual
.field_values()
.expect("can decode field values (2)")
Expand Down Expand Up @@ -228,7 +216,6 @@ mod tests {

let mut event_details = events.iter();
assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
phase: Phase::ApplyExtrinsic(123),
Expand Down Expand Up @@ -277,7 +264,6 @@ mod tests {
let mut event_details = events.iter();

assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
index: 0,
Expand All @@ -290,7 +276,6 @@ mod tests {
},
);
assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
index: 1,
Expand All @@ -303,7 +288,6 @@ mod tests {
},
);
assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
index: 2,
Expand Down Expand Up @@ -348,7 +332,6 @@ mod tests {

let mut events_iter = events.iter();
assert_raw_events_match(
&metadata,
events_iter.next().unwrap().unwrap(),
TestRawEventDetails {
index: 0,
Expand All @@ -361,7 +344,6 @@ mod tests {
},
);
assert_raw_events_match(
&metadata,
events_iter.next().unwrap().unwrap(),
TestRawEventDetails {
index: 1,
Expand Down Expand Up @@ -400,7 +382,6 @@ mod tests {
// Dynamically decode:
let mut event_details = events.iter();
assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
index: 0,
Expand Down Expand Up @@ -439,7 +420,6 @@ mod tests {
// Dynamically decode:
let mut event_details = events.iter();
assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
index: 0,
Expand All @@ -448,7 +428,7 @@ mod tests {
pallet_index: 0,
variant: "A".to_string(),
variant_index: 0,
fields: vec![Value::u128(1)],
fields: vec![Value::unnamed_composite(vec![Value::u128(1)])],
},
);
assert!(event_details.next().is_none());
Expand Down Expand Up @@ -482,7 +462,6 @@ mod tests {
// Dynamically decode:
let mut event_details = events.iter();
assert_raw_events_match(
&metadata,
event_details.next().unwrap().unwrap(),
TestRawEventDetails {
index: 0,
Expand Down
1 change: 0 additions & 1 deletion node-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub use scale_decode::DecodeAsType;
pub mod error;
pub mod events;
pub mod metadata;
pub mod scale_value;
pub mod storage;

#[cfg(any(feature = "mocks", test))]
Expand Down
Loading

0 comments on commit ff4e3d0

Please sign in to comment.