accounts

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficientFunds = fmt.Errorf("insufficient funds")
	ErrConvertToBigInt   = fmt.Errorf("could not convert to big int")
	ErrInvalidNonce      = fmt.Errorf("invalid nonce")
	ErrAccountNotFound   = fmt.Errorf("account not found")
)

Functions

This section is empty.

Types

type Account added in v0.6.5

type Account struct {
	Identifier []byte   `json:"identifier"` // usually address, but can be pubkey if certain key types
	Balance    *big.Int `json:"balance"`
	Nonce      int64    `json:"nonce"`
}

type AccountStore added in v0.6.5

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

func NewAccountStore added in v0.6.5

func NewAccountStore(ctx context.Context, datastore Datastore, committable CommitRegister, opts ...AccountStoreOpts) (*AccountStore, error)

func (*AccountStore) Close added in v0.6.5

func (a *AccountStore) Close() error

func (*AccountStore) Credit added in v0.6.5

func (a *AccountStore) Credit(ctx context.Context, acctID []byte, amt *big.Int) error

Credit credits an account. If the account does not exist, it will be created.

func (*AccountStore) GetAccount added in v0.6.5

func (a *AccountStore) GetAccount(ctx context.Context, ident []byte) (*Account, error)

func (*AccountStore) Spend added in v0.6.5

func (a *AccountStore) Spend(ctx context.Context, spend *Spend) error

Spend spends an amount from an account. It blocks until the spend is written to the database.

func (*AccountStore) Transfer added in v0.6.5

func (a *AccountStore) Transfer(ctx context.Context, to, from []byte, amt *big.Int) error

Transfer sends an amount from the sender's balance to another account. The amount sent is given by the amount. This does not affect the sending account's nonce; a Spend should precede this to pay for required transaction gas and validate/advance the nonce.

type AccountStoreOpts added in v0.6.5

type AccountStoreOpts func(*AccountStore)

func WithGasCosts added in v0.6.5

func WithGasCosts(gas_enabled bool) AccountStoreOpts

func WithLogger added in v0.6.5

func WithLogger(logger log.Logger) AccountStoreOpts

func WithNonces added in v0.6.5

func WithNonces(nonces_enabled bool) AccountStoreOpts

type CommitRegister added in v0.6.5

type CommitRegister interface {
	// Skip returns true if the commit should be skipped.
	// This signals that the account store should not be updated,
	// and simply return nil.
	Skip() bool

	// Register registers a commit.
	// This should be called when data is written to the database.
	Register(value []byte) error
}

CommitRegister is an interface for registering a commit.

type Datastore added in v0.6.5

type Datastore interface {
	Execute(ctx context.Context, stmt string, args map[string]any) ([]map[string]any, error)
	Query(ctx context.Context, query string, args map[string]any) ([]map[string]any, error)
}

type Spend

type Spend struct {
	AccountID []byte
	Amount    *big.Int
	Nonce     int64
}

Spend specifies a the fee and nonce of a transaction for an account. The amount has historically been associated with the transaction's fee (to pay for gas) i.e. the price of a certain transaction type.

Jump to

Keyboard shortcuts

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