mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
Cross-Chain Transfer Generator (#535)
* Attempt at adding Cross-Chain Transfer Generator * Add Transfer subcommand for sending messages to Rialto * Add temp helper script for sending messages * Remove Message and Lane Ids from Dispatch Event * Increase transfer amount used by script * Endow derived Dave account on Rialto with funds * Update Message generator to send more types of messages This commit first of all updates the script to use the new CLI commands for sending messages. Second, it adds messages which are sent from both Target and Source origins. * Generate messages from Root origin * Remove dbg! logs from relayer * Log AccountId as well as HexId * Remove Balances logs * Add InstanceId and MessageId back to Dispatch Event * Add InstanceId and MessageId types for Apps * Add missing comment * Document derived accounts as tests * Move shared commands to variables * Add example usage for send_message script * Add docs to message variants * Fix Clippy complaint
This commit is contained in:
committed by
Bastian Köcher
parent
6f6c8c2417
commit
0ff8c2437c
@@ -101,12 +101,15 @@ pub enum Command {
|
||||
/// Hex-encoded lane id.
|
||||
#[structopt(long)]
|
||||
lane: HexLaneId,
|
||||
/// Message type.
|
||||
#[structopt(long, possible_values = &ToRialtoMessage::variants())]
|
||||
message: ToRialtoMessage,
|
||||
/// Delivery and dispatch fee.
|
||||
#[structopt(long)]
|
||||
fee: bp_millau::Balance,
|
||||
/// Message type.
|
||||
#[structopt(subcommand)]
|
||||
message: ToRialtoMessage,
|
||||
/// The origin to use when dispatching the message on the target chain.
|
||||
#[structopt(long, possible_values = &Origins::variants())]
|
||||
origin: Origins,
|
||||
},
|
||||
/// Serve given lane of Rialto -> Millau messages.
|
||||
RialtoMessagesToMillau {
|
||||
@@ -144,12 +147,18 @@ pub enum Command {
|
||||
},
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[derive(Debug)]
|
||||
/// All possible messages that may be delivered to the Rialto chain.
|
||||
pub enum ToRialtoMessage {
|
||||
Remark,
|
||||
}
|
||||
/// All possible messages that may be delivered to the Rialto chain.
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub enum ToRialtoMessage {
|
||||
/// Make an on-chain remark (comment).
|
||||
Remark,
|
||||
/// Transfer the specified `amount` of native tokens to a particular `recipient`.
|
||||
Transfer {
|
||||
#[structopt(long)]
|
||||
recipient: bp_rialto::AccountId,
|
||||
#[structopt(long)]
|
||||
amount: bp_rialto::Balance,
|
||||
},
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
@@ -160,6 +169,16 @@ arg_enum! {
|
||||
}
|
||||
}
|
||||
|
||||
arg_enum! {
|
||||
#[derive(Debug)]
|
||||
/// The origin to use when dispatching the message on the target chain.
|
||||
pub enum Origins {
|
||||
Root,
|
||||
Target,
|
||||
Source,
|
||||
}
|
||||
}
|
||||
|
||||
/// Lane id.
|
||||
#[derive(Debug)]
|
||||
pub struct HexLaneId(LaneId);
|
||||
|
||||
@@ -248,6 +248,8 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
|
||||
lane,
|
||||
message,
|
||||
fee,
|
||||
origin,
|
||||
..
|
||||
} => {
|
||||
let millau_client = MillauClient::new(ConnectionParams {
|
||||
host: millau.millau_host,
|
||||
@@ -277,33 +279,51 @@ async fn run_command(command: cli::Command) -> Result<(), String> {
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
)),
|
||||
cli::ToRialtoMessage::Transfer { recipient, amount } => {
|
||||
rialto_runtime::Call::Balances(rialto_runtime::BalancesCall::transfer(recipient, amount))
|
||||
}
|
||||
};
|
||||
let rialto_call_weight = rialto_call.get_dispatch_info().weight;
|
||||
|
||||
let rialto_call_weight = rialto_call.get_dispatch_info().weight;
|
||||
let millau_sender_public: bp_millau::AccountSigner = millau_sign.signer.public().clone().into();
|
||||
let millau_account_id: bp_millau::AccountId = millau_sender_public.into_account();
|
||||
let rialto_origin_public = rialto_sign.signer.public();
|
||||
|
||||
let mut rialto_origin_signature_message = Vec::new();
|
||||
rialto_call.encode_to(&mut rialto_origin_signature_message);
|
||||
millau_account_id.encode_to(&mut rialto_origin_signature_message);
|
||||
let rialto_origin_signature = rialto_sign.signer.sign(&rialto_origin_signature_message);
|
||||
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,
|
||||
origin: CallOrigin::SourceAccount(millau_account_id),
|
||||
call: rialto_call.encode(),
|
||||
},
|
||||
cli::Origins::Target => {
|
||||
let mut rialto_origin_signature_message = Vec::new();
|
||||
rialto_call.encode_to(&mut rialto_origin_signature_message);
|
||||
millau_account_id.encode_to(&mut rialto_origin_signature_message);
|
||||
let rialto_origin_signature = rialto_sign.signer.sign(&rialto_origin_signature_message);
|
||||
|
||||
let millau_call =
|
||||
millau_runtime::Call::BridgeRialtoMessageLane(millau_runtime::MessageLaneCall::send_message(
|
||||
lane.into(),
|
||||
MessagePayload {
|
||||
spec_version: rialto_runtime::VERSION.spec_version,
|
||||
weight: rialto_call_weight,
|
||||
origin: CallOrigin::TargetAccount(
|
||||
millau_account_id,
|
||||
millau_account_id.clone(),
|
||||
rialto_origin_public.into(),
|
||||
rialto_origin_signature.into(),
|
||||
),
|
||||
call: rialto_call.encode(),
|
||||
},
|
||||
fee,
|
||||
));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let millau_call = millau_runtime::Call::BridgeRialtoMessageLane(
|
||||
millau_runtime::MessageLaneCall::send_message(lane.into(), payload, fee),
|
||||
);
|
||||
|
||||
let signed_millau_call = Millau::sign_transaction(
|
||||
&millau_client,
|
||||
|
||||
Reference in New Issue
Block a user