Rialto to Millau Transfer Generator (#568)

* Add option to relay for sending transfers to Millau chain

* Endow derived accounts on Millau chain

* Update message generator entrypoint script to send transfers

* Use correct command when sending messages

* Send Root messages from Root origin on source chain

* Wrap calls from Root Origin in Sudo Call

* Allow Root to send messages without paying fees

* Use correct variable when sending messages to Rialto

* Print warning if no message type is provided to script.

* Add note mentioning that certain source origins aren't supported yet

* Use correct runtime when initializing header sync

* Remove option to send messages as Root

* Remove endowment of derived Root accounts

* Fix indentation.

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
Hernando Castano
2020-12-16 06:24:35 -05:00
committed by Bastian Köcher
parent ee655b1057
commit f26775d690
8 changed files with 80 additions and 44 deletions
+18 -10
View File
@@ -138,12 +138,15 @@ pub enum Command {
/// Hex-encoded lane id.
#[structopt(long)]
lane: HexLaneId,
/// Message type.
#[structopt(long, possible_values = &ToMillauMessage::variants())]
message: ToMillauMessage,
/// Delivery and dispatch fee.
#[structopt(long)]
fee: bp_rialto::Balance,
/// Message type.
#[structopt(subcommand)]
message: ToMillauMessage,
/// The origin to use when dispatching the message on the target chain.
#[structopt(long, possible_values = &Origins::variants())]
origin: Origins,
},
}
@@ -161,19 +164,24 @@ pub enum ToRialtoMessage {
},
}
arg_enum! {
#[derive(Debug)]
/// All possible messages that may be delivered to the Millau chain.
pub enum ToMillauMessage {
Remark,
}
/// All possible messages that may be delivered to the Millau chain.
#[derive(StructOpt, Debug)]
pub enum ToMillauMessage {
/// Make an on-chain remark (comment).
Remark,
/// Transfer the specified `amount` of native tokens to a particular `recipient`.
Transfer {
#[structopt(long)]
recipient: bp_millau::AccountId,
#[structopt(long)]
amount: bp_millau::Balance,
},
}
arg_enum! {
#[derive(Debug)]
/// The origin to use when dispatching the message on the target chain.
pub enum Origins {
Root,
Target,
Source,
}
+27 -19
View File
@@ -97,7 +97,7 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
&rialto_client,
&rialto_sign.signer,
rialto_signer_next_index,
millau_runtime::SudoCall::sudo(Box::new(
rialto_runtime::SudoCall::sudo(Box::new(
rialto_runtime::BridgeMillauCall::initialize(initialization_data).into(),
))
.into(),
@@ -290,12 +290,6 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
let rialto_origin_public = rialto_sign.signer.public();
let payload = match origin {
cli::Origins::Root => MessagePayload {
spec_version: rialto_runtime::VERSION.spec_version,
weight: rialto_call_weight,
origin: CallOrigin::SourceRoot,
call: rialto_call.encode(),
},
cli::Origins::Source => MessagePayload {
spec_version: rialto_runtime::VERSION.spec_version,
weight: rialto_call_weight,
@@ -312,7 +306,7 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
spec_version: rialto_runtime::VERSION.spec_version,
weight: rialto_call_weight,
origin: CallOrigin::TargetAccount(
millau_account_id.clone(),
millau_account_id,
rialto_origin_public.into(),
rialto_origin_signature.into(),
),
@@ -383,6 +377,8 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
lane,
message,
fee,
origin,
..
} => {
let rialto_client = RialtoClient::new(ConnectionParams {
host: rialto.rialto_host,
@@ -412,21 +408,29 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
.as_bytes()
.to_vec(),
)),
cli::ToMillauMessage::Transfer { recipient, amount } => {
millau_runtime::Call::Balances(millau_runtime::BalancesCall::transfer(recipient, amount))
}
};
let millau_call_weight = millau_call.get_dispatch_info().weight;
let millau_call_weight = millau_call.get_dispatch_info().weight;
let rialto_sender_public: bp_rialto::AccountSigner = rialto_sign.signer.public().clone().into();
let rialto_account_id: bp_rialto::AccountId = rialto_sender_public.into_account();
let millau_origin_public = millau_sign.signer.public();
let mut millau_origin_signature_message = Vec::new();
millau_call.encode_to(&mut millau_origin_signature_message);
rialto_account_id.encode_to(&mut millau_origin_signature_message);
let millau_origin_signature = millau_sign.signer.sign(&millau_origin_signature_message);
let payload = match origin {
cli::Origins::Source => MessagePayload {
spec_version: millau_runtime::VERSION.spec_version,
weight: millau_call_weight,
origin: CallOrigin::SourceAccount(rialto_account_id),
call: millau_call.encode(),
},
cli::Origins::Target => {
let mut millau_origin_signature_message = Vec::new();
millau_call.encode_to(&mut millau_origin_signature_message);
rialto_account_id.encode_to(&mut millau_origin_signature_message);
let millau_origin_signature = millau_sign.signer.sign(&millau_origin_signature_message);
let rialto_call =
rialto_runtime::Call::BridgeMillauMessageLane(rialto_runtime::MessageLaneCall::send_message(
lane.into(),
MessagePayload {
spec_version: millau_runtime::VERSION.spec_version,
weight: millau_call_weight,
@@ -436,9 +440,13 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
millau_origin_signature.into(),
),
call: millau_call.encode(),
},
fee,
));
}
}
};
let rialto_call = rialto_runtime::Call::BridgeMillauMessageLane(
rialto_runtime::MessageLaneCall::send_message(lane.into(), payload, fee),
);
let signed_rialto_call = Rialto::sign_transaction(
&rialto_client,