Skip to content
This repository has been archived by the owner on Mar 20, 2020. It is now read-only.

Commit

Permalink
Doughnut integartion with substrate 2.0 changes
Browse files Browse the repository at this point in the history
Add doughnut to extrinsic signed extension payload
Add DelegatedOrigin variant to RawOrigin for delegated extrinsics
  • Loading branch information
jordy25519 committed Oct 16, 2019
1 parent 73104d3 commit 2adb838
Show file tree
Hide file tree
Showing 69 changed files with 1,635 additions and 206 deletions.
56 changes: 55 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ members = [
"core/utils/wasm-builder",
"core/utils/wasm-builder-runner",
"core/wasm-interface",
"prml/doughnut",
"srml/support",
"srml/support/procedural",
"srml/support/procedural/tools",
Expand Down
2 changes: 1 addition & 1 deletion core/sr-api-macros/tests/ui/declaring_old_block.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ warning: unused import: `sr_primitives::traits::Block as BlockT`
1 | use sr_primitives::traits::Block as BlockT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
= note: #[warn(unused_imports)] on by default
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ warning: unused import: `sr_primitives::traits::Block as BlockT`
1 | use sr_primitives::traits::Block as BlockT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
= note: #[warn(unused_imports)] on by default
2 changes: 2 additions & 0 deletions core/sr-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ log = { version = "0.4.8", optional = true }
paste = "0.1.6"
rand = { version = "0.7.2", optional = true }
impl-trait-for-tuples = "0.1.2"
doughnut = { package = "doughnut_rs", version = "0.2.0", git = "https://github.com/cennznet/doughnut-rs", default-features = false }

[dev-dependencies]
serde_json = "1.0.40"
Expand All @@ -36,4 +37,5 @@ std = [
"primitives/std",
"app-crypto/std",
"rand",
"doughnut/std",
]
29 changes: 18 additions & 11 deletions core/sr-primitives/src/generic/checked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
//! stage.
use crate::traits::{
self, Member, MaybeDisplay, SignedExtension, Dispatchable, ValidateUnsigned,
self, Dispatchable, DoughnutApi, MaybeDisplay, MaybeDoughnut, Member, SignedExtension, ValidateUnsigned,
};
use crate::weights::{GetDispatchInfo, DispatchInfo};
use crate::transaction_validity::TransactionValidity;
use crate::weights::{GetDispatchInfo, DispatchInfo};

/// Definition of something that the external world might want to say; its
/// existence implies that it has been checked and is good, particularly with
Expand All @@ -37,14 +37,15 @@ pub struct CheckedExtrinsic<AccountId, Call, Extra> {
pub function: Call,
}

impl<AccountId, Call, Extra, Origin> traits::Applyable
impl<AccountId, Call, Extra, Origin, Doughnut> traits::Applyable
for
CheckedExtrinsic<AccountId, Call, Extra>
where
AccountId: Member + MaybeDisplay,
AccountId: Member + MaybeDisplay + AsRef<[u8]>,
Call: Member + Dispatchable<Origin=Origin>,
Extra: SignedExtension<AccountId=AccountId, Call=Call>,
Origin: From<Option<AccountId>>,
Extra: SignedExtension<AccountId=AccountId, Call=Call> + MaybeDoughnut<Doughnut=Doughnut>,
Origin: From<(Option<AccountId>, Option<Doughnut>)>,
Doughnut: Member + DoughnutApi<PublicKey=AccountId>,
{
type AccountId = AccountId;
type Call = Call;
Expand All @@ -71,14 +72,20 @@ where
info: DispatchInfo,
len: usize,
) -> crate::ApplyResult {
let (maybe_who, pre) = if let Some((id, extra)) = self.signed {
let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?;
(Some(id), pre)
let (pre, res) = if let Some((id, extra)) = self.signed {
let pre = Extra::pre_dispatch(&extra, &id, &self.function, info, len)?;
if let Some(doughnut) = extra.doughnut() {
// A delegated transaction
(pre, self.function.dispatch(Origin::from((Some(doughnut.issuer()), Some(doughnut)))))
} else {
// An ordinary signed transaction
(pre, self.function.dispatch(Origin::from((Some(id), None))))
}
} else {
// An inherent unsiged transaction
let pre = Extra::pre_dispatch_unsigned(&self.function, info, len)?;
(None, pre)
(pre, self.function.dispatch(Origin::from((None, None))))
};
let res = self.function.dispatch(Origin::from(maybe_who));
Extra::post_dispatch(pre, info, len);
Ok(res.map_err(Into::into))
}
Expand Down
4 changes: 2 additions & 2 deletions core/sr-primitives/src/generic/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ where
Ok(match self.signature {
Some((signed, signature, extra)) => {
let signed = lookup.lookup(signed)?;
let raw_payload = SignedPayload::new(self.function, extra)?;
let raw_payload = SignedPayload::new(self.function, extra.clone())?;
if !raw_payload.using_encoded(|payload| {
signature.verify(payload, &signed)
signature.verify(&payload[..], &signed)
}) {
return Err(InvalidTransaction::BadProof.into())
}
Expand Down
3 changes: 3 additions & 0 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ pub use sr_arithmetic::{
/// Re-export 128 bit helpers from sr_arithmetic
pub use sr_arithmetic::helpers_128bit;

/// Re-export official v0 Doughnut type
pub use doughnut::v0::parity::DoughnutV0;

/// An abstraction over justification for a block's validity under a consensus algorithm.
///
/// Essentially a finality proof. The exact formulation will vary between consensus
Expand Down
Loading

0 comments on commit 2adb838

Please sign in to comment.