-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it actually work #2
Changes from all commits
48ffb18
ad9406f
032455b
5bd00f9
6b01e20
408435c
94c5cbf
54c52c2
bd67b87
8939fd7
df8874c
e06f5ba
8d6cf6b
5fbe977
c279404
9667b4a
1b71376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this thing doing exactly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nothing now that cli has been removed |
||
|
||
fn main() { | ||
generate_cargo_keys(); | ||
|
||
rerun_if_git_head_changed(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,14 @@ | |
#[cfg(feature = "std")] | ||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); | ||
|
||
use codec::Encode; | ||
use frame_support::debug; | ||
use sp_api::impl_runtime_apis; | ||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; | ||
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Saturating, Verify}; | ||
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, Saturating, StaticLookup, Verify}; | ||
use sp_runtime::SaturatedConversion; | ||
use sp_runtime::{ | ||
create_runtime_str, generic, impl_opaque_keys, | ||
create_runtime_str, generic, impl_opaque_keys, traits, | ||
transaction_validity::{TransactionSource, TransactionValidity}, | ||
ApplyExtrinsicResult, MultiSignature, | ||
}; | ||
|
@@ -133,7 +136,7 @@ impl system::Trait for Runtime { | |
/// The aggregated dispatch type that is available for extrinsics. | ||
type Call = Call; | ||
/// The lookup mechanism to get account ID from whatever is passed in dispatchers. | ||
type Lookup = IdentityLookup<AccountId>; | ||
type Lookup = Indices; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably not |
||
/// The index type for storing how many extrinsics an account has signed. | ||
type Index = Index; | ||
/// The index type for blocks. | ||
|
@@ -184,6 +187,22 @@ impl system::Trait for Runtime { | |
type SystemWeightInfo = (); | ||
} | ||
|
||
parameter_types! { | ||
pub const IndexDeposit: Balance = 1 * DOLLARS; | ||
} | ||
|
||
pub const MILLICENTS: Balance = 1_000_000_000; | ||
pub const CENTS: Balance = 1_000 * MILLICENTS; | ||
pub const DOLLARS: Balance = 100 * CENTS; | ||
|
||
impl indices::Trait for Runtime { | ||
type AccountIndex = AccountIndex; | ||
type Currency = Balances; | ||
type Deposit = IndexDeposit; | ||
type Event = Event; | ||
type WeightInfo = (); | ||
} | ||
|
||
parameter_types! { | ||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2; | ||
} | ||
|
@@ -240,13 +259,80 @@ construct_runtime!( | |
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage}, | ||
Timestamp: timestamp::{Module, Call, Storage, Inherent}, | ||
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>}, | ||
Indices: indices::{Module, Call, Storage, Config<T>, Event<T>}, | ||
TransactionPayment: transaction_payment::{Module, Storage}, | ||
Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>}, | ||
} | ||
); | ||
|
||
impl system::offchain::SigningTypes for Runtime { | ||
type Public = <Signature as traits::Verify>::Signer; | ||
type Signature = MultiSignature; | ||
} | ||
|
||
use sp_application_crypto::sr25519; | ||
use sp_runtime::MultiSigner; | ||
|
||
pub struct RuntimeKeyType; | ||
|
||
impl system::offchain::AppCrypto<MultiSigner, MultiSignature> for RuntimeKeyType { | ||
type RuntimeAppPublic = sr25519::AppPublic; | ||
type GenericSignature = sp_core::sr25519::Signature; | ||
type GenericPublic = sp_core::sr25519::Public; | ||
} | ||
|
||
impl<C> system::offchain::SendTransactionTypes<C> for Runtime | ||
where | ||
Call: From<C>, | ||
{ | ||
type Extrinsic = UncheckedExtrinsic; | ||
type OverarchingCall = Call; | ||
} | ||
|
||
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime | ||
where | ||
Call: From<LocalCall>, | ||
{ | ||
fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>( | ||
call: Call, | ||
public: <Signature as traits::Verify>::Signer, | ||
account: AccountId, | ||
nonce: Index, | ||
) -> Option<(Call, <UncheckedExtrinsic as traits::Extrinsic>::SignaturePayload)> { | ||
// take the biggest period possible. | ||
let period = BlockHashCount::get() | ||
.checked_next_power_of_two() | ||
.map(|c| c / 2) | ||
.unwrap_or(2) as u64; | ||
let current_block = System::block_number() | ||
.saturated_into::<u64>() | ||
// The `System::block_number` is initialized with `n+1`, | ||
// so the actual block number is `n`. | ||
.saturating_sub(1); | ||
let tip = 0; | ||
let extra: SignedExtra = ( | ||
system::CheckSpecVersion::<Runtime>::new(), | ||
system::CheckTxVersion::<Runtime>::new(), | ||
system::CheckGenesis::<Runtime>::new(), | ||
system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)), | ||
system::CheckNonce::<Runtime>::from(nonce), | ||
system::CheckWeight::<Runtime>::new(), | ||
transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip), | ||
); | ||
let raw_payload = SignedPayload::new(call, extra) | ||
.map_err(|e| { | ||
debug::warn!("Unable to create signed payload: {:?}", e); | ||
}) | ||
.ok()?; | ||
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?; | ||
let address = Indices::unlookup(account); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh, didn't know that |
||
let (call, extra, _) = raw_payload.deconstruct(); | ||
Some((call, (address, signature.into(), extra))) | ||
} | ||
} | ||
|
||
/// The address format for describing accounts. | ||
pub type Address = AccountId; | ||
pub type Address = <Indices as StaticLookup>::Source; | ||
/// Block header type as expected by this runtime. | ||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>; | ||
/// Block type as expected by this runtime. | ||
|
@@ -271,6 +357,8 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signatu | |
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>; | ||
/// Executive: handles dispatch to the various modules. | ||
pub type Executive = frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>; | ||
/// Signed payload type | ||
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>; | ||
|
||
impl_runtime_apis! { | ||
impl sp_api::Core<Block> for Runtime { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use runtime::{ | ||
AccountId, Signature, WASM_BINARY, | ||
BalancesConfig, GenesisConfig, IndicesConfig, SudoConfig, SystemConfig, | ||
}; | ||
use sc_service::ChainType; | ||
use sp_core::{sr25519, Pair, Public}; | ||
use sp_runtime::traits::{IdentifyAccount, Verify}; | ||
|
||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. | ||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>; | ||
|
||
/// Generate a crypto pair from seed. | ||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { | ||
TPublic::Pair::from_string(&format!("//{}", seed), None) | ||
.expect("static values are valid; qed") | ||
.public() | ||
} | ||
|
||
type AccountPublic = <Signature as Verify>::Signer; | ||
|
||
pub fn spec_factory(_: String) -> Result<Box<dyn sc_service::ChainSpec>, String> { | ||
// we supply our own chainspec | ||
Ok(Box::new(development_config()?)) | ||
} | ||
|
||
/// Generate an account ID from seed. | ||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId | ||
where | ||
AccountPublic: From<<TPublic::Pair as Pair>::Public>, | ||
{ | ||
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() | ||
} | ||
|
||
pub fn development_config() -> Result<ChainSpec, String> { | ||
Ok(ChainSpec::from_genesis( | ||
"Development", | ||
"dev", | ||
ChainType::Development, | ||
move || { | ||
testnet_genesis( | ||
WASM_BINARY, | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), | ||
], | ||
true, | ||
) | ||
}, | ||
vec![], | ||
None, | ||
None, | ||
None, | ||
None, | ||
)) | ||
} | ||
|
||
/// Configure initial storage state for FRAME modules. | ||
fn testnet_genesis( | ||
wasm_binary: &[u8], | ||
root_key: AccountId, | ||
endowed_accounts: Vec<AccountId>, | ||
_enable_println: bool, | ||
) -> GenesisConfig { | ||
GenesisConfig { | ||
system: Some(SystemConfig { | ||
// Add Wasm runtime to storage. | ||
code: wasm_binary.to_vec(), | ||
changes_trie_config: Default::default(), | ||
}), | ||
balances: Some(BalancesConfig { | ||
// Configure endowed accounts with initial balance of 1 << 60. | ||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), | ||
}), | ||
indices: Some(IndicesConfig { indices: vec![] }), | ||
sudo: Some(SudoConfig { | ||
// Assign network admin rights. | ||
key: root_key, | ||
}), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind updating to
master
?