fix block header encoding
@@ -4,6 +4,7 @@ use alloc::string::String;
use alloc::vec::Vec;
use scale::{Decode, Encode};
use serde::Deserialize;
+use sp_core_hashing::blake2_256;
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
@@ -15,7 +16,6 @@ pub struct BlockHeader<'a> {
}
#[derive(Deserialize, Encode, Clone, Debug, PartialEq)]
-// #[serde(bound(deserialize = "Digest: Deserialize<'de>"))]
pub struct BlockHeaderResult<'a> {
#[serde(alias = "parentHash")]
pub(crate) parent_hash: &'a str,
@@ -31,12 +31,19 @@ pub struct BlockHeaderResult<'a> {
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct BlockHeaderOk {
pub(crate) parent_hash: [u8; 32],
+ #[codec(compact)]
pub(crate) number: u32,
pub(crate) state_root: [u8; 32],
pub(crate) extrinsics_root: [u8; 32],
pub(crate) digest: Digest,
}
+impl BlockHeaderOk {
+ pub fn hash(&self) -> [u8; 32] {
+ blake2_256(&self.encode())
+ }
+}
+
#[derive(Deserialize, Encode, Clone, Debug, PartialEq)]
pub struct NextNonce<'a> {
jsonrpc: &'a str,
