Documentation ¶
Overview ¶
Package model provides data structures that represent anchor and database records.
Index ¶
Constants ¶
const ( BTCTestnet3 = 3 BTCTestnet4 = 4 BTCMainnet = 255 )
Bitcoin networks.
Variables ¶
var ( ErrInvalidSignature = errors.New("ErrInvalidSignature") ErrInvalidVersion = errors.New("ErrInvalidVersion") ErrInvalidBTCNet = errors.New("ErrInvalidBTCNet") )
Errors
Functions ¶
func EncodeOpReturn ¶
EncodeOpReturn encodes the given Anchor to OP_RETURN.
Types ¶
type Anchor ¶
type Anchor struct { Version uint8 BTCNet BTCNet Timestamp time.Time BBc1DomainID [32]byte BBc1TransactionID [32]byte }
Anchor contains an anchor that can be encoded to OP_RETURN.
func DecodeOpReturn ¶
DecodeOpReturn decodes the given bytes array to Anchor.
func NewAnchor ¶
NewAnchor initializes an Anchor.
Parameters:
- btcnet sets target Bitcoin network.
- timestamp sets time stamp.
- bbc1dom sets BBc-1 Domain ID.
- bbc1tx sets BBc-1 Transaction ID.
Anchor.BBc1DomainID and Anchor.BBc1TransactionID are fixed at 32 bytes. If the given []byte is shorter than 32bytes, padding with 0. If the given []byte is longer than 32bytes, only use the first 32 bytes.
type AnchorRecord ¶
type AnchorRecord struct { Anchor *Anchor BTCTransactionID []byte // Data from the Bitcoin transaction. TransactionTime time.Time Confirmations uint // Optional data NOT included in Bitcoin. BBc1DomainName string Note string }
AnchorRecord contains an Anchor and a Bitcoin transaction ID in which the Anchor is embedded. Some additional information from the Bitcoin transaction are also included. Some optional information NOT from the Bitcoin transaction can be added.
func NewAnchorRecord ¶
func NewAnchorRecord(anchor *Anchor, btctx []byte, ts time.Time, conf uint, bbc1domName, note string) *AnchorRecord
NewAnchorRecord initializes an AnchorRecord.
Parameters:
- anchor sets the Anchor
- btctx sets the Bitcoin transaction ID in which anchor is embedded.
- ts sets the time in Bitcoin transaction.
- conf sets the number of confirmations.
- bbc1domName sets the BBc-1 domain name.
- note sets a string for note.
bbc1domName and note are not included in Bitcoin blockchain. They cannot be restored when the datastore is lost.
func (*AnchorRecord) String ¶
func (r *AnchorRecord) String() string
String returns a human-readable expression for the AnchorRecord.