Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nodes/rust/duniter-v2s
  • llaq/lc-core-substrate
  • pini-gh/duniter-v2s
  • vincentux/duniter-v2s
  • mildred/duniter-v2s
  • d0p1/duniter-v2s
  • bgallois/duniter-v2s
  • Nicolas80/duniter-v2s
8 results
Show changes
Showing
with 1079 additions and 83 deletions
[package]
authors = ['librelois <c@elo.tf>']
description = 'FRAME pallet oneshot account.'
edition = '2018'
homepage = 'https://substrate.dev'
license = 'AGPL-3.0'
name = 'pallet-oneshot-account'
readme = 'README.md'
repository = 'https://git.duniter.org/nodes/rust/duniter-v2s'
version = '3.0.0'
[features]
default = ['std']
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"pallet-balances",
]
std = [
'codec/std',
'frame-support/std',
'frame-system/std',
'frame-benchmarking/std',
'sp-core/std',
'sp-io/std',
'sp-runtime/std',
'sp-std/std',
]
try-runtime = ['frame-support/try-runtime']
[dependencies]
# crates.io
codec = { package = 'parity-scale-codec', version = "3.1.5", default-features = false, features = ["derive"] }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
# benchmarks
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', optional = true, default-features = false }
# substrate
[dependencies.frame-benchmarking]
default-features = false
git = 'https://github.com/duniter/substrate'
optional = true
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-system]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dependencies.pallet-transaction-payment]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-core]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-io]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
### DOC ###
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
### DEV ###
[dev-dependencies.sp-io]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
[dev-dependencies.pallet-balances]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
// Copyright 2021-2022 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::pallet_prelude::IsType;
use frame_support::traits::Get;
use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances;
use crate::Pallet;
const SEED: u32 = 0;
benchmarks! {
where_clause { where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>
}
create_oneshot_account {
let existential_deposit = T::ExistentialDeposit::get();
let caller = whitelisted_caller();
// Give some multiple of the existential deposit
let balance = existential_deposit.saturating_mul((2).into());
let _ = T::Currency::make_free_balance_be(&caller, balance.into());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient.clone());
let transfer_amount = existential_deposit;
}: _(RawOrigin::Signed(caller.clone()), recipient_lookup, transfer_amount.into())
verify {
assert_eq!(Balances::<T>::free_balance(&caller), transfer_amount);
assert_eq!(OneshotAccounts::<T>::get(&recipient), Some(transfer_amount.into()));
}
where_clause { where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>+From<T::Balance>
}
consume_oneshot_account {
let existential_deposit = T::ExistentialDeposit::get();
let caller: T::AccountId = whitelisted_caller();
// Give some multiple of the existential deposit
let balance = existential_deposit.saturating_mul((2).into());
OneshotAccounts::<T>::insert(
caller.clone(),
Into::<<T::Currency as Currency<T::AccountId>>::Balance>::into(balance)
);
// Deposit into a normal account is more expensive than into a oneshot account
// so we create the recipient account with an existential deposit.
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient.clone());
let _ = T::Currency::make_free_balance_be(&recipient, existential_deposit.into());
}: _(
RawOrigin::Signed(caller.clone()),
T::BlockNumber::zero(),
Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient_lookup)
)
verify {
assert_eq!(OneshotAccounts::<T>::get(&caller), None);
assert_eq!(
Balances::<T>::free_balance(&recipient),
existential_deposit.saturating_mul((3).into())
);
}
where_clause { where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>+From<T::Balance>
}
consume_oneshot_account_with_remaining {
let existential_deposit = T::ExistentialDeposit::get();
let caller: T::AccountId = whitelisted_caller();
// Give some multiple of the existential deposit
let balance = existential_deposit.saturating_mul((2).into());
OneshotAccounts::<T>::insert(
caller.clone(),
Into::<<T::Currency as Currency<T::AccountId>>::Balance>::into(balance)
);
// Deposit into a normal account is more expensive than into a oneshot account
// so we create the recipient accounts with an existential deposits.
let recipient1: T::AccountId = account("recipient1", 0, SEED);
let recipient1_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient1.clone());
let _ = T::Currency::make_free_balance_be(&recipient1, existential_deposit.into());
let recipient2: T::AccountId = account("recipient2", 1, SEED);
let recipient2_lookup: <T::Lookup as StaticLookup>::Source =
T::Lookup::unlookup(recipient2.clone());
let _ = T::Currency::make_free_balance_be(&recipient2, existential_deposit.into());
}: _(
RawOrigin::Signed(caller.clone()),
T::BlockNumber::zero(),
Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient1_lookup),
Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient2_lookup),
existential_deposit.into()
)
verify {
assert_eq!(OneshotAccounts::<T>::get(&caller), None);
assert_eq!(
Balances::<T>::free_balance(&recipient1),
existential_deposit.saturating_mul((2).into())
);
assert_eq!(
Balances::<T>::free_balance(&recipient2),
existential_deposit.saturating_mul((2).into())
);
}
impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Test
);
}
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::Config;
use codec::{Decode, Encode};
use frame_support::traits::IsSubType;
use frame_support::weights::DispatchInfo;
//use frame_system::Config;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{DispatchInfoOf, Dispatchable, SignedExtension},
transaction_validity::{TransactionValidity, TransactionValidityError},
};
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
#[scale_info(skip_type_params(Runtime))]
pub struct CheckNonce<T: Config>(pub frame_system::CheckNonce<T>);
impl<T: Config> sp_std::fmt::Debug for CheckNonce<T> {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
write!(f, "CheckNonce({})", self.0 .0)
}
#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
Ok(())
}
}
impl<T: Config + TypeInfo> SignedExtension for CheckNonce<T>
where
T::Call: Dispatchable<Info = DispatchInfo> + IsSubType<crate::Call<T>>,
{
type AccountId = <T as frame_system::Config>::AccountId;
type Call = <T as frame_system::Config>::Call;
type AdditionalSigned = ();
type Pre = ();
const IDENTIFIER: &'static str = "CheckNonce";
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
self.0.additional_signed()
}
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<(), TransactionValidityError> {
if let Some(
crate::Call::consume_oneshot_account { .. }
| crate::Call::consume_oneshot_account_with_remaining { .. },
) = call.is_sub_type()
{
Ok(())
} else {
self.0.pre_dispatch(who, call, info, len)
}
}
fn validate(
&self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
self.0.validate(who, call, info, len)
}
}
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
mod benchmarking;
mod check_nonce;
#[cfg(test)]
mod mock;
mod types;
pub use check_nonce::CheckNonce;
pub use pallet::*;
pub use types::*;
use frame_support::pallet_prelude::*;
use frame_support::traits::{
Currency, ExistenceRequirement, Imbalance, IsSubType, WithdrawReasons,
};
use frame_system::pallet_prelude::*;
use pallet_transaction_payment::OnChargeTransaction;
use sp_runtime::traits::{DispatchInfoOf, PostDispatchInfoOf, Saturating, StaticLookup, Zero};
use sp_std::convert::TryInto;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::traits::StorageVersion;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
// CONFIG //
#[pallet::config]
pub trait Config: frame_system::Config + pallet_transaction_payment::Config {
type Currency: Currency<Self::AccountId>;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type InnerOnChargeTransaction: OnChargeTransaction<Self>;
}
// STORAGE //
#[pallet::storage]
#[pallet::getter(fn oneshot_account)]
pub type OneshotAccounts<T: Config> = StorageMap<
_,
Blake2_128Concat,
T::AccountId,
<T::Currency as Currency<T::AccountId>>::Balance,
OptionQuery,
>;
// EVENTS //
#[allow(clippy::type_complexity)]
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
OneshotAccountCreated {
account: T::AccountId,
balance: <T::Currency as Currency<T::AccountId>>::Balance,
creator: T::AccountId,
},
OneshotAccountConsumed {
account: T::AccountId,
dest1: (
T::AccountId,
<T::Currency as Currency<T::AccountId>>::Balance,
),
dest2: Option<(
T::AccountId,
<T::Currency as Currency<T::AccountId>>::Balance,
)>,
},
Withdraw {
account: T::AccountId,
balance: <T::Currency as Currency<T::AccountId>>::Balance,
},
}
// ERRORS //
#[pallet::error]
pub enum Error<T> {
/// Block height is in the future
BlockHeightInFuture,
/// Block height is too old
BlockHeightTooOld,
/// Destination account does not exist
DestAccountNotExist,
/// Destination account has balance less than existential deposit
ExistentialDeposit,
/// Source account has insufficient balance
InsufficientBalance,
/// Destination oneshot account already exists
OneshotAccountAlreadyCreated,
/// Source oneshot account does not exist
OneshotAccountNotExist,
}
// CALLS //
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Create an account that can only be consumed once
///
/// - `dest`: The oneshot account to be created.
/// - `balance`: The balance to be transfered to this oneshot account.
///
/// Origin account is kept alive.
#[pallet::weight(500_000_000)]
pub fn create_oneshot_account(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
#[pallet::compact] value: <T::Currency as Currency<T::AccountId>>::Balance,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
ensure!(
value >= <T::Currency as Currency<T::AccountId>>::minimum_balance(),
Error::<T>::ExistentialDeposit
);
ensure!(
OneshotAccounts::<T>::get(&dest).is_none(),
Error::<T>::OneshotAccountAlreadyCreated
);
<T::Currency as Currency<T::AccountId>>::withdraw(
&transactor,
value,
WithdrawReasons::TRANSFER,
ExistenceRequirement::KeepAlive,
)?;
OneshotAccounts::<T>::insert(&dest, value);
Self::deposit_event(Event::OneshotAccountCreated {
account: dest,
balance: value,
creator: transactor,
});
Ok(())
}
/// Consume a oneshot account and transfer its balance to an account
///
/// - `block_height`: Must be a recent block number. The limit is `BlockHashCount` in the past. (this is to prevent replay attacks)
/// - `dest`: The destination account.
/// - `dest_is_oneshot`: If set to `true`, then a oneshot account is created at `dest`. Else, `dest` has to be an existing account.
#[pallet::weight(500_000_000)]
pub fn consume_oneshot_account(
origin: OriginFor<T>,
block_height: T::BlockNumber,
dest: Account<<T::Lookup as StaticLookup>::Source>,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
let (dest, dest_is_oneshot) = match dest {
Account::Normal(account) => (account, false),
Account::Oneshot(account) => (account, true),
};
let dest = T::Lookup::lookup(dest)?;
let value = OneshotAccounts::<T>::take(&transactor)
.ok_or(Error::<T>::OneshotAccountNotExist)?;
ensure!(
block_height <= frame_system::Pallet::<T>::block_number(),
Error::<T>::BlockHeightInFuture
);
ensure!(
frame_system::pallet::BlockHash::<T>::contains_key(block_height),
Error::<T>::BlockHeightTooOld
);
if dest_is_oneshot {
ensure!(
OneshotAccounts::<T>::get(&dest).is_none(),
Error::<T>::OneshotAccountAlreadyCreated
);
OneshotAccounts::<T>::insert(&dest, value);
Self::deposit_event(Event::OneshotAccountCreated {
account: dest.clone(),
balance: value,
creator: transactor.clone(),
});
} else {
<T::Currency as Currency<T::AccountId>>::deposit_into_existing(&dest, value)?;
}
OneshotAccounts::<T>::remove(&transactor);
Self::deposit_event(Event::OneshotAccountConsumed {
account: transactor,
dest1: (dest, value),
dest2: None,
});
Ok(())
}
/// Consume a oneshot account then transfer some amount to an account,
/// and the remaining amount to another account.
///
/// - `block_height`: Must be a recent block number.
/// The limit is `BlockHashCount` in the past. (this is to prevent replay attacks)
/// - `dest`: The destination account.
/// - `dest_is_oneshot`: If set to `true`, then a oneshot account is created at `dest`. Else, `dest` has to be an existing account.
/// - `dest2`: The second destination account.
/// - `dest2_is_oneshot`: If set to `true`, then a oneshot account is created at `dest2`. Else, `dest2` has to be an existing account.
/// - `balance1`: The amount transfered to `dest`, the leftover being transfered to `dest2`.
#[pallet::weight(500_000_000)]
pub fn consume_oneshot_account_with_remaining(
origin: OriginFor<T>,
block_height: T::BlockNumber,
dest: Account<<T::Lookup as StaticLookup>::Source>,
remaining_to: Account<<T::Lookup as StaticLookup>::Source>,
#[pallet::compact] balance: <T::Currency as Currency<T::AccountId>>::Balance,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
let (dest1, dest1_is_oneshot) = match dest {
Account::Normal(account) => (account, false),
Account::Oneshot(account) => (account, true),
};
let dest1 = T::Lookup::lookup(dest1)?;
let (dest2, dest2_is_oneshot) = match remaining_to {
Account::Normal(account) => (account, false),
Account::Oneshot(account) => (account, true),
};
let dest2 = T::Lookup::lookup(dest2)?;
let value = OneshotAccounts::<T>::take(&transactor)
.ok_or(Error::<T>::OneshotAccountNotExist)?;
let balance1 = balance;
ensure!(value > balance1, Error::<T>::InsufficientBalance);
let balance2 = value.saturating_sub(balance1);
ensure!(
block_height <= frame_system::Pallet::<T>::block_number(),
Error::<T>::BlockHeightInFuture
);
ensure!(
frame_system::pallet::BlockHash::<T>::contains_key(block_height),
Error::<T>::BlockHeightTooOld
);
if dest1_is_oneshot {
ensure!(
OneshotAccounts::<T>::get(&dest1).is_none(),
Error::<T>::OneshotAccountAlreadyCreated
);
ensure!(
balance1 >= <T::Currency as Currency<T::AccountId>>::minimum_balance(),
Error::<T>::ExistentialDeposit
);
} else {
ensure!(
!<T::Currency as Currency<T::AccountId>>::free_balance(&dest1).is_zero(),
Error::<T>::DestAccountNotExist
);
}
if dest2_is_oneshot {
ensure!(
OneshotAccounts::<T>::get(&dest2).is_none(),
Error::<T>::OneshotAccountAlreadyCreated
);
ensure!(
balance2 >= <T::Currency as Currency<T::AccountId>>::minimum_balance(),
Error::<T>::ExistentialDeposit
);
OneshotAccounts::<T>::insert(&dest2, balance2);
Self::deposit_event(Event::OneshotAccountCreated {
account: dest2.clone(),
balance: balance2,
creator: transactor.clone(),
});
} else {
<T::Currency as Currency<T::AccountId>>::deposit_into_existing(&dest2, balance2)?;
}
if dest1_is_oneshot {
OneshotAccounts::<T>::insert(&dest1, balance1);
Self::deposit_event(Event::OneshotAccountCreated {
account: dest1.clone(),
balance: balance1,
creator: transactor.clone(),
});
} else {
<T::Currency as Currency<T::AccountId>>::deposit_into_existing(&dest1, balance1)?;
}
OneshotAccounts::<T>::remove(&transactor);
Self::deposit_event(Event::OneshotAccountConsumed {
account: transactor,
dest1: (dest1, balance1),
dest2: Some((dest2, balance2)),
});
Ok(())
}
}
}
impl<T: Config> OnChargeTransaction<T> for Pallet<T>
where
T::Call: IsSubType<Call<T>>,
T::InnerOnChargeTransaction: OnChargeTransaction<
T,
Balance = <T::Currency as Currency<T::AccountId>>::Balance,
LiquidityInfo = Option<<T::Currency as Currency<T::AccountId>>::NegativeImbalance>,
>,
{
type Balance = <T::Currency as Currency<T::AccountId>>::Balance;
type LiquidityInfo = Option<<T::Currency as Currency<T::AccountId>>::NegativeImbalance>;
fn withdraw_fee(
who: &T::AccountId,
call: &T::Call,
dispatch_info: &DispatchInfoOf<T::Call>,
fee: Self::Balance,
tip: Self::Balance,
) -> Result<Self::LiquidityInfo, TransactionValidityError> {
if let Some(
Call::consume_oneshot_account { .. }
| Call::consume_oneshot_account_with_remaining { .. },
) = call.is_sub_type()
{
if fee.is_zero() {
return Ok(None);
}
if let Some(balance) = OneshotAccounts::<T>::get(&who) {
if balance >= fee {
OneshotAccounts::<T>::insert(who, balance.saturating_sub(fee));
Self::deposit_event(Event::Withdraw {
account: who.clone(),
balance: fee,
});
// TODO
return Ok(Some(
<T::Currency as Currency<T::AccountId>>::NegativeImbalance::zero(),
));
}
}
Err(TransactionValidityError::Invalid(
InvalidTransaction::Payment,
))
} else {
T::InnerOnChargeTransaction::withdraw_fee(who, call, dispatch_info, fee, tip)
}
}
fn correct_and_deposit_fee(
who: &T::AccountId,
dispatch_info: &DispatchInfoOf<T::Call>,
post_info: &PostDispatchInfoOf<T::Call>,
corrected_fee: Self::Balance,
tip: Self::Balance,
already_withdrawn: Self::LiquidityInfo,
) -> Result<(), TransactionValidityError> {
T::InnerOnChargeTransaction::correct_and_deposit_fee(
who,
dispatch_info,
post_info,
corrected_fee,
tip,
already_withdrawn,
)
}
}
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::{self as pallet_oneshot_account};
use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};
use frame_system as system;
use pallet_transaction_payment::CurrencyAdapter;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_std::convert::{TryFrom, TryInto};
type Balance = u64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
OneshotAccount: pallet_oneshot_account::{Pallet, Call, Storage, Event<T>},
}
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42;
}
impl system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
pub const MaxLocks: u32 = 50;
}
impl pallet_balances::Config for Test {
type Balance = Balance;
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Test>;
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
}
impl pallet_transaction_payment::Config for Test {
type Event = Event;
type OnChargeTransaction = OneshotAccount;
type OperationalFeeMultiplier = frame_support::traits::ConstU8<5>;
type WeightToFee = IdentityFee<u64>;
type LengthToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
}
impl pallet_oneshot_account::Config for Test {
type Currency = Balances;
type Event = Event;
type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
}
pub struct HandleFees;
type NegativeImbalance = <Balances as frame_support::traits::Currency<u64>>::NegativeImbalance;
impl frame_support::traits::OnUnbalanced<NegativeImbalance> for HandleFees {
fn on_nonzero_unbalanced(_amount: NegativeImbalance) {}
}
// Build genesis storage according to the mock runtime.
#[allow(dead_code)]
pub fn new_test_ext() -> sp_io::TestExternalities {
GenesisConfig {
system: SystemConfig::default(),
balances: BalancesConfig::default(),
}
.build_storage()
.unwrap()
.into()
}
......@@ -14,39 +14,11 @@
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::IdtyIndex;
use codec::{Decode, Encode};
use frame_support::pallet_prelude::*;
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct MembershipMetaData<AccountId>(pub AccountId);
impl<AccountId: Eq> sp_membership::traits::Validate<AccountId> for MembershipMetaData<AccountId> {
fn validate(&self, account_id: &AccountId) -> bool {
&self.0 == account_id
}
}
/*impl From<AccountId> for MembershipMetaData {
fn from(account_id: AccountId) -> Self {
Self(account_id)
}
}*/
/*impl Into<AccountId> for MembershipMetaData {
fn into(self) -> AccountId {
self.0
}
}*/
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(codec::Decode, codec::Encode, Eq, PartialEq, TypeInfo)]
pub enum WotDiff {
AddNode(IdtyIndex),
AddPendingLink(IdtyIndex, IdtyIndex),
AddLink(IdtyIndex, IdtyIndex),
DelLink(IdtyIndex, IdtyIndex),
DisableNode(IdtyIndex),
}
impl Default for WotDiff {
fn default() -> Self {
unreachable!()
}
#[derive(Clone, Decode, Encode, PartialEq, RuntimeDebug, TypeInfo)]
pub enum Account<AccountId> {
Normal(AccountId),
Oneshot(AccountId),
}
// Copyright 2021-2022 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(clippy::unnecessary_cast)]
use frame_support::weights::{constants::RocksDbWeight, Weight};
/// Weight functions needed for pallet_universal_dividend.
pub trait WeightInfo {
fn create_oneshot_account() -> Weight;
fn consume_oneshot_account() -> Weight;
fn consume_oneshot_account_with_remaining() -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
// Storage: OneshotAccount OneshotAccounts (r:1 w:1)
fn create_oneshot_account() -> Weight {
(45_690_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: OneshotAccount OneshotAccounts (r:1 w:1)
// Storage: System BlockHash (r:1 w:0)
// Storage: System Account (r:1 w:1)
fn consume_oneshot_account() -> Weight {
(50_060_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: OneshotAccount OneshotAccounts (r:1 w:1)
// Storage: System BlockHash (r:1 w:0)
// Storage: System Account (r:2 w:2)
fn consume_oneshot_account_with_remaining() -> Weight {
(69_346_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
}
......@@ -37,37 +37,37 @@ version = "3.1.5"
default-features = false
git = 'https://github.com/duniter/substrate'
optional = true
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-system]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-core]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-io]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
### DOC ###
......
......@@ -33,38 +33,38 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
serde = { version = "1.0.101", features = ["derive"], optional = true }
# substrate bencharks
frame-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', optional = true, default-features = false }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', optional = true, default-features = false }
frame-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', optional = true, default-features = false }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', optional = true, default-features = false }
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-system]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-arithmetic]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-io]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
### DOC ###
......@@ -79,16 +79,16 @@ serde = { version = "1.0.101", features = ["derive"] }
[dev-dependencies.pallet-balances]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dev-dependencies.sp-core]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dev-dependencies.sp-io]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dev-dependencies.sp-runtime]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
......@@ -36,32 +36,32 @@ version = "3.1.5"
default-features = false
git = 'https://github.com/duniter/substrate'
optional = true
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.frame-system]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-io]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
### DOC ###
......
......@@ -33,17 +33,17 @@ version = "3.1.5"
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
### DOC ###
......
......@@ -34,7 +34,7 @@ version = "3.1.5"
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.serde]
version = "1.0.101"
......@@ -44,12 +44,12 @@ features = ["derive"]
[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
[dependencies.sp-std]
default-features = false
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.23'
branch = 'duniter-substrate-v0.9.26'
### DOC ###
......
{
"first_ud": 10000,
"first_ud_reeval": 100800,
"genesis_parameters": {
"genesis_certs_expire_on": 2102400,
"genesis_certs_min_received": 3,
"genesis_memberships_expire_on": 1051200,
"genesis_smith_certs_expire_on": 2102400,
"genesis_smith_certs_min_received": 3,
"genesis_smith_memberships_expire_on": 1051200
},
"identities": {
"Elois": {
"balance": 10000,
......@@ -20,6 +28,11 @@
],
"pubkey": "5H95G8bwuf4yyNNNa83hDhj7wpYaSRhZiGezZ9TDbyqNdAhY"
},
"Elois2": {
"balance": 10000,
"certs": ["tuxmain", "Elois", "HugoTrentesaux"],
"pubkey": "5GFEEx7kqvP4QEPCAXkALeYCG7m8DiA5LQ4YzW62j7FytQyg"
},
"poka": {
"balance": 10000,
"certs": ["cgeek", "vit", "tuxmain", "Elois", "HugoTrentesaux"],
......@@ -136,7 +149,7 @@
"babe_epoch_duration": 600,
"cert_period": 14400,
"cert_max_by_issuer": 100,
"cert_min_received_cert_to_issue_cert": 5,
"cert_min_received_cert_to_issue_cert": 3,
"cert_validity_period": 2102400,
"idty_confirm_period": 14400,
"idty_creation_period": 14400,
......@@ -145,7 +158,7 @@
"ud_creation_period": 14400,
"ud_reeval_period": 100800,
"smith_cert_period": 14400,
"smith_cert_max_by_issuer": 12,
"smith_cert_max_by_issuer": 15,
"smith_cert_min_received_cert_to_issue_cert": 3,
"smith_cert_validity_period": 2102400,
"smith_membership_period": 1051200,
......@@ -153,13 +166,16 @@
"smiths_wot_first_cert_issuable_on": 14400,
"smiths_wot_min_cert_for_membership": 3,
"wot_first_cert_issuable_on": 0,
"wot_min_cert_for_create_idty_right": 5,
"wot_min_cert_for_membership": 5
"wot_min_cert_for_create_idty_right": 3,
"wot_min_cert_for_membership": 3
},
"smiths": {
"Elois": {
"certs": ["poka", "cgeek", "vit", "tuxmain", "HugoTrentesaux", "kapis"],
"session_keys": "0xb67db3acc0ec68327e9e258aa5247a0f504616142ecb445c2540b9bdb223b5bea0beb8d9dea455ad5591961c868e59e0760e6e819a85c89ea7cbb527a0944241a0beb8d9dea455ad5591961c868e59e0760e6e819a85c89ea7cbb527a0944241a0beb8d9dea455ad5591961c868e59e0760e6e819a85c89ea7cbb527a0944241"
"session_keys": "0x92743b12d55242276539d7256951cdfda85371caefbd325396da9331011b737d14084d2537f77e786a75b9bcbe351051fad52946ec211724b5e8c93bb8aa7a6f14084d2537f77e786a75b9bcbe351051fad52946ec211724b5e8c93bb8aa7a6f14084d2537f77e786a75b9bcbe351051fad52946ec211724b5e8c93bb8aa7a6f"
},
"Elois2": {
"certs": ["tuxmain", "Elois", "HugoTrentesaux"]
},
"poka": {
"certs": ["cgeek", "vit", "tuxmain", "Elois", "HugoTrentesaux"]
......@@ -183,6 +199,6 @@
"certs": ["Elois","tuxmain","HugoTrentesaux"]
}
},
"sudo_key": "5Co5AWcBiz4HaAEpu8BxLdghnCob89rFGU5yQ65WP3t2jsyB",
"sudo_key": "5Hm8sBbwuLAU99dBezvgtnRmZCrUy9mhqmbQMFyGTaeATYg7",
"technical_committee": ["Elois", "cgeek", "tuxmain", "HugoTrentesaux"]
}
No preview for this file type
......@@ -39,6 +39,7 @@ std = [
'pallet-identity/std',
'pallet-membership/std',
'pallet-multisig/std',
'pallet-oneshot-account/std',
'pallet-provide-randomness/std',
'pallet-proxy/std',
'pallet-scheduler/std',
......@@ -68,6 +69,7 @@ pallet-duniter-account = { path = '../../pallets/duniter-account', default-featu
pallet-duniter-wot = { path = '../../pallets/duniter-wot', default-features = false }
pallet-identity = { path = '../../pallets/identity', default-features = false }
pallet-membership = { path = '../../pallets/membership', default-features = false }
pallet-oneshot-account = { path = '../../pallets/oneshot-account', default-features = false }
pallet-provide-randomness = { path = '../../pallets/provide-randomness', default-features = false }
pallet-upgrade-origin = { path = '../../pallets/upgrade-origin', default-features = false }
pallet-universal-dividend = { path = '../../pallets/universal-dividend', default-features = false }
......@@ -82,27 +84,27 @@ serde_derive = { version = "1.0.101", optional = true }
smallvec = "1.6.1"
# Substrate
frame-support = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
frame-system = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-multisig = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-proxy = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-scheduler = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-timestamp = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
pallet-treasury = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
sp-arithmetic = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
sp-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
sp-std = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
frame-support = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
frame-system = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-multisig = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-proxy = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-scheduler = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-timestamp = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-treasury = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-arithmetic = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-std = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
# substrate benchmarks
frame-benchmarking = { git = "https://github.com/duniter/substrate", branch = 'duniter-substrate-v0.9.23', default-features = false, optional = true }
frame-system-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false, optional = true }
frame-benchmarking = { git = "https://github.com/duniter/substrate", branch = 'duniter-substrate-v0.9.26', default-features = false, optional = true }
frame-system-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false, optional = true }
# TODO: there is a bad coupling in substrate that force to add this dependency
sp-staking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.23', default-features = false }
sp-staking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
......@@ -238,6 +238,7 @@ macro_rules! runtime_apis {
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_multisig, Multisig);
list_benchmark!(list, extra, pallet_oneshot_account, OneshotAccount);
list_benchmark!(list, extra, pallet_proxy, Proxy);
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
......@@ -284,6 +285,7 @@ macro_rules! runtime_apis {
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_oneshot_account, OneshotAccount);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_scheduler, Scheduler);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
......
......@@ -106,6 +106,11 @@ pub struct SmithsMembershipMetaData<SessionKeysWrapper> {
pub p2p_endpoint: sp_runtime::RuntimeString,
pub session_keys: SessionKeysWrapper,
}
impl<SessionKeysWrapper> Default for SmithsMembershipMetaData<SessionKeysWrapper> {
fn default() -> Self {
unreachable!()
}
}
impl<SessionKeysWrapper> sp_membership::traits::Validate<AccountId>
for SmithsMembershipMetaData<SessionKeysWrapper>
{
......
......@@ -41,10 +41,21 @@ impl<T> pallet_identity::traits::OnIdtyChange<T> for OnIdtyChangeHandler<T>
where
T: frame_system::Config<AccountId = AccountId>,
T: pallet_authority_members::Config<MemberId = IdtyIndex>,
T: pallet_identity::Config<IdtyIndex = IdtyIndex>,
T: pallet_identity::Config<IdtyIndex = IdtyIndex, IdtyData = IdtyData>,
T: pallet_universal_dividend::Config,
{
fn on_idty_change(idty_index: IdtyIndex, idty_event: &IdtyEvent<T>) -> Weight {
match idty_event {
IdtyEvent::Validated => {
pallet_identity::Identities::<T>::mutate_exists(idty_index, |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt {
idty_val.data = IdtyData {
first_eligible_ud:
pallet_universal_dividend::Pallet::<T>::init_first_eligible_ud(),
}
}
});
}
IdtyEvent::ChangedOwnerKey { new_owner_key } => {
if let Err(e) = pallet_authority_members::Pallet::<T>::change_owner_key(
idty_index,
......@@ -56,10 +67,7 @@ where
);
}
}
IdtyEvent::Created { .. }
| IdtyEvent::Confirmed
| IdtyEvent::Validated
| IdtyEvent::Removed { .. } => {}
IdtyEvent::Created { .. } | IdtyEvent::Confirmed | IdtyEvent::Removed { .. } => {}
}
0
}
......@@ -67,31 +75,16 @@ where
pub struct OnMembershipEventHandler<Inner, Runtime>(core::marker::PhantomData<(Inner, Runtime)>);
type MembershipMetaData = pallet_duniter_wot::MembershipMetaData<AccountId>;
impl<
Inner: sp_membership::traits::OnEvent<IdtyIndex, MembershipMetaData>,
Inner: sp_membership::traits::OnEvent<IdtyIndex, ()>,
Runtime: frame_system::Config<AccountId = AccountId>
+ pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex>
+ pallet_membership::Config<Instance1, MetaData = MembershipMetaData>
+ pallet_membership::Config<Instance1, MetaData = ()>
+ pallet_universal_dividend::Config,
> sp_membership::traits::OnEvent<IdtyIndex, MembershipMetaData>
for OnMembershipEventHandler<Inner, Runtime>
> sp_membership::traits::OnEvent<IdtyIndex, ()> for OnMembershipEventHandler<Inner, Runtime>
{
fn on_event(membership_event: &sp_membership::Event<IdtyIndex, MembershipMetaData>) -> Weight {
fn on_event(membership_event: &sp_membership::Event<IdtyIndex, ()>) -> Weight {
(match membership_event {
sp_membership::Event::MembershipAcquired(idty_index, _owner_key) => {
pallet_identity::Identities::<Runtime>::mutate_exists(idty_index, |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt {
idty_val.data = IdtyData {
first_eligible_ud:
pallet_universal_dividend::Pallet::<Runtime>::init_first_eligible_ud(
),
}
}
});
Runtime::DbWeight::get().reads_writes(1, 1)
}
sp_membership::Event::MembershipRevoked(idty_index) => {
if let Some(idty_value) = pallet_identity::Identities::<Runtime>::get(idty_index) {
if let Some(first_ud_index) = idty_value.data.first_eligible_ud.into() {
......
......@@ -173,13 +173,20 @@ macro_rules! pallets_config {
}
}
}
pub struct OnChargeTransaction;
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
type Event = Event;
type OnChargeTransaction = OneshotAccount;
type OperationalFeeMultiplier = frame_support::traits::ConstU8<5>;
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>;
type LengthToFee = common_runtime::fees::LengthToFeeImpl<Balance>;
type FeeMultiplierUpdate = ();
}
impl pallet_oneshot_account::Config for Runtime {
type Currency = Balances;
type Event = Event;
type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
}
// CONSENSUS //
......@@ -381,6 +388,7 @@ macro_rules! pallets_config {
type RejectOrigin = TreasuryRejectOrigin;
type SpendFunds = TreasurySpendFunds<Self>;
type SpendPeriod = SpendPeriod;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;
}
......@@ -422,7 +430,7 @@ macro_rules! pallets_config {
type ChangeOwnerKeyPeriod = ChangeOwnerKeyPeriod;
type ConfirmPeriod = ConfirmPeriod;
type Event = Event;
type EnsureIdtyCallAllowed = Wot;
type EnsureIdtyCallAllowed = (Wot, SmithsSubWot);
type IdtyCreationPeriod = IdtyCreationPeriod;
type IdtyData = IdtyData;
type IdtyIndex = IdtyIndex;
......@@ -443,7 +451,7 @@ macro_rules! pallets_config {
type IdtyId = IdtyIndex;
type IdtyIdOf = common_runtime::providers::IdentityIndexOf<Self>;
type MembershipPeriod = MembershipPeriod;
type MetaData = pallet_duniter_wot::MembershipMetaData<AccountId>;
type MetaData = ();
type OnEvent = OnMembershipEventHandler<Wot, Runtime>;
type PendingMembershipPeriod = PendingMembershipPeriod;
type RevocationPeriod = frame_support::traits::ConstU32<0>;
......
// Copyright 2021-2022 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
//! Autogenerated weights for `pallet_oneshot_account`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-08-08, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// ./duniter
// benchmark
// pallet
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet_oneshot_account
// --extrinsic=*
// --execution=wasm
// --wasm-execution=interpreted-i-know-what-i-do
// --heap-pages=4096
// --header=./file_header.txt
// --output=.
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;
/// Weight functions for `pallet_oneshot_account`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_oneshot_account::WeightInfo for WeightInfo<T> {
// Storage: OneshotAccount OneshotAccounts (r:1 w:1)
fn create_oneshot_account() -> Weight {
(941_602_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: OneshotAccount OneshotAccounts (r:1 w:1)
// Storage: System BlockHash (r:1 w:0)
// Storage: System Account (r:1 w:1)
fn consume_oneshot_account() -> Weight {
(971_453_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: OneshotAccount OneshotAccounts (r:1 w:1)
// Storage: System BlockHash (r:1 w:0)
// Storage: System Account (r:2 w:2)
fn consume_oneshot_account_with_remaining() -> Weight {
(1_500_781_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
}