Merge commit '392447f5c8f986ded2559a78457f4cd87942f393' into update-bridges-subtree-r/w

This commit is contained in:
antonio-dropulic
2021-12-01 09:46:14 +01:00
321 changed files with 28385 additions and 10466 deletions
@@ -16,8 +16,11 @@
//! Types used to connect to the Millau-Substrate chain.
use codec::Encode;
use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, TransactionSignScheme};
use codec::{Compact, Decode, Encode};
use relay_substrate_client::{
BalanceOf, Chain, ChainBase, ChainWithBalances, IndexOf, TransactionEraOf,
TransactionSignScheme, UnsignedTransaction,
};
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
use std::time::Duration;
@@ -34,17 +37,22 @@ impl ChainBase for Millau {
type Hash = millau_runtime::Hash;
type Hasher = millau_runtime::Hashing;
type Header = millau_runtime::Header;
type AccountId = millau_runtime::AccountId;
type Balance = millau_runtime::Balance;
type Index = millau_runtime::Index;
type Signature = millau_runtime::Signature;
}
impl Chain for Millau {
const NAME: &'static str = "Millau";
const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(5);
const STORAGE_PROOF_OVERHEAD: u32 = bp_millau::EXTRA_STORAGE_PROOF_SIZE;
const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_millau::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE;
type AccountId = millau_runtime::AccountId;
type Index = millau_runtime::Index;
type SignedBlock = millau_runtime::SignedBlock;
type Call = millau_runtime::Call;
type Balance = millau_runtime::Balance;
type WeightToFee = bp_millau::WeightToFee;
}
impl ChainWithBalances for Millau {
@@ -64,25 +72,25 @@ impl TransactionSignScheme for Millau {
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,
era: TransactionEraOf<Self::Chain>,
unsigned: UnsignedTransaction<Self::Chain>,
) -> Self::SignedTransaction {
let raw_payload = SignedPayload::from_raw(
call,
unsigned.call,
(
frame_system::CheckSpecVersion::<millau_runtime::Runtime>::new(),
frame_system::CheckTxVersion::<millau_runtime::Runtime>::new(),
frame_system::CheckGenesis::<millau_runtime::Runtime>::new(),
frame_system::CheckEra::<millau_runtime::Runtime>::from(sp_runtime::generic::Era::Immortal),
frame_system::CheckNonce::<millau_runtime::Runtime>::from(signer_nonce),
frame_system::CheckEra::<millau_runtime::Runtime>::from(era.frame_era()),
frame_system::CheckNonce::<millau_runtime::Runtime>::from(unsigned.nonce),
frame_system::CheckWeight::<millau_runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<millau_runtime::Runtime>::from(0),
pallet_transaction_payment::ChargeTransactionPayment::<millau_runtime::Runtime>::from(unsigned.tip),
),
(
millau_runtime::VERSION.spec_version,
millau_runtime::VERSION.transaction_version,
genesis_hash,
genesis_hash,
era.signed_payload(genesis_hash),
(),
(),
(),
@@ -92,7 +100,36 @@ impl TransactionSignScheme for Millau {
let signer: sp_runtime::MultiSigner = signer.public().into();
let (call, extra, _) = raw_payload.deconstruct();
millau_runtime::UncheckedExtrinsic::new_signed(call, signer.into_account(), signature.into(), extra)
millau_runtime::UncheckedExtrinsic::new_signed(
call,
signer.into_account(),
signature.into(),
extra,
)
}
fn is_signed(tx: &Self::SignedTransaction) -> bool {
tx.signature.is_some()
}
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
tx.signature
.as_ref()
.map(|(address, _, _)| {
*address == millau_runtime::Address::from(*signer.public().as_array_ref())
})
.unwrap_or(false)
}
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>> {
let extra = &tx.signature.as_ref()?.2;
Some(UnsignedTransaction {
call: tx.function,
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.4.encode()[..]).ok()?.into(),
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.6.encode()[..])
.ok()?
.into(),
})
}
}