gw

package
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: 9 Imported by: 0

Documentation

Overview

Package gw provides ability to anchor BBc-1 transactions to the Bitcoin block chain, that hides the implementation of BTC (package btc) and Store (package store) from applications.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCouldNotPutAnchor     = errors.New("ErrCouldNotPutAnchor")
	ErrCouldNotStoreRecord   = errors.New("ErrCouldNotStoreRecord")
	ErrCouldNotGetRecord     = errors.New("ErrCouldNotGetRecord")
	ErrCouldNotRefreshRecord = errors.New("ErrCouldNotRefreshRecord")
	ErrCouldNotCloseStore    = errors.New("ErrCouldNotCloseStore")
)

Errors TODO: Handle more error types: e.g. ErrInvalidFee TODO: Provide more error types. e.g. ErrNoConfirmedUTXO

Functions

This section is empty.

Types

type Gateway

type Gateway interface {
	// RegisterTransaction inserts an anchor into Bitcoin block chain
	// by sending a transaction, and returns its Bitcoin transaction ID.
	RegisterTransaction(ctx context.Context, domID, txID []byte) (btcTXID []byte, err error)

	// StoreRecord retrieves a Bitcoin transaction,
	// and saves its AnchorRecord embedded in OP_RETURN in the datastore.
	StoreRecord(ctx context.Context, btcTXID []byte) error

	// GetRecord gets an AnchorRecord
	// specified by the given information from the datastore.
	GetRecord(ctx context.Context, domID, txID []byte) (*model.AnchorRecord, error)

	// RefreshRecord update AnchorRecord specified by domID and txID.
	// Get it from datastore, update AnchorRecord.Confirmations by
	// retrieving and checking the Bitcoin transaction, and then put it into datastore.
	// In addition, changes AnchorRecord.BBc1DomainName or AnchorRecord.Note or both, if the given value is not nil.
	RefreshRecord(ctx context.Context, domID, txID []byte, pBBc1domName, pNote *string) error

	io.Closer
}

Gateway provides features to register and verify BBc-1 transactions.

type GatewayImpl

type GatewayImpl struct {
	BTCNet model.BTCNet
	BTC    btc.BTC
	Wallet btc.Wallet
	Store  store.Store
	// contains filtered or unexported fields
}

func NewGatewayImpl

func NewGatewayImpl(bn model.BTCNet, b btc.BTC, w btc.Wallet, s store.Store) *GatewayImpl

NewGatewayImpl initializes a GatewayImpl.

Parameters:

  • bn sets Bitcoin network to anchor.
  • b sets btc.BTC.
  • w sets btc.Wallet.
  • s sets store.Store.

bn must be same as b.BTCNet. b must be *btc.BitcoinCLI for now.

func (*GatewayImpl) Close

func (g *GatewayImpl) Close() error

Close closes g.Store. No need to close *btc.BitcoinCLI

func (*GatewayImpl) GetRecord

func (g *GatewayImpl) GetRecord(ctx context.Context, domID, txID []byte) (*model.AnchorRecord, error)

func (*GatewayImpl) RefreshRecord

func (g *GatewayImpl) RefreshRecord(ctx context.Context, domID, txID []byte, pBBc1domName, pNote *string) error

func (*GatewayImpl) RegisterTransaction

func (g *GatewayImpl) RegisterTransaction(ctx context.Context, domID, txID []byte) (btcTXID []byte, err error)

func (*GatewayImpl) StoreRecord

func (g *GatewayImpl) StoreRecord(ctx context.Context, btcTXID []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL