mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 16: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
@@ -14,6 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{DispatchClass, DispatchInfo, Pays, Weight};
|
||||
use relay_kusama_client::Kusama;
|
||||
@@ -21,8 +24,10 @@ use sp_version::RuntimeVersion;
|
||||
|
||||
use crate::cli::{
|
||||
bridge,
|
||||
encode_call::{Call, CliEncodeCall},
|
||||
encode_message, CliChain,
|
||||
encode_call::{self, Call, CliEncodeCall},
|
||||
encode_message,
|
||||
send_message::{self, DispatchFeePayment},
|
||||
CliChain,
|
||||
};
|
||||
|
||||
/// Weight of the `system::remark` call at Kusama.
|
||||
@@ -32,13 +37,15 @@ use crate::cli::{
|
||||
pub(crate) const SYSTEM_REMARK_CALL_WEIGHT: Weight = 2 * 1_345_000;
|
||||
|
||||
impl CliEncodeCall for Kusama {
|
||||
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 } => EncodedOrDecodedCall::Encoded(data.0.clone()),
|
||||
Call::Remark { remark_payload, .. } => relay_kusama_client::runtime::Call::System(
|
||||
relay_kusama_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::KUSAMA_TO_POLKADOT_INDEX => {
|
||||
@@ -48,6 +55,7 @@ impl CliEncodeCall for Kusama {
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
.into()
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
@@ -58,13 +66,11 @@ impl CliEncodeCall for Kusama {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(
|
||||
call: &relay_kusama_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(call: &EncodedOrDecodedCall<Self::Call>) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_kusama_client::runtime::Call::System(
|
||||
EncodedOrDecodedCall::Decoded(relay_kusama_client::runtime::Call::System(
|
||||
relay_kusama_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
)) => Ok(DispatchInfo {
|
||||
weight: crate::chains::kusama::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
@@ -78,7 +84,12 @@ impl CliChain for Kusama {
|
||||
const RUNTIME_VERSION: RuntimeVersion = bp_kusama::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = ();
|
||||
type MessagePayload = MessagePayload<
|
||||
bp_kusama::AccountId,
|
||||
bp_polkadot::AccountPublic,
|
||||
bp_polkadot::Signature,
|
||||
Vec<u8>,
|
||||
>;
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
sp_core::crypto::Ss58AddressFormat::from(
|
||||
@@ -88,8 +99,37 @@ impl CliChain for Kusama {
|
||||
}
|
||||
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
message: encode_message::MessagePayload,
|
||||
) -> anyhow::Result<Self::MessagePayload> {
|
||||
anyhow::bail!("Sending messages from Kusama is not yet supported.")
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| anyhow!("Failed to decode Kusama's MessagePayload: {:?}", e)),
|
||||
encode_message::MessagePayload::Call { mut call, mut sender, dispatch_weight } => {
|
||||
type Source = Kusama;
|
||||
type Target = relay_polkadot_client::Polkadot;
|
||||
|
||||
sender.enforce_chain::<Source>();
|
||||
let spec_version = Target::RUNTIME_VERSION.spec_version;
|
||||
let origin = CallOrigin::SourceAccount(sender.raw_id());
|
||||
encode_call::preprocess_call::<Source, Target>(
|
||||
&mut call,
|
||||
bridge::KUSAMA_TO_POLKADOT_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call)?;
|
||||
let dispatch_weight = dispatch_weight.map(Ok).unwrap_or_else(|| {
|
||||
Err(anyhow::format_err!(
|
||||
"Please specify dispatch weight of the encoded Polkadot call"
|
||||
))
|
||||
})?;
|
||||
|
||||
Ok(send_message::message_payload(
|
||||
spec_version,
|
||||
dispatch_weight,
|
||||
origin,
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
|
||||
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||
client
|
||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Kusama::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -96,12 +96,12 @@ pub(crate) async fn update_polkadot_to_kusama_conversion_rate(
|
||||
sp_runtime::FixedU128::from_float(updated_rate),
|
||||
)
|
||||
)
|
||||
),
|
||||
).into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map(drop)
|
||||
|
||||
@@ -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_millau_client::Millau;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
impl CliEncodeCall for Millau {
|
||||
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, .. } =>
|
||||
millau_runtime::Call::System(millau_runtime::SystemCall::remark {
|
||||
remark: remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
}),
|
||||
})
|
||||
.into(),
|
||||
Call::Transfer { recipient, amount } =>
|
||||
millau_runtime::Call::Balances(millau_runtime::BalancesCall::transfer {
|
||||
dest: recipient.raw_id(),
|
||||
value: amount.cast(),
|
||||
}),
|
||||
})
|
||||
.into(),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::MILLAU_TO_RIALTO_INDEX => {
|
||||
@@ -54,6 +57,7 @@ impl CliEncodeCall for Millau {
|
||||
delivery_and_dispatch_fee: fee.cast(),
|
||||
},
|
||||
)
|
||||
.into()
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
@@ -63,8 +67,8 @@ impl CliEncodeCall for Millau {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &millau_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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +94,7 @@ impl CliChain for Millau {
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| anyhow!("Failed to decode Millau's MessagePayload: {:?}", e)),
|
||||
encode_message::MessagePayload::Call { mut call, mut sender } => {
|
||||
encode_message::MessagePayload::Call { mut call, mut sender, dispatch_weight } => {
|
||||
type Source = Millau;
|
||||
type Target = relay_rialto_client::Rialto;
|
||||
|
||||
@@ -102,11 +106,13 @@ impl CliChain for Millau {
|
||||
bridge::MILLAU_TO_RIALTO_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,
|
||||
|
||||
@@ -74,7 +74,7 @@ pub(crate) async fn update_rialto_to_millau_conversion_rate(
|
||||
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||
client
|
||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Millau::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -82,17 +82,16 @@ pub(crate) async fn update_rialto_to_millau_conversion_rate(
|
||||
signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
millau_runtime::MessagesCall::update_pallet_parameter {
|
||||
millau_runtime::Call::from(millau_runtime::MessagesCall::update_pallet_parameter {
|
||||
parameter: millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(
|
||||
sp_runtime::FixedU128::from_float(updated_rate),
|
||||
),
|
||||
}
|
||||
.into(),
|
||||
}).into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map(drop)
|
||||
|
||||
@@ -210,8 +210,9 @@ mod tests {
|
||||
genesis_hash: Default::default(),
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(rialto_call.clone(), 0),
|
||||
});
|
||||
unsigned: UnsignedTransaction::new(rialto_call.clone().into(), 0),
|
||||
})
|
||||
.unwrap();
|
||||
let extra_bytes_in_transaction = rialto_tx.encode().len() - rialto_call.encode().len();
|
||||
assert!(
|
||||
bp_rialto::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
|
||||
@@ -231,8 +232,9 @@ mod tests {
|
||||
genesis_hash: Default::default(),
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(millau_call.clone(), 0),
|
||||
});
|
||||
unsigned: UnsignedTransaction::new(millau_call.clone().into(), 0),
|
||||
})
|
||||
.unwrap();
|
||||
let extra_bytes_in_transaction = millau_tx.encode().len() - millau_call.encode().len();
|
||||
assert!(
|
||||
bp_millau::TX_EXTRA_BYTES as usize >= extra_bytes_in_transaction,
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{DispatchClass, DispatchInfo, Pays, Weight};
|
||||
use relay_polkadot_client::Polkadot;
|
||||
@@ -21,8 +24,10 @@ use sp_version::RuntimeVersion;
|
||||
|
||||
use crate::cli::{
|
||||
bridge,
|
||||
encode_call::{Call, CliEncodeCall},
|
||||
encode_message, CliChain,
|
||||
encode_call::{self, Call, CliEncodeCall},
|
||||
encode_message,
|
||||
send_message::{self, DispatchFeePayment},
|
||||
CliChain,
|
||||
};
|
||||
|
||||
/// Weight of the `system::remark` call at Polkadot.
|
||||
@@ -32,13 +37,15 @@ use crate::cli::{
|
||||
pub(crate) const SYSTEM_REMARK_CALL_WEIGHT: Weight = 2 * 1_345_000;
|
||||
|
||||
impl CliEncodeCall for Polkadot {
|
||||
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 } => EncodedOrDecodedCall::Encoded(data.0.clone()),
|
||||
Call::Remark { remark_payload, .. } => relay_polkadot_client::runtime::Call::System(
|
||||
relay_polkadot_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::POLKADOT_TO_KUSAMA_INDEX => {
|
||||
@@ -48,6 +55,7 @@ impl CliEncodeCall for Polkadot {
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
.into()
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
@@ -58,13 +66,11 @@ impl CliEncodeCall for Polkadot {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(
|
||||
call: &relay_polkadot_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(call: &EncodedOrDecodedCall<Self::Call>) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_polkadot_client::runtime::Call::System(
|
||||
EncodedOrDecodedCall::Decoded(relay_polkadot_client::runtime::Call::System(
|
||||
relay_polkadot_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
)) => Ok(DispatchInfo {
|
||||
weight: crate::chains::polkadot::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
@@ -78,7 +84,12 @@ impl CliChain for Polkadot {
|
||||
const RUNTIME_VERSION: RuntimeVersion = bp_polkadot::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = ();
|
||||
type MessagePayload = MessagePayload<
|
||||
bp_polkadot::AccountId,
|
||||
bp_kusama::AccountPublic,
|
||||
bp_kusama::Signature,
|
||||
Vec<u8>,
|
||||
>;
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
sp_core::crypto::Ss58AddressFormat::from(
|
||||
@@ -88,8 +99,37 @@ impl CliChain for Polkadot {
|
||||
}
|
||||
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
message: encode_message::MessagePayload,
|
||||
) -> anyhow::Result<Self::MessagePayload> {
|
||||
anyhow::bail!("Sending messages from Polkadot is not yet supported.")
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| anyhow!("Failed to decode Polkadot's MessagePayload: {:?}", e)),
|
||||
encode_message::MessagePayload::Call { mut call, mut sender, dispatch_weight } => {
|
||||
type Source = Polkadot;
|
||||
type Target = relay_kusama_client::Kusama;
|
||||
|
||||
sender.enforce_chain::<Source>();
|
||||
let spec_version = Target::RUNTIME_VERSION.spec_version;
|
||||
let origin = CallOrigin::SourceAccount(sender.raw_id());
|
||||
encode_call::preprocess_call::<Source, Target>(
|
||||
&mut call,
|
||||
bridge::POLKADOT_TO_KUSAMA_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call)?;
|
||||
let dispatch_weight = dispatch_weight.map(Ok).unwrap_or_else(|| {
|
||||
Err(anyhow::format_err!(
|
||||
"Please specify dispatch weight of the encoded Kusama call"
|
||||
))
|
||||
})?;
|
||||
|
||||
Ok(send_message::message_payload(
|
||||
spec_version,
|
||||
dispatch_weight,
|
||||
origin,
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
|
||||
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||
client
|
||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Polkadot::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -96,12 +96,12 @@ pub(crate) async fn update_kusama_to_polkadot_conversion_rate(
|
||||
sp_runtime::FixedU128::from_float(updated_rate),
|
||||
)
|
||||
)
|
||||
),
|
||||
).into(),
|
||||
transaction_nonce,
|
||||
)
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map(drop)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -74,7 +74,7 @@ pub(crate) async fn update_millau_to_rialto_conversion_rate(
|
||||
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||
client
|
||||
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Rialto::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -82,17 +82,16 @@ pub(crate) async fn update_millau_to_rialto_conversion_rate(
|
||||
signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
rialto_runtime::MessagesCall::update_pallet_parameter {
|
||||
rialto_runtime::Call::from(rialto_runtime::MessagesCall::update_pallet_parameter {
|
||||
parameter: rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate(
|
||||
sp_runtime::FixedU128::from_float(updated_rate),
|
||||
),
|
||||
}
|
||||
.into(),
|
||||
}).into(),
|
||||
transaction_nonce,
|
||||
)
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map(drop)
|
||||
|
||||
@@ -21,34 +21,37 @@ use crate::cli::{
|
||||
encode_message, CliChain,
|
||||
};
|
||||
use bp_message_dispatch::MessagePayload;
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{DispatchInfo, GetDispatchInfo};
|
||||
use relay_rialto_parachain_client::RialtoParachain;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
impl CliEncodeCall for RialtoParachain {
|
||||
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_parachain_runtime::Call::System(
|
||||
rialto_parachain_runtime::SystemCall::remark {
|
||||
remark: remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
},
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
Call::Transfer { recipient, amount } => rialto_parachain_runtime::Call::Balances(
|
||||
rialto_parachain_runtime::BalancesCall::transfer {
|
||||
dest: recipient.raw_id().into(),
|
||||
value: amount.0,
|
||||
},
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
Call::BridgeSendMessage { .. } => {
|
||||
anyhow::bail!("Bridge messages are not (yet) supported here",)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(call: &rialto_parachain_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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{DispatchClass, DispatchInfo, Pays, Weight};
|
||||
use relay_rococo_client::Rococo;
|
||||
@@ -22,8 +24,10 @@ use sp_version::RuntimeVersion;
|
||||
|
||||
use crate::cli::{
|
||||
bridge,
|
||||
encode_call::{Call, CliEncodeCall},
|
||||
encode_message, CliChain,
|
||||
encode_call::{self, Call, CliEncodeCall},
|
||||
encode_message,
|
||||
send_message::{self, DispatchFeePayment},
|
||||
CliChain,
|
||||
};
|
||||
|
||||
/// Weight of the `system::remark` call at Rococo.
|
||||
@@ -33,13 +37,15 @@ use crate::cli::{
|
||||
pub(crate) const SYSTEM_REMARK_CALL_WEIGHT: Weight = 2 * 1_345_000;
|
||||
|
||||
impl CliEncodeCall for Rococo {
|
||||
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 } => EncodedOrDecodedCall::Encoded(data.0.clone()),
|
||||
Call::Remark { remark_payload, .. } => relay_rococo_client::runtime::Call::System(
|
||||
relay_rococo_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::ROCOCO_TO_WOCOCO_INDEX => {
|
||||
@@ -49,6 +55,7 @@ impl CliEncodeCall for Rococo {
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
.into()
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
@@ -59,13 +66,11 @@ impl CliEncodeCall for Rococo {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(
|
||||
call: &relay_rococo_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(call: &EncodedOrDecodedCall<Self::Call>) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_rococo_client::runtime::Call::System(
|
||||
EncodedOrDecodedCall::Decoded(relay_rococo_client::runtime::Call::System(
|
||||
relay_rococo_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
)) => Ok(DispatchInfo {
|
||||
weight: SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
@@ -79,15 +84,49 @@ impl CliChain for Rococo {
|
||||
const RUNTIME_VERSION: RuntimeVersion = bp_rococo::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = ();
|
||||
type MessagePayload = MessagePayload<
|
||||
bp_rococo::AccountId,
|
||||
bp_wococo::AccountPublic,
|
||||
bp_wococo::Signature,
|
||||
Vec<u8>,
|
||||
>;
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
42
|
||||
}
|
||||
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
message: encode_message::MessagePayload,
|
||||
) -> anyhow::Result<Self::MessagePayload> {
|
||||
Err(anyhow!("Sending messages from Rococo is not yet supported."))
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| anyhow!("Failed to decode Rococo's MessagePayload: {:?}", e)),
|
||||
encode_message::MessagePayload::Call { mut call, mut sender, dispatch_weight } => {
|
||||
type Source = Rococo;
|
||||
type Target = relay_wococo_client::Wococo;
|
||||
|
||||
sender.enforce_chain::<Source>();
|
||||
let spec_version = Target::RUNTIME_VERSION.spec_version;
|
||||
let origin = CallOrigin::SourceAccount(sender.raw_id());
|
||||
encode_call::preprocess_call::<Source, Target>(
|
||||
&mut call,
|
||||
bridge::ROCOCO_TO_WOCOCO_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call)?;
|
||||
let dispatch_weight = dispatch_weight.map(Ok).unwrap_or_else(|| {
|
||||
Err(anyhow::format_err!(
|
||||
"Please specify dispatch weight of the encoded Wococo call"
|
||||
))
|
||||
})?;
|
||||
|
||||
Ok(send_message::message_payload(
|
||||
spec_version,
|
||||
dispatch_weight,
|
||||
origin,
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{DispatchClass, DispatchInfo, Pays};
|
||||
use relay_wococo_client::Wococo;
|
||||
@@ -22,18 +24,22 @@ use sp_version::RuntimeVersion;
|
||||
|
||||
use crate::cli::{
|
||||
bridge,
|
||||
encode_call::{Call, CliEncodeCall},
|
||||
encode_message, CliChain,
|
||||
encode_call::{self, Call, CliEncodeCall},
|
||||
encode_message,
|
||||
send_message::{self, DispatchFeePayment},
|
||||
CliChain,
|
||||
};
|
||||
|
||||
impl CliEncodeCall for Wococo {
|
||||
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 } => EncodedOrDecodedCall::Encoded(data.0.clone()),
|
||||
Call::Remark { remark_payload, .. } => relay_wococo_client::runtime::Call::System(
|
||||
relay_wococo_client::runtime::SystemCall::remark(
|
||||
remark_payload.as_ref().map(|x| x.0.clone()).unwrap_or_default(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
Call::BridgeSendMessage { lane, payload, fee, bridge_instance_index } =>
|
||||
match *bridge_instance_index {
|
||||
bridge::WOCOCO_TO_ROCOCO_INDEX => {
|
||||
@@ -43,6 +49,7 @@ impl CliEncodeCall for Wococo {
|
||||
lane.0, payload, fee.0,
|
||||
),
|
||||
)
|
||||
.into()
|
||||
},
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
@@ -53,18 +60,16 @@ impl CliEncodeCall for Wococo {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_dispatch_info(
|
||||
call: &relay_wococo_client::runtime::Call,
|
||||
) -> anyhow::Result<DispatchInfo> {
|
||||
fn get_dispatch_info(call: &EncodedOrDecodedCall<Self::Call>) -> anyhow::Result<DispatchInfo> {
|
||||
match *call {
|
||||
relay_wococo_client::runtime::Call::System(
|
||||
EncodedOrDecodedCall::Decoded(relay_wococo_client::runtime::Call::System(
|
||||
relay_wococo_client::runtime::SystemCall::remark(_),
|
||||
) => Ok(DispatchInfo {
|
||||
)) => Ok(DispatchInfo {
|
||||
weight: crate::chains::rococo::SYSTEM_REMARK_CALL_WEIGHT,
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
}),
|
||||
_ => anyhow::bail!("Unsupported Rococo call: {:?}", call),
|
||||
_ => anyhow::bail!("Unsupported Wococo call: {:?}", call),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,15 +78,49 @@ impl CliChain for Wococo {
|
||||
const RUNTIME_VERSION: RuntimeVersion = bp_wococo::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = ();
|
||||
type MessagePayload = MessagePayload<
|
||||
bp_wococo::AccountId,
|
||||
bp_rococo::AccountPublic,
|
||||
bp_rococo::Signature,
|
||||
Vec<u8>,
|
||||
>;
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
42
|
||||
}
|
||||
|
||||
fn encode_message(
|
||||
_message: encode_message::MessagePayload,
|
||||
message: encode_message::MessagePayload,
|
||||
) -> anyhow::Result<Self::MessagePayload> {
|
||||
Err(anyhow!("Sending messages from Wococo is not yet supported."))
|
||||
match message {
|
||||
encode_message::MessagePayload::Raw { data } => MessagePayload::decode(&mut &*data.0)
|
||||
.map_err(|e| anyhow!("Failed to decode Wococo's MessagePayload: {:?}", e)),
|
||||
encode_message::MessagePayload::Call { mut call, mut sender, dispatch_weight } => {
|
||||
type Source = Wococo;
|
||||
type Target = relay_rococo_client::Rococo;
|
||||
|
||||
sender.enforce_chain::<Source>();
|
||||
let spec_version = Target::RUNTIME_VERSION.spec_version;
|
||||
let origin = CallOrigin::SourceAccount(sender.raw_id());
|
||||
encode_call::preprocess_call::<Source, Target>(
|
||||
&mut call,
|
||||
bridge::WOCOCO_TO_ROCOCO_INDEX,
|
||||
);
|
||||
let call = Target::encode_call(&call)?;
|
||||
let dispatch_weight = dispatch_weight.map(Ok).unwrap_or_else(|| {
|
||||
Err(anyhow::format_err!(
|
||||
"Please specify dispatch weight of the encoded Rococo call"
|
||||
))
|
||||
})?;
|
||||
|
||||
Ok(send_message::message_payload(
|
||||
spec_version,
|
||||
dispatch_weight,
|
||||
origin,
|
||||
&call,
|
||||
DispatchFeePayment::AtSourceChain,
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user