action

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrActionNotFound       = errors.New("no action ecord could be found")
	ErrMultipleActionsFound = errors.New("multiple action records found")
	ErrActionExists         = errors.New("action record already exists")
)

Functions

This section is empty.

Types

type ByActionId

type ByActionId []*Record

func (ByActionId) Len

func (a ByActionId) Len() int

func (ByActionId) Less

func (a ByActionId) Less(i, j int) bool

func (ByActionId) Swap

func (a ByActionId) Swap(i, j int)

type Record

type Record struct {
	Id uint64

	Intent     string
	IntentType intent.Type

	ActionId   uint32
	ActionType Type

	Source      string  // Source token account involved
	Destination *string // Destination token account involved, when it makes sense

	// Kin quark amount involved, when it makes sense. This must be set for actions
	// that make balance changes across Code accounts! For deferred actions that are
	// initially in the unknown state, the balance may be nil and updated at a later
	// time. Store implementations will enforce which actions will allow quantity updates.
	//
	// todo: We have some options of how to handle balance calculations for actions in
	//       the unknown state. For now, remain in the most flexible state (ie. set quantity
	//       as needed and include everything in the calculation). We'll wait for more
	//       use cases before forming a firm opinion.
	Quantity *uint64

	InitiatorPhoneNumber *string

	State State

	CreatedAt time.Time
}

func (*Record) Clone

func (r *Record) Clone() Record

func (*Record) CopyTo

func (r *Record) CopyTo(dst *Record)

func (*Record) Validate

func (r *Record) Validate() error

type State

type State uint8
const (
	StateUnknown State = iota
	StatePending
	StateRevoked
	StateConfirmed
	StateFailed
)

func (State) IsTerminal

func (s State) IsTerminal() bool

func (State) String

func (s State) String() string

type Store

type Store interface {
	// PutAll creates all actions in one transaction
	PutAll(ctx context.Context, records ...*Record) error

	// Update updates an existing action record
	Update(ctx context.Context, record *Record) error

	// GetById gets an action by its ID
	GetById(ctx context.Context, intent string, actionId uint32) (*Record, error)

	// GetAllByIntent gets all actions for a given intent
	GetAllByIntent(ctx context.Context, intent string) ([]*Record, error)

	// GetAllByAddress gets all actions for a given address as a source or destination.
	//
	// todo: Support paging for accounts that might have many actions when a use case emerges
	GetAllByAddress(ctx context.Context, address string) ([]*Record, error)

	// GetNetBalance gets the net balance of Kin in quarks after appying actions
	// that operate on balances.
	GetNetBalance(ctx context.Context, account string) (int64, error)

	// GetNetBalanceBatch is like GetNetBalance, but for a batch of accounts.
	GetNetBalanceBatch(ctx context.Context, accounts ...string) (map[string]int64, error)

	// GetGiftCardClaimedAction gets the action where the gift card was claimed,
	// which is a NoPrivacyWithdraw with the giftCardVault as a source. This DB
	// cannot validate the account type, so that must be done prior to making this
	// call elsewhere.
	GetGiftCardClaimedAction(ctx context.Context, giftCardVault string) (*Record, error)

	// GetGiftCardAutoReturnAction gets the action where the gift card will be
	// auto-returned, which is a CloseDormantAccount action with the giftCardVault
	// as a source. This DB cannot validate the account type, so that must be done
	// prior to making this call elsewhere.
	GetGiftCardAutoReturnAction(ctx context.Context, giftCardVault string) (*Record, error)
}

type Type

type Type uint8
const (
	UnknownType Type = iota
	OpenAccount
	CloseEmptyAccount
	CloseDormantAccount
	NoPrivacyTransfer
	NoPrivacyWithdraw
	PrivateTransfer // Incorprorates all client-side private movement of funds. Backend processes don't care about the distinction, yet.
	SaveRecentRoot
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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