account

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package account stores and tracks accounts within a Bytom Core.

Package account stores and tracks accounts within a Bytom Core.

Index

Constants

View Source
const (
	//UTXOPreFix is StandardUTXOKey prefix
	UTXOPreFix = "ACU:"
	//SUTXOPrefix is ContractUTXOKey prefix
	SUTXOPrefix = "SCU:"
)

Variables

View Source
var (
	ErrDuplicateAlias  = errors.New("duplicate account alias")
	ErrFindAccount     = errors.New("fail to find account")
	ErrMarshalAccount  = errors.New("failed marshal account")
	ErrInvalidAddress  = errors.New("invalid address")
	ErrFindCtrlProgram = errors.New("fail to find account control program")
)

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")
	// ErrMatchUTXO indicates the account doesn't contain enough utxo to satisfy the reservation.
	ErrMatchUTXO = errors.New("can't match enough valid utxos")
	// ErrReservation indicates the reserver doesn't found the reservation with the provided ID.
	ErrReservation = errors.New("couldn't find reservation")
)

Functions

func Annotated

func Annotated(a *Account) *query.AnnotatedAccount

Annotated init an annotated account object

func ContractKey added in v0.5.0

func ContractKey(hash common.Hash) []byte

ContractKey account control promgram store prefix

func ContractUTXOKey

func ContractUTXOKey(id bc.Hash) []byte

ContractUTXOKey makes a smart contract unspent outputs key to store

func Key

func Key(name string) []byte

Key account store prefix

func MergeSpendAction added in v1.0.2

func MergeSpendAction(spendActions []txbuilder.Action) []txbuilder.Action

MergeSpendAction merge common assetID and accountID spend action

func StandardUTXOKey

func StandardUTXOKey(id bc.Hash) []byte

StandardUTXOKey makes an account unspent outputs key to store

func UtxoToInputs

func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.SigningInstruction, error)

UtxoToInputs convert an utxo to the txinput

Types

type Account

type Account struct {
	*signers.Signer
	ID    string `json:"id"`
	Alias string `json:"alias"`
}

Account is structure of Bytom account

type CtrlProgram

type CtrlProgram struct {
	AccountID      string
	Address        string
	KeyIndex       uint64
	ControlProgram []byte
	Change         bool // Mark whether this control program is for UTXO change
}

CtrlProgram is structure of account control program

type Image added in v0.5.0

type Image struct {
	Slice []*ImageSlice `json:"slices"`
}

Image is the struct for hold export account data

type ImageSlice added in v0.5.0

type ImageSlice struct {
	Account       *Account `json:"account"`
	ContractIndex uint64   `json:"contract_index"`
}

ImageSlice record info of single account

type Manager

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

Manager stores accounts and their associated control programs.

func NewManager

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

NewManager creates a new account manager

func (*Manager) Backup added in v0.5.0

func (m *Manager) Backup() (*Image, error)

Backup export all the account info into image

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string) (*Account, error)

Create creates a new Account.

func (*Manager) CreateAddress

func (m *Manager) CreateAddress(ctx context.Context, accountID string, change bool) (cp *CtrlProgram, err error)

CreateAddress generate an address for the select account

func (*Manager) DecodeSpendAction

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

DecodeSpendAction unmarshal JSON-encoded data of spend action

func (*Manager) DecodeSpendUTXOAction

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

DecodeSpendUTXOAction unmarshal JSON-encoded data of spend utxo action

func (*Manager) DeleteAccount

func (m *Manager) DeleteAccount(aliasOrID string) (err error)

DeleteAccount deletes the account's ID or alias matching accountInfo.

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) (*Account, error)

FindByAlias retrieves an account's Signer record by its alias

func (*Manager) FindByID added in v0.5.0

func (m *Manager) FindByID(ctx context.Context, id string) (*Account, error)

FindByID returns an account's Signer record by its ID.

func (*Manager) GetAccountByProgram added in v1.0.2

func (m *Manager) GetAccountByProgram(program *CtrlProgram) (*Account, error)

GetAccountByProgram return Account by given CtrlProgram

func (*Manager) GetAliasByID

func (m *Manager) GetAliasByID(id string) string

GetAliasByID return the account alias by given ID

func (*Manager) GetCoinbaseControlProgram

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

GetCoinbaseControlProgram will return a coinbase script

func (*Manager) GetProgramByAddress added in v1.0.2

func (m *Manager) GetProgramByAddress(address string) (*CtrlProgram, error)

GetProgramByAddress return CtrlProgram by given address

func (*Manager) IsLocalControlProgram

func (m *Manager) IsLocalControlProgram(prog []byte) bool

IsLocalControlProgram check is the input control program belong to local

func (*Manager) ListAccounts

func (m *Manager) ListAccounts(id string) ([]*Account, error)

ListAccounts will return the accounts in the db

func (*Manager) ListControlProgram

func (m *Manager) ListControlProgram() ([]*CtrlProgram, error)

ListControlProgram return all the local control program

func (*Manager) Restore added in v0.5.0

func (m *Manager) Restore(image *Image) error

Restore import the accountImages into account manage

type UTXO

type UTXO struct {
	OutputID bc.Hash
	SourceID bc.Hash

	// Avoiding AssetAmount here so that new(utxo) doesn't produce an
	// AssetAmount with a nil AssetId.
	AssetID bc.AssetID
	Amount  uint64

	SourcePos      uint64
	ControlProgram []byte

	AccountID           string
	Address             string
	ControlProgramIndex uint64
	ValidHeight         uint64
	Change              bool
}

UTXO describes an individual account utxo.

Jump to

Keyboard shortcuts

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