database

package
v0.8.2-beta Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadSnapshot

func ReadSnapshot(file ioutil2.SectionReader) (height uint64, format uint32, bptRoot []byte, rd ioutil2.SectionReader, err error)

ReadSnapshot reads a snapshot file, returning the header values and a reader.

Types

type Account

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

Account manages a record.

func (*Account) AddPending added in v1.0.0

func (r *Account) AddPending(txid *url.TxID) error

func (*Account) AddSyntheticForAnchor added in v0.6.0

func (r *Account) AddSyntheticForAnchor(anchor [32]byte, txid *url.TxID) error

func (*Account) Chain

func (r *Account) Chain(name string, typ protocol.ChainType) (*Chain, error)

Chain returns a chain manager for the given chain.

func (*Account) GetObject

func (r *Account) GetObject() (*protocol.Object, error)

GetObject loads the object metadata.

func (*Account) GetState

func (r *Account) GetState() (protocol.Account, error)

GetState loads the record state.

func (*Account) GetStateAs

func (r *Account) GetStateAs(state interface{}) error

GetStateAs loads the record state and unmarshals into the given value. In most cases `state` should be a double pointer.

func (*Account) Index

func (r *Account) Index(key ...interface{}) *Value

Index returns a value that can read or write an index value.

func (*Account) IndexChain added in v0.5.1

func (r *Account) IndexChain(name string, major bool) (*Chain, error)

IndexChain returns a chain manager for the index chain of the given chain.

func (*Account) Pending added in v1.0.0

func (r *Account) Pending() (*protocol.TxIdSet, error)

func (*Account) PutState

func (r *Account) PutState(state protocol.Account) error

PutState stores the record state.

func (*Account) ReadChain

func (r *Account) ReadChain(name string) (*Chain, error)

ReadChain returns a read-only chain manager for the given chain.

func (*Account) ReadIndexChain added in v0.5.1

func (r *Account) ReadIndexChain(name string, major bool) (*Chain, error)

ReadIndexChain returns a read-only chain manager for the index chain of the given chain.

func (*Account) RemovePending added in v1.0.0

func (r *Account) RemovePending(txid *url.TxID) error

func (*Account) StateReceipt added in v0.5.1

func (a *Account) StateReceipt() (*managed.Receipt, error)

StateReceipt returns a Merkle receipt for the account state in the BPT.

func (*Account) SyntheticForAnchor added in v0.6.0

func (r *Account) SyntheticForAnchor(anchor [32]byte) ([]*url.TxID, error)

type Batch

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

Batch batches database writes.

func (*Batch) Account

func (b *Batch) Account(u *url.URL) *Account

Account returns an Account for the given URL.

func (*Batch) AccountByID deprecated

func (b *Batch) AccountByID(id []byte) (*Account, error)

AccountByID returns an Account for the given ID.

This is still needed in one place, so the deprecation warning is disabled in order to pass static analysis.

Deprecated: Use Account.

func (*Batch) Begin added in v0.5.1

func (b *Batch) Begin(writable bool) *Batch

func (*Batch) BptReceipt added in v0.5.1

func (b *Batch) BptReceipt(key storage.Key, value [32]byte) (*managed.Receipt, error)

BptReceipt builds a BPT receipt for the given key.

func (*Batch) BptRoot added in v1.0.0

func (b *Batch) BptRoot() []byte

func (*Batch) Commit

func (b *Batch) Commit() error

Commit commits pending writes to the key-value store or the parent batch. Attempting to use the Batch after calling Commit or Discard will result in a panic.

func (*Batch) CommitBpt added in v0.5.1

func (b *Batch) CommitBpt() error

CommitBpt updates the Patricia Tree hashes with the values from the updates since the last update.

func (*Batch) Dirty

func (b *Batch) Dirty() bool

Dirty returns true if anything has been changed.

func (*Batch) Discard

func (b *Batch) Discard()

Discard discards pending writes. Attempting to use the Batch after calling Discard will result in a panic.

func (*Batch) GetMinorRootChainAnchor added in v0.5.1

