light

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 32 Imported by: 6

Documentation

Overview

Package light implements an Accumulate light client.

THIS PACKAGE IS EXPERIMENTAL AND SUBJECT TO CHANGE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByAnchorBlock

func ByAnchorBlock(block uint64) func(*AnchorMetadata) bool

ByAnchorBlock searches for an anchor entry with protocol.AnchorMetadata.MinorBlockIndex equal to or greater than the given value.

func ByIndexBlock

func ByIndexBlock(block uint64) func(*protocol.IndexEntry) bool

ByIndexBlock searches for an index entry with protocol.IndexEntry.BlockIndex equal to or greater than the given value.

func ByIndexRootIndexIndex

func ByIndexRootIndexIndex(rootIndex uint64) func(*protocol.IndexEntry) bool

ByIndexRootIndexIndex searches for an index entry with protocol.IndexEntry.RootIndexIndex equal to or greater than the given value.

func ByIndexSource

func ByIndexSource(source uint64) func(*protocol.IndexEntry) bool

ByIndexSource searches for an index entry with protocol.IndexEntry.Source equal to or greater than the given value.

func ByIndexTime added in v1.4.0

func ByIndexTime(t time.Time) func(*protocol.IndexEntry) bool

ByIndexTime searches for an index entry with protocol.IndexEntry.BlockTime equal to or greater than the given value.

func FindEntry

func FindEntry[T any](entries []T, fn func(T) bool) (int, T, bool)

FindEntry returns the index and value of the first entry for which the predicate is true, assuming it is false for some (possibly empty) prefix and true for the remainder of the entries.

Types

type AnchorMetadata

type AnchorMetadata struct {
	Index       uint64                    `json:"index,omitempty" form:"index" query:"index" validate:"required"`
	Hash        [32]byte                  `json:"hash,omitempty" form:"hash" query:"hash" validate:"required"`
	Anchor      *protocol.PartitionAnchor `json:"anchor,omitempty" form:"anchor" query:"anchor" validate:"required"`
	Transaction *protocol.Transaction     `json:"transaction,omitempty" form:"transaction" query:"transaction" validate:"required"`
	// contains filtered or unexported fields
}

func (*AnchorMetadata) Copy

func (v *AnchorMetadata) Copy() *AnchorMetadata

func (*AnchorMetadata) CopyAsInterface

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

func (*AnchorMetadata) Equal

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

func (*AnchorMetadata) IsValid

func (v *AnchorMetadata) IsValid() error

func (*AnchorMetadata) MarshalBinary

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

func (*AnchorMetadata) MarshalJSON

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

func (*AnchorMetadata) UnmarshalBinary

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

func (*AnchorMetadata) UnmarshalBinaryFrom

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

func (*AnchorMetadata) UnmarshalJSON

func (v *AnchorMetadata) UnmarshalJSON(b []byte) error

type ChainIndex added in v1.4.0

type ChainIndex[T any] struct {
	*merkle.ChainIndex
	// contains filtered or unexported fields
}

func (*ChainIndex[T]) Append added in v1.4.0

func (c *ChainIndex[T]) Append(key T, index uint64) error

func (*ChainIndex[T]) Chain added in v1.4.0

func (c *ChainIndex[T]) Chain() *database.Chain2

func (*ChainIndex[T]) Find added in v1.4.0

func (c *ChainIndex[T]) Find(key T) merkle.ChainSearchResult

func (*ChainIndex[T]) FindExactIndexEntry added in v1.4.0

func (c *ChainIndex[T]) FindExactIndexEntry(key T) (*protocol.IndexEntry, error)

func (*ChainIndex[T]) FindIndexEntryAfter added in v1.4.0

func (c *ChainIndex[T]) FindIndexEntryAfter(key T) (*protocol.IndexEntry, error)

func (*ChainIndex[T]) FindIndexEntryBefore added in v1.4.0

func (c *ChainIndex[T]) FindIndexEntryBefore(key T) (*protocol.IndexEntry, error)

type ChainIndexTime added in v1.4.0

type ChainIndexTime = ChainIndex[time.Time]

type ChainIndexUint added in v1.4.0

type ChainIndexUint = ChainIndex[uint64]

type Client

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

Client is a light client instance.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient creates a new light client instance.

func (*Client) Close

func (c *Client) Close() error

Close frees any resources opened by the light client.

func (*Client) GetBlockForTime added in v1.4.0

func (c *Client) GetBlockForTime(account *url.URL, time time.Time) (uint64, error)

func (*Client) IndexAccountChains

func (c *Client) IndexAccountChains(ctx context.Context, acctUrl *url.URL) error

IndexAccountChains collates the index chain entries for an account's chains.

func (*Client) IndexAccountTransactions

func (c *Client) IndexAccountTransactions(ctx context.Context, accounts ...*url.URL) error

IndexAccountTransaction indexes the local and directory block index and time for the accounts' main chain transactions.

func (*Client) IndexProducedAnchors added in v1.4.0

func (c *Client) IndexProducedAnchors(ctx context.Context, partUrl *url.URL) error

