store

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound         = errors.New("account not found")
	ErrPendingTransferNotFound = errors.New("pending transfer not found")
	ErrDepositAddressNotFound  = errors.New("deposit address not found")
)

errors produced by the store package.

Functions

func PendingTransferToBundle

func PendingTransferToBundle(pt *PendingTransfer) (bundle.Bundle, error)

PendingTransferToBundle converts bundle essences to a (incomplete) bundle.

Types

type AccountState

type AccountState struct {
	KeyIndex         uint64                           `json:"key_index" bson:"key_index"`
	DepositAddresses map[uint64]*StoredDepositAddress `json:"deposit_addresses" bson:"deposit_addresses"`
	PendingTransfers map[string]*PendingTransfer      `json:"pending_transfers" bson:"pending_transfers"`
}

AccountState is the underlying representation of the account data.

func NewAccountState

func NewAccountState() *AccountState

func (*AccountState) IsNew

func (state *AccountState) IsNew() bool

type ExportedAccountState

type ExportedAccountState struct {
	ID   string    `json:"id" bson:"_id"`
	Date time.Time `json:"date" bson:"date"`
	AccountState
}

ExportedAccountState represents an exported account state.

type PendingTransfer

type PendingTransfer struct {
	Bundle []Trytes `json:"bundle" bson:"bundle"`
	Tails  Hashes   `json:"tails" bson:"tails"`
}

PendingTransfer defines a pending transfer in the store which is made up of the bundle's essence trytes and tail hashes of reattachments.

func TrytesToPendingTransfer

func TrytesToPendingTransfer(trytes []Trytes) PendingTransfer

TrytesToPendingTransfer converts the given trytes to its essence trits.

type Store

type Store interface {
	// LoadAccount loads an existing or allocates a new account state from/in the database and returns the state.
	LoadAccount(id string) (*AccountState, error)
	// RemoveAccount removes the account with the given id from the store.
	RemoveAccount(id string) error
	// ImportAccount imports the given account state into the persistence layer.
	// An existing account is overridden by this method.
	ImportAccount(state ExportedAccountState) error
	// ExportAccount exports the given account from the persistence layer.
	ExportAccount(id string) (*ExportedAccountState, error)
	// Returns the last used key index for the given account.
	ReadIndex(id string) (uint64, error)
	// WriteIndex stores the given index as the last used key index for the given account.
	WriteIndex(id string, index uint64) error
	// AddDepositAddress stores the deposit address under the given account with the used key index.
	AddDepositAddress(id string, index uint64, depositAddress *StoredDepositAddress) error
	// RemoveDepositAddress removes the deposit address with the given key index under the given account.
	RemoveDepositAddress(id string, index uint64) error
	// GetDepositAddresses loads the stored deposit addresses of the given account.
	GetDepositAddresses(id string) (map[uint64]*StoredDepositAddress, error)
	// AddPendingTransfer stores the pending transfer under the given account with the origin tail tx hash as a key and
	// removes all deposit addresses which correspond to the used key indices for the transfer.
	AddPendingTransfer(id string, originTailTxHash Hash, bundleTrytes []Trytes, indices ...uint64) error
	// RemovePendingTransfer removes the pending transfer with the given origin tail transaction hash
	// from the given account.
	RemovePendingTransfer(id string, originTailTxHash Hash) error
	// AddTailHash adds the given new tail transaction hash (presumably from a reattachment) under the given pending transfer
	// indexed by the given origin tail transaction hash.
	AddTailHash(id string, originTailTxHash Hash, newTailTxHash Hash) error
	// GetPendingTransfers returns all pending transfers of the given account.
	GetPendingTransfers(id string) (map[string]*PendingTransfer, error)
}

Store defines a persistence layer which takes care of storing account data.

type StoredDepositAddress

type StoredDepositAddress struct {
	deposit.Conditions `bson:"inline"`
	SecurityLevel      consts.SecurityLevel `json:"security_level" bson:"security_level"`
}

StoredDepositAddress defines a stored deposit address. It differs from the normal deposit address only in having an additional field to hold the security level used to generate the deposit address.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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