Documentation ¶
Overview ¶
Package account stores and tracks accounts within a Bytom Core.
Package account stores and tracks accounts within a Bytom Core.
Index ¶
- Constants
- Variables
- func Annotated(a *Account) *query.AnnotatedAccount
- func MergeSpendAction(actions []txbuilder.Action) []txbuilder.Action
- func SpendAccountChain(ctx context.Context, builder *txbuilder.TemplateBuilder, ...) ([]*txbuilder.Template, error)
- func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.SigningInstruction, error)
- type Account
- type AccountStore
- type CtrlProgram
- type Image
- type ImageSlice
- type Manager
- func (m *Manager) AddUnconfirmedUtxo(utxos []*UTXO)
- func (m *Manager) Backup() (*Image, error)
- func (m *Manager) BuildBtmTxChain(utxos []*UTXO, signer *signers.Signer) ([]*txbuilder.Template, *UTXO, error)
- func (m *Manager) Create(xpubs []chainkd.XPub, quorum int, alias string, deriveRule uint8) (*Account, error)
- func (m *Manager) CreateAddress(accountID string, change bool) (cp *CtrlProgram, err error)
- func (m *Manager) CreateBatchAddresses(accountID string, change bool, stopIndex uint64) error
- func (m *Manager) DecodeSpendAction(data []byte) (txbuilder.Action, error)
- func (m *Manager) DecodeSpendUTXOAction(data []byte) (txbuilder.Action, error)
- func (m *Manager) DecodeVetoAction(data []byte) (txbuilder.Action, error)
- func (m *Manager) DeleteAccount(accountID string) error
- func (m *Manager) DeleteStandardUTXO(outputID bc.Hash)
- func (m *Manager) FindByAlias(alias string) (*Account, error)
- func (m *Manager) FindByID(id string) (*Account, error)
- func (m *Manager) GetAccountByProgram(program *CtrlProgram) (*Account, error)
- func (m *Manager) GetAccountByXPubsIndex(xPubs []chainkd.XPub, index uint64) (*Account, error)
- func (m *Manager) GetAliasByID(id string) string
- func (m *Manager) GetBip44ContractIndex(accountID string, change bool) uint64
- func (m *Manager) GetCoinbaseArbitrary() []byte
- func (m *Manager) GetCoinbaseControlProgram() ([]byte, error)
- func (m *Manager) GetCoinbaseCtrlProgram() (*CtrlProgram, error)
- func (m *Manager) GetContractIndex(accountID string) uint64
- func (m *Manager) GetControlProgram(hash bc.Hash) (*CtrlProgram, error)
- func (m *Manager) GetLocalCtrlProgramByAddress(address string) (*CtrlProgram, error)
- func (m *Manager) GetMiningAddress() (string, error)
- func (m *Manager) IsLocalControlProgram(prog []byte) bool
- func (m *Manager) ListAccounts(id string) ([]*Account, error)
- func (m *Manager) ListControlProgram() ([]*CtrlProgram, error)
- func (m *Manager) ListUnconfirmedUtxo(accountID string, isSmartContract bool) []*UTXO
- func (m *Manager) RemoveUnconfirmedUtxo(hashes []*bc.Hash)
- func (m *Manager) Restore(image *Image) error
- func (m *Manager) SaveAccount(account *Account) error
- func (m *Manager) SaveControlPrograms(progs ...*CtrlProgram) error
- func (m *Manager) SetCoinbaseArbitrary(arbitrary []byte)
- func (m *Manager) SetMiningAddress(miningAddress string) (string, error)
- func (m *Manager) SetStandardUTXO(outputID bc.Hash, utxo *UTXO) error
- func (m *Manager) UpdateAccountAlias(accountID string, newAlias string) error
- type UTXO
Constants ¶
const ( // HardenedKeyStart bip32 hierarchical deterministic wallets // keys with index ≥ 0x80000000 are hardened keys HardenedKeyStart = 0x80000000 )
Variables ¶
var ( ErrDuplicateAlias = errors.New("Duplicate account alias") ErrDuplicateIndex = errors.New("Duplicate account with same xPubs and index") ErrFindAccount = errors.New("Failed to find account") ErrMarshalAccount = errors.New("Failed to marshal account") ErrInvalidAddress = errors.New("Invalid address") ErrFindCtrlProgram = errors.New("Failed to find account control program") ErrDeriveRule = errors.New("Invalid key derivation rule") ErrContractIndex = errors.New("Exceeded maximum addresses per account") ErrAccountIndex = errors.New("Exceeded maximum accounts per xpub") ErrFindTransaction = errors.New("No transaction") ErrFindMiningAddress = errors.New("Failed to find mining address") ErrAccountIDEmpty = errors.New("account_id is empty") )
pre-define errors for supporting bytom errorFormatter
var ( ErrInsufficient = errors.New("reservation found insufficient funds") ErrImmature = errors.New("reservation found immature funds") ErrVoteLock = errors.New("Locked by the vote") ErrReserved = errors.New("reservation found outputs already reserved") ErrMatchUTXO = errors.New("can't find utxo with given hash") ErrReservation = errors.New("couldn't find reservation") )
pre-define error types
Functions ¶
func Annotated ¶
func Annotated(a *Account) *query.AnnotatedAccount
Annotated init an annotated account object
func MergeSpendAction ¶
MergeSpendAction merge common assetID and accountID spend action
func SpendAccountChain ¶
func SpendAccountChain(ctx context.Context, builder *txbuilder.TemplateBuilder, action txbuilder.Action) ([]*txbuilder.Template, error)
SpendAccountChain build the spend action with auto merge utxo function
func UtxoToInputs ¶
func UtxoToInputs(signer *signers.Signer, u *UTXO) (*types.TxInput, *txbuilder.SigningInstruction, error)
UtxoToInputs convert an utxo to the txinput
Types ¶
type AccountStore ¶ added in v0.3.0
type AccountStore interface { InitBatch() AccountStore CommitBatch() error DeleteAccount(*Account) error DeleteStandardUTXO(bc.Hash) GetAccountByAlias(string) (*Account, error) GetAccountByID(string) (*Account, error) GetAccountIndex([]chainkd.XPub) uint64 GetBip44ContractIndex(string, bool) uint64 GetCoinbaseArbitrary() []byte GetContractIndex(string) uint64 GetControlProgram(bc.Hash) (*CtrlProgram, error) GetMiningAddress() (*CtrlProgram, error) GetUTXO(bc.Hash) (*UTXO, error) ListAccounts(string) ([]*Account, error) ListControlPrograms() ([]*CtrlProgram, error) ListUTXOs() ([]*UTXO, error) SetAccount(*Account) error SetAccountIndex(*Account) SetBip44ContractIndex(string, bool, uint64) SetCoinbaseArbitrary([]byte) SetContractIndex(string, uint64) SetControlProgram(bc.Hash, *CtrlProgram) error SetMiningAddress(*CtrlProgram) error SetStandardUTXO(bc.Hash, *UTXO) error }
AccountStore interface contains account storage functions.
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
func CreateCtrlProgram ¶
func CreateCtrlProgram(account *Account, addrIdx uint64, change bool) (cp *CtrlProgram, err error)
CreateCtrlProgram generate an address for the select account
type Image ¶
type Image struct {
Slice []*ImageSlice `json:"slices"`
}
Image is the struct for hold export account data
type ImageSlice ¶
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(store AccountStore, chain *protocol.Chain) *Manager
NewManager creates a new account manager
func (*Manager) AddUnconfirmedUtxo ¶
AddUnconfirmedUtxo add untxo list to utxoKeeper
func (*Manager) BuildBtmTxChain ¶ added in v0.3.0
func (*Manager) Create ¶
func (m *Manager) Create(xpubs []chainkd.XPub, quorum int, alias string, deriveRule uint8) (*Account, error)
Create creates and save a new Account.
func (*Manager) CreateAddress ¶
func (m *Manager) CreateAddress(accountID string, change bool) (cp *CtrlProgram, err error)
CreateAddress generate an address for the select account
func (*Manager) CreateBatchAddresses ¶
CreateBatchAddresses generate a batch of addresses for the select account
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) DecodeVetoAction ¶
DecodeVetoAction unmarshal JSON-encoded data of spend action
func (*Manager) DeleteAccount ¶
DeleteAccount deletes the account's ID or alias matching account ID.
func (*Manager) DeleteStandardUTXO ¶ added in v0.3.0
func (*Manager) FindByAlias ¶
FindByAlias retrieves an account's Signer record by its alias
func (*Manager) GetAccountByProgram ¶
func (m *Manager) GetAccountByProgram(program *CtrlProgram) (*Account, error)
GetAccountByProgram return Account by given CtrlProgram
func (*Manager) GetAccountByXPubsIndex ¶
GetAccountByXPubsIndex get account by xPubs and index
func (*Manager) GetAliasByID ¶
GetAliasByID return the account alias by given ID
func (*Manager) GetBip44ContractIndex ¶
GetBip44ContractIndex return the current bip44 contract index
func (*Manager) GetCoinbaseArbitrary ¶
func (*Manager) GetCoinbaseControlProgram ¶
GetCoinbaseControlProgram will return a coinbase script
func (*Manager) GetCoinbaseCtrlProgram ¶
func (m *Manager) GetCoinbaseCtrlProgram() (*CtrlProgram, error)
GetCoinbaseCtrlProgram will return the coinbase CtrlProgram
func (*Manager) GetContractIndex ¶
func (*Manager) GetControlProgram ¶ added in v0.3.0
func (m *Manager) GetControlProgram(hash bc.Hash) (*CtrlProgram, error)
func (*Manager) GetLocalCtrlProgramByAddress ¶
func (m *Manager) GetLocalCtrlProgramByAddress(address string) (*CtrlProgram, error)
GetLocalCtrlProgramByAddress return CtrlProgram by given address
func (*Manager) GetMiningAddress ¶
GetMiningAddress will return the mining address
func (*Manager) IsLocalControlProgram ¶
IsLocalControlProgram check is the input control program belong to local
func (*Manager) ListAccounts ¶
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) ListUnconfirmedUtxo ¶
func (*Manager) RemoveUnconfirmedUtxo ¶
RemoveUnconfirmedUtxo remove utxos from the utxoKeeper
func (*Manager) SaveAccount ¶
SaveAccount save a new account.
func (*Manager) SaveControlPrograms ¶
func (m *Manager) SaveControlPrograms(progs ...*CtrlProgram) error
SaveControlPrograms save account control programs
func (*Manager) SetCoinbaseArbitrary ¶
func (*Manager) SetMiningAddress ¶
SetMiningAddress will set the mining address