SubmitMillauToRialtoMessage subcommand in substrate-relay (#460)

* substrate-relay::SubmitMillauToRialtoMessage

* typo

* Update relays/substrate/src/cli.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2020-10-28 10:04:06 +03:00
committed by Bastian Köcher
parent a6048bca59
commit b99fa90edd
7 changed files with 210 additions and 8 deletions
+2
View File
@@ -18,4 +18,6 @@ millau-runtime = { path = "../../bin/millau/runtime" }
# Substrate Dependencies
frame-system = "2.0"
pallet-transaction-payment = "2.0"
sp-core = "2.0"
sp-runtime = "2.0"
+69 -3
View File
@@ -16,10 +16,14 @@
//! Types used to connect to the Millau-Substrate chain.
use relay_substrate_client::{Chain, ChainBase};
use codec::Encode;
use headers_relay::sync_types::SourceHeader;
use sp_runtime::traits::Header as HeaderT;
use relay_substrate_client::{Chain, ChainBase, Client, TransactionSignScheme};
use sp_core::Pair;
use sp_runtime::{
generic::SignedPayload,
traits::{Header as HeaderT, IdentifyAccount},
};
/// Millau header id.
pub type HeaderId = relay_utils::HeaderId<millau_runtime::Hash, millau_runtime::BlockNumber>;
@@ -42,6 +46,68 @@ impl Chain for Millau {
type Call = millau_runtime::Call;
}
impl TransactionSignScheme for Millau {
type Chain = Millau;
type AccountKeyPair = sp_core::sr25519::Pair;
type SignedTransaction = millau_runtime::UncheckedExtrinsic;
fn sign_transaction(
client: &Client<Self>,
signer: &Self::AccountKeyPair,
signer_nonce: <Self::Chain as Chain>::Index,
call: <Self::Chain as Chain>::Call,
) -> Self::SignedTransaction {
let raw_payload = SignedPayload::from_raw(
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::CheckWeight::<millau_runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<millau_runtime::Runtime>::from(0),
),
(
millau_runtime::VERSION.spec_version,
millau_runtime::VERSION.transaction_version,
*client.genesis_hash(),
*client.genesis_hash(),
(),
(),
(),
),
);
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
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 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())
}
}
/// Millau header type used in headers sync.
#[derive(Clone, Debug, PartialEq)]
pub struct SyncHeader(millau_runtime::Header);