Skip to content

Commit

Permalink
Added grandpa types to rust sdk (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox authored Aug 23, 2024
1 parent c69585e commit ecb6136
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions avail-rust/src/primitives/block/grandpa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use codec::{Codec, Decode};
use serde::{Serialize, Serializer};

use crate::avail::runtime_types::sp_consensus_grandpa::app::Public;

#[derive(Decode)]
pub struct AuthorityId(pub Public);

impl Serialize for AuthorityId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let raw = hex::encode(self.0 .0 .0);
serializer.serialize_str(&raw)
}
}

pub type AuthorityIndex = u64;
pub type AuthorityWeight = u64;
pub type AuthorityList = Vec<(AuthorityId, AuthorityWeight)>;

#[derive(Decode, Serialize)]
pub struct ScheduledChange<N> {
/// The new authorities after the change, along with their respective weights.
pub next_authorities: AuthorityList,
/// The number of blocks to delay.
pub delay: N,
}
/// An consensus log item for GRANDPA.
#[derive(Decode, Serialize)]
pub enum ConsensusLog<N: Codec> {
#[codec(index = 1)]
ScheduledChange(ScheduledChange<N>),
#[codec(index = 2)]
ForcedChange(N, ScheduledChange<N>),
#[codec(index = 3)]
OnDisabled(AuthorityIndex),
#[codec(index = 4)]
Pause(N),
#[codec(index = 5)]
Resume(N),
}
1 change: 1 addition & 0 deletions avail-rust/src/primitives/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod extrinsics;
pub mod extrinsics_params;
pub mod grandpa;
pub mod header;

pub use extrinsics::AppUncheckedExtrinsic;
Expand Down

0 comments on commit ecb6136

Please sign in to comment.