Contracts: validate net_change instead of unwrapping

contract `new` and the foreign `contract_new` API unwrapped the optional
net_change field, so a request omitting it panicked the wallet. Return an
error instead.

- new::compute and foreign::contract_new: net_change.ok_or_else(..).
- test: contract_new with no net change errors rather than panicking.

Addresses PR #754 review (new.rs, foreign.rs).
This commit is contained in:
jwinterm
2026-06-04 19:34:21 -04:00
parent 571b1f968a
commit 15cbbc96e8
3 changed files with 41 additions and 2 deletions
+3 -1
View File
@@ -251,7 +251,9 @@ where
C: NodeClient + 'a,
K: Keychain + 'a,
{
let net_change = args.setup_args.net_change.unwrap();
let net_change = args.setup_args.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(
"Can't create a non-receiving contract from a foreign API.".to_string(),