IndexProducedAnchors collates a partition's produced block anchors.

func (*Client) IndexReceivedAnchors added in v1.4.0

func (c *Client) IndexReceivedAnchors(ctx context.Context, partUrl *url.URL) error

IndexReceivedAnchors collates a partition's received block anchors.

func (*Client) OpenDB

func (c *Client) OpenDB(writable bool) *DB

OpenDB opens a DB.

func (*Client) PullAccount

func (c *Client) PullAccount(ctx context.Context, acctUrl *url.URL) error

PullAccount fetches the latest version of the account and its chains.

func (*Client) PullAccountWithChains added in v1.4.0

func (c *Client) PullAccountWithChains(ctx context.Context, acctUrl *url.URL, predicate func(*api.ChainRecord) bool) error

func (*Client) PullMessagesForAccount added in v1.2.0

func (c *Client) PullMessagesForAccount(ctx context.Context, account *url.URL, chains ...string) error

func (*Client) PullMessagesForAccountSince added in v1.4.0

func (c *Client) PullMessagesForAccountSince(ctx context.Context, account *url.URL, since time.Time, chains ...string) error

func (*Client) PullPendingTransactionsForAccount

func (c *Client) PullPendingTransactionsForAccount(ctx context.Context, account *url.URL) error

func (*Client) PullTransactions

func (c *Client) PullTransactions(ctx context.Context, txids ...*url.TxID) error

PullTransaction fetches a set of transactions.

func (*Client) PullTransactionsForAccount

func (c *Client) PullTransactionsForAccount(ctx context.Context, account *url.URL, chains ...string) error

PullTransactionsForAccount fetches transactions from the account's chains.

DEPRECATED: Use PullMessagesForAccount.

type ClientOption

type ClientOption func(c *Client) error

func BadgerStore

func BadgerStore(filepath string, opts ...badger.Option) ClientOption

func ClientV2

func ClientV2(client *client.Client) ClientOption

func Logger deprecated

func Logger(logger log.Logger, keyVals ...any) ClientOption

Logger sets the logger.

Deprecated: Unused - using slog instead.

func MemoryStore

func MemoryStore() ClientOption

func Querier added in v1.2.0

func Querier(querier api.Querier) ClientOption

func Router added in v1.4.0

func Router(r routing.Router) ClientOption

func RouterFromStore added in v1.4.0

func RouterFromStore() ClientOption

func Server

func Server(server string) ClientOption

func Store

func Store(s keyvalue.Beginner, prefix string) ClientOption

type DB

type DB struct {
	*database.Batch
	// contains filtered or unexported fields
}

DB is the light client database.

func OpenDB added in v1.4.0

func OpenDB(store keyvalue.Beginner, prefix *record.Key, writable bool) *DB

func (*DB) Commit

func (db *DB) Commit() error

Commit commits changes to the database.

func (*DB) Index

func (db *DB) Index() *IndexDB

type EventMetadata

type EventMetadata struct {
	LocalBlock     uint64    `json:"localBlock,omitempty" form:"localBlock" query:"localBlock" validate:"required"`
	LocalTime      time.Time `json:"localTime,omitempty" form:"localTime" query:"localTime" validate:"required"`
	DirectoryBlock uint64    `json:"directoryBlock,omitempty" form:"directoryBlock" query:"directoryBlock" validate:"required"`
	DirectoryTime  time.Time `json:"directoryTime,omitempty" form:"directoryTime" query:"directoryTime" validate:"required"`
	// contains filtered or unexported fields
}

func (*EventMetadata) Copy

func (v *EventMetadata) Copy() *EventMetadata

func (*EventMetadata) CopyAsInterface

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

func (*EventMetadata) Equal

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

func (*EventMetadata) IsValid

func (v *EventMetadata) IsValid() error

func (*EventMetadata) MarshalBinary

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

func (*EventMetadata) MarshalJSON

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

func (*EventMetadata) UnmarshalBinary

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

func (*EventMetadata) UnmarshalBinaryFrom

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

func (*EventMetadata) UnmarshalJSON

func (v *EventMetadata) UnmarshalJSON(b []byte) error

type IndexDB

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

func (*IndexDB) Account

func (c *IndexDB) Account(url *url.URL) *IndexDBAccount

func (*IndexDB) Commit added in v1.4.0

func (c *IndexDB) Commit() error

func (*IndexDB) IsDirty added in v1.4.0

func (c *IndexDB) IsDirty() bool

func (*IndexDB) Key added in v1.4.0

func (c *IndexDB) Key() *record.Key

func (*IndexDB) Partition

func (c *IndexDB) Partition(url *url.URL) *IndexDBPartition

func (*IndexDB) Resolve added in v1.4.0

func (c *IndexDB) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*IndexDB) Transaction

func (c *IndexDB) Transaction(hash [32]byte) *IndexDBTransaction

func (*IndexDB) Walk added in v1.4.0

func (c *IndexDB) Walk(opts record.WalkOptions, fn record.WalkFunc) error

type IndexDBAccount

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

func (*IndexDBAccount) Chain

