Documentation
¶
Index ¶
- Constants
- Variables
- func BuildP2PKHAddress(pubHash []byte, netParams *consensus.Params) string
- func BuildP2SHAddress(scriptHash []byte, netParams *consensus.Params) string
- func FindTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string) bool
- func NewRecoveryManager(store WalletStore, accountMgr *account.Manager) *recoveryManager
- type AccountBalance
- type AccountVotes
- type RecoveryState
- type SortByHeight
- type SortByTimestamp
- type StatusInfo
- type Summary
- type TxSummary
- type Wallet
- func (w *Wallet) AddUnconfirmedTx(txD *protocol.TxDesc)
- func (w *Wallet) AttachBlock(block *types.Block) error
- func (w *Wallet) BuildAnnotatedInput(tx *types.Tx, i uint32) *query.AnnotatedInput
- func (w *Wallet) BuildAnnotatedOutput(tx *types.Tx, idx int) *query.AnnotatedOutput
- func (w *Wallet) DeleteAccount(accountID string) (err error)
- func (w *Wallet) DetachBlock(block *types.Block) error
- func (w *Wallet) GetAccountBalances(accountID string, id string) ([]AccountBalance, error)
- func (w *Wallet) GetAccountUtxos(accountID string, id string, unconfirmed, isSmartContract bool, vote bool) []*account.UTXO
- func (w *Wallet) GetAccountVotes(accountID string, id string) ([]AccountVotes, error)
- func (w *Wallet) GetTransactionByTxID(txID string) (*query.AnnotatedTx, error)
- func (w *Wallet) GetTransactions(accountID string, StartTxID string, count uint, unconfirmed bool) ([]*query.AnnotatedTx, error)
- func (w *Wallet) GetTransactionsSummary(transactions []*query.AnnotatedTx) []TxSummary
- func (w *Wallet) GetUnconfirmedTxByTxID(txID string) (*query.AnnotatedTx, error)
- func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, error)
- func (w *Wallet) GetWalletStatusInfo() StatusInfo
- func (w *Wallet) LoadWalletInfo() error
- func (w *Wallet) MemPoolTxQueryLoop()
- func (w *Wallet) RemoveUnconfirmedTx(txD *protocol.TxDesc)
- func (w *Wallet) RescanBlocks()
- func (w *Wallet) Rollback(targetHeight uint64) error
- func (w *Wallet) Run() error
- func (w *Wallet) UpdateAccountAlias(accountID string, newAlias string) (err error)
- type WalletStore
Constants ¶
const ( UnconfirmedTxCheckPeriod = 30 * time.Minute MaxUnconfirmedTxDuration = 24 * time.Hour )
const (
//SINGLE single sign
SINGLE = 1
)
Variables ¶
var ( // ErrRecoveryBusy another recovery in progress, can not get recovery manager lock ErrRecoveryBusy = errors.New("another recovery in progress") // ErrInvalidAcctID can not find account by account id ErrInvalidAcctID = errors.New("invalid account id") ErrGetRecoveryStatus = errors.New("failed to get recovery status.") ErrRecoveryStatus = errors.New("recovery status is nil.") )
Functions ¶
func BuildP2PKHAddress ¶ added in v0.2.0
func BuildP2SHAddress ¶ added in v0.2.0
func FindTransactionsByAccount ¶ added in v0.3.0
func FindTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string) bool
func NewRecoveryManager ¶ added in v0.3.0
func NewRecoveryManager(store WalletStore, accountMgr *account.Manager) *recoveryManager
NewRecoveryManager create recovery manger.
Types ¶
type AccountBalance ¶
type AccountBalance struct {
AccountID string `json:"account_id"`
Alias string `json:"account_alias"`
AssetAlias string `json:"asset_alias"`
AssetID string `json:"asset_id"`
Amount uint64 `json:"amount"`
AssetDefinition map[string]interface{} `json:"asset_definition"`
}
AccountBalance account balance
type AccountVotes ¶
type AccountVotes struct {
AccountID string `json:"account_id"`
Alias string `json:"account_alias"`
TotalVoteNumber uint64 `json:"total_vote_number"`
VoteDetails []voteDetail `json:"vote_details"`
}
AccountVotes account vote
type RecoveryState ¶ added in v0.3.0
type RecoveryState struct {
// XPubs recovery account xPubs
XPubs []chainkd.XPub
// The time to start the recovery task, used to detemine whether
// recovery task is completed.
StartTime time.Time
// XPubsStatus maintains a map of each requested XPub to its active
// account recovery state.
XPubsStatus *branchRecoveryState
// AcctStatus maintains a map of each requested key scope to its active
// recovery state.
AccountsStatus map[string]*addressRecoveryState
}
RecoveryState used to record the status of a recovery process.
type SortByHeight ¶ added in v0.3.0
type SortByHeight []*query.AnnotatedTx
SortByHeight implements sort.Interface for AnnotatedTx slices
func (SortByHeight) Len ¶ added in v0.3.0
func (a SortByHeight) Len() int
func (SortByHeight) Less ¶ added in v0.3.0
func (a SortByHeight) Less(i, j int) bool
func (SortByHeight) Swap ¶ added in v0.3.0
func (a SortByHeight) Swap(i, j int)
type SortByTimestamp ¶
type SortByTimestamp []*query.AnnotatedTx
SortByTimestamp implements sort.Interface for AnnotatedTx slices
func (SortByTimestamp) Len ¶
func (a SortByTimestamp) Len() int
func (SortByTimestamp) Less ¶
func (a SortByTimestamp) Less(i, j int) bool
func (SortByTimestamp) Swap ¶
func (a SortByTimestamp) Swap(i, j int)
type StatusInfo ¶
type StatusInfo struct {
Version uint
WorkHeight uint64
WorkHash bc.Hash
BestHeight uint64
BestHash bc.Hash
}
StatusInfo is base valid block info to handle orphan block rollback
type Summary ¶
type Summary struct {
Type string `json:"type"`
AssetID bc.AssetID `json:"asset_id,omitempty"`
AssetAlias string `json:"asset_alias,omitempty"`
Amount uint64 `json:"amount,omitempty"`
AccountID string `json:"account_id,omitempty"`
AccountAlias string `json:"account_alias,omitempty"`
Arbitrary chainjson.HexBytes `json:"arbitrary,omitempty"`
}
Summary is the struct of transaction's input and output summary
type TxSummary ¶
type TxSummary struct {
ID bc.Hash `json:"tx_id"`
Timestamp uint64 `json:"block_time"`
Inputs []Summary `json:"inputs"`
Outputs []Summary `json:"outputs"`
}
TxSummary is the struct of transaction summary
type Wallet ¶
type Wallet struct {
Store WalletStore
Status StatusInfo
TxIndexFlag bool
AccountMgr *account.Manager
AssetReg *asset.Registry
Hsm *pseudohsm.HSM
Chain *protocol.Chain
RecoveryMgr *recoveryManager
EventDispatcher *event.Dispatcher
TxMsgSub *event.Subscription
// contains filtered or unexported fields
}
Wallet is related to storing account unspent outputs
func NewWallet ¶
func NewWallet(store WalletStore, account *account.Manager, asset *asset.Registry, hsm *pseudohsm.HSM, chain *protocol.Chain, dispatcher *event.Dispatcher, txIndexFlag bool) (*Wallet, error)
NewWallet return a new wallet instance
func (*Wallet) AddUnconfirmedTx ¶
AddUnconfirmedTx handle wallet status update when tx add into txpool
func (*Wallet) AttachBlock ¶
AttachBlock attach a new block
func (*Wallet) BuildAnnotatedInput ¶
BuildAnnotatedInput build the annotated input.
func (*Wallet) BuildAnnotatedOutput ¶
BuildAnnotatedOutput build the annotated output.
func (*Wallet) DeleteAccount ¶
DeleteAccount deletes account matching accountID, then rescan wallet
func (*Wallet) DetachBlock ¶
DetachBlock detach a block and rollback state
func (*Wallet) GetAccountBalances ¶
func (w *Wallet) GetAccountBalances(accountID string, id string) ([]AccountBalance, error)
GetAccountBalances return all account balances
func (*Wallet) GetAccountUtxos ¶
func (w *Wallet) GetAccountUtxos(accountID string, id string, unconfirmed, isSmartContract bool, vote bool) []*account.UTXO
GetAccountUtxos return all account unspent outputs
func (*Wallet) GetAccountVotes ¶
func (w *Wallet) GetAccountVotes(accountID string, id string) ([]AccountVotes, error)
GetAccountVotes return all account votes
func (*Wallet) GetTransactionByTxID ¶
func (w *Wallet) GetTransactionByTxID(txID string) (*query.AnnotatedTx, error)
GetTransactionByTxID get transaction by txID
func (*Wallet) GetTransactions ¶
func (w *Wallet) GetTransactions(accountID string, StartTxID string, count uint, unconfirmed bool) ([]*query.AnnotatedTx, error)
GetTransactions get all walletDB transactions or unconfirmed transactions, and filter transactions by accountID and StartTxID optional
func (*Wallet) GetTransactionsSummary ¶
func (w *Wallet) GetTransactionsSummary(transactions []*query.AnnotatedTx) []TxSummary
GetTransactionsSummary get transactions summary
func (*Wallet) GetUnconfirmedTxByTxID ¶
func (w *Wallet) GetUnconfirmedTxByTxID(txID string) (*query.AnnotatedTx, error)
GetUnconfirmedTxByTxID get unconfirmed transaction by txID
func (*Wallet) GetUnconfirmedTxs ¶
func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, error)
GetUnconfirmedTxs get account unconfirmed transactions, filter transactions by accountID when accountID is not empty
func (*Wallet) GetWalletStatusInfo ¶
func (w *Wallet) GetWalletStatusInfo() StatusInfo
GetWalletStatusInfo return current wallet StatusInfo
func (*Wallet) LoadWalletInfo ¶ added in v0.3.0
LoadWalletInfo return stored wallet info and nil, if error, return initial wallet info and err
func (*Wallet) MemPoolTxQueryLoop ¶ added in v0.3.0
func (w *Wallet) MemPoolTxQueryLoop()
MemPoolTxQueryLoop constantly pass a transaction accepted by mempool to the wallet.
func (*Wallet) RemoveUnconfirmedTx ¶
RemoveUnconfirmedTx handle wallet status update when tx removed from txpool
func (*Wallet) RescanBlocks ¶
func (w *Wallet) RescanBlocks()
RescanBlocks provide a trigger to rescan blocks
type WalletStore ¶ added in v0.3.0
type WalletStore interface {
InitBatch() WalletStore
CommitBatch() error
DeleteContractUTXO(bc.Hash)
DeleteRecoveryStatus()
DeleteTransactions(uint64)
DeleteUnconfirmedTransaction(string)
DeleteWalletTransactions()
DeleteWalletUTXOs()
GetAsset(*bc.AssetID) (*asset.Asset, error)
GetGlobalTransactionIndex(string) []byte
GetStandardUTXO(bc.Hash) (*acc.UTXO, error)
GetTransaction(string) (*query.AnnotatedTx, error)
GetUnconfirmedTransaction(string) (*query.AnnotatedTx, error)
GetRecoveryStatus() (*RecoveryState, error)
GetWalletInfo() (*StatusInfo, error)
ListAccountUTXOs(string, bool) ([]*acc.UTXO, error)
ListTransactions(string, string, uint, bool) ([]*query.AnnotatedTx, error)
ListUnconfirmedTransactions() ([]*query.AnnotatedTx, error)
SetAssetDefinition(*bc.AssetID, []byte)
SetContractUTXO(bc.Hash, *acc.UTXO) error
SetGlobalTransactionIndex(string, *bc.Hash, uint64)
SetRecoveryStatus(*RecoveryState) error
SetTransaction(uint64, *query.AnnotatedTx) error
SetUnconfirmedTransaction(string, *query.AnnotatedTx) error
SetWalletInfo(*StatusInfo) error
}
WalletStore interface contains wallet storage functions.