mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Westend Mock Runtime and Client (#874)
* Copy-Pasta Call code from mock Rococo to mock Westend runtime * Update Westend client to include signing and call related code * Add missing part of license header * Move `account_info_storage_key` to `polkadot-core` crate
This commit is contained in:
committed by
Bastian Köcher
parent
c6ae74725b
commit
81d4eb9ea6
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
@@ -22,6 +25,9 @@ use std::time::Duration;
|
||||
/// Rococo header id.
|
||||
pub type HeaderId = relay_utils::HeaderId<bp_rococo::Hash, bp_rococo::BlockNumber>;
|
||||
|
||||
/// Rococo header type used in headers sync.
|
||||
pub type SyncHeader = relay_substrate_client::SyncHeader<bp_rococo::Header>;
|
||||
|
||||
/// Rococo chain definition
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Rococo;
|
||||
@@ -111,6 +117,3 @@ impl Default for SigningParams {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Rococo header type used in headers sync.
|
||||
pub type SyncHeader = relay_substrate_client::SyncHeader<bp_rococo::Header>;
|
||||
|
||||
@@ -16,12 +16,18 @@
|
||||
|
||||
//! Types used to connect to the Westend chain.
|
||||
|
||||
use relay_substrate_client::{Chain, ChainBase};
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, TransactionSignScheme};
|
||||
use sp_core::{storage::StorageKey, Pair};
|
||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
||||
use std::time::Duration;
|
||||
|
||||
/// Westend header id.
|
||||
pub type HeaderId = relay_utils::HeaderId<bp_westend::Hash, bp_westend::BlockNumber>;
|
||||
|
||||
/// Westend header type used in headers sync.
|
||||
pub type SyncHeader = relay_substrate_client::SyncHeader<bp_westend::Header>;
|
||||
|
||||
/// Westend chain definition
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Westend;
|
||||
@@ -40,8 +46,74 @@ impl Chain for Westend {
|
||||
type AccountId = bp_westend::AccountId;
|
||||
type Index = bp_westend::Nonce;
|
||||
type SignedBlock = bp_westend::SignedBlock;
|
||||
type Call = ();
|
||||
type Call = bp_westend::Call;
|
||||
}
|
||||
|
||||
/// Westend header type used in headers sync.
|
||||
pub type SyncHeader = relay_substrate_client::SyncHeader<bp_westend::Header>;
|
||||
impl ChainWithBalances for Westend {
|
||||
type NativeBalance = bp_westend::Balance;
|
||||
|
||||
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
|
||||
StorageKey(bp_westend::account_info_storage_key(account_id))
|
||||
}
|
||||
}
|
||||
|
||||
impl TransactionSignScheme for Westend {
|
||||
type Chain = Westend;
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction = bp_westend::UncheckedExtrinsic;
|
||||
|
||||
fn sign_transaction(
|
||||
genesis_hash: <Self::Chain as ChainBase>::Hash,
|
||||
signer: &Self::AccountKeyPair,
|
||||
signer_nonce: <Self::Chain as Chain>::Index,
|
||||
call: <Self::Chain as Chain>::Call,
|
||||
) -> Self::SignedTransaction {
|
||||
let raw_payload = SignedPayload::new(
|
||||
call,
|
||||
bp_westend::SignedExtensions::new(
|
||||
bp_westend::VERSION,
|
||||
sp_runtime::generic::Era::Immortal,
|
||||
genesis_hash,
|
||||
signer_nonce,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.expect("SignedExtension never fails.");
|
||||
|
||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
||||
let (call, extra, _) = raw_payload.deconstruct();
|
||||
|
||||
bp_westend::UncheckedExtrinsic::new_signed(call, signer.into_account(), signature.into(), extra)
|
||||
}
|
||||
}
|
||||
|
||||
/// Westend signing params.
|
||||
#[derive(Clone)]
|
||||
pub struct SigningParams {
|
||||
/// Substrate transactions signer.
|
||||
pub signer: sp_core::sr25519::Pair,
|
||||
}
|
||||
|
||||
impl SigningParams {
|
||||
/// Create signing params from SURI and password.
|
||||
pub fn from_suri(suri: &str, password: Option<&str>) -> Result<Self, sp_core::crypto::SecretStringError> {
|
||||
Ok(SigningParams {
|
||||
signer: sp_core::sr25519::Pair::from_string(suri, password)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for SigningParams {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{}", self.signer.public())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SigningParams {
|
||||
fn default() -> Self {
|
||||
SigningParams {
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user