model

package
Version: v0.0.0-...-aec784a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package model provides data structures that represent anchor and database records.

Index

Constants

View Source
const (
	BTCTestnet3 = 3
	BTCTestnet4 = 4
	BTCMainnet  = 255
)

Bitcoin networks.

Variables

View Source
var (
	ErrInvalidSignature = errors.New("ErrInvalidSignature")
	ErrInvalidVersion   = errors.New("ErrInvalidVersion")
	ErrInvalidBTCNet    = errors.New("ErrInvalidBTCNet")
)

Errors

Functions

func EncodeOpReturn

func EncodeOpReturn(a *Anchor) [80]byte

EncodeOpReturn encodes the given Anchor to OP_RETURN.

func XAnchorVersion

func XAnchorVersion(v uint8)

XAnchorVersion sets anchorVersion for test.

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

func DecodeOpReturn(b [80]byte) (*Anchor, error)

DecodeOpReturn decodes the given bytes array to Anchor.

func NewAnchor

func NewAnchor(btcnet BTCNet, timestamp time.Time, bbc1dom, bbc1tx []byte) *Anchor

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.

func (*Anchor) String

func (a *Anchor) String() string

String returns a human-readable expression for the Anchor.

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.

type BTCNet

type BTCNet uint8

BTCNet represents a Bitcoin network.

func (BTCNet) String

func (n BTCNet) String() string

String returns the name of n.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL