Documentation ¶
Overview ¶
Copyright (c) 2022 The utreexo developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- func DisableLog()
- func UseLogger(logger btclog.Logger)
- type Config
- type HDVersion
- type LeafDataExtras
- type MempoolTx
- type RelevantTxData
- type StatusUpdate
- type TxData
- type WalletConfig
- type WalletState
- type WatchOnlyWalletManager
- func (wm *WatchOnlyWalletManager) GetHistory(wantHash chainhash.Hash) []TxData
- func (wm *WatchOnlyWalletManager) GetMempool(wantHash chainhash.Hash) []TxData
- func (wm *WatchOnlyWalletManager) GetMempoolBalance(wantHash chainhash.Hash) int64
- func (wm *WatchOnlyWalletManager) GetMerkle(txHash chainhash.Hash) ([]*chainhash.Hash, int, int)
- func (wm *WatchOnlyWalletManager) GetProof() blockchain.ChainTipProof
- func (wm *WatchOnlyWalletManager) GetScriptHash(wantHash chainhash.Hash) []byte
- func (wm *WatchOnlyWalletManager) GetScriptHashBalance(wantHash chainhash.Hash) int64
- func (wm *WatchOnlyWalletManager) GetTXIDFromBlockPos(blockHeight, posInBlock int, getMerkleProof bool) (chainhash.Hash, []*chainhash.Hash)
- func (wm *WatchOnlyWalletManager) GetTx(txHash chainhash.Hash) *wire.MsgTx
- func (wm *WatchOnlyWalletManager) GetUnspent(wantHash chainhash.Hash) []LeafDataExtras
- func (wm *WatchOnlyWalletManager) Getbalance() int64
- func (m *WatchOnlyWalletManager) NotifyNewTransactions(txns []*mempool.TxDesc)
- func (wm *WatchOnlyWalletManager) ProveTx(tx *btcutil.Tx) (*wire.UData, error)
- func (wm *WatchOnlyWalletManager) RegisterAddress(address string) error
- func (wm *WatchOnlyWalletManager) RegisterExtendedPubkey(extendedKey string, hdVersion *HDVersion) error
- func (wm *WatchOnlyWalletManager) ScriptHashSubscribe(receiveChan chan interface{})
- func (m *WatchOnlyWalletManager) Start()
- func (m *WatchOnlyWalletManager) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type Config ¶
type Config struct { Chain *blockchain.BlockChain TxMemPool *mempool.TxPool ChainParams *chaincfg.Params DataDir string GapLimit uint32 }
Config is a configuration struct used to initialize a new WatchOnlyWalletManager.
type HDVersion ¶
type HDVersion uint32
HDVersion represents the different supported schemes of hierarchical derivation.
const ( // HDVersionMainNetBIP0044 is the HDVersion for BIP-0044 on the main // network. HDVersionMainNetBIP0044 HDVersion = 0x0488b21e // xpub // HDVersionMainNetBIP0049 is the HDVersion for BIP-0049 on the main // network. HDVersionMainNetBIP0049 HDVersion = 0x049d7cb2 // ypub // HDVersionMainNetBIP0084 is the HDVersion for BIP-0084 on the main // network. HDVersionMainNetBIP0084 HDVersion = 0x04b24746 // zpub // HDVersionTestNetBIP0044 is the HDVersion for BIP-0044 on the test // network. HDVersionTestNetBIP0044 HDVersion = 0x043587cf // tpub // HDVersionTestNetBIP0049 is the HDVersion for BIP-0049 on the test // network. HDVersionTestNetBIP0049 HDVersion = 0x044a5262 // upub // HDVersionTestNetBIP0084 is the HDVersion for BIP-0084 on the test // network. HDVersionTestNetBIP0084 HDVersion = 0x045f1cf6 // vpub // HDVersionSimNetBIP0044 is the HDVersion for BIP-0044 on the // simulation test network. There aren't any other versions defined for // the simulation test network. HDVersionSimNetBIP0044 HDVersion = 0x0420bd3a // spub )
type LeafDataExtras ¶
type LeafDataExtras struct { // LeafData is the The underlying leaf data. LeafData wire.LeafData `json:"leafdata"` // BlockIdx is the in block position of the tx of the leafdata. Coinbases // are always a blockindex of 0. BlockIdx int `json:"blockindex"` // BlockHeight is the height of this leafdata. If the leaf data is for an stxo, // block height is where the leaf was spent. BlockHeight int `json:"blockheight"` }
LeafDataExtras is all the leaf data plus all other data that an electrum server would need for a relevant txo.
func (LeafDataExtras) MarshalJSON ¶
func (tx LeafDataExtras) MarshalJSON() ([]byte, error)
func (*LeafDataExtras) UnmarshalJSON ¶
func (tx *LeafDataExtras) UnmarshalJSON(data []byte) error
type MempoolTx ¶
type MempoolTx struct { // Tx is the raw tx along with metadata useful for memepool txs. Tx *mempool.TxDesc `json:"tx"` // Confirmed states if all the inputs are confirmed or not. Confirmed bool `json:"confirmed"` // Pkscript is the scripts for the inputs of the tx. Pkscript map[wire.OutPoint][]byte `json:"pkscripts"` }
MempoolTx is the underlying tx descriptor with data useful for electrum servers.
func (MempoolTx) MarshalJSON ¶
func (*MempoolTx) UnmarshalJSON ¶
type RelevantTxData ¶
type RelevantTxData struct { // BlockIndex is the position in the block the tx is at. BlockIndex int `json:"position"` // BlockHeight is the block this tx was included in. BlockHeight int `json:"blockheight"` // Tx is the raw tx of for this tx. Tx *wire.MsgTx `json:"tx"` // MerkleProof is the hashes needed to hash to the merkle root commited // in the block. MerkleProof []*chainhash.Hash `json:"merkleproof"` }
RelevantTxData includes all the extra data that an electrum server could request that's related to a tx.
func (RelevantTxData) MarshalJSON ¶
func (tx RelevantTxData) MarshalJSON() ([]byte, error)
func (*RelevantTxData) UnmarshalJSON ¶
func (tx *RelevantTxData) UnmarshalJSON(data []byte) error
type StatusUpdate ¶
type StatusUpdate struct { // ScriptHash is the hash of an address. Refer to the electrum protocol doc // for more info: electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html ScriptHash chainhash.Hash // Status is the hash of all the txs. This is what's needed for // electrum servers to indicate a receive/spend happened to an // address. Status []byte }
StatusUpdate the two pieces of data needed to alert an electrum client that an address had coins spent/received.
type TxData ¶
type TxData struct { // Hash is the txid of the transaction. Hash chainhash.Hash // Idx is the output index of the tx. If we're referring to a txin, the // idx is -1. Idx int // BlockIndex is the index this tx is at the block level. BlockIndex int // Amount is the value in satoshis a txo is worth. -1 if we're referring to // a txin. Amount int64 // Height is where this tx is confirmed at. -1 if the tx is in the mempool. Height int32 // Fee is the fee paid for this tx. Fee int64 // AllInputsConfirmed of true states that this tx isn't spending an // unconfirmed tx. AllInputsConfirmed bool }
TxData is all the data for a tx that an electrum server would need access to to satisfy the electrum protocol methods. This struct is mainly used to communicate between the wallet and the electrum server.
type WalletConfig ¶
type WalletConfig struct { Net string ExtendedKeys map[string]HDVersion Addresses map[string]struct{} GapLimit uint32 }
WalletConfig defines the config for the wallet.
func (WalletConfig) MarshalJSON ¶
func (ws WalletConfig) MarshalJSON() ([]byte, error)
func (*WalletConfig) UnmarshalJSON ¶
func (ws *WalletConfig) UnmarshalJSON(data []byte) error
type WalletState ¶
type WalletState struct { // WatchedKeys are a map of maps mapping master pubkeys to addresses and a bool // if true, indicates that the address is a change address. WatchedKeys map[string]map[string]bool `json:"watchedkeys"` // LastExternalIndex refers to the bip32 index used for the external wallet. // These are used to derive address given out to others for payment. LastExternalIndex map[string]uint32 `json:"lastexternalindex"` // LastInternalIndex refers to the bip32 index used for the internal wallet. // These are used for deriving change addresses. LastInternalIndex map[string]uint32 `json:"lastinternalindex"` // BestHash is the latest block hash this wallet state is synced to. BestHash chainhash.Hash `json:"besthash"` // NumLeaves are the total number of leaves in the accumulator. Needed for some proof related // functions. NumLeaves uint64 `json:"numleaves"` // UtreexoLeaves are hashes of the utxos that this wallet controls. UtreexoLeaves []utreexo.Hash `json:"utreexoleaves"` // Utreexo is all the proof needed to prove the UtreexoLeaves. UtreexoProof utreexo.Proof `json:"utreexoproof"` // RelevantUtxos are the utxos that this wallet controls. RelevantUtxos map[wire.OutPoint]LeafDataExtras `json:"relevantutxos"` // RelevantStxos are the relevant utxos that were spent. Only needed for reorgs. RelevantStxos map[wire.OutPoint]LeafDataExtras `json:"relevantstxos"` // RelevantTxs keep track of relevant data for each tx. RelevantTxs map[chainhash.Hash]RelevantTxData `json:"relevanttxs"` // RelevantMempoolTxs are the mempool txs that the wallet controls. RelevantMempoolTxs map[chainhash.Hash]MempoolTx `json:"relevantmempooltxs"` }
WalletState keeps track of all the current relevant utxos. It includes a batched utreexo proof of all the relevant utxos.
func (WalletState) MarshalJSON ¶
func (wp WalletState) MarshalJSON() ([]byte, error)
func (*WalletState) UnmarshalJSON ¶
func (wp *WalletState) UnmarshalJSON(data []byte) error
type WatchOnlyWalletManager ¶
type WatchOnlyWalletManager struct {
// contains filtered or unexported fields
}
WatchOnlyWalletManager is used to keep track of utxos and the utreexo proofs for those utxos.
func New ¶
func New(config *Config) (*WatchOnlyWalletManager, error)
New constructs a new instance of the watch-only wallet manager.
func (*WatchOnlyWalletManager) GetHistory ¶
func (wm *WatchOnlyWalletManager) GetHistory(wantHash chainhash.Hash) []TxData
GetHistory returns all the txs that this watch only wallet is keeping track of for the given want hash.
func (*WatchOnlyWalletManager) GetMempool ¶
func (wm *WatchOnlyWalletManager) GetMempool(wantHash chainhash.Hash) []TxData
GetMempool returns all the mempool txs that is relevant to the given want hash.
func (*WatchOnlyWalletManager) GetMempoolBalance ¶
func (wm *WatchOnlyWalletManager) GetMempoolBalance(wantHash chainhash.Hash) int64
GetMempoolBalance returns the summed balance of all the unconfirmed txos relevant to the given want hash.
func (*WatchOnlyWalletManager) GetMerkle ¶
GetMerkle returns the merkle proof, block height, and the position of the tx in the block.
func (*WatchOnlyWalletManager) GetProof ¶
func (wm *WatchOnlyWalletManager) GetProof() blockchain.ChainTipProof
GetProof returns a proof that can be used to verify the utreexo leaves.
func (*WatchOnlyWalletManager) GetScriptHash ¶
func (wm *WatchOnlyWalletManager) GetScriptHash(wantHash chainhash.Hash) []byte
GetScriptHash returns a hash of all the utxos that the wantHash address controls.
func (*WatchOnlyWalletManager) GetScriptHashBalance ¶
func (wm *WatchOnlyWalletManager) GetScriptHashBalance(wantHash chainhash.Hash) int64
GetScriptHashBalance returns the balance of the wanted hash for the utxos this wallet is tracking.
func (*WatchOnlyWalletManager) GetTXIDFromBlockPos ¶
func (wm *WatchOnlyWalletManager) GetTXIDFromBlockPos(blockHeight, posInBlock int, getMerkleProof bool) (chainhash.Hash, []*chainhash.Hash)
GetTXIDFromBlockPos returns the txid of tx given its position in the block. Passing in true for getMerkleProof will have the function return a non-nil slice of merkle nodes.
func (*WatchOnlyWalletManager) GetTx ¶
func (wm *WatchOnlyWalletManager) GetTx(txHash chainhash.Hash) *wire.MsgTx
Get tx returns the tx for the given tx hash. Returns nil if the watch only wallet does not have it.
func (*WatchOnlyWalletManager) GetUnspent ¶
func (wm *WatchOnlyWalletManager) GetUnspent(wantHash chainhash.Hash) []LeafDataExtras
GetUnspent returns the tx data of the unspent txs that this watch only wallet is keeping track of.
func (*WatchOnlyWalletManager) Getbalance ¶
func (wm *WatchOnlyWalletManager) Getbalance() int64
Getbalance totals up the balance in the utxos it's keeping track of.
func (*WatchOnlyWalletManager) NotifyNewTransactions ¶
func (m *WatchOnlyWalletManager) NotifyNewTransactions(txns []*mempool.TxDesc)
NotifyNewTransactions notifies all the subscribers of the passed in txns. This function is provided so that the main utreexod server can notify the watch only wallet that there are new txns verified and in the mempool.
func (*WatchOnlyWalletManager) ProveTx ¶
ProveTx generates a udata that will prove the given tx to another utreexo node.
func (*WatchOnlyWalletManager) RegisterAddress ¶
func (wm *WatchOnlyWalletManager) RegisterAddress(address string) error
RegisterAddress registers an address for the watch only wallet to keep track of.
func (*WatchOnlyWalletManager) RegisterExtendedPubkey ¶
func (wm *WatchOnlyWalletManager) RegisterExtendedPubkey(extendedKey string, hdVersion *HDVersion) error
RegisterExtendedPubkey registers an extended pubkey for the watch only wallet to keep track of.
func (*WatchOnlyWalletManager) ScriptHashSubscribe ¶
func (wm *WatchOnlyWalletManager) ScriptHashSubscribe(receiveChan chan interface{})
ScriptHashSubscribe will add the given channel to be sent a status update whenever a new event has happened in the watch only wallet.
func (*WatchOnlyWalletManager) Start ¶
func (m *WatchOnlyWalletManager) Start()
Start starts the watch only wallet manager.
func (*WatchOnlyWalletManager) Stop ¶
func (m *WatchOnlyWalletManager) Stop()
Stop stops the watch only wallet manager.