data

package
v0.0.0-...-14fb5e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 28 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockFiles

func BlockFiles(blocksDir string, re *regexp.Regexp, limit int) (files []os.FileInfo, err error)

BlockFiles finds suitable block files.

func FileExists

func FileExists(path string) (bool, error)

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

func ListTransactionsFile(ticker string, address string, fileName string, txDir string) string

ListTransactionsFile returns the file on disk for the listtransactions address.

func LoadTokenConfigs

func LoadTokenConfigs(path string) bool

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

func NextBlock(sc *bufio.Reader, network []byte, handle func([]byte) bool) (bool, error)

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

func PluginAddAddrToCache(bp Plugin, tx *Tx)

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

func PluginLoadBlocks(bp Plugin, blocksDir string) (err error)

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

func PluginReadBlock(bp Plugin, buf io.ReadSeeker) (block *wire.MsgBlock, err error)

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

func PluginReadTransaction(bp Plugin, buf io.ReadSeeker) (tx *wire.MsgTx, err error)

ReadTransaction deserializes bytes into transaction

func PluginSegwitActivated

func PluginSegwitActivated(bp Plugin, defaultActivation int64) int64

PluginSegwitActivated returns the segwit activation unix time.

func PluginTicker

func PluginTicker(bp Plugin, defaultTicker string) string

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

func ReadTransaction(buf io.ReadSeeker, txAllowWitness bool) (tx *wire.MsgTx, err error)

ReadTransaction reads the transaction.

func ReadVins

func ReadVins(buf io.ReadSeeker) (vins []*wire.TxIn, txVinsLen uint64, err error)

ReadVins deserializes tx vins.

func ReadVouts

func ReadVouts(buf io.ReadSeeker) (vouts []*wire.TxOut, txVoutLen uint64, err error)

ReadVouts deserializes tx vouts.

func ShardsData

func ShardsData(desiredShards int, blocksLen int) (shards, rng, remainder int)

ShardsData returns an optimal shard count, range, and remainder for the desired shard count.

func ShardsIter

func ShardsIter(shards int, currentShard int, rng int, remainder int) (start, end int)

ShardsIter returns the iteration details for the current shard.

func ShutdownNow

func ShutdownNow()

Shutdown starts the shutdown process. Thread safe.

Types

type Block

type Block interface {
	Block() *wire.MsgBlock
	Hash() chainhash.Hash
	Height() int64
	// contains filtered or unexported methods
}

type BlockTx

type BlockTx struct {
	OutP        *wire.OutPoint
	Transaction *wire.MsgTx
}

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 ConfigPlugin interface {
	Config() chaincfg.Params
}

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

func PluginAddBlocks(bp Plugin, blocks []byte) (txs []*Tx, err error)

PluginAddBlocks process new blocks received by the network to keep internal chain data up to date.

func PluginImportTransactions

func PluginImportTransactions(bp Plugin, transactions []*wire.MsgTx) (txs []*Tx, err error)

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

func PluginProcessBlocks(bp Plugin, sc *bufio.Reader) (txs []*Tx, err error)

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

func PluginProcessTxs(bp Plugin, sendTxs []*Tx, receiveTxs []*Tx) (txs []*Tx)

PluginProcessTxs processes and consolidates send and receive transactions.

func ProcessTransactions

func ProcessTransactions(plugin Plugin, blockTime time.Time, transactions []*wire.MsgTx, txIndex map[wire.OutPoint]*BlockTx) (sendTxs, receiveTxs []*Tx)

ProcessTransactions will process all transactions in blocks.

func (*Tx) Key

func (tx *Tx) Key() string

func (*Tx) KeyCategory

func (tx *Tx) KeyCategory(txid string, vout int32, category string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL