chain_getBlock extrinsics encoding (#1024)

* deserialize without decoding

* change decoding approach

* fix tests

* decode without allocating

* strip compact prefix

* cargo fmt

* nit adjustment
This commit is contained in:
Tadeo Hepperle
2023-07-13 13:34:58 +02:00
committed by GitHub
parent 9a8fc33f2f
commit cd310b9877
4 changed files with 36 additions and 38 deletions
+9 -1
View File
@@ -11,7 +11,7 @@ mod multi_signature;
mod static_type;
mod wrapper_opaque;
use codec::{Decode, Encode};
use codec::{Compact, Decode, Encode};
use derivative::Derivative;
pub use account_id::AccountId32;
@@ -35,6 +35,14 @@ impl codec::Encode for Encoded {
}
}
/// Decodes a compact encoded value from the beginning of the provided bytes,
/// returning the value and any remaining bytes.
pub(crate) fn strip_compact_prefix(bytes: &[u8]) -> Result<(u64, &[u8]), codec::Error> {
let cursor = &mut &*bytes;
let val = <Compact<u64>>::decode(cursor)?;
Ok((val.0, *cursor))
}
/// A version of [`std::marker::PhantomData`] that is also Send and Sync (which is fine
/// because regardless of the generic param, it is always possible to Send + Sync this
/// 0 size type).