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 392 additions and 336 deletions
......@@ -25,7 +25,8 @@ use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockWeights: frame_system::limits::BlockWeights = block_weights((WEIGHT_PER_SECOND * 2)
.set_proof_size(5 * 1024 * 1024), NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 4450;
......
[build-dependencies.substrate-wasm-builder]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
branch = 'duniter-substrate-v0.9.32'
[package]
authors = ['Axiom-Team Developers <https://axiom-team.fr>']
......@@ -104,6 +104,7 @@ std = [
'sp-version/std',
]
try-runtime = [
"common-runtime/try-runtime",
"frame-executive/try-runtime",
"frame-try-runtime",
"frame-system/try-runtime",
......@@ -126,10 +127,10 @@ try-runtime = [
]
[dev-dependencies]
sp-consensus-vrf = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-finality-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-keyring = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-consensus-vrf = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
sp-finality-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
sp-keyring = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
[dependencies]
# local
......@@ -156,45 +157,45 @@ serde = { version = "1.0.101", default-features = false }
serde_derive = { version = "1.0.101", optional = true }
# substrate
frame-try-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false, optional = true }
frame-executive = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', 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 }
frame-system-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false}
pallet-atomic-swap = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-authorship = { 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-collective = { 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-im-online = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-offences = { 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-preimage = { 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-sudo = { 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-transaction-payment = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-transaction-payment-rpc-runtime-api = { 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 }
pallet-utility = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-api = { 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-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-block-builder = { 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-inherents = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-offchain = { 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-session = { 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 }
sp-transaction-pool = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-version = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
frame-try-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false, optional = true }
frame-executive = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
frame-support = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
frame-system = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
frame-system-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false}
pallet-atomic-swap = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-authorship = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-collective = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-im-online = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-offences = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-multisig = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-preimage = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-proxy = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-scheduler = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-sudo = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-timestamp = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-transaction-payment = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-treasury = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-utility = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-arithmetic = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-block-builder = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-inherents = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-offchain = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-std = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-transaction-pool = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-version = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
# substrate benchmarking
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 }
frame-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false, optional = true }
frame-system-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false, optional = true }
......@@ -35,6 +35,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_duniter_test_parameters::Parameters as GenesisParameters;
pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
......@@ -109,7 +110,8 @@ pub fn native_version() -> NativeVersion {
/// Block type as expected by this runtime.
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckNonZeroSender<Runtime>,
......@@ -134,32 +136,58 @@ pub type Executive = frame_executive::Executive<
pub type TechnicalCommitteeInstance = Instance2;
#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
// Duniter
// NOTE: Make sure to prefix these with `common_runtime::` so
// the that path resolves correctly in the generated file.
[common_runtime::oneshot_account, OneshotAccount]
[common_runtime::universal_dividend, UniversalDividend]
[common_runtime::upgrade_origin, UpgradeOrigin]
// Substrate
[pallet_balances, Balances]
[frame_benchmarking::baseline, Baseline::<Runtime>]
[pallet_collective, TechnicalCommittee]
[pallet_im_online, ImOnline]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[frame_system, SystemBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_treasury, Treasury]
[pallet_utility, Utility]
);
}
pub struct BaseCallFilter;
#[cfg(not(feature = "runtime-benchmarks"))]
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
impl Contains<RuntimeCall> for BaseCallFilter {
fn contains(call: &RuntimeCall) -> bool {
!matches!(
call,
Call::System(
/*RuntimeCall::System(
frame_system::Call::remark { .. } | frame_system::Call::remark_with_event { .. }
) | Call::Membership(
) | */
RuntimeCall::Membership(
pallet_membership::Call::request_membership { .. }
| pallet_membership::Call::claim_membership { .. }
| pallet_membership::Call::revoke_membership { .. }
) | Call::Session(_)
) | RuntimeCall::Session(_)
)
}
}
#[cfg(feature = "runtime-benchmarks")]
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
impl Contains<RuntimeCall> for BaseCallFilter {
fn contains(call: &RuntimeCall) -> bool {
!matches!(
call,
Call::Membership(
RuntimeCall::Membership(
pallet_membership::Call::request_membership { .. }
| pallet_membership::Call::claim_membership { .. }
| pallet_membership::Call::revoke_membership { .. }
) | Call::Session(_)
) | RuntimeCall::Session(_)
)
}
}
......@@ -190,29 +218,32 @@ impl Default for ProxyType {
Self::AlmostAny
}
}
impl frame_support::traits::InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::AlmostAny => {
// Some calls are never authorized from a proxied account
!matches!(
c,
Call::Cert(..) | Call::Identity(..) | Call::SmithsCert(..)
RuntimeCall::Cert(..) | RuntimeCall::Identity(..) | RuntimeCall::SmithsCert(..)
)
}
ProxyType::TransferOnly => {
matches!(c, Call::Balances(..) | Call::UniversalDividend(..))
matches!(
c,
RuntimeCall::Balances(..) | RuntimeCall::UniversalDividend(..)
)
}
ProxyType::CancelProxy => {
matches!(
c,
Call::Proxy(pallet_proxy::Call::reject_announcement { .. })
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
)
}
ProxyType::TechnicalCommitteePropose => {
matches!(
c,
Call::TechnicalCommittee(pallet_collective::Call::propose { .. })
RuntimeCall::TechnicalCommittee(pallet_collective::Call::propose { .. })
)
}
}
......@@ -260,8 +291,8 @@ common_runtime::pallets_config! {
}
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
}
}
......@@ -331,10 +362,10 @@ construct_runtime!(
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Call: From<C>,
RuntimeCall: From<C>,
{
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = Call;
type OverarchingCall = RuntimeCall;
}
// All of our runtimes share most of their Runtime API implementations.
......
......@@ -19,13 +19,13 @@ use crate::*;
pub struct MigrationsV400;
impl frame_support::traits::OnRuntimeUpgrade for MigrationsV400 {
fn on_runtime_upgrade() -> Weight {
let mut weight = 1_000_000_000; // Safety margin
let mut weight = Weight::from_ref_time(1_000_000_000); // Safety margin
type OldvalueType = AccountId;
pallet_membership::PendingMembership::<Runtime, Instance1>::translate_values(
|_: OldvalueType| {
weight += <Runtime as frame_system::Config>::DbWeight::get().write;
*weight.ref_time_mut() += <Runtime as frame_system::Config>::DbWeight::get().write;
Some(())
},
);
......@@ -34,12 +34,12 @@ impl frame_support::traits::OnRuntimeUpgrade for MigrationsV400 {
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
Ok(())
fn pre_upgrade() -> Result<frame_benchmarking::Vec<u8>, &'static str> {
Ok(Vec::new())
}
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: frame_benchmarking::Vec<u8>) -> Result<(), &'static str> {
Ok(())
}
}
......@@ -25,7 +25,8 @@ use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockWeights: frame_system::limits::BlockWeights = block_weights((WEIGHT_PER_SECOND * 2)
.set_proof_size(5 * 1024 * 1024), NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 42;
......
......@@ -92,15 +92,15 @@ fn test_remove_identity() {
None
));
System::assert_has_event(Event::Membership(
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipRevoked(4),
));
System::assert_has_event(Event::System(frame_system::Event::KilledAccount {
System::assert_has_event(RuntimeEvent::System(frame_system::Event::KilledAccount {
account: AccountKeyring::Dave.to_account_id(),
}));
System::assert_has_event(Event::Identity(pallet_identity::Event::IdtyRemoved {
idty_index: 4,
}));
System::assert_has_event(RuntimeEvent::Identity(
pallet_identity::Event::IdtyRemoved { idty_index: 4 },
));
});
}
#[test]
......@@ -116,27 +116,27 @@ fn test_remove_identity_after_one_ud() {
));
// Verify events
System::assert_has_event(Event::Membership(
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipRevoked(4),
));
System::assert_has_event(Event::Balances(pallet_balances::Event::Deposit {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
who: AccountKeyring::Dave.to_account_id(),
amount: 1_000,
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Endowed {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Endowed {
account: AccountKeyring::Dave.to_account_id(),
free_balance: 1_000,
}));
System::assert_has_event(Event::UniversalDividend(
System::assert_has_event(RuntimeEvent::UniversalDividend(
pallet_universal_dividend::Event::UdsAutoPaidAtRemoval {
count: 1,
total: 1_000,
who: AccountKeyring::Dave.to_account_id(),
},
));
System::assert_has_event(Event::Identity(pallet_identity::Event::IdtyRemoved {
idty_index: 4,
}));
System::assert_has_event(RuntimeEvent::Identity(
pallet_identity::Event::IdtyRemoved { idty_index: 4 },
));
// Verify state
assert!(Identity::identity(4).is_none());
......@@ -158,18 +158,18 @@ fn test_remove_smith_identity() {
None
));
// Verify events
System::assert_has_event(Event::SmithsMembership(
System::assert_has_event(RuntimeEvent::SmithsMembership(
pallet_membership::Event::MembershipRevoked(3),
));
System::assert_has_event(Event::AuthorityMembers(
System::assert_has_event(RuntimeEvent::AuthorityMembers(
pallet_authority_members::Event::MemberRemoved(3),
));
System::assert_has_event(Event::Membership(
System::assert_has_event(RuntimeEvent::Membership(
pallet_membership::Event::MembershipRevoked(3),
));
System::assert_has_event(Event::Identity(pallet_identity::Event::IdtyRemoved {
idty_index: 3,
}));
System::assert_has_event(RuntimeEvent::Identity(
pallet_identity::Event::IdtyRemoved { idty_index: 3 },
));
});
}
......@@ -188,14 +188,14 @@ fn test_create_new_account_with_insufficient_balance() {
400
));
System::assert_has_event(Event::System(frame_system::Event::NewAccount {
System::assert_has_event(RuntimeEvent::System(frame_system::Event::NewAccount {
account: AccountKeyring::Eve.to_account_id(),
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Endowed {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Endowed {
account: AccountKeyring::Eve.to_account_id(),
free_balance: 400,
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Transfer {
from: AccountKeyring::Alice.to_account_id(),
to: AccountKeyring::Eve.to_account_id(),
amount: 400,
......@@ -205,17 +205,17 @@ fn test_create_new_account_with_insufficient_balance() {
// to pay the "new account tax"
run_to_block(3);
System::assert_has_event(Event::Account(
System::assert_has_event(RuntimeEvent::Account(
pallet_duniter_account::Event::ForceDestroy {
who: AccountKeyring::Eve.to_account_id(),
balance: 400,
},
));
System::assert_has_event(Event::Balances(pallet_balances::Event::Deposit {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
who: Treasury::account_id(),
amount: 400,
}));
System::assert_has_event(Event::Treasury(pallet_treasury::Event::Deposit {
System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit {
value: 400,
}));
......@@ -242,14 +242,14 @@ fn test_create_new_account() {
500
));
//println!("{:#?}", System::events());
System::assert_has_event(Event::System(frame_system::Event::NewAccount {
System::assert_has_event(RuntimeEvent::System(frame_system::Event::NewAccount {
account: AccountKeyring::Eve.to_account_id(),
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Endowed {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Endowed {
account: AccountKeyring::Eve.to_account_id(),
free_balance: 500,
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Transfer {
from: AccountKeyring::Alice.to_account_id(),
to: AccountKeyring::Eve.to_account_id(),
amount: 500,
......@@ -259,15 +259,15 @@ fn test_create_new_account() {
// and new account tax should be collected and deposited in the treasury
run_to_block(3);
System::assert_has_event(Event::Balances(pallet_balances::Event::Withdraw {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Withdraw {
who: AccountKeyring::Eve.to_account_id(),
amount: 300,
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Deposit {
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit {
who: Treasury::account_id(),
amount: 300,
}));
System::assert_has_event(Event::Treasury(pallet_treasury::Event::Deposit {
System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit {
value: 300,
}));
......
[build-dependencies.substrate-wasm-builder]
git = 'https://github.com/duniter/substrate'
branch = 'duniter-substrate-v0.9.26'
branch = 'duniter-substrate-v0.9.32'
[package]
authors = ['Axiom-Team Developers <https://axiom-team.fr>']
......@@ -103,10 +103,10 @@ try-runtime = [
]
[dev-dependencies]
sp-consensus-vrf = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-finality-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-keyring = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26' }
sp-consensus-vrf = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
sp-finality-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
sp-keyring = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32' }
[dependencies]
# local
......@@ -132,43 +132,43 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
serde = { version = "1.0.101", optional = true, features = ["derive"] }
# substrate
frame-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', optional = true }
frame-try-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false, optional = true }
frame-executive = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', 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 }
frame-system-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', optional = true }
frame-system-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false}
pallet-atomic-swap = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-authorship = { 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-collective = { 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-im-online = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-offences = { 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-preimage = { 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-sudo = { 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-transaction-payment = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
pallet-transaction-payment-rpc-runtime-api = { 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 }
pallet-utility = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-api = { 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-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-block-builder = { 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-inherents = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-offchain = { 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-session = { 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 }
sp-transaction-pool = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
sp-version = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.26', default-features = false }
frame-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', optional = true }
frame-try-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false, optional = true }
frame-executive = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
frame-support = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
frame-system = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
frame-system-benchmarking = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', optional = true }
frame-system-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false}
pallet-atomic-swap = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-authorship = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-collective = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-im-online = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-offences = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-multisig = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-preimage = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-proxy = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-scheduler = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-sudo = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-timestamp = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-transaction-payment = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-treasury = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
pallet-utility = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-arithmetic = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-block-builder = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-inherents = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-offchain = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-std = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-transaction-pool = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-version = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
......@@ -103,7 +103,8 @@ pub fn native_version() -> NativeVersion {
/// Block type as expected by this runtime.
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckNonZeroSender<Runtime>,
......@@ -127,17 +128,42 @@ pub type Executive = frame_executive::Executive<
pub type TechnicalCommitteeInstance = Instance2;
#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
// Duniter
// NOTE: Make sure to prefix these with `common_runtime::` so
// the that path resolves correctly in the generated file.
[common_runtime::oneshot_account, OneshotAccount]
[common_runtime::universal_dividend, UniversalDividend]
[common_runtime::upgrade_origin, UpgradeOrigin]
// Substrate
[pallet_balances, Balances]
[frame_benchmarking::baseline, Baseline::<Runtime>]
[pallet_collective, TechnicalCommittee]
[pallet_im_online, ImOnline]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[frame_system, SystemBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_treasury, Treasury]
[pallet_utility, Utility]
);
}
pub struct BaseCallFilter;
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
impl Contains<RuntimeCall> for BaseCallFilter {
fn contains(call: &RuntimeCall) -> bool {
!matches!(
call,
Call::System(
RuntimeCall::System(
frame_system::Call::remark { .. } | frame_system::Call::remark_with_event { .. }
) | Call::Membership(
) | RuntimeCall::Membership(
pallet_membership::Call::claim_membership { .. }
| pallet_membership::Call::revoke_membership { .. }
) | Call::Session(_)
) | RuntimeCall::Session(_)
)
}
}
......@@ -167,23 +193,26 @@ impl Default for ProxyType {
Self::AlmostAny
}
}
impl frame_support::traits::InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::AlmostAny => {
// Some calls are never authorized from a proxied account
!matches!(
c,
Call::Cert(..) | Call::Identity(..) | Call::SmithsCert(..)
RuntimeCall::Cert(..) | RuntimeCall::Identity(..) | RuntimeCall::SmithsCert(..)
)
}
ProxyType::TransferOnly => {
matches!(c, Call::Balances(..) | Call::UniversalDividend(..))
matches!(
c,
RuntimeCall::Balances(..) | RuntimeCall::UniversalDividend(..)
)
}
ProxyType::CancelProxy => {
matches!(
c,
Call::Proxy(pallet_proxy::Call::reject_announcement { .. })
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
)
}
}
......@@ -192,8 +221,8 @@ impl frame_support::traits::InstanceFilter<Call> for ProxyType {
common_runtime::pallets_config! {
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
}
}
......@@ -260,10 +289,10 @@ construct_runtime!(
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Call: From<C>,
RuntimeCall: From<C>,
{
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = Call;
type OverarchingCall = RuntimeCall;
}
// All of our runtimes share most of their Runtime API implementations.
......
......@@ -25,7 +25,8 @@ use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockWeights: frame_system::limits::BlockWeights = block_weights((WEIGHT_PER_SECOND * 2)
.set_proof_size(5 * 1024 * 1024), NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 42;
......
[toolchain]
channel = "nightly-2022-04-20"
channel = "nightly-2022-10-09"
components = [ "rustfmt", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
......@@ -22,7 +22,7 @@ SPEC_DIR="${4:-resources}"
echo "CURRENCY=$CURRENCY"
# constants
DUNITER_IMAGE_TAG="sha-99fb985b"
DUNITER_IMAGE_TAG="sha-366af125"
# Clean and (re-)create working forders
rm -rf $WORK_DIR
......
......@@ -14,7 +14,7 @@ name = "xtask"
[dependencies]
anyhow = "1.0.32"
clap = { version = "3.0", features = ["derive"] }
clap = { version = "4.0", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "full", "bit-vec"] }
frame-metadata = "15.0.0"
graphql_client = "0.10.0"
......@@ -29,3 +29,4 @@ serde_json = "1.0"
tokio = { version = "1.15.0", features = ["macros"] }
version_check = "0.9.2"
version-compare = "0.0.11"
tera = { version = "1", default-features = false }
\ No newline at end of file
There are **{{ calls_counter }}** {{ category_name }} calls from **{{ pallets | length }}** pallets.
{% for pallet in pallets -%}
### {{ pallet.name }} - {{ pallet.index }}
{% for call in pallet.calls -%}
#### {{ call.name }} - {{ call.index }}
<details><summary><code>{{ call.name }}(
{%- for param in call.params -%}
{{ param.name }}{% if loop.last != true %}, {% endif %}
{%- endfor -%}
)</code></summary>
```rust
{% for param in call.params -%}
{{ param.name }}: {{ param.type_name }}
{% endfor -%}
```
</details>
{# replace markdown sytax in documentation breaking the final result #}
{{ call.documentation | replace(from="# WARNING:", to="WARNING:") }}
{% endfor -%}
{% endfor -%}
# Runtime calls
Calls are categorized according to the dispatch origin they require:
1. **User calls**: the dispatch origin for this kind of call must be signed by
the transactor. This is the only call category that can be submitted with an extrinsic.
1. **Root calls**: This kind of call requires a special origin that can only be invoked
through on-chain governance mechanisms.
1. **Inherent calls**: This kind of call is invoked by the author of the block itself
(usually automatically by the node).
1. **Disabled calls**: These calls can not be called directly, they are reserved for internal use by other runtime calls.
{% set pallets = user_calls_pallets -%}
{% set calls_counter = user_calls_counter -%}
{% set category_name = "user" -%}
## User calls
{% include "runtime-calls-category.md" %}
{% set pallets = root_calls_pallets -%}
{% set calls_counter = root_calls_counter -%}
{% set category_name = "root" -%}
## Root calls
{% include "runtime-calls-category.md" %}
{% set pallets = disabled_calls_pallets %}
{% set calls_counter = disabled_calls_counter %}
{% set category_name = "disabled" %}
## Disabled calls
{% include "runtime-calls-category.md" -%}
......@@ -17,15 +17,87 @@
use anyhow::{bail, Context, Result};
use codec::Decode;
use scale_info::form::PortableForm;
use serde::Serialize;
use std::{
fs::File,
io::{Read, Write},
};
use tera::Tera;
// consts
const CALLS_DOC_FILEPATH: &str = "docs/api/runtime-calls.md";
const TEMPLATES_GLOB: &str = "xtask/res/templates/*.md";
// define structs and implementations
type RuntimeCalls = Vec<Pallet>;
#[derive(Clone, Serialize)]
struct Pallet {
index: u8,
name: String,
calls: Vec<Call>,
}
impl Pallet {
fn new(
index: u8,
name: String,
scale_type_def: &scale_info::TypeDef<PortableForm>,
) -> Result<Self> {
if let scale_info::TypeDef::Variant(calls_enum) = scale_type_def {
Ok(Self {
index,
name,
calls: calls_enum.variants().iter().map(Into::into).collect(),
})
} else {
bail!("Invalid metadata")
}
}
}
#[derive(Clone, Serialize)]
struct Call {
documentation: String,
index: u8,
name: String,
params: Vec<CallParam>,
}
impl From<&scale_info::Variant<PortableForm>> for Call {
fn from(variant: &scale_info::Variant<PortableForm>) -> Self {
Self {
documentation: variant
.docs()
.iter()
.take_while(|line| !line.starts_with("# <weight>"))
.cloned()
.collect::<Vec<_>>()
.join("\n"),
index: variant.index(),
name: variant.name().to_owned(),
params: variant.fields().iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, Serialize)]
struct CallParam {
name: String,
type_name: String,
}
impl From<&scale_info::Field<PortableForm>> for CallParam {
fn from(field: &scale_info::Field<PortableForm>) -> Self {
Self {
name: field.name().cloned().unwrap_or_default(),
type_name: field.type_name().cloned().unwrap_or_default(),
}
}
}
enum CallCategory {
Disabled,
Inherent,
......@@ -81,65 +153,7 @@ impl CallCategory {
}
}
#[derive(Clone)]
struct Pallet {
index: u8,
name: String,
calls: Vec<Call>,
}
impl Pallet {
fn new(
index: u8,
name: String,
scale_type_def: &scale_info::TypeDef<PortableForm>,
) -> Result<Self> {
if let scale_info::TypeDef::Variant(calls_enum) = scale_type_def {
Ok(Self {
index,
name,
calls: calls_enum.variants().iter().map(Into::into).collect(),
})
} else {
bail!("Invalid metadata")
}
}
}
#[derive(Clone)]
struct Call {
docs: Vec<String>,
index: u8,
name: String,
params: Vec<CallParam>,
}
impl From<&scale_info::Variant<PortableForm>> for Call {
fn from(variant: &scale_info::Variant<PortableForm>) -> Self {
Self {
docs: variant.docs().to_vec(),
index: variant.index(),
name: variant.name().to_owned(),
params: variant.fields().iter().map(Into::into).collect(),
}
}
}
#[derive(Clone)]
struct CallParam {
name: String,
type_name: String,
}
impl From<&scale_info::Field<PortableForm>> for CallParam {
fn from(field: &scale_info::Field<PortableForm>) -> Self {
Self {
name: field.name().cloned().unwrap_or_default(),
type_name: field.type_name().cloned().unwrap_or_default(),
}
}
}
/// generate runtime calls documentation
pub(super) fn gen_calls_doc() -> Result<()> {
// Read metadata
let mut file = std::fs::File::open("resources/metadata.scale")
......@@ -192,7 +206,9 @@ fn get_calls_from_metadata_v14(
Ok(pallets)
}
/// use template to render markdown file with runtime calls documentation
fn print_runtime_calls(pallets: RuntimeCalls) -> String {
// init variables
let mut user_calls_counter = 0;
let user_calls_pallets: RuntimeCalls = pallets
.iter()
......@@ -245,109 +261,24 @@ fn print_runtime_calls(pallets: RuntimeCalls) -> String {
})
.collect();
let mut output = String::new();
output.push_str("# Runtime calls\n\n");
output.push_str("Calls are categorized according to the dispatch origin they require:\n\n");
output.push_str(
r#"1. User calls: the dispatch origin for this kind of call must be Signed by
the transactor. This is the only call category that can be submitted with an extrinsic.
"#,
);
output.push_str(
r#"1. Root calls: This kind of call requires a special origin that can only be invoked
through on-chain governance mechanisms.
"#,
);
output.push_str(
r#"1. Inherent calls: This kind of call is invoked by the author of the block itself
(usually automatically by the node).
"#,
);
output.push_str(
r#"1. Disabled calls: These calls are disabled for different reasons (to be documented).
"#,
);
output.push_str("\n\n## User calls\n\n");
output.push_str(&print_calls_category(
user_calls_counter,
"user",
user_calls_pallets,
));
output.push_str("\n\n## Root calls\n\n");
output.push_str(&print_calls_category(
root_calls_counter,
"root",
root_calls_pallets,
));
output.push_str("\n\n## Disabled calls\n\n");
output.push_str(&print_calls_category(
disabled_calls_counter,
"disabled",
disabled_calls_pallets,
));
output
}
fn print_calls_category(calls_counter: usize, category_name: &str, pallets: Vec<Pallet>) -> String {
let mut output = String::new();
output.push_str(&format!(
"There are **{}** {} calls organized in **{}** pallets.\n",
calls_counter,
category_name,
pallets.len()
));
for pallet in pallets {
output.push_str(&format!("\n### {}: {}\n\n", pallet.index, pallet.name));
for call in pallet.calls {
output.push_str(&format!(
"<details><summary>{}: {}({})</summary>\n<p>\n\n{}</p>\n</details>\n\n",
call.index,
call.name,
print_call_params(&call.params),
print_call_details(&call),
));
// compile template
let tera = match Tera::new(TEMPLATES_GLOB) {
Ok(t) => t,
Err(e) => {
println!("Parsing error(s): {}", e);
::std::process::exit(1);
}
}
output
}
};
fn print_call_details(call: &Call) -> String {
let mut output = String::new();
output.push_str(&format!("### Index\n\n`{}`\n\n", call.index));
output.push_str(&format!(
"### Documentation\n\n{}\n\n",
call.docs
.iter()
.take_while(|line| !line.starts_with("# <weight>"))
.cloned()
.collect::<Vec<_>>()
.join("\n")
));
if !call.params.is_empty() {
output.push_str("### Types of parameters\n\n```rust\n");
output.push_str(
&call
.params
.iter()
.map(|param| format!("{}: {}", param.name, param.type_name))
.collect::<Vec<_>>()
.join(",\n"),
);
output.push_str("\n```\n\n");
}
output
}
// fills tera context for rendering
let mut context = tera::Context::new();
context.insert("user_calls_counter", &user_calls_counter);
context.insert("user_calls_pallets", &user_calls_pallets);
context.insert("root_calls_counter", &root_calls_counter);
context.insert("root_calls_pallets", &root_calls_pallets);
context.insert("disabled_calls_counter", &disabled_calls_counter);
context.insert("disabled_calls_pallets", &disabled_calls_pallets);
fn print_call_params(call_params: &[CallParam]) -> String {
call_params
.iter()
.map(|param| param.name.clone())
.collect::<Vec<_>>()
.join(", ")
tera.render("runtime-calls.md", &context)
.expect("template error")
}
......@@ -42,10 +42,10 @@ enum DuniterXTaskCommand {
GenCallsDoc,
/// Inject runtime code in raw specs
InjectRuntimeCode {
#[clap(short, long, parse(from_os_str))]
#[clap(short, long)]
/// Runtime filepath
runtime: PathBuf,
#[clap(short = 's', long, parse(from_os_str))]
#[clap(short = 's', long)]
/// Raw spec filepath
raw_spec: PathBuf,
},
......@@ -61,7 +61,7 @@ async fn main() -> Result<()> {
let args = DuniterXTask::parse();
if !version_check::is_min_version(MIN_RUST_VERSION).unwrap_or(false)
&& exec_should_success(Command::new("rustup").args(&["update", "stable"])).is_err()
&& exec_should_success(Command::new("rustup").args(["update", "stable"])).is_err()
{
eprintln!(
"Duniter requires stable Rust {} or higher. If you installed the Rust toolchain via rustup, please execute the command `rustup update stable`.",
......@@ -125,7 +125,7 @@ fn inject_runtime_code(raw_spec: &Path, runtime: &Path) -> Result<()> {
.with_context(|| "invalid raw spec file")?
.insert(
CODE_KEY.to_owned(),
serde_json::Value::String(unsafe { std::mem::transmute(hex_runtime_code) }),
serde_json::Value::String(hex_runtime_code),
);
// Write modified raw specs
......@@ -139,16 +139,16 @@ fn inject_runtime_code(raw_spec: &Path, runtime: &Path) -> Result<()> {
}
fn build(_production: bool) -> Result<()> {
exec_should_success(Command::new("cargo").args(&["clean", "-p", "duniter"]))?;
exec_should_success(Command::new("cargo").args(&["build", "--locked"]))?;
exec_should_success(Command::new("mkdir").args(&["build"]))?;
exec_should_success(Command::new("mv").args(&["target/debug/duniter", "build/duniter"]))?;
exec_should_success(Command::new("cargo").args(["clean", "-p", "duniter"]))?;
exec_should_success(Command::new("cargo").args(["build", "--locked"]))?;
exec_should_success(Command::new("mkdir").args(["build"]))?;
exec_should_success(Command::new("mv").args(["target/debug/duniter", "build/duniter"]))?;
Ok(())
}
fn test() -> Result<()> {
exec_should_success(Command::new("cargo").args(&[
exec_should_success(Command::new("cargo").args([
"test",
"--workspace",
"--exclude",
......