claimtrie/claim/id.go
Tzu-Jung Lee ed4478bc72 cleanup: reorg the code for dependencies.
Move self-contained pieces into their own package.
This spells out the depedencies and the context each
sub-package focuses on.

Not the final structure as it's WIP.
Just tying the knots while climbing up the rope.
2018-07-09 10:48:33 -07:00

36 lines
608 B
Go

package claim
import (
"bytes"
"encoding/binary"
"encoding/hex"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
)
// NewID ...
func NewID(op wire.OutPoint) ID {
w := bytes.NewBuffer(op.Hash[:])
if err := binary.Write(w, binary.BigEndian, op.Index); err != nil {
panic(err)
}
var id ID
copy(id[:], btcutil.Hash160(w.Bytes()))
return id
}
// NewIDFromString ...
func NewIDFromString(s string) (ID, error) {
b, err := hex.DecodeString(s)
var id ID
copy(id[:], b)
return id, err
}
// ID ...
type ID [20]byte
func (id ID) String() string {
return hex.EncodeToString(id[:])
}