share receiving contract check

This commit is contained in:
wiesche
2026-09-12 19:40:11 +02:00
parent b648b65024
commit a6b6595a34
+16 -18
View File
@@ -246,6 +246,20 @@ where
Ok(sl) Ok(sl)
} }
// The foreign API only handles the receiving side
fn check_receiving_contract(net_change: Option<i64>, action: &str) -> Result<(), Error> {
let net_change = net_change.ok_or_else(|| {
Error::GenericError("Contract requires a net change (--send or --receive)".to_string())
})?;
if net_change <= 0 {
return Err(Error::GenericError(format!(
"Can't {} a non-receiving contract from a foreign API.",
action
)));
}
Ok(())
}
/// Initialize a receive transaction contract /// Initialize a receive transaction contract
pub fn contract_new<C, K>( pub fn contract_new<C, K>(
w: &mut WalletBackend<C, K>, w: &mut WalletBackend<C, K>,
@@ -256,15 +270,7 @@ where
C: NodeClient, C: NodeClient,
K: Keychain, K: Keychain,
{ {
let net_change = args.setup_args.net_change.ok_or_else(|| { check_receiving_contract(args.setup_args.net_change, "create")?;
Error::GenericError("Contract requires a net change (--send or --receive)".to_string())
})?;
// The foreign API only handles the receiving side.
if net_change <= 0 {
return Err(Error::GenericError(
"Can't create a non-receiving contract from a foreign API.".to_string(),
));
}
owner_contract_new(w, keychain_mask, args) owner_contract_new(w, keychain_mask, args)
} }
@@ -279,15 +285,7 @@ where
C: NodeClient, C: NodeClient,
K: Keychain, K: Keychain,
{ {
let net_change = args.net_change.ok_or_else(|| { check_receiving_contract(args.net_change, "sign")?;
Error::GenericError("Contract requires a net change (--send or --receive)".to_string())
})?;
// The foreign API only handles the receiving side.
if net_change <= 0 {
return Err(Error::GenericError(
"Can't sign a non-receiving contract from a foreign API.".to_string(),
));
}
owner_contract_sign(w, keychain_mask, args, slate) owner_contract_sign(w, keychain_mask, args, slate)
} }