client

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 8 Imported by: 5

Documentation

Overview

Package client contains the shared client types, including the options used to construct a Client instance, and the records iterator used to represent the results of an action call. This package also defines the Client interface that should be satisfied by different implementations, such as a gateway client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	CallAction(ctx context.Context, dbid string, action string, inputs []any) (*Records, error)
	ChainID() string
	ChainInfo(ctx context.Context) (*types.ChainInfo, error)
	DeployDatabase(ctx context.Context, payload *transactions.Schema, opts ...TxOpt) (transactions.TxHash, error)
	DropDatabase(ctx context.Context, name string, opts ...TxOpt) (transactions.TxHash, error)
	DropDatabaseID(ctx context.Context, dbid string, opts ...TxOpt) (transactions.TxHash, error)
	ExecuteAction(ctx context.Context, dbid string, action string, tuples [][]any, opts ...TxOpt) (transactions.TxHash, error)
	GetAccount(ctx context.Context, pubKey []byte, status types.AccountStatus) (*types.Account, error)
	GetSchema(ctx context.Context, dbid string) (*transactions.Schema, error)
	ListDatabases(ctx context.Context, owner []byte) ([]*types.DatasetIdentifier, error)
	Ping(ctx context.Context) (string, error)
	Query(ctx context.Context, dbid string, query string) (*Records, error)
	TxQuery(ctx context.Context, txHash []byte) (*transactions.TcTxQueryResponse, error)
	WaitTx(ctx context.Context, txHash []byte, interval time.Duration) (*transactions.TcTxQueryResponse, error)
	Transfer(ctx context.Context, to []byte, amount *big.Int, opts ...TxOpt) (transactions.TxHash, error)
}

Client defines methods are used to talk to a Kwil provider.

type Option

type Option func(*Options)

func SilenceWarnings

func SilenceWarnings() Option

SilenceWarnings silences warnings from the client.

func WithChainID

func WithChainID(chainID string) Option

WithChainID sets the chain ID to use when authoring transactions. The chain ID will be used in all transactions, which helps prevent replay attacks on different chains. On the initial connection, the remote node's chain ID is checked against ours to ensure were are on the right network. If the chain ID is empty, we will create and sign transactions for whatever network the remote node claims, which should only be done for testing or when in secure communication with a trusted node (using TLS or Unix sockets).

func WithLogger

func WithLogger(logger log.Logger) Option

func WithSigner

func WithSigner(signer auth.Signer) Option

WithSigner sets a signer to use when authoring transactions.

type Options

type Options struct {
	// Logger is the logger to use for the client.
	Logger log.Logger

	// Signer will be used to sign transactions and set the Sender field on call messages.
	Signer auth.Signer

	// The chain ID will be used in all transactions, which helps prevent replay attacks on
	// different chains. On the initial connection, the remote node's chain ID is
	// checked against ours to ensure were are on the right network. If the chain ID
	// is empty, we will create and sign transactions for whatever network the
	// remote node claims, which should only be done for testing or when in secure
	// communication with a trusted node (using TLS or Unix sockets).
	ChainID string

	// Silence silences warnings logged from the client.
	Silence bool
}

Options are options that can be set for the client

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default options for the client.

func (*Options) Apply

func (c *Options) Apply(opts *Options)

Apply applies the passed options to the receiver.

type Record

type Record map[string]any

Record represents a single row in a set of records.

func (Record) Map

func (r Record) Map() map[string]any

Map returns the record as a map. This is equivalent to map[string]any(r). This returns a reference to the underlying map represented by the Record.

func (Record) String

func (r Record) String() map[string]string

String converts the Record into a map with the values converted to strings.

type Records

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

Records providers an iterator over a set of records.

func NewRecords

func NewRecords(records []*Record) *Records

NewRecords constructs a Records instance for iterating over a Record slice. DEPRECATED: This is intended for internal use. If you have all the records in a slice, you don't need to construct a Records iterator.

func NewRecordsFromMaps

func NewRecordsFromMaps(recs []map[string]any) *Records

NewRecordsFromMaps creates a Records from a slice of the maps of the same shape as an individual Record.

func (*Records) Export

func (r *Records) Export() []map[string]any

Export returns all of the records in a slice. The map in each slice is equivalent to a Record, which is keyed by the column name.

func (*Records) ExportString

func (r *Records) ExportString() []map[string]string

ExportString is like Export, but the values in each map are converted to strings.

func (*Records) Next

func (r *Records) Next() bool

Next steps to the next Record, returning false if there are no more records. Next must be used prior to accessing the first record with the Record method.

func (*Records) Record

func (r *Records) Record() *Record

Record returns the current Record. Use Next to iterate through the records.

func (*Records) Reset

func (r *Records) Reset()

Reset resets the iterator to the initial state. Use Next to get the first record.

type TxOpt

type TxOpt func(*TxOptions)

TxOpt sets an option used when making and broadcasting a transaction.

func WithFee

func WithFee(fee *big.Int) TxOpt

WithFee sets the Fee to use on the transaction, otherwise an EstimateCode RPC will be performed for the action.

func WithNonce

func WithNonce(nonce int64) TxOpt

WithNonce sets the nonce to use for the transaction.

func WithSyncBroadcast

func WithSyncBroadcast(wait bool) TxOpt

WithSyncBroadcast indicates that broadcast should wait for the transaction to be included in a block, not merely accepted into mempool.

type TxOptions

type TxOptions struct {
	Nonce int64
	Fee   *big.Int

	SyncBcast bool // wait for mining on broadcast
}

func GetTxOpts

func GetTxOpts(opts []TxOpt) *TxOptions

Jump to

Keyboard shortcuts

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