Skip to content

Commit

Permalink
types: Use distinguishers for v2 IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Oct 13, 2023
1 parent 6ca0ac7 commit 9cbf7aa
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ var (
SpecifierEd25519 = NewSpecifier("ed25519")
SpecifierSiacoinOutput = NewSpecifier("siacoin output")
SpecifierSiafundOutput = NewSpecifier("siafund output")
SpecifierClaimOutput = NewSpecifier("claim output")
SpecifierFileContract = NewSpecifier("file contract")
SpecifierStorageProof = NewSpecifier("storage proof")
SpecifierAttestation = NewSpecifier("attestation")
SpecifierFoundation = NewSpecifier("foundation")
SpecifierEntropy = NewSpecifier("entropy")
)
Expand Down Expand Up @@ -325,7 +323,7 @@ func (fcid FileContractID) V2RenterOutputID() SiacoinOutputID {
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierSiacoinOutput.EncodeTo(h.E)
h.WriteDistinguisher("id/v2filecontractoutput")
fcid.EncodeTo(h.E)
h.E.WriteUint64(0)
return SiacoinOutputID(h.Sum())
Expand All @@ -336,7 +334,7 @@ func (fcid FileContractID) V2HostOutputID() SiacoinOutputID {
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierSiacoinOutput.EncodeTo(h.E)
h.WriteDistinguisher("id/v2filecontractoutput")
fcid.EncodeTo(h.E)
h.E.WriteUint64(1)
return SiacoinOutputID(h.Sum())
Expand All @@ -347,7 +345,7 @@ func (fcid FileContractID) V2RenewalID() FileContractID {
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierFileContract.EncodeTo(h.E)
h.WriteDistinguisher("id/v2filecontractrenewal")
fcid.EncodeTo(h.E)
return FileContractID(h.Sum())
}
Expand Down Expand Up @@ -780,7 +778,7 @@ func (*V2Transaction) SiacoinOutputID(txid TransactionID, i int) SiacoinOutputID
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierSiacoinOutput.EncodeTo(h.E)
h.WriteDistinguisher("id/siacoinoutput")
txid.EncodeTo(h.E)
h.E.WriteUint64(uint64(i))
return SiacoinOutputID(h.Sum())
Expand All @@ -791,7 +789,7 @@ func (*V2Transaction) SiafundOutputID(txid TransactionID, i int) SiafundOutputID
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierSiafundOutput.EncodeTo(h.E)
h.WriteDistinguisher("id/siafundoutput")
txid.EncodeTo(h.E)
h.E.WriteUint64(uint64(i))
return SiafundOutputID(h.Sum())
Expand All @@ -802,7 +800,7 @@ func (*V2Transaction) V2FileContractID(txid TransactionID, i int) FileContractID
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierFileContract.EncodeTo(h.E)
h.WriteDistinguisher("id/filecontract")
txid.EncodeTo(h.E)
h.E.WriteUint64(uint64(i))
return FileContractID(h.Sum())
Expand All @@ -813,7 +811,7 @@ func (*V2Transaction) AttestationID(txid TransactionID, i int) Hash256 {
h := hasherPool.Get().(*Hasher)
defer hasherPool.Put(h)
h.Reset()
SpecifierAttestation.EncodeTo(h.E)
h.WriteDistinguisher("id/attestation")
txid.EncodeTo(h.E)
h.E.WriteUint64(uint64(i))
return h.Sum()
Expand Down

0 comments on commit 9cbf7aa

Please sign in to comment.