mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-21 09:08:32 +02:00
De-panic and validate contract CLI input handling
Bad input to the contract CLI could abort the process:
- a non-numeric --make-outputs value reached output_amounts(), which
unwrap()s the float parse;
- `contract new` with neither --send nor --receive hit a panic in
get_net_change;
- `contract sign` panicked ("No address to encrypt for") when given no
--encrypt-for and an incoming slate with no embedded sender.
Validate --make-outputs and require exactly one of --send/--receive at
parse time (ParseError, before reaching the panicking paths), and return a
typed error instead of panicking when there is no address to encrypt for.
Verified at runtime: each now yields a clean "Invalid Arguments" error.
This commit is contained in:
@@ -1887,8 +1887,10 @@ where
|
||||
if args.counterparty_addr.is_some() {
|
||||
args.counterparty_addr.unwrap()
|
||||
} else {
|
||||
if !slatepack.sender.is_some() {
|
||||
panic!("No address to encrypt for. Contracts only support encrypted slates right now.");
|
||||
if slatepack.sender.is_none() {
|
||||
return Err(grin_wallet_libwallet::Error::GenericError(
|
||||
"No address to encrypt for: pass --encrypt-for. Contracts only support encrypted slates.".into(),
|
||||
));
|
||||
}
|
||||
String::try_from(&slatepack.sender.unwrap())?
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user