Skip to content

Commit

Permalink
use visitor of decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
haerdib committed Jun 16, 2023
1 parent cdc946f commit bc6caf5
Show file tree
Hide file tree
Showing 10 changed files with 770 additions and 963 deletions.
523 changes: 0 additions & 523 deletions node-api/src/decoder/decode.rs

This file was deleted.

137 changes: 0 additions & 137 deletions node-api/src/decoder/mod.rs

This file was deleted.

4 changes: 1 addition & 3 deletions node-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use scale_info::TypeDef;

// Re-expose the errors we use from other crates here:
pub use crate::{
decoder::{DecodeError, EncodeError},
metadata::{InvalidMetadataError, MetadataError},
scale_value::DecodeError,
};
pub use sp_core::crypto::SecretStringError;
pub use sp_runtime::transaction_validity::TransactionValidityError;
Expand All @@ -55,8 +55,6 @@ pub enum Error {
Runtime(DispatchError),
/// Error decoding to a [`crate::dynamic::Value`].
DecodeValue(DecodeError),
/// Error encoding from a [`crate::dynamic::Value`].
EncodeValue(EncodeError<()>),
/// Transaction progress error.
Transaction(TransactionError),
/// Block related error.
Expand Down
18 changes: 9 additions & 9 deletions node-api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

use crate::{
alloc::{string::ToString, sync::Arc, vec, vec::Vec},
decoder::{decode_as_type, Composite, TypeId},
error::{DispatchError, Error},
metadata::EventMetadata,
scale_value::{decode_as_type, Composite, TypeId},
Metadata, Phase, StaticEvent,
};
use codec::{Compact, Decode, Error as CodecError};
Expand Down Expand Up @@ -329,7 +329,7 @@ impl EventDetails {
mod tests {
use super::*;
use crate::{
decoder::Value,
scale_value::Value,
test_utils::{event_record, events, events_raw, metadata},
};
use codec::Encode;
Expand Down Expand Up @@ -365,7 +365,7 @@ mod tests {
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::decoder::encode_as_type(field.clone(), field.context, types, &mut actual_bytes)
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());
Expand Down Expand Up @@ -417,7 +417,7 @@ mod tests {
variant: "A".to_string(),
variant_index: 0,
fields: vec![
Value::uint(1u8),
Value::u128(1u128),
Value::bool(true),
Value::unnamed_composite(vec![Value::string("Hi")]),
],
Expand Down Expand Up @@ -464,7 +464,7 @@ mod tests {
pallet_index: 0,
variant: "A".to_string(),
variant_index: 0,
fields: vec![Value::uint(1u8)],
fields: vec![Value::u128(1u128)],
},
);
assert_raw_events_match(
Expand All @@ -490,7 +490,7 @@ mod tests {
pallet_index: 0,
variant: "A".to_string(),
variant_index: 0,
fields: vec![Value::uint(234u16)],
fields: vec![Value::u128(234u128)],
},
);
assert!(event_details.next().is_none());
Expand Down Expand Up @@ -534,7 +534,7 @@ mod tests {
pallet_index: 0,
variant: "A".to_string(),
variant_index: 0,
fields: vec![Value::uint(1u8)],
fields: vec![Value::u128(1u128)],
},
);
assert_raw_events_match(
Expand Down Expand Up @@ -585,7 +585,7 @@ mod tests {
pallet_index: 0,
variant: "A".to_string(),
variant_index: 0,
fields: vec![Value::uint(1u8)],
fields: vec![Value::u128(1u128)],
},
);
assert!(event_details.next().is_none());
Expand Down Expand Up @@ -623,7 +623,7 @@ mod tests {
pallet_index: 0,
variant: "A".to_string(),
variant_index: 0,
fields: vec![Value::unnamed_composite(vec![Value::uint(1u8)])],
fields: vec![Value::unnamed_composite(vec![Value::u128(1u128)])],
},
);
assert!(event_details.next().is_none());
Expand Down
4 changes: 2 additions & 2 deletions node-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ extern crate alloc;
use alloc::{borrow::ToOwned, vec::Vec};
use codec::{Decode, Encode};

pub use decoder::{DecodeError, EncodeError};
pub use events::{EventDetails, Events};
pub use metadata::{Metadata, MetadataError};
pub use scale_decode::DecodeError;

pub mod decoder;
pub mod error;
pub mod events;
pub mod metadata;
pub mod scale_decode;
pub mod scale_value;
pub mod storage;

#[cfg(any(feature = "mocks", test))]
Expand Down
File renamed without changes.
Loading

0 comments on commit bc6caf5

Please sign in to comment.