Make target signer optional when sending message. (#1018)

* make target signer optional in send message.

* remove non-used argument

* fmt

* better doc

* trigger build

* fix clippy
This commit is contained in:
kaichao
2021-06-25 15:22:18 +08:00
committed by Bastian Köcher
parent 79e7845544
commit 655901250d
@@ -41,9 +41,12 @@ pub struct SendMessage {
source: SourceConnectionParams,
#[structopt(flatten)]
source_sign: SourceSigningParams,
// TODO [#885] Move TargetSign to origins
#[structopt(flatten)]
target_sign: TargetSigningParams,
/// The SURI of secret key to use when transactions are submitted to the Target node.
#[structopt(long, required_if("origin", "Target"))]
target_signer: Option<String>,
/// The password for the SURI of secret key to use when transactions are submitted to the Target node.
#[structopt(long)]
target_signer_password: Option<String>,
/// Hex-encoded lane id. Defaults to `00000000`.
#[structopt(long, default_value = "00000000")]
lane: HexLaneId,
@@ -69,7 +72,8 @@ impl SendMessage {
crate::select_full_bridge!(self.bridge, {
let SendMessage {
source_sign,
target_sign,
target_signer,
target_signer_password,
ref mut message,
dispatch_weight,
origin,
@@ -78,7 +82,6 @@ impl SendMessage {
} = self;
let source_sign = source_sign.to_keypair::<Source>()?;
let target_sign = target_sign.to_keypair::<Target>()?;
encode_call::preprocess_call::<Source, Target>(message, bridge.bridge_instance_index());
let target_call = Target::encode_call(message)?;
@@ -98,6 +101,13 @@ impl SendMessage {
match origin {
Origins::Source => CallOrigin::SourceAccount(source_account_id),
Origins::Target => {
let target_sign = TargetSigningParams {
target_signer: target_signer.clone().ok_or_else(|| {
anyhow::format_err!("The argument target_signer is not available")
})?,
target_signer_password: target_signer_password.clone(),
};
let target_sign = target_sign.to_keypair::<Target>()?;
let digest = account_ownership_digest(
&target_call,
source_account_id.clone(),
@@ -255,8 +265,6 @@ mod tests {
"1234",
"--source-signer",
"//Alice",
"--target-signer",
"//Bob",
"remark",
"--remark-payload",
"1234",
@@ -321,4 +329,24 @@ mod tests {
}
);
}
#[test]
fn target_signer_must_exist_if_origin_is_target() {
// given
let send_message = SendMessage::from_iter_safe(vec![
"send-message",
"MillauToRialto",
"--source-port",
"1234",
"--source-signer",
"//Alice",
"--origin",
"Target",
"remark",
"--remark-payload",
"1234",
]);
assert!(send_message.is_err());
}
}