-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added grandpa types to rust sdk (#642)
- Loading branch information
1 parent
c69585e
commit ecb6136
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters