Documentation ¶
Overview ¶
Copyright (c) 2020 Michael Madgett Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php.
Copyright (c) 2020 Michael Madgett Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php.
Copyright (c) 2020 Michael Madgett Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php.
Copyright (c) 2020 Michael Madgett Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php.
Copyright (c) 2020 Michael Madgett Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php.
Copyright (c) 2020 Michael Madgett Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php.
Index ¶
- func BlockFiles(blocksDir string, re *regexp.Regexp, limit int) (files []os.FileInfo, err error)
- func FileExists(path string) (bool, error)
- func IsShuttingDown() bool
- func ListTransactionsFile(ticker string, address string, fileName string, txDir string) string
- func LoadTokenConfigs(path string) bool
- func NetworkLE(net wire.BitcoinNet) []byte
- func NextBlock(sc *bufio.Reader, network []byte, handle func([]byte) bool) (bool, error)
- func PluginAddAddrToCache(bp Plugin, tx *Tx)
- func PluginGetRawMempool(bp RPCMempoolPlugin) ([]string, error)
- func PluginLoadBlocks(bp Plugin, blocksDir string) (err error)
- func PluginRPCGetRawTransaction(plugin ReadTransactionPlugin, txid string, tokenCfg TokenConfig) (tx *wire.MsgTx, err error)
- func PluginRPCGetRawTransactions(plugin ReadTransactionPlugin, txids []string, tokenCfg TokenConfig) (txs []*wire.MsgTx, err error)
- func PluginReadBlock(bp Plugin, buf io.ReadSeeker) (block *wire.MsgBlock, err error)
- func PluginReadBlockHeader(bp Plugin, buf io.ReadSeeker) (header *wire.BlockHeader, err error)
- func PluginReadTransaction(bp Plugin, buf io.ReadSeeker) (tx *wire.MsgTx, err error)
- func PluginSegwitActivated(bp Plugin, defaultActivation int64) int64
- func PluginTicker(bp Plugin, defaultTicker string) string
- func PluginWriteListTransactions(bp Plugin, fromMonth time.Time, toMonth time.Time, address, txDir string) error
- func RPCRequest(method string, tokencfg TokenConfig, params []interface{}) ([]byte, error)
- func ReadBlock(buf io.ReadSeeker, header *wire.BlockHeader, witnessTime int64) (block *wire.MsgBlock, err error)
- func ReadBlockHeader(buf io.ReadSeeker) (header *wire.BlockHeader, err error)
- func ReadTransaction(buf io.ReadSeeker, txAllowWitness bool) (tx *wire.MsgTx, err error)
- func ReadVins(buf io.ReadSeeker) (vins []*wire.TxIn, txVinsLen uint64, err error)
- func ReadVouts(buf io.ReadSeeker) (vouts []*wire.TxOut, txVoutLen uint64, err error)
- func ShardsData(desiredShards int, blocksLen int) (shards, rng, remainder int)
- func ShardsIter(shards int, currentShard int, rng int, remainder int) (start, end int)
- func ShutdownNow()
- type Block
- type BlockTx
- type ChainBlock
- type Config
- type ConfigPlugin
- type ListTransactionsPlugin
- type Plugin
- type RPCMempoolPlugin
- type RPCRawTransactionsPlugin
- type RPCResult
- type ReadTransactionPlugin
- type TokenConfig
- type TokenPlugin
- type Tx
- func ExtractAddresses(scriptPk []byte, txHash string, txVout int, amount float64, ...) (txs []*Tx)
- func PluginAddBlocks(bp Plugin, blocks []byte) (txs []*Tx, err error)
- func PluginImportTransactions(bp Plugin, transactions []*wire.MsgTx) (txs []*Tx, err error)
- func PluginListTransactions(bp Plugin, fromTime, toTime int64, addresses []string) (txs []*Tx, err error)
- func PluginProcessBlocks(bp Plugin, sc *bufio.Reader) (txs []*Tx, err error)
- func PluginProcessTxShard(bp Plugin, blocks []*ChainBlock, start, end int, wg *sync.WaitGroup) (txs []*Tx)
- func PluginProcessTxs(bp Plugin, sendTxs []*Tx, receiveTxs []*Tx) (txs []*Tx)
- func ProcessTransactions(plugin Plugin, blockTime time.Time, transactions []*wire.MsgTx, ...) (sendTxs, receiveTxs []*Tx)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockFiles ¶
BlockFiles finds suitable block files.
func FileExists ¶
FileExists returns whether the given file or directory exists.
func IsShuttingDown ¶
func IsShuttingDown() bool
IsShuttingDown returns true if shutdown was requested. Thread safe.
func ListTransactionsFile ¶
ListTransactionsFile returns the file on disk for the listtransactions address.
func LoadTokenConfigs ¶
LoadTokenConfigs loads the token configurations at the specified path.
func NetworkLE ¶
func NetworkLE(net wire.BitcoinNet) []byte
NetworkLE returns the little endian byte representation of the network magic number.
func NextBlock ¶
NextBlock finds all the blocks in the buffer and sends a seeked buffer to a delegate handler. This is a long running operation and checks for shutdown.
func PluginAddAddrToCache ¶
PluginAddAddrToCache adds the tx to the cache. Not thread safe, expects any mutexes to be locked outside this call.
func PluginGetRawMempool ¶
func PluginGetRawMempool(bp RPCMempoolPlugin) ([]string, error)
PluginGetRawMempool calls getrawmempool on the specified rpc endpoint.
func PluginLoadBlocks ¶
PluginLoadBlocks load all transactions in the blocks dir.
func PluginRPCGetRawTransaction ¶
func PluginRPCGetRawTransaction(plugin ReadTransactionPlugin, txid string, tokenCfg TokenConfig) (tx *wire.MsgTx, err error)
PluginRPCGetRawTransaction fetches the raw transaction hex and parses into wire tx.
func PluginRPCGetRawTransactions ¶
func PluginRPCGetRawTransactions(plugin ReadTransactionPlugin, txids []string, tokenCfg TokenConfig) (txs []*wire.MsgTx, err error)
PluginRPCGetRawTransactions calls getrawtransaction on each tx on the specified rpc endpoint.
func PluginReadBlock ¶
ReadBlock deserializes bytes into block
func PluginReadBlockHeader ¶
func PluginReadBlockHeader(bp Plugin, buf io.ReadSeeker) (header *wire.BlockHeader, err error)
ReadBlockHeader deserializes block header.
func PluginReadTransaction ¶
ReadTransaction deserializes bytes into transaction
func PluginSegwitActivated ¶
PluginSegwitActivated returns the segwit activation unix time.
func PluginTicker ¶
PluginTicker returns the ticker symbol (e.g. BLOCK, BTC, LTC).
func PluginWriteListTransactions ¶
func PluginWriteListTransactions(bp Plugin, fromMonth time.Time, toMonth time.Time, address, txDir string) error
PluginWriteListTransactions writes the listtransactions data to disk. This data is organized on disk by address and then month. The json file in this directory contains transaction output that is sorted ascending by time.
func RPCRequest ¶
func RPCRequest(method string, tokencfg TokenConfig, params []interface{}) ([]byte, error)
RPCRequest performs suitable rpc client request with basic auth and timeout.
func ReadBlock ¶
func ReadBlock(buf io.ReadSeeker, header *wire.BlockHeader, witnessTime int64) (block *wire.MsgBlock, err error)
ReadBlock reads the block.
func ReadBlockHeader ¶
func ReadBlockHeader(buf io.ReadSeeker) (header *wire.BlockHeader, err error)
ReadBlockHeader reads the block header into the default Bitcoin header.
func ReadTransaction ¶
ReadTransaction reads the transaction.
func ShardsData ¶
ShardsData returns an optimal shard count, range, and remainder for the desired shard count.
func ShardsIter ¶
ShardsIter returns the iteration details for the current shard.
Types ¶
type ChainBlock ¶
type ChainBlock struct {
// contains filtered or unexported fields
}
func NewChainBlock ¶
func NewChainBlock(block *wire.MsgBlock) *ChainBlock
NewChainBlock returns a block instance.
func PluginReadBlocks ¶
func PluginReadBlocks(bp Plugin, sc *bufio.Reader, network []byte) (blocks []*ChainBlock, err error)
PluginReadBlocks loads block from the reader.
func (*ChainBlock) Block ¶
func (b *ChainBlock) Block() *wire.MsgBlock
func (*ChainBlock) Hash ¶
func (b *ChainBlock) Hash() chainhash.Hash
func (*ChainBlock) Height ¶
func (b *ChainBlock) Height() int64
type Config ¶
type Config struct {
Blockchain map[string]TokenConfig `yaml:"blockchain"`
}
Config describes the default configuration file format.
type ConfigPlugin ¶
type ListTransactionsPlugin ¶
type ListTransactionsPlugin interface { ListTransactions(fromTime, toTime int64, addresses []string) ([]*Tx, error) WriteListTransactions(fromMonth time.Time, toMonth time.Time, txDir string) error WriteListTransactionsForAddress(address string, fromMonth time.Time, toMonth time.Time, txDir string) error }
type Plugin ¶
type Plugin interface { Mu() *sync.RWMutex BlocksDir() string Ticker() string Ready() bool SetReady() Network() wire.BitcoinNet ConfigPlugin TokenPlugin TxIndex() map[wire.OutPoint]*BlockTx TxCache() map[string]map[string]*Tx SegwitActivated() int64 LoadBlocks(blocksDir string) error ReadBlock(buf io.ReadSeeker) (*wire.MsgBlock, error) ReadBlockHeader(buf io.ReadSeeker) (*wire.BlockHeader, error) ReadTransactionPlugin ReadBlocks(sc *bufio.Reader) ([]*ChainBlock, error) ProcessBlocks(sc *bufio.Reader) ([]*Tx, error) ProcessTxShard(blocks []*ChainBlock, start, end int, wg *sync.WaitGroup) []*Tx ProcessTxs(sendTxs []*Tx, receiveTxs []*Tx) (txs []*Tx) AddTransactionToCache(tx *Tx) AddBlocks(blocks []byte) ([]*Tx, error) ImportTransactions(transactions []*wire.MsgTx) ([]*Tx, error) }
type RPCMempoolPlugin ¶
type RPCMempoolPlugin interface { TokenPlugin GetRawMempool() ([]string, error) }
type RPCRawTransactionsPlugin ¶
type RPCRawTransactionsPlugin interface { TokenPlugin ReadTransactionPlugin GetRawTransaction(txid string) (*wire.MsgTx, error) GetRawTransactions(txids []string) ([]*wire.MsgTx, error) }
type RPCResult ¶
type RPCResult struct { Error interface{} `json:"error,omitempty"` Id string `json:"id,omitempty"` }
type ReadTransactionPlugin ¶
type ReadTransactionPlugin interface {
ReadTransaction(buf io.ReadSeeker) (*wire.MsgTx, error)
}
type TokenConfig ¶
type TokenConfig struct { Ticker string `yaml:"ticker"` RPCHost string `yaml:"rpchost"` RPCPort int `yaml:"rpcport"` RPCUser string `yaml:"rpcuser"` RPCPass string `yaml:"rpcpass"` SegwitActivated int64 `yaml:"segwitactivated"` BlocksDir string `yaml:"blocksdir"` TxLimitPerMonth int `yaml:"txlimit"` OutputDir string `yaml:"outputdir"` }
func GetTokenConfig ¶
func GetTokenConfig(name string) (TokenConfig, error)
GetTokenConfig returns loaded token config with name.
func GetTokenConfigs ¶
func GetTokenConfigs() []TokenConfig
GetTokenConfigs returns all token configurations.
func (TokenConfig) IsNull ¶
func (t TokenConfig) IsNull() bool
func (TokenConfig) RPCHttp ¶
func (t TokenConfig) RPCHttp() string
type TokenPlugin ¶
type TokenPlugin interface {
TokenConf() TokenConfig
}
type Tx ¶
type Tx struct { Txid string `json:"txid"` Vout int32 `json:"n"` Address string `json:"address"` Category string `json:"category"` // send, receive Amount float64 `json:"amount"` Time int64 `json:"time"` Confirmations uint32 `json:"confirmations"` Blockhash *chainhash.Hash `json:"-"` OutP *wire.OutPoint `json:"-"` }
func ExtractAddresses ¶
func ExtractAddresses(scriptPk []byte, txHash string, txVout int, amount float64, blockTime time.Time, confirmations int, category string, blockHash *chainhash.Hash, outp *wire.OutPoint, cfg *chaincfg.Params) (txs []*Tx)
ExtractAddresses derives transactions from scriptPubKey.
func PluginAddBlocks ¶
PluginAddBlocks process new blocks received by the network to keep internal chain data up to date.
func PluginImportTransactions ¶
PluginImportTransactions imports the specified transactions into the data store.
func PluginListTransactions ¶
func PluginListTransactions(bp Plugin, fromTime, toTime int64, addresses []string) (txs []*Tx, err error)
PluginListTransactions returns all transactions over the time period that are associated with the specified addresses.
func PluginProcessBlocks ¶
PluginProcessBlocks will process all blocks in the buffer.
func PluginProcessTxShard ¶
func PluginProcessTxShard(bp Plugin, blocks []*ChainBlock, start, end int, wg *sync.WaitGroup) (txs []*Tx)
PluginProcessTxShard processes all transactions over specified range of blocks. Creates all send and receive transactions in the range. Thread safe.
func PluginProcessTxs ¶
PluginProcessTxs processes and consolidates send and receive transactions.