Documentation ¶
Index ¶
- Variables
- func BytesToUin64(bytes []byte) uint64
- func CoinBucket(bucket []byte, coin types.CoinID) []byte
- func Create(ns walletdb.ReadWriteBucket) error
- func DependencySort(txs map[hash.Hash]*types.Transaction) []*types.Transaction
- func DropTransactionHistory(ns walletdb.ReadWriteBucket) error
- func IsCoinBaseTx(tx *types.Transaction) bool
- func TxRawIsCoinBase(tx corejson.TxRawResult) bool
- func Uint64ToBytes(value uint64) []byte
- type AddrTxOutput
- type AddrTxOutputs
- type Block
- type BlockMeta
- type Credit
- type CreditRecord
- type DebitRecord
- type Error
- type ErrorCode
- type MigrationManager
- func (m *MigrationManager) CurrentVersion(ns walletdb.ReadBucket) (uint32, error)
- func (m *MigrationManager) Name() string
- func (m *MigrationManager) Namespace() walletdb.ReadWriteBucket
- func (m *MigrationManager) SetVersion(ns walletdb.ReadWriteBucket, version uint32) error
- func (m *MigrationManager) Versions() []migration.Version
- type SpendStatus
- type SpendTo
- type Store
- func (s *Store) AddCredit(ns walletdb.ReadWriteBucket, rec *TxRecord, block *BlockMeta, index uint32, ...) error
- func (s *Store) Balance(ns walletdb.ReadBucket, minConf int32, syncOrder int32, coinId types.CoinID) (types.Amount, error)
- func (s *Store) GetAddrTxOut(ns walletdb.ReadWriteBucket, address string, point types.TxOutPoint) (*AddrTxOutput, error)
- func (s *Store) InsertAddrTxOut(ns walletdb.ReadWriteBucket, txOut *AddrTxOutput) error
- func (s *Store) InsertTx(ns walletdb.ReadWriteBucket, rec *TxRecord, block *BlockMeta) error
- func (s *Store) PreviousPkScripts(ns walletdb.ReadBucket, rec *TxRecord, block *Block) ([][]byte, error)
- func (s *Store) RangeTransactions(ns walletdb.ReadBucket, begin, end int32, f func([]TxDetails) (bool, error)) error
- func (s *Store) RemoveUnMinedTx(ns walletdb.ReadWriteBucket, rec *TxRecord) error
- func (s *Store) Rollback(ns walletdb.ReadWriteBucket, height int32) error
- func (s *Store) TxDetails(ns walletdb.ReadBucket, txHash *hash.Hash) (*TxDetails, error)
- func (s *Store) UnMinedTxHashes(ns walletdb.ReadBucket) ([]*hash.Hash, error)
- func (s *Store) UnMinedTxs(ns walletdb.ReadBucket) ([]*types.Transaction, error)
- func (s *Store) UniqueTxDetails(ns walletdb.ReadBucket, txHash *hash.Hash, block *Block) (*TxDetails, error)
- func (s *Store) UnspentOutputs(ns walletdb.ReadBucket) ([]Credit, error)
- func (s *Store) UpdateAddrTxIn(ns walletdb.ReadWriteBucket, addr string, outPoint *types.TxOutPoint) error
- func (s *Store) UpdateAddrTxOut(ns walletdb.ReadWriteBucket, txOut *AddrTxOutput) error
- type TxConfirmed
- type TxDetails
- type TxInputPoint
- type TxRecord
- type TxStatus
- type UTxo
- type UnconfirmTx
Constants ¶
This section is empty.
Variables ¶
var ( BucketUnConfirmed = []byte("uc") BucketAddrtxin = []byte("in") BucketAddrtxout = []byte("out") BucketTxJson = []byte("txjson") BucketSync = []byte("sync") BucketHeight = []byte("h") )
Bucket names
Functions ¶
func BytesToUin64 ¶
func Create ¶
func Create(ns walletdb.ReadWriteBucket) error
Create creates a new persistent transaction store in the walletdb namespace. Creating the store when one already exists in this namespace will error with ErrAlreadyExists.
func DependencySort ¶
func DependencySort(txs map[hash.Hash]*types.Transaction) []*types.Transaction
func DropTransactionHistory ¶
func DropTransactionHistory(ns walletdb.ReadWriteBucket) error
func IsCoinBaseTx ¶
func IsCoinBaseTx(tx *types.Transaction) bool
func TxRawIsCoinBase ¶
func TxRawIsCoinBase(tx corejson.TxRawResult) bool
func Uint64ToBytes ¶
Types ¶
type AddrTxOutput ¶
type AddrTxOutput struct { Address string TxId hash.Hash Index uint32 Amount types.Amount Block Block Spend SpendStatus SpendTo *SpendTo Status TxStatus Locked uint32 IsBlue bool PkScript string }
func DecodeAddrTxOutput ¶
func DecodeAddrTxOutput(bytes []byte) (*AddrTxOutput, error)
func NewAddrTxOutput ¶
func NewAddrTxOutput() *AddrTxOutput
func (*AddrTxOutput) Encode ¶
func (a *AddrTxOutput) Encode() []byte
type AddrTxOutputs ¶
type AddrTxOutputs []AddrTxOutput
func (AddrTxOutputs) Len ¶
func (s AddrTxOutputs) Len() int
func (AddrTxOutputs) Less ¶
func (s AddrTxOutputs) Less(i, j int) bool
func (AddrTxOutputs) Swap ¶
func (s AddrTxOutputs) Swap(i, j int)
type Block ¶
Block contains the minimum amount of data to uniquely identify any block on either the best or side chain.
type BlockMeta ¶
BlockMeta contains the unique identification for a block and any metadata pertaining to the block. At the moment, this additional metadata only includes the block time from the block header.
type Credit ¶
type Credit struct { types.TxOutPoint BlockMeta Amount types.Amount PkScript []byte Received time.Time FromCoinBase bool }
Credit is the type representing a transaction output which was spent or is still spendable by wallet. A UTXO is an unspent Credit, but not all Credits are UTXOs.
type CreditRecord ¶
CreditRecord contains metadata regarding a transaction credit for a known transaction. Further details may be looked up by indexing a wire.MsgTx.TxOut with the Index field.
type DebitRecord ¶
DebitRecord contains metadata regarding a transaction debit for a known transaction. Further details may be looked up by indexing a wire.MsgTx.TxIn with the Index field.
type Error ¶
type Error struct { Code ErrorCode // Describes the kind of error Desc string // Human readable description of the issue Err error // Underlying error, optional }
Error provides a single type for errors that can happen during Store operation.
type ErrorCode ¶
type ErrorCode uint8
ErrorCode identifies a category of error.
const ( // ErrDatabase indicates an error with the underlying database. When // this error code is set, the Err field of the Error will be // set to the underlying error returned from the database. ErrDatabase ErrorCode = iota // ErrData describes an error where data stored in the transaction // database is incorrect. This may be due to missing values, values of // wrong sizes, or data from different buckets that is inconsistent with // itself. Recovering from an ErrData requires rebuilding all // transaction history or manual database surgery. If the failure was // not due to data corruption, this error category indicates a // programming error in this package. ErrData // ErrInput describes an error where the variables passed into this // function by the caller are obviously incorrect. Examples include // passing transactions which do not serialize, or attempting to insert // a credit at an index for which no transaction output exists. ErrInput // ErrAlreadyExists describes an error where creating the store cannot // continue because a store already exists in the namespace. ErrAlreadyExists // ErrNoExists describes an error where the store cannot be opened due to // it not already existing in the namespace. This error should be // handled by creating a new store. ErrNoExists // ErrNeedsUpgrade describes an error during store opening where the // database contains an older version of the store. ErrNeedsUpgrade // ErrUnknownVersion describes an error where the store already exists // but the database version is newer than latest version known to this // software. This likely indicates an outdated binary. ErrUnknownVersion )
These constants are used to identify a specific Error.
type MigrationManager ¶
type MigrationManager struct {
// contains filtered or unexported fields
}
MigrationManager is an implementation of the migration.Manager interface that will be used to handle migrations for the address manager. It exposes the necessary parameters required to successfully perform migrations.
func (*MigrationManager) CurrentVersion ¶
func (m *MigrationManager) CurrentVersion(ns walletdb.ReadBucket) (uint32, error)
CurrentVersion returns the current version of the service's database.
NOTE: This method is part of the migration.Manager interface.
func (*MigrationManager) Name ¶
func (m *MigrationManager) Name() string
Name returns the name of the service we'll be attempting to upgrade. NOTE: This method is part of the migration.Manager interface.
func (*MigrationManager) Namespace ¶
func (m *MigrationManager) Namespace() walletdb.ReadWriteBucket
Namespace returns the top-level bucket of the service.
NOTE: This method is part of the migration.Manager interface.
func (*MigrationManager) SetVersion ¶
func (m *MigrationManager) SetVersion(ns walletdb.ReadWriteBucket, version uint32) error
SetVersion sets the version of the service's database.
NOTE: This method is part of the migration.Manager interface.
func (*MigrationManager) Versions ¶
func (m *MigrationManager) Versions() []migration.Version
Versions returns all of the available database versions of the service.
NOTE: This method is part of the migration.Manager interface.
type SpendStatus ¶
type SpendStatus uint16
const ( SpendStatusUnspent SpendStatus = 0 SpendStatusSpend SpendStatus = 1 )
type Store ¶
type Store struct { // Event callbacks. These execute in the same goroutine as the wtxmgr // caller. NotifyUnspent func(hash *hash.Hash, index uint32) // contains filtered or unexported fields }
Store implements a transaction store for storing and managing wallet transactions.
func Open ¶
Open opens the wallet transaction store from a walletdb namespace. If the store does not exist, ErrNoExist is returned.
func (*Store) AddCredit ¶
func (s *Store) AddCredit(ns walletdb.ReadWriteBucket, rec *TxRecord, block *BlockMeta, index uint32, change bool) error
AddCredit marks a transaction record as containing a transaction output spendable by wallet. The output is added unspent, and is marked spent when a new transaction spending the output is inserted into the store.
func (*Store) Balance ¶
func (s *Store) Balance(ns walletdb.ReadBucket, minConf int32, syncOrder int32, coinId types.CoinID) (types.Amount, error)
Balance returns the spendable wallet balance (total value of all unspent transaction outputs) given a minimum of minConf confirmations, calculated at a current chain height of curHeight. Coinbase outputs are only included in the balance if maturity has been reached.
Balance may return unexpected results if syncHeight is lower than the block height of the most recent mined transaction in the store.
func (*Store) GetAddrTxOut ¶
func (s *Store) GetAddrTxOut(ns walletdb.ReadWriteBucket, address string, point types.TxOutPoint) (*AddrTxOutput, error)
func (*Store) InsertAddrTxOut ¶
func (s *Store) InsertAddrTxOut(ns walletdb.ReadWriteBucket, txOut *AddrTxOutput) error
func (*Store) InsertTx ¶
InsertTx records a transaction as belonging to a wallet's transaction history. If block is nil, the transaction is considered unspent, and the transaction's index must be unset.
func (*Store) PreviousPkScripts ¶
func (s *Store) PreviousPkScripts(ns walletdb.ReadBucket, rec *TxRecord, block *Block) ([][]byte, error)
PreviousPkScripts returns a slice of previous output scripts for each credit output this transaction record debits from.
func (*Store) RangeTransactions ¶
func (s *Store) RangeTransactions(ns walletdb.ReadBucket, begin, end int32, f func([]TxDetails) (bool, error)) error
RangeTransactions runs the function f on all transaction details between blocks on the best chain over the height range [begin,end]. The special height -1 may be used to also include unMined transactions. If the end height comes before the begin height, blocks are iterated in reverse order and unMined transactions (if any) are processed first.
The function f may return an error which, if non-nil, is propagated to the caller. Additionally, a boolean return value allows exiting the function early without reading any additional transactions early when true.
All calls to f are guaranteed to be passed a slice with more than zero elements. The slice may be reused for multiple blocks, so it is not safe to use it after the loop iteration it was acquired.
func (*Store) RemoveUnMinedTx ¶
func (s *Store) RemoveUnMinedTx(ns walletdb.ReadWriteBucket, rec *TxRecord) error
RemoveUnMinedTx attempts to remove an unMined transaction from the transaction store. This is to be used in the scenario that a transaction that we attempt to rebroadcast, turns out to double spend one of our existing inputs. This function we remove the conflicting transaction identified by the tx record, and also recursively remove all transactions that depend on it.
func (*Store) Rollback ¶
func (s *Store) Rollback(ns walletdb.ReadWriteBucket, height int32) error
Rollback removes all blocks at height onwards, moving any transactions within each block to the unconfirmed pool.
func (*Store) TxDetails ¶
TxDetails looks up all recorded details regarding a transaction with some hash. In case of a hash collision, the most recent transaction with a matching hash is returned.
Not finding a transaction with this hash is not an error. In this case, a nil TxDetails is returned.
func (*Store) UnMinedTxHashes ¶
UnMinedTxHashes returns the hashes of all transactions not known to have been mined in a block.
func (*Store) UnMinedTxs ¶
func (s *Store) UnMinedTxs(ns walletdb.ReadBucket) ([]*types.Transaction, error)
UnMinedTxs returns the underlying transactions for all unMined transactions which are not known to have been mined in a block. Transactions are guaranteed to be sorted by their dependency order.
func (*Store) UniqueTxDetails ¶
func (s *Store) UniqueTxDetails(ns walletdb.ReadBucket, txHash *hash.Hash, block *Block) (*TxDetails, error)
UniqueTxDetails looks up all recorded details for a transaction recorded mined in some particular block, or an unMined transaction if block is nil.
Not finding a transaction with this hash from this block is not an error. In this case, a nil TxDetails is returned.
func (*Store) UnspentOutputs ¶
func (s *Store) UnspentOutputs(ns walletdb.ReadBucket) ([]Credit, error)
UnspentOutputs returns all unspent received transaction outputs. The order is undefined.
func (*Store) UpdateAddrTxIn ¶
func (s *Store) UpdateAddrTxIn(ns walletdb.ReadWriteBucket, addr string, outPoint *types.TxOutPoint) error
func (*Store) UpdateAddrTxOut ¶
func (s *Store) UpdateAddrTxOut(ns walletdb.ReadWriteBucket, txOut *AddrTxOutput) error
type TxConfirmed ¶
type TxDetails ¶
type TxDetails struct { TxRecord Block BlockMeta Credits []CreditRecord Debits []DebitRecord }
TxDetails is intended to provide callers with access to rich details regarding a relevant transaction and which inputs and outputs are credit or debits.
type TxInputPoint ¶
type TxInputPoint struct { TxOutPoint types.TxOutPoint SpendTo SpendTo }
type TxRecord ¶
type TxRecord struct { MsgTx types.Transaction Hash hash.Hash Received time.Time SerializedTx []byte // Optional: may be nil }
TxRecord represents a transaction managed by the Store.
type UnconfirmTx ¶
func UnMarshalUnconfirmTx ¶
func UnMarshalUnconfirmTx(bytes []byte) (*UnconfirmTx, error)
func (*UnconfirmTx) Marshal ¶
func (u *UnconfirmTx) Marshal() []byte