The latest Substrate Node Template v3 compiled from Substrate (#160)
parent
8370ddd69c
commit
0a0a91d578
|
@ -1,22 +1,16 @@
|
||||||
root = true
|
root = true
|
||||||
[*.rs]
|
|
||||||
indent_style=tab
|
[*]
|
||||||
indent_size=tab
|
indent_style=space
|
||||||
tab_width=4
|
indent_size=2
|
||||||
|
tab_width=2
|
||||||
end_of_line=lf
|
end_of_line=lf
|
||||||
charset=utf-8
|
charset=utf-8
|
||||||
trim_trailing_whitespace=true
|
trim_trailing_whitespace=true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{rs,toml}]
|
||||||
|
indent_style=tab
|
||||||
|
indent_size=tab
|
||||||
|
tab_width=4
|
||||||
max_line_length=100
|
max_line_length=100
|
||||||
insert_final_newline=true
|
|
||||||
|
|
||||||
[*.yml]
|
|
||||||
indent_style=space
|
|
||||||
indent_size=2
|
|
||||||
tab_width=8
|
|
||||||
end_of_line=lf
|
|
||||||
|
|
||||||
[*.sh]
|
|
||||||
indent_style=space
|
|
||||||
indent_size=2
|
|
||||||
tab_width=8
|
|
||||||
end_of_line=lf
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,8 @@
|
||||||
[profile.release]
|
|
||||||
panic = 'unwind'
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
'node',
|
'node',
|
||||||
'pallets/*',
|
'pallets/*',
|
||||||
'runtime',
|
'runtime',
|
||||||
]
|
]
|
||||||
|
[profile.release]
|
||||||
|
panic = 'unwind'
|
||||||
|
|
|
@ -22,11 +22,8 @@ substrate-build-script-utils = '3.0.0'
|
||||||
jsonrpc-core = '15.1.0'
|
jsonrpc-core = '15.1.0'
|
||||||
structopt = '0.3.8'
|
structopt = '0.3.8'
|
||||||
|
|
||||||
# local dependencies
|
|
||||||
node-template-runtime = { path = '../runtime', version = '3.0.0' }
|
|
||||||
|
|
||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
frame-benchmarking = '3.0.0'
|
frame-benchmarking = '3.1.0'
|
||||||
frame-benchmarking-cli = '3.0.0'
|
frame-benchmarking-cli = '3.0.0'
|
||||||
pallet-transaction-payment-rpc = '3.0.0'
|
pallet-transaction-payment-rpc = '3.0.0'
|
||||||
sc-basic-authorship = '0.9.0'
|
sc-basic-authorship = '0.9.0'
|
||||||
|
@ -40,6 +37,7 @@ sc-keystore = '3.0.0'
|
||||||
sc-rpc = '3.0.0'
|
sc-rpc = '3.0.0'
|
||||||
sc-rpc-api = '0.9.0'
|
sc-rpc-api = '0.9.0'
|
||||||
sc-service = { features = ['wasmtime'], version = '0.9.0' }
|
sc-service = { features = ['wasmtime'], version = '0.9.0' }
|
||||||
|
sc-telemetry = '3.0.0'
|
||||||
sc-transaction-pool = '3.0.0'
|
sc-transaction-pool = '3.0.0'
|
||||||
sp-api = '3.0.0'
|
sp-api = '3.0.0'
|
||||||
sp-block-builder = '3.0.0'
|
sp-block-builder = '3.0.0'
|
||||||
|
@ -53,6 +51,9 @@ sp-runtime = '3.0.0'
|
||||||
sp-transaction-pool = '3.0.0'
|
sp-transaction-pool = '3.0.0'
|
||||||
substrate-frame-rpc-system = '3.0.0'
|
substrate-frame-rpc-system = '3.0.0'
|
||||||
|
|
||||||
|
# local dependencies
|
||||||
|
node-template-runtime = { path = '../runtime', version = '3.0.0' }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
runtime-benchmarks = ['node-template-runtime/runtime-benchmarks']
|
runtime-benchmarks = ['node-template-runtime/runtime-benchmarks']
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn development_config() -> Result<ChainSpec, String> {
|
pub fn development_config() -> Result<ChainSpec, String> {
|
||||||
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?;
|
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
|
||||||
|
|
||||||
Ok(ChainSpec::from_genesis(
|
Ok(ChainSpec::from_genesis(
|
||||||
// Name
|
// Name
|
||||||
|
@ -78,7 +78,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_testnet_config() -> Result<ChainSpec, String> {
|
pub fn local_testnet_config() -> Result<ChainSpec, String> {
|
||||||
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?;
|
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
|
||||||
|
|
||||||
Ok(ChainSpec::from_genesis(
|
Ok(ChainSpec::from_genesis(
|
||||||
// Name
|
// Name
|
||||||
|
|
|
@ -8,7 +8,7 @@ use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
|
||||||
use sp_inherents::InherentDataProviders;
|
use sp_inherents::InherentDataProviders;
|
||||||
use sc_executor::native_executor_instance;
|
use sc_executor::native_executor_instance;
|
||||||
pub use sc_executor::NativeExecutor;
|
pub use sc_executor::NativeExecutor;
|
||||||
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
|
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
|
||||||
use sc_finality_grandpa::SharedVoterState;
|
use sc_finality_grandpa::SharedVoterState;
|
||||||
use sc_keystore::LocalKeystore;
|
use sc_keystore::LocalKeystore;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
||||||
return Err(ServiceError::Other(
|
return Err(ServiceError::Other(
|
||||||
format!("Remote Keystores are not supported.")))
|
format!("Remote Keystores are not supported.")))
|
||||||
}
|
}
|
||||||
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
|
let inherent_data_providers = InherentDataProviders::new();
|
||||||
|
|
||||||
let (client, backend, keystore_container, task_manager) =
|
let (client, backend, keystore_container, task_manager) =
|
||||||
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
|
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
|
||||||
|
@ -59,7 +59,9 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
||||||
);
|
);
|
||||||
|
|
||||||
let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
|
let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
|
||||||
client.clone(), &(client.clone() as Arc<_>), select_chain.clone(),
|
client.clone(),
|
||||||
|
&(client.clone() as Arc<_>),
|
||||||
|
select_chain.clone(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
|
let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
|
||||||
|
@ -78,7 +80,13 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(sc_service::PartialComponents {
|
Ok(sc_service::PartialComponents {
|
||||||
client, backend, task_manager, import_queue, keystore_container, select_chain, transaction_pool,
|
client,
|
||||||
|
backend,
|
||||||
|
task_manager,
|
||||||
|
import_queue,
|
||||||
|
keystore_container,
|
||||||
|
select_chain,
|
||||||
|
transaction_pool,
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
other: (aura_block_import, grandpa_link),
|
other: (aura_block_import, grandpa_link),
|
||||||
})
|
})
|
||||||
|
@ -94,7 +102,13 @@ fn remote_keystore(_url: &String) -> Result<Arc<LocalKeystore>, &'static str> {
|
||||||
/// Builds a new service for a full client.
|
/// Builds a new service for a full client.
|
||||||
pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError> {
|
pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||||
let sc_service::PartialComponents {
|
let sc_service::PartialComponents {
|
||||||
client, backend, mut task_manager, import_queue, mut keystore_container, select_chain, transaction_pool,
|
client,
|
||||||
|
backend,
|
||||||
|
mut task_manager,
|
||||||
|
import_queue,
|
||||||
|
mut keystore_container,
|
||||||
|
select_chain,
|
||||||
|
transaction_pool,
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
other: (block_import, grandpa_link),
|
other: (block_import, grandpa_link),
|
||||||
} = new_partial(&config)?;
|
} = new_partial(&config)?;
|
||||||
|
@ -168,7 +182,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if role.is_authority() {
|
if role.is_authority() {
|
||||||
let proposer = sc_basic_authorship::ProposerFactory::new(
|
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
|
||||||
task_manager.spawn_handle(),
|
task_manager.spawn_handle(),
|
||||||
client.clone(),
|
client.clone(),
|
||||||
transaction_pool,
|
transaction_pool,
|
||||||
|
@ -178,12 +192,12 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||||
let can_author_with =
|
let can_author_with =
|
||||||
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
|
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
|
||||||
|
|
||||||
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _, _>(
|
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _,_>(
|
||||||
sc_consensus_aura::slot_duration(&*client)?,
|
sc_consensus_aura::slot_duration(&*client)?,
|
||||||
client.clone(),
|
client.clone(),
|
||||||
select_chain,
|
select_chain,
|
||||||
block_import,
|
block_import,
|
||||||
proposer,
|
proposer_factory,
|
||||||
network.clone(),
|
network.clone(),
|
||||||
inherent_data_providers.clone(),
|
inherent_data_providers.clone(),
|
||||||
force_authoring,
|
force_authoring,
|
||||||
|
@ -226,10 +240,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||||
config: grandpa_config,
|
config: grandpa_config,
|
||||||
link: grandpa_link,
|
link: grandpa_link,
|
||||||
network,
|
network,
|
||||||
telemetry_on_connect: telemetry_connection_notifier.map(|x| x.on_connect_stream()),
|
|
||||||
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
|
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
|
||||||
prometheus_registry,
|
prometheus_registry,
|
||||||
shared_voter_state: SharedVoterState::empty(),
|
shared_voter_state: SharedVoterState::empty(),
|
||||||
|
telemetry_on_connect: telemetry_connection_notifier.map(|x| x.on_connect_stream()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// the GRANDPA voter task is considered infallible, i.e.
|
// the GRANDPA voter task is considered infallible, i.e.
|
||||||
|
|
|
@ -5,22 +5,18 @@ edition = '2018'
|
||||||
homepage = 'https://substrate.dev'
|
homepage = 'https://substrate.dev'
|
||||||
license = 'Unlicense'
|
license = 'Unlicense'
|
||||||
name = 'pallet-template'
|
name = 'pallet-template'
|
||||||
|
readme = 'README.md'
|
||||||
repository = 'https://github.com/substrate-developer-hub/substrate-node-template/'
|
repository = 'https://github.com/substrate-developer-hub/substrate-node-template/'
|
||||||
version = '3.0.0'
|
version = '3.0.0'
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ['x86_64-unknown-linux-gnu']
|
targets = ['x86_64-unknown-linux-gnu']
|
||||||
|
|
||||||
# alias "parity-scale-code" to "codec"
|
|
||||||
[dependencies.codec]
|
|
||||||
default-features = false
|
|
||||||
features = ['derive']
|
|
||||||
package = 'parity-scale-codec'
|
|
||||||
version = '2.0.0'
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
frame-support = { default-features = false, version = '3.0.0' }
|
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' }
|
||||||
frame-system = { default-features = false, version = '3.0.0' }
|
frame-system = { default-features = false, version = '3.0.0' }
|
||||||
|
frame-support = { default-features = false, version = '3.0.0' }
|
||||||
|
frame-benchmarking = { default-features = false, optional = true, version = '3.1.0' }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0.119" }
|
serde = { version = "1.0.119" }
|
||||||
|
@ -31,7 +27,12 @@ sp-runtime = { default-features = false, version = '3.0.0' }
|
||||||
[features]
|
[features]
|
||||||
default = ['std']
|
default = ['std']
|
||||||
std = [
|
std = [
|
||||||
'codec/std',
|
'codec/std',
|
||||||
'frame-support/std',
|
'frame-support/std',
|
||||||
'frame-system/std',
|
'frame-system/std',
|
||||||
|
'frame-benchmarking/std',
|
||||||
]
|
]
|
||||||
|
runtime-benchmarks = ['frame-benchmarking']
|
||||||
|
# Note: frame-support `try-runtime` feature is released after v3.
|
||||||
|
# Uncomment the following line when `frame-support` version > `3.0.0`.
|
||||||
|
# try-runtime = ['frame-support/try-runtime']
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
License: Unlicense
|
|
@ -0,0 +1,24 @@
|
||||||
|
//! Benchmarking setup for pallet-template
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use frame_system::RawOrigin;
|
||||||
|
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
|
||||||
|
#[allow(unused)]
|
||||||
|
use crate::Module as Template;
|
||||||
|
|
||||||
|
benchmarks! {
|
||||||
|
do_something {
|
||||||
|
let s in 0 .. 100;
|
||||||
|
let caller: T::AccountId = whitelisted_caller();
|
||||||
|
}: _(RawOrigin::Signed(caller), s)
|
||||||
|
verify {
|
||||||
|
assert_eq!(Something::<T>::get(), Some(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_benchmark_test_suite!(
|
||||||
|
Template,
|
||||||
|
crate::mock::new_test_ext(),
|
||||||
|
crate::mock::Test,
|
||||||
|
);
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
/// Edit this file to define custom logic or remove it if it is not needed.
|
/// Edit this file to define custom logic or remove it if it is not needed.
|
||||||
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
|
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
|
||||||
/// https://substrate.dev/docs/en/knowledgebase/runtime/frame
|
/// <https://substrate.dev/docs/en/knowledgebase/runtime/frame>
|
||||||
|
|
||||||
use frame_support::{decl_module, decl_storage, decl_event, decl_error, dispatch, traits::Get};
|
pub use pallet::*;
|
||||||
use frame_system::ensure_signed;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mock;
|
mod mock;
|
||||||
|
@ -13,89 +12,94 @@ mod mock;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
/// Configure the pallet by specifying the parameters and types on which it depends.
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
pub trait Config: frame_system::Config {
|
mod benchmarking;
|
||||||
/// Because this pallet emits events, it depends on the runtime's definition of an event.
|
|
||||||
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The pallet's runtime storage items.
|
#[frame_support::pallet]
|
||||||
// https://substrate.dev/docs/en/knowledgebase/runtime/storage
|
pub mod pallet {
|
||||||
decl_storage! {
|
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
|
||||||
// A unique name is used to ensure that the pallet's storage items are isolated.
|
use frame_system::pallet_prelude::*;
|
||||||
// This name may be updated, but each pallet in the runtime must use a unique name.
|
|
||||||
// ---------------------------------vvvvvvvvvvvvvv
|
/// Configure the pallet by specifying the parameters and types on which it depends.
|
||||||
trait Store for Module<T: Config> as TemplateModule {
|
#[pallet::config]
|
||||||
// Learn more about declaring storage items:
|
pub trait Config: frame_system::Config {
|
||||||
// https://substrate.dev/docs/en/knowledgebase/runtime/storage#declaring-storage-items
|
/// Because this pallet emits events, it depends on the runtime's definition of an event.
|
||||||
Something get(fn something): Option<u32>;
|
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Pallets use events to inform users when important changes are made.
|
#[pallet::pallet]
|
||||||
// https://substrate.dev/docs/en/knowledgebase/runtime/events
|
#[pallet::generate_store(pub(super) trait Store)]
|
||||||
decl_event!(
|
pub struct Pallet<T>(_);
|
||||||
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId {
|
|
||||||
|
// The pallet's runtime storage items.
|
||||||
|
// https://substrate.dev/docs/en/knowledgebase/runtime/storage
|
||||||
|
#[pallet::storage]
|
||||||
|
#[pallet::getter(fn something)]
|
||||||
|
// Learn more about declaring storage items:
|
||||||
|
// https://substrate.dev/docs/en/knowledgebase/runtime/storage#declaring-storage-items
|
||||||
|
pub type Something<T> = StorageValue<_, u32>;
|
||||||
|
|
||||||
|
// Pallets use events to inform users when important changes are made.
|
||||||
|
// https://substrate.dev/docs/en/knowledgebase/runtime/events
|
||||||
|
#[pallet::event]
|
||||||
|
#[pallet::metadata(T::AccountId = "AccountId")]
|
||||||
|
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||||
|
pub enum Event<T: Config> {
|
||||||
/// Event documentation should end with an array that provides descriptive names for event
|
/// Event documentation should end with an array that provides descriptive names for event
|
||||||
/// parameters. [something, who]
|
/// parameters. [something, who]
|
||||||
SomethingStored(u32, AccountId),
|
SomethingStored(u32, T::AccountId),
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
// Errors inform users that something went wrong.
|
// Errors inform users that something went wrong.
|
||||||
decl_error! {
|
#[pallet::error]
|
||||||
pub enum Error for Module<T: Config> {
|
pub enum Error<T> {
|
||||||
/// Error names should be descriptive.
|
/// Error names should be descriptive.
|
||||||
NoneValue,
|
NoneValue,
|
||||||
/// Errors should have helpful documentation associated with them.
|
/// Errors should have helpful documentation associated with them.
|
||||||
StorageOverflow,
|
StorageOverflow,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Dispatchable functions allows users to interact with the pallet and invoke state changes.
|
#[pallet::hooks]
|
||||||
// These functions materialize as "extrinsics", which are often compared to transactions.
|
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||||
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
|
|
||||||
decl_module! {
|
|
||||||
pub struct Module<T: Config> for enum Call where origin: T::Origin {
|
|
||||||
// Errors must be initialized if they are used by the pallet.
|
|
||||||
type Error = Error<T>;
|
|
||||||
|
|
||||||
// Events must be initialized if they are used by the pallet.
|
|
||||||
fn deposit_event() = default;
|
|
||||||
|
|
||||||
|
// Dispatchable functions allows users to interact with the pallet and invoke state changes.
|
||||||
|
// These functions materialize as "extrinsics", which are often compared to transactions.
|
||||||
|
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
|
||||||
|
#[pallet::call]
|
||||||
|
impl<T:Config> Pallet<T> {
|
||||||
/// An example dispatchable that takes a singles value as a parameter, writes the value to
|
/// An example dispatchable that takes a singles value as a parameter, writes the value to
|
||||||
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
|
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
|
||||||
#[weight = 10_000 + T::DbWeight::get().writes(1)]
|
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
|
||||||
pub fn do_something(origin, something: u32) -> dispatch::DispatchResult {
|
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResultWithPostInfo {
|
||||||
// Check that the extrinsic was signed and get the signer.
|
// Check that the extrinsic was signed and get the signer.
|
||||||
// This function will return an error if the extrinsic is not signed.
|
// This function will return an error if the extrinsic is not signed.
|
||||||
// https://substrate.dev/docs/en/knowledgebase/runtime/origin
|
// https://substrate.dev/docs/en/knowledgebase/runtime/origin
|
||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
// Update storage.
|
// Update storage.
|
||||||
Something::put(something);
|
<Something<T>>::put(something);
|
||||||
|
|
||||||
// Emit an event.
|
// Emit an event.
|
||||||
Self::deposit_event(RawEvent::SomethingStored(something, who));
|
Self::deposit_event(Event::SomethingStored(something, who));
|
||||||
// Return a successful DispatchResult
|
// Return a successful DispatchResultWithPostInfo
|
||||||
Ok(())
|
Ok(().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An example dispatchable that may throw a custom error.
|
/// An example dispatchable that may throw a custom error.
|
||||||
#[weight = 10_000 + T::DbWeight::get().reads_writes(1,1)]
|
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
|
||||||
pub fn cause_error(origin) -> dispatch::DispatchResult {
|
pub fn cause_error(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||||
let _who = ensure_signed(origin)?;
|
let _who = ensure_signed(origin)?;
|
||||||
|
|
||||||
// Read a value from storage.
|
// Read a value from storage.
|
||||||
match Something::get() {
|
match <Something<T>>::get() {
|
||||||
// Return an error if the value has not been set.
|
// Return an error if the value has not been set.
|
||||||
None => Err(Error::<T>::NoneValue)?,
|
None => Err(Error::<T>::NoneValue)?,
|
||||||
Some(old) => {
|
Some(old) => {
|
||||||
// Increment the value read from storage; will error in the event of overflow.
|
// Increment the value read from storage; will error in the event of overflow.
|
||||||
let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;
|
let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;
|
||||||
// Update the value in storage with the incremented result.
|
// Update the value in storage with the incremented result.
|
||||||
Something::put(new);
|
<Something<T>>::put(new);
|
||||||
Ok(())
|
Ok(().into())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,19 +13,10 @@ targets = ['x86_64-unknown-linux-gnu']
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
substrate-wasm-builder = '4.0.0'
|
substrate-wasm-builder = '4.0.0'
|
||||||
|
|
||||||
# alias "parity-scale-code" to "codec"
|
|
||||||
[dependencies.codec]
|
|
||||||
default-features = false
|
|
||||||
features = ['derive']
|
|
||||||
package = 'parity-scale-codec'
|
|
||||||
version = '2.0.0'
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0' }
|
||||||
hex-literal = { optional = true, version = '0.3.1' }
|
hex-literal = { optional = true, version = '0.3.1' }
|
||||||
serde = { features = ['derive'], optional = true, version = '1.0.119' }
|
serde = { version = "1.0.119", optional = true, features = ["derive"] }
|
||||||
|
|
||||||
# local dependencies
|
|
||||||
pallet-template = { path = '../pallets/template', default-features = false, version = '3.0.0' }
|
|
||||||
|
|
||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
frame-benchmarking = { default-features = false, optional = true, version = '3.0.0' }
|
frame-benchmarking = { default-features = false, optional = true, version = '3.0.0' }
|
||||||
|
@ -54,25 +45,28 @@ sp-std = { default-features = false, version = '3.0.0' }
|
||||||
sp-transaction-pool = { default-features = false, version = '3.0.0' }
|
sp-transaction-pool = { default-features = false, version = '3.0.0' }
|
||||||
sp-version = { default-features = false, version = '3.0.0' }
|
sp-version = { default-features = false, version = '3.0.0' }
|
||||||
|
|
||||||
|
# local dependencies
|
||||||
|
pallet-template = { default-features = false, path = '../pallets/template', version = '3.0.0' }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ['std']
|
default = ['std']
|
||||||
runtime-benchmarks = [
|
runtime-benchmarks = [
|
||||||
'hex-literal',
|
|
||||||
'frame-benchmarking',
|
'frame-benchmarking',
|
||||||
'frame-support/runtime-benchmarks',
|
'frame-support/runtime-benchmarks',
|
||||||
'frame-system-benchmarking',
|
'frame-system-benchmarking',
|
||||||
'frame-system/runtime-benchmarks',
|
'frame-system/runtime-benchmarks',
|
||||||
|
'hex-literal',
|
||||||
'pallet-balances/runtime-benchmarks',
|
'pallet-balances/runtime-benchmarks',
|
||||||
|
'pallet-template/runtime-benchmarks',
|
||||||
'pallet-timestamp/runtime-benchmarks',
|
'pallet-timestamp/runtime-benchmarks',
|
||||||
'sp-runtime/runtime-benchmarks',
|
'sp-runtime/runtime-benchmarks',
|
||||||
]
|
]
|
||||||
std = [
|
std = [
|
||||||
'codec/std',
|
'codec/std',
|
||||||
'serde',
|
|
||||||
'frame-executive/std',
|
'frame-executive/std',
|
||||||
'frame-support/std',
|
'frame-support/std',
|
||||||
'frame-system/std',
|
|
||||||
'frame-system-rpc-runtime-api/std',
|
'frame-system-rpc-runtime-api/std',
|
||||||
|
'frame-system/std',
|
||||||
'pallet-aura/std',
|
'pallet-aura/std',
|
||||||
'pallet-balances/std',
|
'pallet-balances/std',
|
||||||
'pallet-grandpa/std',
|
'pallet-grandpa/std',
|
||||||
|
@ -80,8 +74,9 @@ std = [
|
||||||
'pallet-sudo/std',
|
'pallet-sudo/std',
|
||||||
'pallet-template/std',
|
'pallet-template/std',
|
||||||
'pallet-timestamp/std',
|
'pallet-timestamp/std',
|
||||||
'pallet-transaction-payment/std',
|
|
||||||
'pallet-transaction-payment-rpc-runtime-api/std',
|
'pallet-transaction-payment-rpc-runtime-api/std',
|
||||||
|
'pallet-transaction-payment/std',
|
||||||
|
'serde',
|
||||||
'sp-api/std',
|
'sp-api/std',
|
||||||
'sp-block-builder/std',
|
'sp-block-builder/std',
|
||||||
'sp-consensus-aura/std',
|
'sp-consensus-aura/std',
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use substrate_wasm_builder::WasmBuilder;
|
use substrate_wasm_builder::WasmBuilder;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
WasmBuilder::new()
|
WasmBuilder::new()
|
||||||
.with_current_project()
|
.with_current_project()
|
||||||
.import_memory()
|
.export_heap_base()
|
||||||
.export_heap_base()
|
.import_memory()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use sp_runtime::{
|
||||||
transaction_validity::{TransactionValidity, TransactionSource},
|
transaction_validity::{TransactionValidity, TransactionSource},
|
||||||
};
|
};
|
||||||
use sp_runtime::traits::{
|
use sp_runtime::traits::{
|
||||||
AccountIdLookup, BlakeTwo256, Block as BlockT, Verify, IdentifyAccount, NumberFor,
|
BlakeTwo256, Block as BlockT, AccountIdLookup, Verify, IdentifyAccount, NumberFor,
|
||||||
};
|
};
|
||||||
use sp_api::impl_runtime_apis;
|
use sp_api::impl_runtime_apis;
|
||||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||||
|
@ -92,17 +92,23 @@ pub mod opaque {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To learn more about runtime versioning and what each of the following value means:
|
||||||
|
// https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning
|
||||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||||
spec_name: create_runtime_str!("node-template"),
|
spec_name: create_runtime_str!("node-template"),
|
||||||
impl_name: create_runtime_str!("node-template"),
|
impl_name: create_runtime_str!("node-template"),
|
||||||
authoring_version: 1,
|
authoring_version: 1,
|
||||||
|
// The version of the runtime specification. A full node will not attempt to use its native
|
||||||
|
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
|
||||||
|
// `spec_version`, and `authoring_version` are the same between Wasm and native.
|
||||||
|
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
|
||||||
|
// the compatible custom types.
|
||||||
spec_version: 100,
|
spec_version: 100,
|
||||||
impl_version: 1,
|
impl_version: 1,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
transaction_version: 1,
|
transaction_version: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// This determines the average expected block time that we are targeting.
|
/// This determines the average expected block time that we are targeting.
|
||||||
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
|
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
|
||||||
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
|
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
|
||||||
|
@ -259,7 +265,7 @@ impl pallet_sudo::Config for Runtime {
|
||||||
type Call = Call;
|
type Call = Call;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configure the template pallet in pallets/template.
|
/// Configure the pallet-template in pallets/template.
|
||||||
impl pallet_template::Config for Runtime {
|
impl pallet_template::Config for Runtime {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
}
|
}
|
||||||
|
@ -279,7 +285,7 @@ construct_runtime!(
|
||||||
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
TransactionPayment: pallet_transaction_payment::{Module, Storage},
|
TransactionPayment: pallet_transaction_payment::{Module, Storage},
|
||||||
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
|
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
|
||||||
// Include the custom logic from the template pallet in the runtime.
|
// Include the custom logic from the pallet-template in the runtime.
|
||||||
TemplateModule: pallet_template::{Module, Call, Storage, Event<T>},
|
TemplateModule: pallet_template::{Module, Call, Storage, Event<T>},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -324,7 +330,7 @@ impl_runtime_apis! {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_block(block: Block) {
|
fn execute_block(block: Block) {
|
||||||
Executive::execute_block(block)
|
Executive::execute_block(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize_block(header: &<Block as BlockT>::Header) {
|
fn initialize_block(header: &<Block as BlockT>::Header) {
|
||||||
|
@ -347,8 +353,7 @@ impl_runtime_apis! {
|
||||||
Executive::finalize_block()
|
Executive::finalize_block()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inherent_extrinsics(data: sp_inherents::InherentData) ->
|
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||||
Vec<<Block as BlockT>::Extrinsic> {
|
|
||||||
data.create_extrinsics()
|
data.create_extrinsics()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,8 +438,7 @@ impl_runtime_apis! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
|
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
|
||||||
for Runtime {
|
|
||||||
fn query_info(
|
fn query_info(
|
||||||
uxt: <Block as BlockT>::Extrinsic,
|
uxt: <Block as BlockT>::Extrinsic,
|
||||||
len: u32,
|
len: u32,
|
||||||
|
@ -456,25 +460,20 @@ impl_runtime_apis! {
|
||||||
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
|
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
|
||||||
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
|
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
|
||||||
|
|
||||||
use frame_system_benchmarking::Module as SystemBench;
|
use frame_system_benchmarking::Pallet as SystemBench;
|
||||||
impl frame_system_benchmarking::Config for Runtime {}
|
impl frame_system_benchmarking::Config for Runtime {}
|
||||||
|
|
||||||
let whitelist: Vec<TrackedStorageKey> = vec![
|
let whitelist: Vec<TrackedStorageKey> = vec![
|
||||||
// Block Number
|
// Block Number
|
||||||
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac")
|
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
|
||||||
.to_vec().into(),
|
|
||||||
// Total Issuance
|
// Total Issuance
|
||||||
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80")
|
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
|
||||||
.to_vec().into(),
|
|
||||||
// Execution Phase
|
// Execution Phase
|
||||||
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a")
|
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
|
||||||
.to_vec().into(),
|
|
||||||
// Event Count
|
// Event Count
|
||||||
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850")
|
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
|
||||||
.to_vec().into(),
|
|
||||||
// System Events
|
// System Events
|
||||||
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7")
|
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
|
||||||
.to_vec().into(),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut batches = Vec::<BenchmarkBatch>::new();
|
let mut batches = Vec::<BenchmarkBatch>::new();
|
||||||
|
@ -483,6 +482,7 @@ impl_runtime_apis! {
|
||||||
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
|
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
|
||||||
add_benchmark!(params, batches, pallet_balances, Balances);
|
add_benchmark!(params, batches, pallet_balances, Balances);
|
||||||
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
|
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
|
||||||
|
add_benchmark!(params, batches, pallet_template, TemplateModule);
|
||||||
|
|
||||||
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
|
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
|
||||||
Ok(batches)
|
Ok(batches)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# This script meant to be run on Unix/Linux based systems
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "*** Start Substrate node template ***"
|
echo "*** Start Substrate node template ***"
|
||||||
|
@ -7,4 +7,4 @@ echo "*** Start Substrate node template ***"
|
||||||
cd $(dirname ${BASH_SOURCE[0]})/..
|
cd $(dirname ${BASH_SOURCE[0]})/..
|
||||||
|
|
||||||
docker-compose down --remove-orphans
|
docker-compose down --remove-orphans
|
||||||
docker-compose run --rm --service-ports dev $@
|
docker-compose run --rm --service-ports dev $@
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# This script meant to be run on Unix/Linux based systems
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "*** Initializing WASM build environment"
|
||||||
|
|
||||||
|
if [ -z $CI_PROJECT_NAME ] ; then
|
||||||
|
rustup update nightly
|
||||||
|
rustup update stable
|
||||||
|
fi
|
||||||
|
|
||||||
|
rustup target add wasm32-unknown-unknown --toolchain nightly
|
Loading…
Reference in New Issue