account

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2017 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package account stores and tracks accounts within a Chain Core.

Index

Constants

View Source
const (
	//UTXOPreFix is account unspent outputs store db by key with this prefix
	UTXOPreFix = "ACU:"
)

Variables

View Source
var (
	ErrDuplicateAlias = errors.New("duplicate account alias")
	ErrBadIdentifier  = errors.New("either ID or alias must be specified, and not both")
)

pre-define errors for supporting bytom errorFormatter

View Source
var (
	// ErrInsufficient indicates the account doesn't contain enough
	// units of the requested asset to satisfy the reservation.
	// New units must be deposited into the account in order to
	// satisfy the request; change will not be sufficient.
	ErrInsufficient = errors.New("reservation found insufficient funds")

	// ErrReserved indicates that a reservation could not be
	// satisfied because some of the outputs were already reserved.
	// When those reservations are finalized into a transaction
	// (and no other transaction spends funds from the account),
	// new change outputs will be created
	// in sufficient amounts to satisfy the request.
	ErrReserved = errors.New("reservation found outputs already reserved")
)

Functions

func Annotated

func Annotated(a *Account) (*query.AnnotatedAccount, error)

Annotated init an annotated account object

Types

type Account

type Account struct {
	*signers.Signer
	Alias string
	Tags  map[string]interface{}
}

Account is structure of Bytom account

type Manager

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

Manager stores accounts and their associated control programs.

func NewManager

func NewManager(db, walletDB dbm.DB, walletHeightFn func() uint64, chain *protocol.Chain) *Manager

NewManager creates a new account manager

func (*Manager) AnnotateTxs

func (m *Manager) AnnotateTxs(txs []*query.AnnotatedTx) error

AnnotateTxs adds account data to transactions

func (*Manager) BuildAccountUTXOs added in v0.2.0

func (m *Manager) BuildAccountUTXOs(batch *db.Batch, b *legacy.Block)

BuildAccountUTXOs process valid blocks to build account unspent outputs db

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string, tags map[string]interface{}, clientToken string) (*Account, error)

Create creates a new Account.

func (*Manager) CreateControlProgram

func (m *Manager) CreateControlProgram(ctx context.Context, accountID string, change bool, expiresAt time.Time) ([]byte, error)

CreateControlProgram creates a control program that is tied to the Account and stores it in the database.

func (*Manager) CreateReceiver

func (m *Manager) CreateReceiver(ctx context.Context, accInfo string, expiresAt time.Time) (*txbuilder.Receiver, error)

CreateReceiver creates a new account receiver for an account with the provided expiry. If a zero time is provided for the expiry, a default expiry of 30 days from the current time is used.

func (*Manager) DecodeControlAction

func (m *Manager) DecodeControlAction(data []byte) (txbuilder.Action, error)

func (*Manager) DecodeSpendAction

func (m *Manager) DecodeSpendAction(data []byte) (txbuilder.Action, error)

func (*Manager) DecodeSpendUTXOAction

func (m *Manager) DecodeSpendUTXOAction(data []byte) (txbuilder.Action, error)

func (*Manager) ExpireReservations

func (m *Manager) ExpireReservations(ctx context.Context, period time.Duration)

ExpireReservations removes reservations that have expired periodically. It blocks until the context is canceled.

func (*Manager) FindByAlias

func (m *Manager) FindByAlias(ctx context.Context, alias string) (*signers.Signer, error)

FindByAlias retrieves an account's Signer record by its alias

func (*Manager) GetCoinbaseControlProgram added in v0.2.0

func (m *Manager) GetCoinbaseControlProgram(height uint64) ([]byte, error)

GetCoinbaseControlProgram will return a coinbase script

func (*Manager) NewControlAction

func (m *Manager) NewControlAction(amt bc.AssetAmount, accountID string, refData chainjson.Map) txbuilder.Action

func (*Manager) NewSpendAction

func (m *Manager) NewSpendAction(amt bc.AssetAmount, accountID string, refData chainjson.Map, clientToken *string) txbuilder.Action

func (*Manager) NewSpendUTXOAction

func (m *Manager) NewSpendUTXOAction(outputID bc.Hash) txbuilder.Action

func (*Manager) QueryAll

func (m *Manager) QueryAll(ctx context.Context) (interface{}, error)

QueryAll will return all the account in the db

func (*Manager) ReverseAccountUTXOs added in v0.2.0

func (m *Manager) ReverseAccountUTXOs(batch *db.Batch, b *legacy.Block)

ReverseAccountUTXOs process the invalid blocks when orphan block rollback

func (*Manager) UpdateTags

func (m *Manager) UpdateTags(ctx context.Context, id, alias *string, tags map[string]interface{}) error

UpdateTags modifies the tags of the specified account. The account may be identified either by ID or Alias, but not both.

type UTXO added in v0.2.0

type UTXO struct {
	OutputID     []byte
	AssetID      []byte
	Amount       uint64
	AccountID    string
	ProgramIndex uint64
	Program      []byte
	SourceID     []byte
	SourcePos    uint64
	RefData      []byte
	Change       bool
}

UTXO is a structure about account unspent outputs

Jump to

Keyboard shortcuts

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