Merge remote-tracking branch 'origin/master' into dapps-accounts-rpc

This commit is contained in:
Gav Wood 2016-12-15 13:51:22 +01:00
commit 1ea521ea7d
No known key found for this signature in database
GPG Key ID: C49C1ACA1CC9B252
4 changed files with 55 additions and 3 deletions

View File

@ -19,8 +19,12 @@
},
"genesis": {
"seal": {
"generic": {
"rlp": "f88980b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f843b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
"tendermint": {
"round": "0x0",
"proposal": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"precommits": [
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
]
}
},
"difficulty": "0x20000",

View File

@ -44,6 +44,16 @@ pub struct AuthorityRound {
pub signature: H520,
}
/// Tendermint seal.
pub struct Tendermint {
/// Seal round.
pub round: usize,
/// Proposal seal signature.
pub proposal: H520,
/// Precommit seal signatures.
pub precommits: Vec<H520>,
}
impl Into<Generic> for AuthorityRound {
fn into(self) -> Generic {
let mut s = RlpStream::new_list(2);
@ -52,6 +62,14 @@ impl Into<Generic> for AuthorityRound {
}
}
impl Into<Generic> for Tendermint {
fn into(self) -> Generic {
let mut s = RlpStream::new_list(3);
s.append(&self.round).append(&self.proposal).append(&self.precommits);
Generic(s.out())
}
}
pub struct Generic(pub Vec<u8>);
/// Genesis seal type.
@ -60,6 +78,8 @@ pub enum Seal {
Ethereum(Ethereum),
/// AuthorityRound seal.
AuthorityRound(AuthorityRound),
/// Tendermint seal.
Tendermint(Tendermint),
/// Generic RLP seal.
Generic(Generic),
}
@ -75,6 +95,11 @@ impl From<ethjson::spec::Seal> for Seal {
step: ar.step.into(),
signature: ar.signature.into()
}),
ethjson::spec::Seal::Tendermint(tender) => Seal::Tendermint(Tendermint {
round: tender.round.into(),
proposal: tender.proposal.into(),
precommits: tender.precommits.into_iter().map(Into::into).collect()
}),
ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic(g.into())),
}
}
@ -86,6 +111,7 @@ impl Into<Generic> for Seal {
Seal::Generic(generic) => generic,
Seal::Ethereum(eth) => eth.into(),
Seal::AuthorityRound(ar) => ar.into(),
Seal::Tendermint(tender) => tender.into(),
}
}
}

View File

@ -34,7 +34,7 @@ pub use self::builtin::{Builtin, Pricing, Linear};
pub use self::genesis::Genesis;
pub use self::params::Params;
pub use self::spec::Spec;
pub use self::seal::{Seal, Ethereum, AuthorityRoundSeal};
pub use self::seal::{Seal, Ethereum, AuthorityRoundSeal, TendermintSeal};
pub use self::engine::Engine;
pub use self::state::State;
pub use self::ethash::{Ethash, EthashParams};

View File

@ -39,6 +39,17 @@ pub struct AuthorityRoundSeal {
pub signature: H520,
}
/// Tendermint seal.
#[derive(Debug, PartialEq, Deserialize)]
pub struct TendermintSeal {
/// Seal round.
pub round: Uint,
/// Proposal seal signature.
pub proposal: H520,
/// Proposal seal signature.
pub precommits: Vec<H520>,
}
/// Seal variants.
#[derive(Debug, PartialEq, Deserialize)]
pub enum Seal {
@ -48,6 +59,9 @@ pub enum Seal {
/// AuthorityRound seal.
#[serde(rename="authority_round")]
AuthorityRound(AuthorityRoundSeal),
/// Tendermint seal.
#[serde(rename="tendermint")]
Tendermint(TendermintSeal),
/// Generic seal.
#[serde(rename="generic")]
Generic(Bytes),
@ -72,6 +86,14 @@ mod tests {
"step": "0x0",
"signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
}
},{
"tendermint": {
"round": "0x0",
"proposal": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"precommits": [
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
]
}
}]"#;
let _deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();
// TODO: validate all fields