Documentation
¶
Overview ¶
Package account stores and tracks accounts within a Chain Core.
Index ¶
- Constants
- Variables
- func Annotated(a *Account) (*query.AnnotatedAccount, error)
- func CPKey(hash common.Hash) []byte
- func Key(name string) []byte
- func UTXOKey(id bc.Hash) []byte
- func UtxoToInputs(account *signers.Signer, u *UTXO, refData []byte) (*legacy.TxInput, *txbuilder.SigningInstruction, error)
- type Account
- type CtrlProgram
- type Manager
- func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string, ...) (*Account, error)
- func (m *Manager) CreateAddress(ctx context.Context, accountInfo string, expiresAt time.Time) (*txbuilder.Receiver, error)
- func (m *Manager) CreateControlProgram(ctx context.Context, accountID string, change bool, expiresAt time.Time) ([]byte, error)
- func (m *Manager) CreateP2PKH(ctx context.Context, accountID string, change bool, expiresAt time.Time) (*CtrlProgram, error)
- func (m *Manager) CreateReceiver(ctx context.Context, accountInfo string, expiresAt time.Time) (*txbuilder.Receiver, error)
- func (m *Manager) DecodeControlAction(data []byte) (txbuilder.Action, error)
- func (m *Manager) DecodeSpendAction(data []byte) (txbuilder.Action, error)
- func (m *Manager) DecodeSpendUTXOAction(data []byte) (txbuilder.Action, error)
- func (m *Manager) DeleteAccount(in struct{ ... }) error
- func (m *Manager) ExpireReservations(ctx context.Context, period time.Duration)
- func (m *Manager) FindByAlias(ctx context.Context, alias string) (*signers.Signer, error)
- func (m *Manager) GetAliasByID(id string) string
- func (m *Manager) GetCoinbaseControlProgram(height uint64) ([]byte, error)
- func (m *Manager) ListAccounts(id string) ([]annotatedAccount, error)
- func (m *Manager) NewControlAction(amt bc.AssetAmount, accountID string, refData chainjson.Map) txbuilder.Action
- func (m *Manager) UpdateTags(ctx context.Context, accountInfo string, tags map[string]interface{}) error
- type UTXO
Constants ¶
const (
//UTXOPreFix is AccountUTXOKey prefix
UTXOPreFix = "ACU:"
)
Variables ¶
var ( ErrDuplicateAlias = errors.New("duplicate account alias") ErrFindAccount = errors.New("fail to find account") ErrMarshalAccount = errors.New("failed marshal account") ErrMarshalTags = errors.New("failed marshal account to update tags") ErrStandardQuorum = errors.New("need single key pair account to create standard transaction") )
pre-define errors for supporting bytom errorFormatter
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{} `json:"tags,omitempty"`
}
Account is structure of Bytom account
type CtrlProgram ¶ added in v0.3.0
type CtrlProgram struct {
AccountID string
Address string
KeyIndex uint64
ControlProgram []byte
Change bool
ExpiresAt time.Time
}
CtrlProgram is structure of account control program
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager stores accounts and their associated control programs.
func NewManager ¶
NewManager creates a new account manager
func (*Manager) Create ¶
func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string, tags map[string]interface{}, accessToken string) (*Account, error)
Create creates a new Account.
func (*Manager) CreateAddress ¶ added in v0.3.0
func (m *Manager) CreateAddress(ctx context.Context, accountInfo string, expiresAt time.Time) (*txbuilder.Receiver, error)
CreateAddress creates a new address receiver for an 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) CreateP2PKH ¶ added in v0.3.0
func (m *Manager) CreateP2PKH(ctx context.Context, accountID string, change bool, expiresAt time.Time) (*CtrlProgram, error)
CreateP2PKH generate an address for the select account
func (*Manager) CreateReceiver ¶
func (m *Manager) CreateReceiver(ctx context.Context, accountInfo 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 ¶
DecodeControlAction unmarshal JSON-encoded data of control action
func (*Manager) DecodeSpendAction ¶
DecodeSpendAction unmarshal JSON-encoded data of spend action
func (*Manager) DecodeSpendUTXOAction ¶
DecodeSpendUTXOAction unmarshal JSON-encoded data of spend utxo action
func (*Manager) DeleteAccount ¶ added in v0.3.0
DeleteAccount deletes the account's ID or alias matching accountInfo.
func (*Manager) ExpireReservations ¶
ExpireReservations removes reservations that have expired periodically. It blocks until the context is canceled.
func (*Manager) FindByAlias ¶
FindByAlias retrieves an account's Signer record by its alias
func (*Manager) GetAliasByID ¶ added in v0.3.0
func (*Manager) GetCoinbaseControlProgram ¶ added in v0.2.0
GetCoinbaseControlProgram will return a coinbase script
func (*Manager) ListAccounts ¶ added in v0.3.0
ListAccounts will return the accounts in the db
func (*Manager) NewControlAction ¶
func (m *Manager) NewControlAction(amt bc.AssetAmount, accountID string, refData chainjson.Map) txbuilder.Action
NewControlAction create new control action
type UTXO ¶ added in v0.2.0
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
RefDataHash bc.Hash
AccountID string
Address string
ControlProgramIndex uint64
}
UTXO describes an individual account utxo.