account

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: AGPL-3.0 Imports: 28 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:"
)
View Source
const (
	// HardenedKeyStart bip32 hierarchical deterministic wallets
	// keys with index ≥ 0x80000000 are hardened keys
	HardenedKeyStart = 0x80000000
)

Variables

View Source
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")
)

pre-define errors for supporting bytom errorFormatter

View Source
var (
	ErrInsufficient = errors.New("reservation found insufficient funds")
	ErrImmature     = errors.New("reservation found immature funds")
	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

View Source
var (
	CoinbaseAbKey = []byte("CoinbaseArbitrary")
)

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 GetAccountIndexKey added in v1.0.7

func GetAccountIndexKey(xpubs []chainkd.XPub) []byte

func Key

func Key(name string) []byte

Key account store prefix

func MergeSpendAction added in v1.0.2

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

MergeSpendAction merge common assetID and accountID spend action

func SpendAccountChain added in v1.0.7

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 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

func CreateAccount added in v1.0.7

func CreateAccount(xpubs []chainkd.XPub, quorum int, alias string, acctIndex uint64, deriveRule uint8) (*Account, error)

CreateAccount creates a new 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

func CreateCtrlProgram added in v1.0.7

func CreateCtrlProgram(account *Account, addrIdx uint64, change bool) (cp *CtrlProgram, err error)

CreateCtrlProgram generate an address for the select account

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) AddUnconfirmedUtxo added in v1.0.4

func (m *Manager) AddUnconfirmedUtxo(utxos []*UTXO)

AddUnconfirmedUtxo add untxo list to utxoKeeper

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(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 added in v1.0.7

func (m *Manager) CreateBatchAddresses(accountID string, change bool, stopIndex uint64) error

CreateBatchAddresses generate a batch of addresses 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) DecodeVetoAction added in v1.2.1

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

DecodeVetoAction unmarshal JSON-encoded data of spend action

func (*Manager) DeleteAccount

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

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

func (*Manager) FindByAlias

func (m *Manager) FindByAlias(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(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) GetAccountByXPubsIndex added in v1.0.7

func (m *Manager) GetAccountByXPubsIndex(xPubs []chainkd.XPub, index uint64) (*Account, error)

GetAccountByXPubsIndex get account by xPubs and index

func (*Manager) GetAliasByID

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

GetAliasByID return the account alias by given ID

func (*Manager) GetBip44ContractIndex added in v1.0.7

func (m *Manager) GetBip44ContractIndex(accountID string, change bool) uint64

GetBip44ContractIndex return the current bip44 contract index

func (*Manager) GetCoinbaseArbitrary added in v1.0.5

func (m *Manager) GetCoinbaseArbitrary() []byte

func (*Manager) GetCoinbaseControlProgram

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

GetCoinbaseControlProgram will return a coinbase script

func (*Manager) GetCoinbaseCtrlProgram added in v1.0.5

func (m *Manager) GetCoinbaseCtrlProgram() (*CtrlProgram, error)

GetCoinbaseCtrlProgram will return the coinbase CtrlProgram

func (*Manager) GetContractIndex added in v1.0.4

func (m *Manager) GetContractIndex(accountID string) uint64

GetContractIndex return the current index

func (*Manager) GetLocalCtrlProgramByAddress added in v1.0.5

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

GetLocalCtrlProgramByAddress return CtrlProgram by given address

func (*Manager) GetMiningAddress added in v1.0.5

func (m *Manager) GetMiningAddress() (string, error)

GetMiningAddress will return the mining 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) ListUnconfirmedUtxo added in v1.0.4

func (m *Manager) ListUnconfirmedUtxo(accountID string, isSmartContract bool) []*UTXO

func (*Manager) RemoveUnconfirmedUtxo added in v1.0.4

func (m *Manager) RemoveUnconfirmedUtxo(hashes []*bc.Hash)

RemoveUnconfirmedUtxo remove utxos from the utxoKeeper

func (*Manager) Restore added in v0.5.0

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

Restore import the accountImages into account manage

func (*Manager) SaveAccount added in v1.0.7

func (m *Manager) SaveAccount(account *Account) error

SaveAccount save a new account.

func (*Manager) SaveControlPrograms added in v1.0.7

func (m *Manager) SaveControlPrograms(progs ...*CtrlProgram) error

SaveControlPrograms save account control programs

func (*Manager) SetCoinbaseArbitrary added in v1.0.5

func (m *Manager) SetCoinbaseArbitrary(arbitrary []byte)

func (*Manager) SetMiningAddress added in v1.0.5

func (m *Manager) SetMiningAddress(miningAddress string) (string, error)

SetMiningAddress will set the mining address

func (*Manager) UpdateAccountAlias added in v1.0.7

func (m *Manager) UpdateAccountAlias(accountID string, newAlias string) (err error)

type UTXO

type UTXO struct {
	OutputID            bc.Hash
	SourceID            bc.Hash
	AssetID             bc.AssetID
	Amount              uint64
	SourcePos           uint64
	ControlProgram      []byte
	Vote                []byte
	StateData           [][]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