Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WriteObject for hash #1094

Merged
merged 2 commits into from
Jun 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func (d *Digest) Sum(b []byte) Hash {
return Hash(d.Hash.Sum(b))
}

// WriteObject adds an interface data to the running hash.
// It never retruns an error.
func (d *Digest) WriteObject(v interface{}) (int, error) {
return d.Write(structhash.Dump(v, 0))
}

// A Hash is a type for representing hash with base58 encode and decode functions.
type Hash []byte

Expand All @@ -40,7 +46,7 @@ func New() *Digest {
// Dump takes an interface and returns its hash representation.
func Dump(v interface{}) Hash {
d := New()
d.Write(structhash.Dump(v, 0))
d.WriteObject(v)
return d.Sum(nil)
}

Expand Down