func (b *Batch) GetMinorRootChainAnchor(network *config.Network) ([]byte, error)

func (*Batch) Import

func (b *Batch) Import(db interface{ Export() map[storage.Key][]byte }) error

Import imports values from another database.

func (*Batch) RestoreSnapshot

func (b *Batch) RestoreSnapshot(file ioutil2.SectionReader) error

RestoreSnapshot loads the full state of the partition from a file.

func (*Batch) SaveSnapshot

func (b *Batch) SaveSnapshot(file io.WriteSeeker, network *config.Network) error

SaveSnapshot writes the full state of the partition out to a file.

func (*Batch) Transaction

func (b *Batch) Transaction(id []byte) *Transaction

Transaction returns a Transaction for the given transaction ID.

func (*Batch) Update added in v0.5.1

func (b *Batch) Update(fn func(batch *Batch) error) error

Update runs the function with a writable transaction and commits if the function succeeds.

func (*Batch) View added in v0.5.1

func (b *Batch) View(fn func(batch *Batch) error) error

View runs the function with a read-only transaction.

type Chain

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

Chain manages a Merkle tree (chain).

func (*Chain) AddEntry

func (c *Chain) AddEntry(entry []byte, unique bool) error

AddEntry adds an entry to the chain

func (*Chain) Anchor

func (c *Chain) Anchor() []byte

Anchor calculates the anchor of the current Merkle state.

func (*Chain) AnchorAt added in v0.5.1

func (c *Chain) AnchorAt(height uint64) ([]byte, error)

AnchorAt calculates the anchor of the chain at the given height.

func (*Chain) CurrentState added in v0.5.1

func (c *Chain) CurrentState() *managed.MerkleState

CurrentState returns the current state of the chain.

func (*Chain) Entries

func (c *Chain) Entries(start int64, end int64) ([][]byte, error)

Entries returns entries in the given range.

func (*Chain) Entry

func (c *Chain) Entry(height int64) ([]byte, error)

Entry loads the entry in the chain at the given height.

func (*Chain) EntryAs added in v0.5.1

func (c *Chain) EntryAs(height int64, value encoding.BinaryUnmarshaler) error

EntryAs loads and unmarshals the entry in the chain at the given height.

func (*Chain) Height

func (c *Chain) Height() int64

Height returns the height of the chain.

func (*Chain) HeightOf

func (c *Chain) HeightOf(hash []byte) (int64, error)

HeightOf returns the height of the given entry in the chain.

func (*Chain) Pending

func (c *Chain) Pending() []managed.Hash

Pending returns the pending roots of the current Merkle state.

func (*Chain) Receipt

func (c *Chain) Receipt(from, to int64) (*managed.Receipt, error)

Receipt builds a receipt from one index to another

func (*Chain) State

func (c *Chain) State(height int64) (*managed.MerkleState, error)

State returns the state of the chain at the given height.

type Database

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

Database is an Accumulate database.

func New

func New(store storage.KeyValueStore, logger log.Logger) *Database

New creates a new database using the given key-value store.

func Open

func Open(cfg *config.Config, logger log.Logger) (*Database, error)

Open opens a key-value store and creates a new database with it.

func OpenBadger added in v0.5.1

func OpenBadger(filepath string, logger log.Logger) (*Database, error)

func OpenEtcd added in v0.5.1

func OpenEtcd(prefix string, config *clientv3.Config, logger log.Logger) (*Database, error)

func OpenInMemory added in v0.5.1

func OpenInMemory(logger log.Logger) *Database

func (*Database) Begin

func (d *Database) Begin(writable bool) *Batch

Begin starts a new batch.

func (*Database) Close

func (d *Database) Close() error

Close closes the database and the key-value store.

func (*Database) Update added in v0.5.1

func (d *Database) Update(fn func(batch *Batch) error) error

Update runs the function with a writable transaction and commits if the function succeeds.

func (*Database) View added in v0.5.1

func (d *Database) View(fn func(batch *Batch) error) error

