Skip to content

Commit

Permalink
Merge pull request #268 from SiaFoundation/nate/validate-v2-transacti…
Browse files Browse the repository at this point in the history
…on-policies

Fix panic when validating v2 transactions
  • Loading branch information
lukechampine authored Jan 29, 2025
2 parents 0349a9a + e1258be commit 5ce4a94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
default: major
---

# Fixed a panic when unmarshalling unknown spend policy types

An error will now be returned when trying to encode a transaction with an unset `SpendPolicy`
2 changes: 2 additions & 0 deletions types/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ func (p *SpendPolicy) UnmarshalJSON(b []byte) (err error) {
var pt PolicyTypeUnlockConditions
err = json.Unmarshal(v.Policy, (*UnlockConditions)(&pt))
p.Type = pt
default:
err = fmt.Errorf("unknown policy type %q", v.Type)
}
return
}
Expand Down
3 changes: 3 additions & 0 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ func TestV2TransactionJSONMarshalling(t *testing.T) {
LeafIndex: frand.Uint64n(math.MaxUint64),
},
},
SatisfiedPolicy: SatisfiedPolicy{
Policy: AnyoneCanSpend(),
},
},
},
}
Expand Down

0 comments on commit 5ce4a94

Please sign in to comment.