store

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

Documentation

Overview

Package store provides ability to store anchors and related data, that brings an abstraction layer between the Gateway (package gw) and databases.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToOpen   = errors.New("ErrFailedToOpen")
	ErrFailedToClose  = errors.New("ErrFailedToClose")
	ErrFailedToGet    = errors.New("ErrFailedToGet")
	ErrFailedToPut    = errors.New("ErrFailedToPut")
	ErrFailedToUpdate = errors.New("ErrFailedToUpdate")
)

Errors

Functions

This section is empty.

Types

type AnchorEntity

type AnchorEntity struct {
	CID               string    `docstore:"cid"`
	BBc1DomainID      []byte    `docstore:"bbc1domid"`
	BBc1TransactionID []byte    `docstore:"bbc1txid"`
	AnchorVersion     uint8     `docstore:"anchorver"`
	BTCNet            uint8     `docstore:"btcnet"`
	AnchorTime        time.Time `docstore:"anchortime"`
	BTCTransactionID  []byte    `docstore:"btctxid"`
	TransactionTime   time.Time `docstore:"txtime"`
	Confirmations     uint      `docstore:"confirmations"`
	BBc1DomainName    string    `docstore:"bbc1dom"`
	Note              string    `docstore:"note"`
}

AnchorEntity contains data equivalent to AnchorRecord, but focuses on placing data in the datastore. In particular, CID is a key field that contains a combined string that starts with BBc-1 domain ID, followed by transaction ID.

func NewAnchorEntity

func NewAnchorEntity(r *model.AnchorRecord) *AnchorEntity

NewAnchorEntity initializes an AnchorEntity from the given AnchorRecord.

func (*AnchorEntity) AnchorRecord

func (e *AnchorEntity) AnchorRecord() *model.AnchorRecord

AnchorRecord returns an AnchorRecord from the AnchorEntity.

type Docstore

type Docstore struct {
	// contains filtered or unexported fields
}

func NewDocstore

func NewDocstore(conn string) *Docstore

func (*Docstore) Close

func (d *Docstore) Close() error

Close closes the Docstore.

func (*Docstore) Get

func (d *Docstore) Get(ctx context.Context, bbc1dom, bbc1tx []byte) (*model.AnchorRecord, error)

func (*Docstore) GetEntity

func (d *Docstore) GetEntity(ctx context.Context, e *AnchorEntity) error

func (*Docstore) Open

func (d *Docstore) Open() error

Open opens d.coll once.

func (*Docstore) Put

func (d *Docstore) Put(ctx context.Context, r *model.AnchorRecord) error

func (*Docstore) PutEntity

func (d *Docstore) PutEntity(ctx context.Context, e *AnchorEntity) error

func (*Docstore) UpdateBBc1DomainName

func (d *Docstore) UpdateBBc1DomainName(ctx context.Context, bbc1dom, bbc1tx []byte, bbc1domName string) error

func (*Docstore) UpdateConfirmations

func (d *Docstore) UpdateConfirmations(ctx context.Context, bbc1dom, bbc1tx []byte, confirmations uint) error

func (*Docstore) UpdateEntity

func (d *Docstore) UpdateEntity(ctx context.Context, e *AnchorEntity, updateConfirmations, updateBBc1Dom, updateNote bool) error

UpdateEntity updates the AnchorEntity specified by e.CID. It updates Confirmations, BBc1DomainName, and Note only, as other data must not be changed.

func (*Docstore) UpdateNote

func (d *Docstore) UpdateNote(ctx context.Context, bbc1dom, bbc1tx []byte, note string) error

type Store

type Store interface {
	// Put adds or replaces an AnchorRecord in O(1) time.
	Put(ctx context.Context, r *model.AnchorRecord) error

	// Get returns the AnchorRecord specified by bbc1dom and bbc1tx in O(1) time.
	Get(ctx context.Context, bbc1dom, bbc1tx []byte) (*model.AnchorRecord, error)

	// UpdateConfirmations updates Confirmations
	//  in the AnchorRecord specified by bbc1dom and bbc1tx.
	UpdateConfirmations(ctx context.Context, bbc1dom, bbc1tx []byte, confirmations uint) error

	// UpdateBBc1DomainName updates BBc1DomainName
	// in the AnchorRecord specified by bbc1dom and bbc1tx.
	UpdateBBc1DomainName(ctx context.Context, bbc1dom, bbc1tx []byte, bbc1domName string) error

	// UpdateNote updates Note
	// in the AnchorRecord specified by bbc1dom and bbc1tx.
	UpdateNote(ctx context.Context, bbc1dom, bbc1tx []byte, note string) error

	io.Closer
}

Store provides features to store anchor data in a datastore. Anchor data (especially the Bitcoin transaction IDs) should be stored, as finding an Anchor needs walking through all Bitcoin blockchains and is time consuming.

Jump to

Keyboard shortcuts

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