Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ use runtime_support::dispatch::Result;
use primitives::traits::{Zero, One, SimpleArithmetic, OnFinalise, MakePayment,
As, Lookup, Member, CheckedAdd, CheckedSub};
use address::Address as RawAddress;
use system::ensure_signed;

mod mock;

Expand Down Expand Up @@ -130,7 +129,7 @@ pub trait Trait: system::Trait {

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn transfer(origin, dest: RawAddress<T::AccountId, T::AccountIndex>, value: T::Balance) -> Result;
fn transfer(SystemOrigin(Signed(who)), dest: RawAddress<T::AccountId, T::AccountIndex>, value: T::Balance) -> Result;
fn set_balance(who: RawAddress<T::AccountId, T::AccountIndex>, free: T::Balance, reserved: T::Balance) -> Result;
}
}
Expand Down Expand Up @@ -279,8 +278,7 @@ impl<T: Trait> Module<T> {
// PUBLIC DISPATCH

/// Transfer some liquid free balance to another staker.
pub fn transfer(origin: T::Origin, dest: Address<T>, value: T::Balance) -> Result {
let transactor = ensure_signed(origin)?;
pub fn transfer(transactor: T::AccountId, dest: Address<T>, value: T::Balance) -> Result {

let dest = Self::lookup(dest)?;
let from_balance = Self::free_balance(&transactor);
Expand Down
34 changes: 17 additions & 17 deletions srml/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn indexing_lookup_should_work() {
fn default_indexing_on_new_accounts_should_work() {
with_externalities(&mut new_test_ext(10, true), || {
assert_eq!(Balances::lookup_index(4), None);
assert_ok!(Balances::transfer(Some(1).into(), 5.into(), 10));
assert_ok!(Balances::transfer(1, 5.into(), 10));
assert_eq!(Balances::lookup_index(4), Some(5));
});
}
Expand All @@ -57,7 +57,7 @@ fn default_indexing_on_new_accounts_should_work2() {
with_externalities(&mut new_test_ext2(10, true), || {
assert_eq!(Balances::lookup_index(4), None);
// account 1 has 256 * 10 = 2560, account 5 is not exist, ext_deposit is 10, value is 10
assert_ok!(Balances::transfer(Some(1).into(), 5.into(), 10));
assert_ok!(Balances::transfer(1, 5.into(), 10));
assert_eq!(Balances::lookup_index(4), Some(5));

assert_eq!(Balances::free_balance(&1), 256 * 10 - 10 - 50); // 10 is value, 50 is creation_free
Expand All @@ -69,7 +69,7 @@ fn default_indexing_on_new_accounts_should_not_work2() {
with_externalities(&mut new_test_ext2(10, true), || {
assert_eq!(Balances::lookup_index(4), None);
// account 1 has 256 * 10 = 2560, account 5 is not exist, ext_deposit is 10, value is 9, not satisfies for ext_deposit
assert_noop!(Balances::transfer(Some(1).into(), 5.into(), 9), "value too low to create account");
assert_noop!(Balances::transfer(1, 5.into(), 9), "value too low to create account");
assert_eq!(Balances::lookup_index(4), None); // account 5 should not exist
assert_eq!(Balances::free_balance(&1), 256 * 10);
});
Expand All @@ -82,7 +82,7 @@ fn dust_account_removal_should_work() {
assert_eq!(System::account_nonce(&2), 1);
assert_eq!(Balances::total_balance(&2), 256 * 20);

assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 10 + 1)); // index 1 (account 2) becomes zombie
assert_ok!(Balances::transfer(2, 5.into(), 256 * 10 + 1)); // index 1 (account 2) becomes zombie
assert_eq!(Balances::total_balance(&2), 0);
assert_eq!(Balances::total_balance(&5), 256 * 10 + 1);
assert_eq!(System::account_nonce(&2), 0);
Expand All @@ -95,7 +95,7 @@ fn dust_account_removal_should_work2() {
System::inc_account_nonce(&2);
assert_eq!(System::account_nonce(&2), 1);
assert_eq!(Balances::total_balance(&2), 256 * 20);
assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 10)); // index 1 (account 2) becomes zombie for 256*10 + 50(fee) < 256 * 10 (ext_deposit)
assert_ok!(Balances::transfer(2, 5.into(), 256 * 10)); // index 1 (account 2) becomes zombie for 256*10 + 50(fee) < 256 * 10 (ext_deposit)
assert_eq!(Balances::total_balance(&2), 0);
assert_eq!(Balances::total_balance(&5), 256 * 10);
assert_eq!(System::account_nonce(&2), 0);
Expand All @@ -109,10 +109,10 @@ fn reclaim_indexing_on_new_accounts_should_work() {
assert_eq!(Balances::lookup_index(4), None);
assert_eq!(Balances::total_balance(&2), 256 * 20);

assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 20)); // account 2 becomes zombie freeing index 1 for reclaim)
assert_ok!(Balances::transfer(2, 5.into(), 256 * 20)); // account 2 becomes zombie freeing index 1 for reclaim)
assert_eq!(Balances::total_balance(&2), 0);

assert_ok!(Balances::transfer(Some(5).into(), 6.into(), 256 * 1 + 0x69)); // account 6 takes index 1.
assert_ok!(Balances::transfer(5, 6.into(), 256 * 1 + 0x69)); // account 6 takes index 1.
assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69);
assert_eq!(Balances::lookup_index(1), Some(6));
});
Expand All @@ -125,10 +125,10 @@ fn reclaim_indexing_on_new_accounts_should_work2() {
assert_eq!(Balances::lookup_index(4), None);
assert_eq!(Balances::total_balance(&2), 256 * 20);

assert_ok!(Balances::transfer(Some(2).into(), 5.into(), 256 * 20 - 50)); // account 2 becomes zombie freeing index 1 for reclaim) 50 is creation fee
assert_ok!(Balances::transfer(2, 5.into(), 256 * 20 - 50)); // account 2 becomes zombie freeing index 1 for reclaim) 50 is creation fee
assert_eq!(Balances::total_balance(&2), 0);

assert_ok!(Balances::transfer(Some(5).into(), 6.into(), 256 * 1 + 0x69)); // account 6 takes index 1.
assert_ok!(Balances::transfer(5, 6.into(), 256 * 1 + 0x69)); // account 6 takes index 1.
assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69);
assert_eq!(Balances::lookup_index(1), Some(6));
});
Expand All @@ -147,7 +147,7 @@ fn reserved_balance_should_prevent_reclaim_count() {
assert_eq!(Balances::total_balance(&2), 256 * 19 + 1); // reserve still exists.
assert_eq!(System::account_nonce(&2), 1);

assert_ok!(Balances::transfer(Some(4).into(), 5.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5.
assert_ok!(Balances::transfer(4, 5.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5.
assert_eq!(Balances::total_balance(&5), 256 * 1 + 0x69);
assert_eq!(Balances::lookup_index(1), Some(2)); // but fails.
assert_eq!(System::account_nonce(&2), 1);
Expand All @@ -156,7 +156,7 @@ fn reserved_balance_should_prevent_reclaim_count() {
assert_eq!(Balances::total_balance(&2), 0); // "free" account deleted."
assert_eq!(System::account_nonce(&2), 0);

assert_ok!(Balances::transfer(Some(4).into(), 6.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6.
assert_ok!(Balances::transfer(4, 6.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6.
assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69);
assert_eq!(Balances::lookup_index(1), Some(6)); // and succeeds.
});
Expand All @@ -175,7 +175,7 @@ fn reserved_balance_should_prevent_reclaim_count2() {
assert_eq!(Balances::total_balance(&2), 256 * 19 + 1); // reserve still exists.
assert_eq!(System::account_nonce(&2), 1);

assert_ok!(Balances::transfer(Some(4).into(), 5.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5.
assert_ok!(Balances::transfer(4, 5.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5.
assert_eq!(Balances::total_balance(&5), 256 * 1 + 0x69);
assert_eq!(Balances::lookup_index(1), Some(2)); // but fails.
assert_eq!(System::account_nonce(&2), 1);
Expand All @@ -184,7 +184,7 @@ fn reserved_balance_should_prevent_reclaim_count2() {
assert_eq!(Balances::total_balance(&2), 0); // "free" account deleted."
assert_eq!(System::account_nonce(&2), 0);

assert_ok!(Balances::transfer(Some(4).into(), 6.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6.
assert_ok!(Balances::transfer(4, 6.into(), 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6.
assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69);
assert_eq!(Balances::lookup_index(1), Some(6)); // and succeeds.
});
Expand All @@ -208,7 +208,7 @@ fn balance_transfer_works() {
with_externalities(&mut new_test_ext(0, false), || {
Balances::set_free_balance(&1, 111);
Balances::increase_total_stake_by(111);
assert_ok!(Balances::transfer(Some(1).into(), 2.into(), 69));
assert_ok!(Balances::transfer(1, 2.into(), 69));
assert_eq!(Balances::total_balance(&1), 42);
assert_eq!(Balances::total_balance(&2), 69);
});
Expand Down Expand Up @@ -236,7 +236,7 @@ fn balance_transfer_when_reserved_should_not_work() {
with_externalities(&mut new_test_ext(0, false), || {
Balances::set_free_balance(&1, 111);
assert_ok!(Balances::reserve(&1, 69));
assert_noop!(Balances::transfer(Some(1).into(), 2.into(), 69), "balance too low to send value");
assert_noop!(Balances::transfer(1, 2.into(), 69), "balance too low to send value");
});
}

Expand Down Expand Up @@ -367,7 +367,7 @@ fn transferring_too_high_value_should_not_panic() {
<FreeBalance<Runtime>>::insert(2, 1);

assert_err!(
Balances::transfer(Some(1).into(), 2.into(), u64::max_value()),
Balances::transfer(1, 2.into(), u64::max_value()),
"destination balance too high to receive value"
);

Expand All @@ -393,7 +393,7 @@ fn account_removal_on_free_too_low() {
// Transfer funds from account 1 of such amount that after this transfer
// the balance of account 1 will be below the exsistential threshold.
// This should lead to the removal of all balance of this account.
assert_ok!(Balances::transfer(Some(1).into(), 2.into(), 20));
assert_ok!(Balances::transfer(1, 2.into(), 20));

// Verify free balance removal of account 1.
assert_eq!(Balances::free_balance(&1), 0);
Expand Down
18 changes: 7 additions & 11 deletions srml/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Conensus module for runtime; manages the authority set ready for the native code.
//! Consensus module for runtime; manages the authority set ready for the native code.

#![cfg_attr(not(feature = "std"), no_std)]

Expand Down Expand Up @@ -48,7 +48,6 @@ use runtime_support::storage::StorageValue;
use runtime_support::storage::unhashed::StorageVec;
use primitives::traits::{MaybeSerializeDebug, OnFinalise, Member, DigestItem};
use primitives::bft::MisbehaviorReport;
use system::{ensure_signed, ensure_inherent};

#[cfg(any(feature = "std", test))]
use substrate_primitives::Blake2Hasher;
Expand Down Expand Up @@ -129,9 +128,9 @@ decl_storage! {

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn report_misbehavior(origin, report: MisbehaviorReport<T::Hash, T::BlockNumber>) -> Result;
fn note_offline(origin, offline_val_indices: Vec<u32>) -> Result;
fn remark(origin, remark: Vec<u8>) -> Result;
fn report_misbehavior(SystemOrigin(Signed(who)), report: MisbehaviorReport<T::Hash, T::BlockNumber>) -> Result;
fn note_offline(SystemOrigin(Inherent), offline_val_indices: Vec<u32>) -> Result;
fn remark(SystemOrigin(Signed(who)), remark: Vec<u8>) -> Result;
fn set_code(new: Vec<u8>) -> Result;
fn set_storage(items: Vec<KeyValue>) -> Result;
}
Expand All @@ -158,17 +157,15 @@ impl<T: Trait> Module<T> {
}

/// Report some misbehaviour.
fn report_misbehavior(origin: T::Origin, _report: MisbehaviorReport<T::Hash, T::BlockNumber>) -> Result {
ensure_signed(origin)?;
fn report_misbehavior(_who: T::AccountId, _report: MisbehaviorReport<T::Hash, T::BlockNumber>) -> Result {
// TODO.
Ok(())
}

/// Note the previous block's validator missed their opportunity to propose a block. This only comes in
/// if 2/3+1 of the validators agree that no proposal was submitted. It's only relevant
/// for the previous block.
fn note_offline(origin: T::Origin, offline_val_indices: Vec<u32>) -> Result {
ensure_inherent(origin)?;
fn note_offline(offline_val_indices: Vec<u32>) -> Result {
assert!(
<system::Module<T>>::extrinsic_index() == Some(T::NOTE_OFFLINE_POSITION),
"note_offline extrinsic must be at position {} in the block",
Expand All @@ -183,8 +180,7 @@ impl<T: Trait> Module<T> {
}

/// Make some on-chain remark.
fn remark(origin: T::Origin, _remark: Vec<u8>) -> Result {
ensure_signed(origin)?;
fn remark(_who: T::AccountId, _remark: Vec<u8>) -> Result {
Ok(())
}

Expand Down
11 changes: 4 additions & 7 deletions srml/contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ use codec::Codec;
use runtime_primitives::traits::{Hash, As, SimpleArithmetic, OnFinalise};
use runtime_support::dispatch::Result;
use runtime_support::{Parameter, StorageMap, StorageValue};
use system::ensure_signed;

pub trait Trait: balances::Trait {
/// Function type to get the contract address given the creator.
Expand Down Expand Up @@ -152,15 +151,15 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
// TODO: Change AccountId to staking::Address
fn call(
origin,
SystemOrigin(Signed(origin)),
dest: T::AccountId,
value: T::Balance,
gas_limit: T::Gas,
data: Vec<u8>
) -> Result;

fn create(
origin,
SystemOrigin(Signed(origin)),
value: T::Balance,
gas_limit: T::Gas,
init_code: Vec<u8>,
Expand Down Expand Up @@ -208,13 +207,12 @@ impl<T: Trait> double_map::StorageDoubleMap for StorageOf<T> {
impl<T: Trait> Module<T> {
/// Make a call to a specified account, optionally transferring some balance.
fn call(
origin: <T as system::Trait>::Origin,
origin: T::AccountId,
dest: T::AccountId,
value: T::Balance,
gas_limit: T::Gas,
data: Vec<u8>,
) -> Result {
let origin = ensure_signed(origin)?;

// Pay for the gas upfront.
//
Expand Down Expand Up @@ -255,13 +253,12 @@ impl<T: Trait> Module<T> {
/// after the execution is saved as the `code` of the account. That code will be invoked
/// upon any message received by this account.
fn create(
origin: <T as system::Trait>::Origin,
origin: T::AccountId,
endowment: T::Balance,
gas_limit: T::Gas,
ctor_code: Vec<u8>,
data: Vec<u8>,
) -> Result {
let origin = ensure_signed(origin)?;

// Pay for the gas upfront.
//
Expand Down
Loading