Skip to content

Commit

Permalink
types: use const instead of magic strings for v2 resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jul 23, 2024
1 parent 698efe3 commit 9ae5cfa
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import (
"lukechampine.com/frand"
)

const (
v2ResolutionRenewal = "renewal"
v2ResolutionStorageProof = "storageProof"
v2ResolutionFinalization = "finalization"
v2ResolutionExpiration = "expiration"
)

const (
// MaxRevisionNumber is used to finalize a FileContract. When a contract's
// RevisionNumber is set to this value, no further revisions are possible.
Expand Down Expand Up @@ -1131,13 +1138,13 @@ func (res V2FileContractResolution) MarshalJSON() ([]byte, error) {
var typ string
switch res.Resolution.(type) {
case *V2FileContractRenewal:
typ = "renewal"
typ = v2ResolutionRenewal
case *V2StorageProof:
typ = "storageProof"
typ = v2ResolutionStorageProof
case *V2FileContractFinalization:
typ = "finalization"
typ = v2ResolutionFinalization
case *V2FileContractExpiration:
typ = "expiration"
typ = v2ResolutionExpiration
default:
panic(fmt.Sprintf("unhandled file contract resolution type %T", res.Resolution))
}
Expand All @@ -1159,13 +1166,13 @@ func (res *V2FileContractResolution) UnmarshalJSON(b []byte) error {
return err
}
switch p.Type {
case "renewal":
case v2ResolutionRenewal:
res.Resolution = new(V2FileContractRenewal)
case "storageProof":
case v2ResolutionStorageProof:
res.Resolution = new(V2StorageProof)
case "finalization":
case v2ResolutionFinalization:
res.Resolution = new(V2FileContractFinalization)
case "expiration":
case v2ResolutionExpiration:
res.Resolution = new(V2FileContractExpiration)
default:
return fmt.Errorf("unknown file contract resolution type %q", p.Type)
Expand Down

0 comments on commit 9ae5cfa

Please sign in to comment.