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