Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 61a5661

Browse files
committed
build.sh passes
1 parent aedc271 commit 61a5661

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

core/sr-primitives/src/traits.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,17 +737,19 @@ pub trait Checkable<Context>: Sized {
737737
pub trait BlindCheckable: Sized {
738738
/// Returned if `check` succeeds.
739739
type Checked;
740+
/// Returned if `check` failed.
741+
type Error;
740742

741743
/// Check self.
742-
fn check(self) -> Result<Self::Checked, &'static str>;
744+
fn check(self) -> Result<Self::Checked, Self::Error>;
743745
}
744746

745747
// Every `BlindCheckable` is also a `StaticCheckable` for arbitrary `Context`.
746748
impl<T: BlindCheckable, Context> Checkable<Context> for T {
747749
type Checked = <Self as BlindCheckable>::Checked;
748-
type Error = &'static str;
750+
type Error = <Self as BlindCheckable>::Error;
749751

750-
fn check(self, _c: &Context) -> Result<Self::Checked, &'static str> {
752+
fn check(self, _c: &Context) -> Result<Self::Checked, Self::Error> {
751753
BlindCheckable::check(self)
752754
}
753755
}

core/test-runtime/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use runtime_primitives::{
3737
ApplyResult,
3838
create_runtime_str,
3939
transaction_validity::TransactionValidity,
40+
Error,
4041
traits::{
4142
BlindCheckable, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT,
4243
GetNodeBlockType, GetRuntimeBlockType, Verify
@@ -117,18 +118,19 @@ impl serde::Serialize for Extrinsic {
117118

118119
impl BlindCheckable for Extrinsic {
119120
type Checked = Self;
121+
type Error = Error;
120122

121-
fn check(self) -> Result<Self, &'static str> {
123+
fn check(self) -> Result<Self, Error> {
122124
match self {
123125
Extrinsic::AuthoritiesChange(new_auth) => Ok(Extrinsic::AuthoritiesChange(new_auth)),
124126
Extrinsic::Transfer(transfer, signature) => {
125127
if runtime_primitives::verify_encoded_lazy(&signature, &transfer, &transfer.from) {
126128
Ok(Extrinsic::Transfer(transfer, signature))
127129
} else {
128-
Err(runtime_primitives::BAD_SIGNATURE)
130+
Err(Error::BadSignature)
129131
}
130132
},
131-
Extrinsic::IncludeData(_) => Err(runtime_primitives::BAD_SIGNATURE),
133+
Extrinsic::IncludeData(_) => Err(Error::BadSignature),
132134
}
133135
}
134136
}

core/test-runtime/src/system.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ fn execute_block_with_state_root_handler(
106106
// execute transactions
107107
block.extrinsics.iter().enumerate().for_each(|(i, e)| {
108108
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &(i as u32));
109-
execute_transaction_backend(e).unwrap_or_else(|_| panic!("Invalid transaction"));
109+
match execute_transaction_backend(e) {
110+
ApplyResult::Success => (),
111+
_ => panic!("Invalid transaction"),
112+
};
110113
storage::unhashed::kill(well_known_keys::EXTRINSIC_INDEX);
111114
});
112115

@@ -233,11 +236,13 @@ fn check_signature(utx: &Extrinsic) -> Result<(), ApplyError> {
233236
}
234237

235238
fn execute_transaction_backend(utx: &Extrinsic) -> ApplyResult {
236-
check_signature(utx)?;
237-
match utx {
238-
Extrinsic::Transfer(ref transfer, _) => execute_transfer_backend(transfer),
239-
Extrinsic::AuthoritiesChange(ref new_auth) => execute_new_authorities_backend(new_auth),
240-
Extrinsic::IncludeData(_) => ApplyResult::Success,
239+
match check_signature(utx) {
240+
Ok(_) => match utx {
241+
Extrinsic::Transfer(ref transfer, _) => execute_transfer_backend(transfer),
242+
Extrinsic::AuthoritiesChange(ref new_auth) => execute_new_authorities_backend(new_auth),
243+
Extrinsic::IncludeData(_) => ApplyResult::Success,
244+
},
245+
Err(err) => ApplyResult::ApplyError(err)
241246
}
242247
}
243248

@@ -246,7 +251,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyResult {
246251
let nonce_key = tx.from.to_keyed_vec(NONCE_OF);
247252
let expected_nonce: u64 = storage::hashed::get_or(&blake2_256, &nonce_key, 0);
248253
if !(tx.nonce == expected_nonce) {
249-
return Err(ApplyError::Stale)
254+
return ApplyResult::ApplyError(ApplyError::Stale)
250255
}
251256

252257
// increment nonce in storage
@@ -258,7 +263,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyResult {
258263

259264
// enact transfer
260265
if !(tx.amount <= from_balance) {
261-
return Err(ApplyError::CantPay)
266+
return ApplyResult::ApplyError(ApplyError::CantPay)
262267
}
263268
let to_balance_key = tx.to.to_keyed_vec(BALANCE_OF);
264269
let to_balance: u64 = storage::hashed::get_or(&blake2_256, &to_balance_key, 0);

node-template/runtime/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ impl system::Trait for Runtime {
126126
type Event = Event;
127127
/// The ubiquitous origin type.
128128
type Origin = Origin;
129+
/// The ubiquitous error type.
130+
type Error = Error;
129131
}
130132

131133
impl aura::Trait for Runtime {

0 commit comments

Comments
 (0)