mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 19:51:02 +00:00
Encode and estimate Rococo/Wococo/Kusama/Polkadot messages (#1322)
* encode and estimate Rococo/Wococo/Kusama/Polkadot messages * allow send-message for non-bundled chains * weight -> dispatch-weight * fmt * fix spelling
This commit is contained in:
committed by
Bastian Köcher
parent
097a28418b
commit
efa3e97210
@@ -25,24 +25,27 @@ use crate::cli::{
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{DispatchInfo, GetDispatchInfo};
|
||||
use relay_rialto_client::Rialto;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
impl CliEncodeCall for Rialto {
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call> {
|
||||
fn encode_call(call: &Call) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
|
||||
Ok(match call {
|
||||
Call::Raw { data } => Decode::decode(&mut &*data.0)?,
|
||||
Call::Raw { data } => Self::Call::decode(&mut &*data.0)?.into(),
|
||||
Call::Remark { remark_payload, .. } =>
|
||||
rialto_runtime::Call::System(rialto_runtime::SystemCall::remark {
|
||||
remark: remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
}),
|
||||
})
|
||||
.into(),
|
||||
Call::Transfer { recipient, amount } =>
|
||||
rialto_runtime::Call::Balances(rialto_runtime::BalancesCall::transfer {
|
||||
dest: recipient.raw_id().into(),
|
||||
value: amount.0,
|
||||
}),
|
||||
})
|
||||
.into(),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::RIALTO_TO_MILLAU_INDEX => {
|
||||
@@ -54,6 +57,7 @@ impl CliEncodeCall for Rialto {
|
||||
delivery_and_dispatch_fee: fee.0,
|
||||
},
|
||||
)
|
||||
.into()
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
@@ -63,8 +67,8 @@ impl CliEncodeCall for Rialto {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &rialto_runtime::Call) -> anyhow::Result<DispatchInfo> {
|
||||
Ok(call.get_dispatch_info())
|
||||
fn get_dispatch_info(call: &EncodedOrDecodedCall<Self::Call>) -> anyhow::Result<DispatchInfo> {
|
||||
Ok(call.to_decoded()?.get_dispatch_info())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +93,7 @@ impl CliChain for Rialto {
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| anyhow!("Failed to decode Rialto's MessagePayload: {:?}", e)),
|
||||
encode_message::MessagePayload::Call { mut call, mut sender } => {
|
||||
encode_message::MessagePayload::Call { mut call, mut sender, dispatch_weight } => {
|
||||
type Source = Rialto;
|
||||
type Target = relay_millau_client::Millau;
|
||||
|
||||
@@ -101,11 +105,13 @@ impl CliChain for Rialto {
|
||||
bridge::RIALTO_TO_MILLAU_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call)?;
|
||||
let weight = call.get_dispatch_info().weight;
|
||||
let dispatch_weight = dispatch_weight.map(Ok).unwrap_or_else(|| {
|
||||
call.to_decoded().map(|call| call.get_dispatch_info().weight)
|
||||
})?;
|
||||
|
||||
Ok(send_message::message_payload(
|
||||
spec_version,
|
||||
weight,
|
||||
dispatch_weight,
|
||||
origin,
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
|
||||
Reference in New Issue
Block a user