func (c *IndexDBAccount) Chain(name string) *IndexDBAccountChain

func (*IndexDBAccount) Commit added in v1.4.0

func (c *IndexDBAccount) Commit() error

func (*IndexDBAccount) DidIndexTransactionExecution

func (c *IndexDBAccount) DidIndexTransactionExecution() values.Set[[32]byte]

func (*IndexDBAccount) IsDirty added in v1.4.0

func (c *IndexDBAccount) IsDirty() bool

func (*IndexDBAccount) Key added in v1.4.0

func (c *IndexDBAccount) Key() *record.Key

func (*IndexDBAccount) Resolve added in v1.4.0

func (c *IndexDBAccount) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*IndexDBAccount) Walk added in v1.4.0

type IndexDBAccountChain

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

func (*IndexDBAccountChain) BlockIndex added in v1.4.0

func (c *IndexDBAccountChain) BlockIndex() *ChainIndexUint

func (*IndexDBAccountChain) BlockTime added in v1.4.0

func (c *IndexDBAccountChain) BlockTime() *ChainIndexTime

func (*IndexDBAccountChain) Commit added in v1.4.0

func (c *IndexDBAccountChain) Commit() error

func (*IndexDBAccountChain) DidLoad added in v1.4.0

func (i *IndexDBAccountChain) DidLoad() RangeSet

func (*IndexDBAccountChain) IsDirty added in v1.4.0

func (c *IndexDBAccountChain) IsDirty() bool

func (*IndexDBAccountChain) Key added in v1.4.0

func (c *IndexDBAccountChain) Key() *record.Key

func (*IndexDBAccountChain) Resolve added in v1.4.0

func (c *IndexDBAccountChain) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*IndexDBAccountChain) RootIndexIndex added in v1.4.0

func (c *IndexDBAccountChain) RootIndexIndex() *ChainIndexUint

func (*IndexDBAccountChain) SourceIndex added in v1.4.0

func (c *IndexDBAccountChain) SourceIndex() *ChainIndexUint

func (*IndexDBAccountChain) Walk added in v1.4.0

type IndexDBPartition

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

func (*IndexDBPartition) Anchors

func (*IndexDBPartition) Commit added in v1.4.0

func (c *IndexDBPartition) Commit() error

func (*IndexDBPartition) IsDirty added in v1.4.0

func (c *IndexDBPartition) IsDirty() bool

func (*IndexDBPartition) Key added in v1.4.0

func (c *IndexDBPartition) Key() *record.Key

func (*IndexDBPartition) Resolve added in v1.4.0

func (c *IndexDBPartition) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*IndexDBPartition) Walk added in v1.4.0

type IndexDBPartitionAnchors added in v1.4.0

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

func (*IndexDBPartitionAnchors) Commit added in v1.4.0

func (c *IndexDBPartitionAnchors) Commit() error

func (*IndexDBPartitionAnchors) IsDirty added in v1.4.0

func (c *IndexDBPartitionAnchors) IsDirty() bool

func (*IndexDBPartitionAnchors) Key added in v1.4.0

func (*IndexDBPartitionAnchors) Produced added in v1.4.0

func (*IndexDBPartitionAnchors) Received added in v1.4.0

func (c *IndexDBPartitionAnchors) Received(url *url.URL) *ChainIndexUint

func (*IndexDBPartitionAnchors) Resolve added in v1.4.0

func (*IndexDBPartitionAnchors) Walk added in v1.4.0

type IndexDBTransaction

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

func (*IndexDBTransaction) Commit added in v1.4.0

func (c *IndexDBTransaction) Commit() error

func (*IndexDBTransaction) Executed

func (c *IndexDBTransaction) Executed() values.Value[*EventMetadata]

func (*IndexDBTransaction) IsDirty added in v1.4.0

func (c *IndexDBTransaction) IsDirty() bool

func (*IndexDBTransaction) Key added in v1.4.0

func (c *IndexDBTransaction) Key() *record.Key

func (*IndexDBTransaction) Resolve added in v1.4.0

func (c *IndexDBTransaction) Resolve(key *record.Key) (record.Record, *record.Key, error)

func (*IndexDBTransaction) Walk added in v1.4.0

type IndexedList added in v1.4.0

type IndexedList[T any] struct {
	values.List[T]
}

func (*IndexedList[T]) Find added in v1.4.0

func (l *IndexedList[T]) Find(fn func(T) bool) (int, T, error)

Find returns the index and value of the first entry for which the predicate is true, assuming it is false for some (possibly empty) prefix and true for the remainder of the entries.

func (*IndexedList[T]) Scan added in v1.4.0

func (l *IndexedList[T]) Scan(fn func(T) bool) (int, T, error)

Scan does a linear scan for the first element for which the predicate is true.

type RangeSet added in v1.4.0

type RangeSet struct {
	values.Value[*rangeSet]
}

func (RangeSet) Add added in v1.4.0

func (r RangeSet) Add(v uint64) (bool, error)

func (RangeSet) Contains added in v1.4.0

func (r RangeSet) Contains(v uint64) (bool, error)

Jump to

Keyboard shortcuts

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