View runs the function with a read-only transaction.

type SigOrTxn added in v0.6.0

type SigOrTxn struct {
	Transaction *protocol.Transaction `json:"transaction,omitempty" form:"transaction" query:"transaction" validate:"required"`
	Signature   protocol.Signature    `json:"signature,omitempty" form:"signature" query:"signature" validate:"required"`
	Txid        *url.TxID             `json:"txid,omitempty" form:"txid" query:"txid" validate:"required"`
	// contains filtered or unexported fields
}

func (*SigOrTxn) Copy added in v0.6.0

func (v *SigOrTxn) Copy() *SigOrTxn

func (*SigOrTxn) CopyAsInterface added in v0.6.0

func (v *SigOrTxn) CopyAsInterface() interface{}

func (*SigOrTxn) Equal added in v0.6.0

func (v *SigOrTxn) Equal(u *SigOrTxn) bool

func (*SigOrTxn) IsValid added in v0.6.0

func (v *SigOrTxn) IsValid() error

func (*SigOrTxn) MarshalBinary added in v0.6.0

func (v *SigOrTxn) MarshalBinary() ([]byte, error)

func (*SigOrTxn) MarshalJSON added in v0.6.0

func (v *SigOrTxn) MarshalJSON() ([]byte, error)

func (*SigOrTxn) UnmarshalBinary added in v0.6.0

func (v *SigOrTxn) UnmarshalBinary(data []byte) error

func (*SigOrTxn) UnmarshalBinaryFrom added in v0.6.0

func (v *SigOrTxn) UnmarshalBinaryFrom(rd io.Reader) error

func (*SigOrTxn) UnmarshalJSON added in v0.6.0

func (v *SigOrTxn) UnmarshalJSON(data []byte) error

type SigSetEntry added in v1.0.0

type SigSetEntry struct {
	System        bool                   `json:"system,omitempty" form:"system" query:"system" validate:"required"`
	Type          protocol.SignatureType `json:"type,omitempty" form:"type" query:"type" validate:"required"`
	KeyEntryIndex uint64                 `json:"keyEntryIndex,omitempty" form:"keyEntryIndex" query:"keyEntryIndex" validate:"required"`
	SignatureHash [32]byte               `json:"signatureHash,omitempty" form:"signatureHash" query:"signatureHash" validate:"required"`
	// contains filtered or unexported fields
}

func (*SigSetEntry) Compare added in v1.0.0

func (s *SigSetEntry) Compare(t *SigSetEntry) int

func (*SigSetEntry) Copy added in v1.0.0

func (v *SigSetEntry) Copy() *SigSetEntry

func (*SigSetEntry) CopyAsInterface added in v1.0.0

func (v *SigSetEntry) CopyAsInterface() interface{}

func (*SigSetEntry) Equal added in v1.0.0

func (v *SigSetEntry) Equal(u *SigSetEntry) bool

func (*SigSetEntry) IsValid added in v1.0.0

func (v *SigSetEntry) IsValid() error

func (*SigSetEntry) MarshalBinary added in v1.0.0

func (v *SigSetEntry) MarshalBinary() ([]byte, error)

func (*SigSetEntry) MarshalJSON added in v1.0.0

func (v *SigSetEntry) MarshalJSON() ([]byte, error)

func (*SigSetEntry) UnmarshalBinary added in v1.0.0

func (v *SigSetEntry) UnmarshalBinary(data []byte) error

func (*SigSetEntry) UnmarshalBinaryFrom added in v1.0.0

func (v *SigSetEntry) UnmarshalBinaryFrom(rd io.Reader) error

func (*SigSetEntry) UnmarshalJSON added in v1.0.0

func (v *SigSetEntry) UnmarshalJSON(data []byte) error

type SignatureSet added in v0.5.1

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

func (*SignatureSet) Add added in v0.5.1

func (s *SignatureSet) Add(keyEntryIndex uint64, newSignature protocol.Signature) (int, error)

Add adds a signature to the signature set. Add does nothing if the signature set already includes the signer's public key. The entry hash must refer to a signature chain entry.

