Documentation ¶
Index ¶
- Constants
- Variables
- func CheckDoubleSpends(argTx *wire.MsgTx, txs []*wire.MsgTx) ([]*wire.ShaHash, error)
- func MakeMerkleParent(left *wire.ShaHash, right *wire.ShaHash) *wire.ShaHash
- func NewCoin(txid []byte, index uint32, value btc.Amount, numConfs int64, ...) coinset.Coin
- func OutPointsEqual(a, b wire.OutPoint) bool
- type Blockchain
- func (b *Blockchain) CheckHeader(header wire.BlockHeader, prevHeader StoredHeader) (bool, uint32)
- func (b *Blockchain) CommitHeader(header wire.BlockHeader) (bool, error)
- func (b *Blockchain) GetBlockLocatorHashes() []*wire.ShaHash
- func (b *Blockchain) GetEpoch() (*wire.BlockHeader, error)
- func (b *Blockchain) GetNPrevBlockHashes(n int) []*wire.ShaHash
- type ChainState
- type Coin
- type ConnectionState
- type Datastore
- type FeeLevel
- type HashAndHeight
- type HeaderDB
- func (h *HeaderDB) GetBestHeader() (sh StoredHeader, err error)
- func (h *HeaderDB) GetPreviousHeader(header wire.BlockHeader) (sh StoredHeader, err error)
- func (h *HeaderDB) Height() (uint32, error)
- func (h *HeaderDB) Print()
- func (h *HeaderDB) Prune() error
- func (h *HeaderDB) Put(sh StoredHeader, newBestHeader bool) error
- type Headers
- type KeyPath
- type KeyPurpose
- type Keys
- type Peer
- func (p *Peer) AskForBlocks() error
- func (p *Peer) AskForHeaders() error
- func (p *Peer) AskForMerkleBlock(hash wire.ShaHash)
- func (p *Peer) AskForTx(txid wire.ShaHash)
- func (p *Peer) GetDataHandler(m *wire.MsgGetData)
- func (p *Peer) HeaderHandler(m *wire.MsgHeaders)
- func (p *Peer) IngestBlockAndHeader(m *wire.MsgMerkleBlock)
- func (p *Peer) IngestHeaders(m *wire.MsgHeaders) (bool, error)
- func (p *Peer) IngestMerkleBlock(m *wire.MsgMerkleBlock)
- func (p *Peer) InvHandler(m *wire.MsgInv)
- func (p *Peer) NewOutgoingTx(tx *wire.MsgTx) error
- func (p *Peer) PongBack(nonce uint64)
- func (p *Peer) Rebroadcast()
- func (p *Peer) SendFilter(f *bloom.Filter)
- func (p *Peer) TxHandler(m *wire.MsgTx)
- func (p *Peer) UpdateFilterAndSend()
- type SPVWallet
- func (w *SPVWallet) Balance() (confirmed, unconfirmed int64)
- func (w *SPVWallet) CurrencyCode() string
- func (w *SPVWallet) CurrentAddress(purpose KeyPurpose) *btc.AddressPubKeyHash
- func (w *SPVWallet) MasterPrivateKey() *hd.ExtendedKey
- func (w *SPVWallet) MasterPublicKey() *hd.ExtendedKey
- func (w *SPVWallet) Params() *chaincfg.Params
- func (w *SPVWallet) Spend(amount int64, addr btc.Address, feeLevel FeeLevel) error
- func (w *SPVWallet) Start()
- type State
- type StoredHeader
- type Stxo
- type Stxos
- type TxStore
- func (t *TxStore) GetCurrentKey(purpose KeyPurpose) *hd.ExtendedKey
- func (ts *TxStore) GetDBSyncHeight() (int32, error)
- func (t *TxStore) GetFreshKey(purpose KeyPurpose) *hd.ExtendedKey
- func (t *TxStore) GetKeyForScript(scriptPubKey []byte) (*hd.ExtendedKey, error)
- func (t *TxStore) GetKeys() []*hd.ExtendedKey
- func (ts *TxStore) GetPendingInv() (*wire.MsgInv, error)
- func (t *TxStore) GimmeFilter() (*bloom.Filter, error)
- func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error)
- func (ts *TxStore) PopulateAdrs() error
- func (ts *TxStore) SetDBSyncHeight(n int32) error
- type Txns
- type Utxo
- type Utxos
Constants ¶
const ( MAX_HEADERS = 2000 MAINNET_CHECKPOINT_HEIGHT = 407232 TESTNET3_CHECKPOINT_HEIGHT = 895104 )
const ( EXTERNAL = 0 INTERNAL = 1 )
const ( CONNECTING = 0 CONNECTED = 1 DEAD = 2 )
const ( PRIOIRTY = 0 NORMAL = 1 ECONOMIC = 2 )
const ( SYNCING = 0 WAITING = 1 REORG = 2 )
const LOOKAHEADWINDOW = 100
const MAX_PEERS = 10
const (
VERSION = 70012
)
const WALLET_VERSION = "0.1.0"
Variables ¶
var ( BKTHeaders = []byte("Headers") BKTChainTip = []byte("ChainTip") KEYChainTip = []byte("ChainTip") )
var MainnetCheckpoint wire.BlockHeader
var Testnet3Checkpoint wire.BlockHeader
Functions ¶
func CheckDoubleSpends ¶
GetDoubleSpends takes a transaction and compares it with all transactions in the db. It returns a slice of all txids in the db which are double spent by the received tx.
func MakeMerkleParent ¶
func OutPointsEqual ¶
need this because before I was comparing pointers maybe? so they were the same outpoint but stored in 2 places so false negative?
Types ¶
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
func NewBlockchain ¶
func NewBlockchain(filePath string, params *chaincfg.Params) *Blockchain
func (*Blockchain) CheckHeader ¶
func (b *Blockchain) CheckHeader(header wire.BlockHeader, prevHeader StoredHeader) (bool, uint32)
func (*Blockchain) CommitHeader ¶
func (b *Blockchain) CommitHeader(header wire.BlockHeader) (bool, error)
func (*Blockchain) GetBlockLocatorHashes ¶
func (b *Blockchain) GetBlockLocatorHashes() []*wire.ShaHash
func (*Blockchain) GetEpoch ¶
func (b *Blockchain) GetEpoch() (*wire.BlockHeader, error)
func (*Blockchain) GetNPrevBlockHashes ¶
func (b *Blockchain) GetNPrevBlockHashes(n int) []*wire.ShaHash
type ChainState ¶
type ChainState int
type Coin ¶
type ConnectionState ¶
type ConnectionState int
type HashAndHeight ¶
type HashAndHeight struct {
// contains filtered or unexported fields
}
HashAndHeight is needed instead of just height in case a fullnode responds abnormally (?) by sending out of order merkleblocks. we cache a merkleroot:height pair in the queue so we don't have to look them up from the disk. Also used when inv messages indicate blocks so we can add the header and parse the txs in one request instead of requesting headers first.
func NewRootAndHeight ¶
func NewRootAndHeight(b wire.ShaHash, h int32) (hah HashAndHeight)
NewRootAndHeight saves like 2 lines.
type HeaderDB ¶
type HeaderDB struct {
// contains filtered or unexported fields
}
func NewHeaderDB ¶
func (*HeaderDB) GetBestHeader ¶
func (h *HeaderDB) GetBestHeader() (sh StoredHeader, err error)
func (*HeaderDB) GetPreviousHeader ¶
func (h *HeaderDB) GetPreviousHeader(header wire.BlockHeader) (sh StoredHeader, err error)
type Headers ¶
type Headers interface { // Put a block header to the database // Total work and height are required to be calculated prior to insertion // If this is the new best header, the chain tip should also be updated Put(header StoredHeader, newBestHeader bool) error // Delete all headers after the MAX_HEADERS most recent Prune() error // Returns all information about the previous header GetPreviousHeader(header wire.BlockHeader) (StoredHeader, error) // Retreive the best header from the database GetBestHeader() (StoredHeader, error) // Get the height of chain Height() (uint32, error) // Print all headers Print() }
type KeyPath ¶
type KeyPath struct { Purpose KeyPurpose Index int }
type KeyPurpose ¶
type KeyPurpose int
type Keys ¶
type Keys interface { // Put a bip32 key to the database Put(scriptPubKey []byte, keyPath KeyPath) error // Mark the script as used MarkKeyAsUsed(scriptPubKey []byte) error // Fetch the last index for the given key purpose // The bool should state whether the key has been used or not GetLastKeyIndex(purpose KeyPurpose) (int, bool, error) // Returns the first unused path for the given purpose GetPathForScript(scriptPubKey []byte) (KeyPath, error) // Get the first unused index for the given purpose GetUnused(purpose KeyPurpose) (int, error) // Fetch all key paths GetAll() ([]KeyPath, error) // Get the number of unused keys following the last used key // for each key purpose. GetLookaheadWindows() map[KeyPurpose]int }
Keys provides a database interface for the wallet to save key material, track used keys, and manage the look ahead window.
type Peer ¶
type Peer struct { WBytes uint64 // total bytes written RBytes uint64 // total bytes read TS *TxStore // transaction store to write to // known good txids and their heights OKTxids map[wire.ShaHash]int32 OKMutex sync.Mutex // contains filtered or unexported fields }
func NewPeer ¶
func NewPeer(remoteNode string, blockchain *Blockchain, inTs *TxStore, params *chaincfg.Params, userAgent string, diconnectChan chan string, downloadPeer bool) (*Peer, error)
OpenPV starts a
func (*Peer) AskForBlocks ¶
AskForMerkBlocks requests blocks from current to last right now this asks for 1 block per getData message. Maybe it's faster to ask for many in a each message?
func (*Peer) AskForHeaders ¶
func (*Peer) AskForMerkleBlock ¶
func (*Peer) AskForTx ¶
AskForTx requests a tx we heard about from an inv message. It's one at a time but should be fast enough. I don't like this function because SPV shouldn't even ask...
func (*Peer) GetDataHandler ¶
func (p *Peer) GetDataHandler(m *wire.MsgGetData)
GetDataHandler responds to requests for tx data, which happen after advertising our txs via an inv message
func (*Peer) HeaderHandler ¶
func (p *Peer) HeaderHandler(m *wire.MsgHeaders)
func (*Peer) IngestBlockAndHeader ¶
func (p *Peer) IngestBlockAndHeader(m *wire.MsgMerkleBlock)
func (*Peer) IngestHeaders ¶
func (p *Peer) IngestHeaders(m *wire.MsgHeaders) (bool, error)
IngestHeaders takes in a bunch of headers and appends them to the local header file, checking that they fit. If there's no headers, it assumes we're done and returns false. If it worked it assumes there's more to request and returns true.
func (*Peer) IngestMerkleBlock ¶
func (p *Peer) IngestMerkleBlock(m *wire.MsgMerkleBlock)
func (*Peer) InvHandler ¶
func (*Peer) Rebroadcast ¶
func (p *Peer) Rebroadcast()
Rebroadcast sends an inv message of all the unconfirmed txs the db is aware of. This is called after every sync. Only txids so hopefully not too annoying for nodes.
func (*Peer) SendFilter ¶
func (*Peer) TxHandler ¶
TxHandler takes in transaction messages that come in from either a request after an inv message or after a merkle block message.
func (*Peer) UpdateFilterAndSend ¶
func (p *Peer) UpdateFilterAndSend()
type SPVWallet ¶
type SPVWallet struct {
// contains filtered or unexported fields
}
func NewSPVWallet ¶
func (*SPVWallet) CurrencyCode ¶
func (*SPVWallet) CurrentAddress ¶
func (w *SPVWallet) CurrentAddress(purpose KeyPurpose) *btc.AddressPubKeyHash
func (*SPVWallet) MasterPrivateKey ¶
func (w *SPVWallet) MasterPrivateKey() *hd.ExtendedKey
func (*SPVWallet) MasterPublicKey ¶
func (w *SPVWallet) MasterPublicKey() *hd.ExtendedKey
type StoredHeader ¶
type StoredHeader struct {
// contains filtered or unexported fields
}
type Stxo ¶
type Stxo struct { Utxo Utxo // when it used to be a utxo SpendHeight int32 // height at which it met its demise SpendTxid wire.ShaHash // the tx that consumed it }
Stxo is a utxo that has moved on.
type TxStore ¶
type TxStore struct { Adrs []btcutil.Address Param *chaincfg.Params // contains filtered or unexported fields }
func NewTxStore ¶
func (*TxStore) GetCurrentKey ¶
func (t *TxStore) GetCurrentKey(purpose KeyPurpose) *hd.ExtendedKey
func (*TxStore) GetDBSyncHeight ¶
SyncHeight returns the chain height to which the db has synced
func (*TxStore) GetFreshKey ¶
func (t *TxStore) GetFreshKey(purpose KeyPurpose) *hd.ExtendedKey
func (*TxStore) GetKeyForScript ¶
func (t *TxStore) GetKeyForScript(scriptPubKey []byte) (*hd.ExtendedKey, error)
func (*TxStore) GetKeys ¶
func (t *TxStore) GetKeys() []*hd.ExtendedKey
func (*TxStore) GetPendingInv ¶
GetPendingInv returns an inv message containing all txs known to the db which are at height 0 (not known to be confirmed). This can be useful on startup or to rebroadcast unconfirmed txs.
func (*TxStore) GimmeFilter ¶
... or I'm gonna fade away
func (*TxStore) Ingest ¶
Ingest puts a tx into the DB atomically. This can result in a gain, a loss, or no result. Gain or loss in satoshis is returned.
func (*TxStore) PopulateAdrs ¶
PopulateAdrs just puts a bunch of adrs in ram; it doesn't touch the DB
func (*TxStore) SetDBSyncHeight ¶
SetDBSyncHeight sets sync height of the db, indicated the latest block of which it has ingested all the transactions.
type Txns ¶
type Txns interface { // Put a new transaction to the database Put(txn *wire.MsgTx) error // Fetch a tx given it's hash Get(txid wire.ShaHash) (*wire.MsgTx, error) // Fetch all transactions from the db GetAll() ([]*wire.MsgTx, error) // Delete a transactions from the db Delete(txid *wire.ShaHash) error }