mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11: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,
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::{
|
||||
},
|
||||
select_full_bridge,
|
||||
};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use frame_support::weights::DispatchInfo;
|
||||
use relay_substrate_client::Chain;
|
||||
use structopt::StructOpt;
|
||||
@@ -85,10 +86,10 @@ pub enum Call {
|
||||
|
||||
pub trait CliEncodeCall: Chain {
|
||||
/// Encode a CLI call.
|
||||
fn encode_call(call: &Call) -> anyhow::Result<Self::Call>;
|
||||
fn encode_call(call: &Call) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>>;
|
||||
|
||||
/// Get dispatch info for the call.
|
||||
fn get_dispatch_info(call: &Self::Call) -> anyhow::Result<DispatchInfo>;
|
||||
fn get_dispatch_info(call: &EncodedOrDecodedCall<Self::Call>) -> anyhow::Result<DispatchInfo>;
|
||||
}
|
||||
|
||||
impl EncodeCall {
|
||||
@@ -100,7 +101,10 @@ impl EncodeCall {
|
||||
let encoded = HexBytes::encode(&call);
|
||||
|
||||
log::info!(target: "bridge", "Generated {} call: {:#?}", Source::NAME, call);
|
||||
log::info!(target: "bridge", "Weight of {} call: {}", Source::NAME, Source::get_dispatch_info(&call)?.weight);
|
||||
log::info!(target: "bridge", "Weight of {} call: {}", Source::NAME, Source::get_dispatch_info(&call)
|
||||
.map(|dispatch_info| format!("{}", dispatch_info.weight))
|
||||
.unwrap_or_else(|_| "<unknown>".to_string())
|
||||
);
|
||||
log::info!(target: "bridge", "Encoded {} call: {:?}", Source::NAME, encoded);
|
||||
|
||||
Ok(encoded)
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::{
|
||||
cli::{bridge::FullBridge, AccountId, CliChain, HexBytes},
|
||||
select_full_bridge,
|
||||
};
|
||||
use frame_support::weights::Weight;
|
||||
use structopt::StructOpt;
|
||||
use strum::VariantNames;
|
||||
|
||||
@@ -37,6 +38,12 @@ pub enum MessagePayload {
|
||||
/// SS58 encoded Source account that will send the payload.
|
||||
#[structopt(long)]
|
||||
sender: AccountId,
|
||||
/// Weight of the call.
|
||||
///
|
||||
/// It must be specified if the chain runtime is not bundled with the relay, or if
|
||||
/// you want to override bundled weight.
|
||||
#[structopt(long)]
|
||||
dispatch_weight: Option<Weight>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -97,6 +104,8 @@ mod tests {
|
||||
"call",
|
||||
"--sender",
|
||||
&sender,
|
||||
"--dispatch-weight",
|
||||
"42",
|
||||
"remark",
|
||||
"--remark-size",
|
||||
"12",
|
||||
@@ -106,6 +115,6 @@ mod tests {
|
||||
let hex = encode_message.encode().unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(format!("{:?}", hex), "0x01000000000000000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c000130000000000000000000000000");
|
||||
assert_eq!(format!("{:?}", hex), "0x010000002a0000000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c000130000000000000000000000000");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,8 @@ mod tests {
|
||||
"call",
|
||||
"--sender",
|
||||
&alice,
|
||||
"--dispatch-weight",
|
||||
"42",
|
||||
"remark",
|
||||
"--remark-payload",
|
||||
"1234",
|
||||
@@ -129,7 +131,8 @@ mod tests {
|
||||
call: encode_call::Call::Remark {
|
||||
remark_payload: Some(HexBytes(vec![0x12, 0x34])),
|
||||
remark_size: None,
|
||||
}
|
||||
},
|
||||
dispatch_weight: Some(42),
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -222,7 +222,7 @@ impl InitBridge {
|
||||
target_client.clone(),
|
||||
target_sign.public().into(),
|
||||
move |transaction_nonce, initialization_data| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Target::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -230,12 +230,12 @@ impl InitBridge {
|
||||
signer: target_sign,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
encode_init_bridge(initialization_data),
|
||||
encode_init_bridge(initialization_data).into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -132,7 +132,7 @@ impl RegisterParachain {
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
relay_sudo_account.clone(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Relaychain::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -140,12 +140,12 @@ impl RegisterParachain {
|
||||
signer: reserve_parachain_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
reserve_parachain_id_call,
|
||||
reserve_parachain_id_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await?,
|
||||
@@ -181,7 +181,7 @@ impl RegisterParachain {
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
relay_sudo_account.clone(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Relaychain::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -189,12 +189,12 @@ impl RegisterParachain {
|
||||
signer: register_parathread_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
register_parathread_call,
|
||||
register_parathread_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await?,
|
||||
@@ -243,17 +243,20 @@ impl RegisterParachain {
|
||||
let force_lease_signer = relay_sign.clone();
|
||||
relay_client
|
||||
.submit_signed_extrinsic(relay_sudo_account.clone(), move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Relaychain::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: force_lease_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(force_lease_call, transaction_nonce),
|
||||
})
|
||||
unsigned: UnsignedTransaction::new(
|
||||
force_lease_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
})
|
||||
.await?;
|
||||
log::info!(target: "bridge", "Registered parachain leases: {:?}. Waiting for onboarding", para_id);
|
||||
|
||||
@@ -615,17 +615,17 @@ where
|
||||
let (spec_version, transaction_version) = client.simple_runtime_version().await?;
|
||||
client
|
||||
.submit_signed_extrinsic(sign.public().into(), move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
C::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash,
|
||||
signer: sign,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||
})
|
||||
unsigned: UnsignedTransaction::new(call.into(), transaction_nonce),
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map(drop)
|
||||
|
||||
@@ -445,7 +445,7 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
signer: key_pair.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: unsigned_tx.clone(),
|
||||
}),
|
||||
})?,
|
||||
)
|
||||
.await??
|
||||
.priority;
|
||||
@@ -468,7 +468,7 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
signer: key_pair.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: unsigned_tx,
|
||||
}),
|
||||
})?,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -124,9 +124,13 @@ impl SendMessage {
|
||||
let payload = {
|
||||
let target_call_weight = prepare_call_dispatch_weight(
|
||||
dispatch_weight,
|
||||
ExplicitOrMaximal::Explicit(Target::get_dispatch_info(&target_call)?.weight),
|
||||
|| {
|
||||
Ok(ExplicitOrMaximal::Explicit(
|
||||
Target::get_dispatch_info(&target_call)?.weight,
|
||||
))
|
||||
},
|
||||
compute_maximal_message_dispatch_weight(Target::max_extrinsic_weight()),
|
||||
);
|
||||
)?;
|
||||
let source_sender_public: MultiSigner = source_sign.public().into();
|
||||
let source_account_id = source_sender_public.into_account();
|
||||
|
||||
@@ -200,7 +204,7 @@ impl SendMessage {
|
||||
signer: source_sign.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(send_message_call.clone(), 0),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
))
|
||||
.await?;
|
||||
@@ -213,7 +217,7 @@ impl SendMessage {
|
||||
signer: source_sign.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(send_message_call, transaction_nonce),
|
||||
})
|
||||
})?
|
||||
.encode();
|
||||
|
||||
log::info!(
|
||||
@@ -241,7 +245,7 @@ impl SendMessage {
|
||||
HexBytes::encode(&signed_source_call)
|
||||
);
|
||||
|
||||
Bytes(signed_source_call)
|
||||
Ok(Bytes(signed_source_call))
|
||||
})
|
||||
.await?;
|
||||
});
|
||||
@@ -252,12 +256,16 @@ impl SendMessage {
|
||||
|
||||
fn prepare_call_dispatch_weight(
|
||||
user_specified_dispatch_weight: &Option<ExplicitOrMaximal<Weight>>,
|
||||
weight_from_pre_dispatch_call: ExplicitOrMaximal<Weight>,
|
||||
weight_from_pre_dispatch_call: impl Fn() -> anyhow::Result<ExplicitOrMaximal<Weight>>,
|
||||
maximal_allowed_weight: Weight,
|
||||
) -> Weight {
|
||||
match user_specified_dispatch_weight.clone().unwrap_or(weight_from_pre_dispatch_call) {
|
||||
ExplicitOrMaximal::Explicit(weight) => weight,
|
||||
ExplicitOrMaximal::Maximal => maximal_allowed_weight,
|
||||
) -> anyhow::Result<Weight> {
|
||||
match user_specified_dispatch_weight
|
||||
.clone()
|
||||
.map(Ok)
|
||||
.unwrap_or_else(weight_from_pre_dispatch_call)?
|
||||
{
|
||||
ExplicitOrMaximal::Explicit(weight) => Ok(weight),
|
||||
ExplicitOrMaximal::Maximal => Ok(maximal_allowed_weight),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ impl SwapTokens {
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
accounts.source_account_at_this_chain.clone(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Source::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -253,12 +253,12 @@ impl SwapTokens {
|
||||
signer: create_swap_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
create_swap_call,
|
||||
create_swap_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await?,
|
||||
@@ -386,7 +386,7 @@ impl SwapTokens {
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
accounts.target_account_at_bridged_chain.clone(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Target::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -394,12 +394,12 @@ impl SwapTokens {
|
||||
signer: target_sign,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
send_message_call,
|
||||
send_message_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await?,
|
||||
@@ -430,7 +430,7 @@ impl SwapTokens {
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
accounts.source_account_at_this_chain.clone(),
|
||||
move |_, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
Source::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -438,12 +438,12 @@ impl SwapTokens {
|
||||
signer: source_sign,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
cancel_swap_call,
|
||||
cancel_swap_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await?,
|
||||
|
||||
Reference in New Issue
Block a user