func (*SignatureSet) Count added in v0.5.1

func (s *SignatureSet) Count() int

func (*SignatureSet) Entries added in v1.0.0

func (s *SignatureSet) Entries() []SigSetEntry

type Transaction

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

Transaction manages a transaction.

func (*Transaction) AddSignature added in v0.5.1

func (t *Transaction) AddSignature(keyEntryIndex uint64, newSignature protocol.Signature) (int, error)

AddSignature loads the appropriate siganture set and adds the signature to it.

func (*Transaction) AddSyntheticTxns

func (t *Transaction) AddSyntheticTxns(txids ...*url.TxID) error

AddSyntheticTxns is a convenience method that calls GetSyntheticTxns, adds the IDs, and calls PutSyntheticTxns.

func (*Transaction) AddSystemSignature added in v1.0.0

func (t *Transaction) AddSystemSignature(net *config.Network, newSignature protocol.Signature) (int, error)

AddSystemSignature adds a system signature to the operator signature set. AddSystemSignature panics if the signature is not a system signature.

func (*Transaction) GetState

func (t *Transaction) GetState() (*SigOrTxn, error)

GetState loads the transaction state.

func (*Transaction) GetStatus

func (t *Transaction) GetStatus() (*protocol.TransactionStatus, error)

GetStatus loads the transaction status.

func (*Transaction) GetSyntheticTxns

func (t *Transaction) GetSyntheticTxns() (*protocol.TxIdSet, error)

GetSyntheticTxns loads the IDs of synthetic transactions produced by the transaction.

func (*Transaction) Index

func (t *Transaction) Index(key ...interface{}) *Value

Index returns a value that can read or write an index value.

func (*Transaction) PutState

func (t *Transaction) PutState(v *SigOrTxn) error

PutState stores the transaction state.

func (*Transaction) PutStatus

func (t *Transaction) PutStatus(v *protocol.TransactionStatus) error

PutStatus stores the transaction status.

func (*Transaction) PutSyntheticTxns added in v0.5.1

func (t *Transaction) PutSyntheticTxns(v *protocol.TxIdSet) error

PutSyntheticTxns stores the IDs of synthetic transactions produced by the transaction.

func (*Transaction) ReadSignatures added in v0.5.1

func (t *Transaction) ReadSignatures(signer *url.URL) (*SignatureSet, error)

ReadSignatures returns a read-only signature set for the given signer.

func (*Transaction) ReadSignaturesForSigner added in v0.6.0

func (t *Transaction) ReadSignaturesForSigner(signer protocol.Signer) (*SignatureSet, error)

SignaturesForSigner returns a read-only signature set for the given signer account.

func (*Transaction) Signatures added in v0.5.1

func (t *Transaction) Signatures(signer *url.URL) (*SignatureSet, error)

Signatures returns a signature set for the given signer.

func (*Transaction) SignaturesForSigner added in v0.6.0

func (t *Transaction) SignaturesForSigner(signer protocol.Signer) (*SignatureSet, error)

SignaturesForSigner returns a signature set for the given signer account.

type TypedValue added in v0.5.1

type TypedValue interface {
	encoding.BinaryMarshaler
	CopyAsInterface() interface{}
}

type Value

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

Value reads and writes a value.

func (*Value) Get

func (v *Value) Get() ([]byte, error)

Get loads the value.

func (*Value) GetAs

func (v *Value) GetAs(u encoding.BinaryUnmarshaler) error

GetAs loads the value and unmarshals it into the given value.

func (*Value) Key

func (v *Value) Key() storage.Key

Key returns the value's storage key.

func (*Value) Put

func (v *Value) Put(data []byte) error

Put stores the value.

func (*Value) PutAs

func (v *Value) PutAs(u encoding.BinaryMarshaler) error

PutAs marshals the given value and stores it.

type ValueUnmarshalFunc added in v0.5.1

type ValueUnmarshalFunc func([]byte) (TypedValue, error)

Jump to

Keyboard shortcuts

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