mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-29 18:33:56 +01:00
Replace reachable panics in contract flow with typed errors
Contract setup/sign and output selection used panic! on protocol-reachable invariant violations: receiver fee exceeding net_change, net_change / num_participants mismatch between the setup and sign phases, a negative change output, conflicting selection args, and a failed kernel-excess computation. A crafted or inconsistent counterparty slate could abort the wallet. Return Error::GenericError (or propagate the underlying error) instead; build_output_amount_list now returns Result.
This commit is contained in:
@@ -95,11 +95,11 @@ where
|
||||
// Make sure `my_fee < net_change` holds for the receiver. This can't be true for a self-spend, because nobody
|
||||
// has a net_change > 0 which makes a self-spend ok to be a net negative when fees are included.
|
||||
if net_change > 0 && my_fee.fee() > net_change.abs() as u64 {
|
||||
panic!(
|
||||
return Err(Error::GenericError(format!(
|
||||
"My contribution as a receiver would be net negative. my_fee: {}, net_change: {}",
|
||||
my_fee.fee(),
|
||||
net_change
|
||||
);
|
||||
)));
|
||||
}
|
||||
// Add my share of fee contribution to the slate fees
|
||||
slate.fee_fields = FeeFields::new(0, slate.fee_fields.fee() + my_fee.fee())?;
|
||||
|
||||
Reference in New Issue
Block a user