mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-29 02:14:16 +01:00
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:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user