Skip to content

Commit

Permalink
ensure transaction amount and inputs not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Mar 15, 2019
1 parent 1c47831 commit 94cd41a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion common/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (tx *SignedTransaction) Validate(store DataStore) error {
return fmt.Errorf("invalid tx version %d", tx.Version)
}

if len(tx.Inputs) < 1 || len(tx.Outputs) < 1 {
return fmt.Errorf("invalid tx inputs or outputs %d %d", len(tx.Inputs), len(tx.Outputs))
}

if len(tx.Inputs) != len(tx.Signatures) {
return fmt.Errorf("invalid tx signature number %d %d", len(tx.Inputs), len(tx.Signatures))
}
Expand Down Expand Up @@ -206,7 +210,7 @@ func (tx *SignedTransaction) Validate(store DataStore) error {
}
}

if inputAmount.Cmp(outputAmount) != 0 {
if inputAmount.Sign() <= 0 || inputAmount.Cmp(outputAmount) != 0 {
return fmt.Errorf("invalid input output amount %s %s", inputAmount.String(), outputAmount.String())
}
return nil
Expand Down

0 comments on commit 94cd41a

Please sign in to comment.