bitcoin

package module
v1.0.86 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 23 Imported by: 9

README

go-bitcoin

Go wrapper for bitcoin RPC

RPC services

Start by creating a connection to a bitcoin node

  b, err := New("rcp host", rpc port, "rpc username", "rpc password", false)
  if err != nil {
    log.Fatal(err)
  }

Then make a call to bitcoin

  res, err := b.GetBlockchainInfo()
  if err != nil {
    log.Fatal(err)
  }
  fmt.Printf("%#v\n", res)

Available calls are:

GetConnectionCount()
GetBlockchainInfo()
GetNetworkInfo()
GetNetTotals()
GetMiningInfo()
Uptime()
GetMempoolInfo()
GetRawMempool(details bool)
GetChainTxStats(blockcount int)
ValidateAddress(address string)
GetHelp()
GetBestBlockHash()
GetBlockHash(blockHeight int)
SendRawTransaction(hex string)
GetBlock(blockHash string)
GetBlockOverview(blockHash string)
GetBlockHex(blockHash string)
GetRawTransaction(txID string)
GetRawTransactionHex(txID string)
GetBlockTemplate(includeSegwit bool)
GetMiningCandidate()
SubmitBlock(hexData string)
SubmitMiningSolution(candidateID string, nonce uint32,
                     coinbase string, time uint32, version uint32)
GetDifficulty()
DecodeRawTransaction(txHex string)
GetTxOut(txHex string, vout int, includeMempool bool)
ListUnspent(addresses []string)

ZMQ

It is also possible to subscribe to a bitcoin node and be notified about new transactions and new blocks via the node's ZMQ interface.

First, create a ZMQ instance:

  zmq := bitcoin.NewZMQ("localhost", 28332)

Then create a buffered or unbuffered channel of strings and a goroutine to consume the channel:

	ch := make(chan string)

	go func() {
		for c := range ch {
			log.Println(c)
		}
	}()

Finally, subscribe to "hashblock" or "hashtx" topics passing in your channel:

	err := zmq.Subscribe("hashblock", ch)
	if err != nil {
		log.Fatalln(err)
	}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout = errors.New("Timeout reading data from server")
)

Functions

func TransactionFromBytes added in v1.0.9

func TransactionFromBytes(b []byte) (*transaction, int)

TransactionFromBytes takes a slice of bytes and constructs a Transaction object

func TransactionFromHex added in v1.0.9

func TransactionFromHex(h string) (*transaction, int)

TransactionFromHex takes a hex string and constructs a Transaction object

func WithOptionalLogger added in v1.0.81

func WithOptionalLogger(l Logger) func(*rpcClient)

func WithTimeoutDuration added in v1.0.81

func WithTimeoutDuration(d time.Duration) func(*rpcClient)

Types

type Address

type Address struct {
	IsValid      bool   `json:"isvalid"`
	Address      string `json:"address"`
	ScriptPubKey string `json:"scriptPubKey"`
	IsMine       bool   `json:"ismine"`
	IsWatchOnly  bool   `json:"iswatchonly"`
	IsScript     bool   `json:"isscript"`
}

Address comment

type BatchResults added in v1.0.64

type BatchResults struct {
	Known       []string      `json:"known"`
	Evicted     []string      `json:"evicted"`
	Invalid     []*TxResponse `json:"invalid"`
	Unconfirmed []*TxResponse `json:"unconfirmed"`
}

type BatchedTransaction added in v1.0.65

type BatchedTransaction struct {
	Hex                      string                 `json:"hex"`
	AllowHighFees            bool                   `json:"allowhighfees"`
	DontCheckFee             bool                   `json:"dontcheckfee"`
	ListUnconfirmedAncestors bool                   `json:"listunconfirmedancestors"`
	Config                   map[string]interface{} `json:"config,omitempty"`
}

type BitIndex added in v1.0.17

type BitIndex struct {
	BaseURL string
}

BitIndex comment

func NewBitIndexClient added in v1.0.17

func NewBitIndexClient(url string) (*BitIndex, error)

NewBitIndexClient returns a new bitIndex client for the given url

func (*BitIndex) GetUtxos added in v1.0.17

func (b *BitIndex) GetUtxos(addr string) (*UtxoResponse, error)

GetUtxos comment

type Bitcoind

type Bitcoind struct {
	Storage *cache.Cache

	IPAddress string
	// contains filtered or unexported fields
}

A Bitcoind represents a Bitcoind client

func New

func New(host string, port int, user, passwd string, useSSL bool, opts ...Option) (*Bitcoind, error)

New return a new bitcoind

func NewFromURL added in v1.0.75

func NewFromURL(url *url.URL, useSSL bool, opts ...Option) (*Bitcoind, error)

func (*Bitcoind) DecodeRawTransaction added in v1.0.8

func (b *Bitcoind) DecodeRawTransaction(txHex string) (string, error)

DecodeRawTransaction comment

func (*Bitcoind) DumpPrivKey added in v1.0.85

func (b *Bitcoind) DumpPrivKey(address string) (string, error)

func (*Bitcoind) Generate added in v1.0.37

func (b *Bitcoind) Generate(amount float64) ([]string, error)

Generate for regtest

func (*Bitcoind) GenerateToAddress added in v1.0.37

func (b *Bitcoind) GenerateToAddress(amount float64, address string) ([]string, error)

GenerateToAddress for regtest

func (*Bitcoind) GetBestBlockHash

func (b *Bitcoind) GetBestBlockHash() (hash string, err error)

GetBestBlockHash comment

func (*Bitcoind) GetBlock

func (b *Bitcoind) GetBlock(blockHash string) (block *Block, err error)

GetBlock returns information about the block with the given hash.

func (*Bitcoind) GetBlockByHeight added in v1.0.62

func (b *Bitcoind) GetBlockByHeight(blockHeight int) (block *Block, err error)

func (*Bitcoind) GetBlockHash

func (b *Bitcoind) GetBlockHash(blockHeight int) (blockHash string, err error)

GetBlockHash comment

func (*Bitcoind) GetBlockHeader added in v1.0.17

func (b *Bitcoind) GetBlockHeader(blockHash string) (blockHeader *BlockHeader, err error)

GetBlockHeader returns the block header for the given hash.

func (*Bitcoind) GetBlockHeaderAndCoinbase added in v1.0.33

func (b *Bitcoind) GetBlockHeaderAndCoinbase(blockHash string) (blockHeaderAndCoinbase *BlockHeaderAndCoinbase, err error)

GetBlockHeaderAndCoinbase returns information about the block with the given hash.

func (*Bitcoind) GetBlockHeaderHex added in v1.0.13

func (b *Bitcoind) GetBlockHeaderHex(blockHash string) (blockHeader *string, err error)

GetBlockHeaderHex returns the block header hex for the given hash.

func (*Bitcoind) GetBlockHex

func (b *Bitcoind) GetBlockHex(blockHash string) (raw *string, err error)

GetBlockHex returns information about the block with the given hash.

func (*Bitcoind) GetBlockOverview added in v1.0.6

func (b *Bitcoind) GetBlockOverview(blockHash string) (block *BlockOverview, err error)

GetBlockOverview returns basic information about the block with the given hash.

func (*Bitcoind) GetBlockStats added in v1.0.66

func (b *Bitcoind) GetBlockStats(blockHash string) (block *BlockStats, err error)

GetBlockStats returns block stats from the given block hash.

func (*Bitcoind) GetBlockStatsByHeight added in v1.0.66

func (b *Bitcoind) GetBlockStatsByHeight(blockHeight int) (block *BlockStats, err error)

GetBlockStatsByHeight returns block stats from the given block height.

func (*Bitcoind) GetBlockTemplate

func (b *Bitcoind) GetBlockTemplate(includeSegwit bool) (template *BlockTemplate, err error)

GetBlockTemplate comment

func (*Bitcoind) GetBlockchainInfo

func (b *Bitcoind) GetBlockchainInfo() (info BlockchainInfo, err error)

GetBlockchainInfo returns the number of connections to other nodes.

func (*Bitcoind) GetChainTips added in v1.0.55

func (b *Bitcoind) GetChainTips() (tips ChainTips, err error)

GetChainTips return information about all known tips in the block tree, including the main chain as well as orphaned branches. Possible values for status: 1. "invalid" This branch contains at least one invalid block 2. "headers-only" Not all blocks for this branch are available, but the headers are valid 3. "valid-headers" All blocks are available for this branch, but they were never fully validated 4. "valid-fork" This branch is not part of the active chain, but is fully validated 5. "active" This is the tip of the active main chain, which is certainly valid

func (*Bitcoind) GetChainTxStats

func (b *Bitcoind) GetChainTxStats(blockcount int) (stats ChainTXStats, err error)

GetChainTxStats returns the number of connections to other nodes.

func (*Bitcoind) GetConnectionCount

func (b *Bitcoind) GetConnectionCount() (count uint64, err error)

GetConnectionCount returns the number of connections to other nodes.

func (*Bitcoind) GetDifficulty

func (b *Bitcoind) GetDifficulty() (difficulty float64, err error)

GetDifficulty comment

func (*Bitcoind) GetHelp

func (b *Bitcoind) GetHelp() (j []byte, err error)

GetHelp returns the number of connections to other nodes.

func (*Bitcoind) GetInfo added in v1.0.16

func (b *Bitcoind) GetInfo() (info GetInfo, err error)

GetInfo returns the number of connections to other nodes.

func (*Bitcoind) GetMempoolAncestors added in v1.0.55

func (b *Bitcoind) GetMempoolAncestors(txid string, details bool) (raw []byte, err error)

GetMempoolAncestors if txid is in the mempool, returns all in-mempool ancestors..

func (*Bitcoind) GetMempoolDescendants added in v1.0.55

func (b *Bitcoind) GetMempoolDescendants(txid string, details bool) (raw []byte, err error)

GetMempoolDescendants if txid is in the mempool, returns all in-mempool descendants..

func (*Bitcoind) GetMempoolEntry added in v1.0.74

func (b *Bitcoind) GetMempoolEntry(txid string) (entry MempoolEntry, err error)

GetMempoolEntry returns the entry in the current mempool for a specific tx id

func (*Bitcoind) GetMempoolInfo

func (b *Bitcoind) GetMempoolInfo() (info MempoolInfo, err error)

GetMempoolInfo comment

func (*Bitcoind) GetMiningCandidate

func (b *Bitcoind) GetMiningCandidate() (template *MiningCandidate, err error)

GetMiningCandidate comment

func (*Bitcoind) GetMiningInfo

func (b *Bitcoind) GetMiningInfo() (info MiningInfo, err error)

GetMiningInfo comment

func (*Bitcoind) GetNetTotals

func (b *Bitcoind) GetNetTotals() (totals NetTotals, err error)

GetNetTotals returns the number of connections to other nodes.

func (*Bitcoind) GetNetworkInfo

func (b *Bitcoind) GetNetworkInfo() (info NetworkInfo, err error)

GetNetworkInfo returns the number of connections to other nodes.

func (*Bitcoind) GetNewAddress added in v1.0.85

func (b *Bitcoind) GetNewAddress() (string, error)

func (*Bitcoind) GetPeerInfo

func (b *Bitcoind) GetPeerInfo() (info PeerInfo, err error)

GetPeerInfo returns the number of connections to other nodes.

func (*Bitcoind) GetRawBlock added in v1.0.17

func (b *Bitcoind) GetRawBlock(blockHash string) ([]byte, error)

GetRawBlock returns the raw bytes of the block with the given hash.

func (*Bitcoind) GetRawBlockReader added in v1.0.43

func (b *Bitcoind) GetRawBlockReader(blockHash string) (io.ReadCloser, error)

GetRawBlockReader returns a reader of the block with the given hash.

func (*Bitcoind) GetRawBlockRest added in v1.0.44

func (b *Bitcoind) GetRawBlockRest(blockHash string) (io.ReadCloser, error)

func (*Bitcoind) GetRawMempool

func (b *Bitcoind) GetRawMempool(details bool) (raw []byte, err error)

GetRawMempool returns the number of connections to other nodes.

func (*Bitcoind) GetRawNonFinalMempool added in v1.0.55

func (b *Bitcoind) GetRawNonFinalMempool() ([]string, error)

GetRawNonFinalMempool returns all transaction ids in the non-final memory pool as a json array of string transaction ids.

func (*Bitcoind) GetRawTransaction

func (b *Bitcoind) GetRawTransaction(txID string) (rawTx *RawTransaction, err error)

GetRawTransaction returns raw transaction representation for given transaction id.

func (*Bitcoind) GetRawTransactionHex

func (b *Bitcoind) GetRawTransactionHex(txID string) (rawTx *string, err error)

GetRawTransactionHex returns raw transaction representation for given transaction id.

func (*Bitcoind) GetRawTransactionRest added in v1.0.47

func (b *Bitcoind) GetRawTransactionRest(txid string) (io.ReadCloser, error)

func (*Bitcoind) GetSettings added in v1.0.76

func (b *Bitcoind) GetSettings() (settings Settings, err error)

GetInfo returns the number of connections to other nodes.

func (*Bitcoind) GetTxOut added in v1.0.11

func (b *Bitcoind) GetTxOut(txHex string, vout int, includeMempool bool) (res *TXOut, err error)

func (*Bitcoind) ListUnspent added in v1.0.13

func (b *Bitcoind) ListUnspent(addresses []string) (res []*UnspentTransaction, err error)

ListUnspent comment

func (*Bitcoind) SendRawTransaction

func (b *Bitcoind) SendRawTransaction(hex string) (txid string, err error)

func (*Bitcoind) SendRawTransactionWithoutFeeCheck added in v1.0.27

func (b *Bitcoind) SendRawTransactionWithoutFeeCheck(hex string) (txid string, err error)

func (*Bitcoind) SendRawTransactionWithoutFeeCheckOrScriptCheck added in v1.0.58

func (b *Bitcoind) SendRawTransactionWithoutFeeCheckOrScriptCheck(raw string) (string, error)

func (*Bitcoind) SendRawTransactions added in v1.0.64

func (b *Bitcoind) SendRawTransactions(batchedTransactions []*BatchedTransaction, config map[string]interface{}) (*BatchResults, error)

func (*Bitcoind) SendToAddress added in v1.0.17

func (b *Bitcoind) SendToAddress(address string, amount float64) (string, error)

SendToAddress comment

func (*Bitcoind) SetAccount added in v1.0.85

func (b *Bitcoind) SetAccount(address, account string) error

func (*Bitcoind) SignRawTransaction added in v1.0.17

func (b *Bitcoind) SignRawTransaction(hex string) (sr *SignRawTransactionResponse, err error)

SignRawTransaction comment

func (*Bitcoind) SubmitBlock

func (b *Bitcoind) SubmitBlock(hexData string) (result string, err error)

SubmitBlock comment

func (*Bitcoind) SubmitMiningSolution

func (b *Bitcoind) SubmitMiningSolution(miningCandidateID string, nonce uint32, coinbase string, time uint32, version uint32) (result string, err error)

SubmitMiningSolution comment

func (*Bitcoind) Uptime

func (b *Bitcoind) Uptime() (uptime uint64, err error)

Uptime returns the number of connections to other nodes.

func (*Bitcoind) ValidateAddress

func (b *Bitcoind) ValidateAddress(address string) (addr Address, err error)

ValidateAddress returns the number of connections to other nodes.

type Block

type Block struct {
	Hash              string   `json:"hash"`
	Confirmations     int64    `json:"confirmations"`
	Size              uint64   `json:"size"`
	Height            uint64   `json:"height"`
	Version           int64    `json:"version"`
	VersionHex        string   `json:"versionHex"`
	MerkleRoot        string   `json:"merkleroot"`
	TxCount           uint64   `json:"txcount"`
	NTx               uint64   `json:"nTx"`
	NumTx             uint64   `json:"num_tx"`
	Tx                []string `json:"tx"`
	Time              uint64   `json:"time"`
	MedianTime        uint64   `json:"mediantime"`
	Nonce             uint64   `json:"nonce"`
	Bits              string   `json:"bits"`
	Difficulty        float64  `json:"difficulty"`
	Chainwork         string   `json:"chainwork"`
	PreviousBlockHash string   `json:"previousblockhash"`
	NextBlockHash     string   `json:"nextblockhash"`
	// extra properties
	CoinbaseTx *RawTransaction `json:"coinbaseTx"`
	TotalFees  float64         `json:"totalFees"`
	Miner      string          `json:"miner"`
	Pagination *BlockPage      `json:"pages"`
}

Block struct

type Block2 added in v1.0.17

type Block2 struct {
	Hash              string   `json:"hash"`
	Size              int      `json:"size"`
	Height            int      `json:"height"`
	Version           uint32   `json:"version"`
	VersionHex        string   `json:"versionHex"`
	MerkleRoot        string   `json:"merkleroot"`
	TxCount           uint64   `json:"txcount"`
	NTx               uint64   `json:"nTx"`
	NumTx             uint64   `json:"num_tx"`
	Tx                []string `json:"tx"`
	Time              uint32   `json:"time"`
	MedianTime        uint32   `json:"mediantime"`
	Nonce             uint32   `json:"nonce"`
	Bits              string   `json:"bits"`
	Difficulty        float64  `json:"difficulty"`
	Chainwork         string   `json:"chainwork"`
	PreviousBlockHash string   `json:"previousblockhash"`
	NextBlockHash     string   `json:"nextblockhash"`
	BlockSubsidy      uint64   `json:"blockSubsidy"`
	BlockReward       uint64   `json:"blockReward"`
	USDPrice          float64  `json:"usdPrice"`
	Miner             string   `json:"miner"`
}

Block2 struct

type BlockHeader added in v1.0.17

type BlockHeader struct {
	Hash              string  `json:"hash"`
	Confirmations     int64   `json:"confirmations"`
	Size              uint64  `json:"size"`
	Height            uint64  `json:"height"`
	Version           uint64  `json:"version"`
	VersionHex        string  `json:"versionHex"`
	MerkleRoot        string  `json:"merkleroot"`
	Time              uint64  `json:"time"`
	MedianTime        uint64  `json:"mediantime"`
	Nonce             uint64  `json:"nonce"`
	Bits              string  `json:"bits"`
	Difficulty        float64 `json:"difficulty"`
	Chainwork         string  `json:"chainwork"`
	PreviousBlockHash string  `json:"previousblockhash"`
	NextBlockHash     string  `json:"nextblockhash"`
	NTx               uint64  `json:"nTx"`
	TxCount           uint64  `json:"num_tx"`
}

BlockHeader comment

type BlockHeaderAndCoinbase added in v1.0.33

type BlockHeaderAndCoinbase struct {
	Hash              string           `json:"hash"`
	Confirmations     int64            `json:"confirmations"`
	Size              uint64           `json:"size"`
	Height            uint64           `json:"height"`
	Version           uint64           `json:"version"`
	VersionHex        string           `json:"versionHex"`
	MerkleRoot        string           `json:"merkleroot"`
	NumTx             uint64           `json:"num_tx"`
	Time              uint64           `json:"time"`
	MedianTime        uint64           `json:"mediantime"`
	Nonce             uint64           `json:"nonce"`
	Bits              string           `json:"bits"`
	Difficulty        float64          `json:"difficulty"`
	Chainwork         string           `json:"chainwork"`
	PreviousBlockHash string           `json:"previousblockhash"`
	NextBlockHash     string           `json:"nextblockhash"`
	Tx                []RawTransaction `json:"tx"`
}

BlockHeaderAndCoinbase comment

type BlockOverview added in v1.0.6

type BlockOverview struct {
	Hash          string `json:"hash"`
	Confirmations int64  `json:"confirmations"`
	Size          uint64 `json:"size"`
	Height        uint64 `json:"height"`
	Version       int64  `json:"version"`
	VersionHex    string `json:"versionHex"`
	MerkleRoot    string `json:"merkleroot"`
	// TxCount           uint64  `json:"txcount"`
	Time              uint64  `json:"time"`
	MedianTime        uint64  `json:"mediantime"`
	Nonce             uint64  `json:"nonce"`
	Bits              string  `json:"bits"`
	Difficulty        float64 `json:"difficulty"`
	Chainwork         string  `json:"chainwork"`
	PreviousBlockHash string  `json:"previousblockhash"`
	NextBlockHash     string  `json:"nextblockhash"`
}

BlockOverview struct

type BlockPage

type BlockPage struct {
	URI  []string `json:"uri"`
	Size uint64   `json:"size"`
}

BlockPage to store links

type BlockStats added in v1.0.66

type BlockStats struct {
	AvgFee        float64 `json:"avgfee"`
	AvgFeeRate    float64 `json:"avgfeerate"`
	AvgTxSize     int     `json:"avgtxsize"`
	BlockHash     string  `json:"blockhash"`
	Height        int     `json:"height"`
	Ins           int     `json:"ins"`
	MaxFee        float64 `json:"maxfee"`
	MaxFeeRate    float64 `json:"maxfeerate"`
	MaxTxSize     int     `json:"maxtxsize"`
	MedianFee     float64 `json:"medianfee"`
	MedianFeeRate float64 `json:"medianfeerate"`
	MedianTime    int     `json:"mediantime"`
	MedianTxSize  int     `json:"mediantxsize"`
	MinFee        float64 `json:"minfee"`
	MinFeeRate    float64 `json:"minfeerate"`
	MinTxSize     int     `json:"mintxsize"`
	Outs          int     `json:"outs"`
	Subsidy       float64 `json:"subsidy"`
	Time          int     `json:"time"`
	TotalOut      float64 `json:"total_out"`
	TotalSize     int     `json:"total_size"`
	TotalFee      float64 `json:"totalfee"`
	Txs           int     `json:"txs"`
	UtxoIncrease  int     `json:"utxo_increase"`
	UtxoSizeInc   int     `json:"utxo_size_inc"`
}

type BlockTemplate

type BlockTemplate struct {
	Version                  uint32        `json:"version"`
	PreviousBlockHash        string        `json:"previousblockhash"`
	Target                   string        `json:"target"`
	Transactions             []Transaction `json:"transactions"`
	Bits                     string        `json:"bits"`
	CurTime                  uint64        `json:"curtime"`
	CoinbaseValue            uint64        `json:"coinbasevalue"`
	Height                   uint32        `json:"height"`
	MinTime                  uint64        `json:"mintime"`
	NonceRange               string        `json:"noncerange"`
	DefaultWitnessCommitment string        `json:"default_witness_commitment"`
	SizeLimit                uint64        `json:"sizelimit"`
	WeightLimit              uint64        `json:"weightlimit"`
	SigOpLimit               int64         `json:"sigoplimit"`
	VBRequired               int64         `json:"vbrequired"`
	// extra mining candidate fields
	IsMiningCandidate bool             `json:"-"`
	MiningCandidateID string           `json:"-"`
	MiningCandidate   *MiningCandidate `json:"-"`
	MerkleBranches    []string         `json:"-"`
}

BlockTemplate comment

type BlockTxid

type BlockTxid struct {
	BlockHash  string   `json:"blockhash"`
	Tx         []string `json:"tx"`
	StartIndex uint64   `json:"startIndex"`
	EndIndex   uint64   `json:"endIndex"`
	Count      uint64   `json:"count"`
}

BlockTxid comment

type BlockchainInfo

type BlockchainInfo struct {
	Chain                string  `json:"chain"`
	Blocks               int32   `json:"blocks"`
	Headers              int32   `json:"headers"`
	BestBlockHash        string  `json:"bestblockhash"`
	Difficulty           float64 `json:"difficulty"`
	MedianTime           int64   `json:"mediantime"`
	VerificationProgress float64 `json:"verificationprogress,omitempty"`
	Pruned               bool    `json:"pruned"`
	PruneHeight          int32   `json:"pruneheight,omitempty"`
	ChainWork            string  `json:"chainwork,omitempty"`
}

BlockchainInfo comment

type BytesData

type BytesData struct {
	Addr        int `json:"addr"`
	BlockTXN    int `json:"blocktxn"`
	CmpctBlock  int `json:"cmpctblock"`
	FeeFilter   int `json:"feefilter"`
	GetAddr     int `json:"getaddr"`
	GetData     int `json:"getdata"`
	GetHeaders  int `json:"getheaders"`
	Headers     int `json:"headers"`
	Inv         int `json:"inv"`
	NotFound    int `json:"notfound"`
	Ping        int `json:"ping"`
	Pong        int `json:"pong"`
	Reject      int `json:"reject"`
	SendCmpct   int `json:"sendcmpct"`
	SendHeaders int `json:"sendheaders"`
	TX          int `json:"tx"`
	VerAck      int `json:"verack"`
	Version     int `json:"version"`
}

BytesData struct

type ChainTXStats

type ChainTXStats struct {
	Time             int     `json:"time"`
	TXCount          int     `json:"txcount"`
	WindowBlockCount int     `json:"window_block_count"`
	WindowTXCount    int     `json:"window_tx_count"`
	WindowInterval   int     `json:"window_interval"`
	TXRate           float64 `json:"txrate"`
}

ChainTXStats struct

type ChainTips added in v1.0.55

type ChainTips []Tip

ChainTips comment

type DefaultLogger added in v1.0.70

type DefaultLogger struct{}

func (*DefaultLogger) Debugf added in v1.0.70

func (l *DefaultLogger) Debugf(format string, args ...interface{})

func (*DefaultLogger) Errorf added in v1.0.70

func (l *DefaultLogger) Errorf(format string, args ...interface{})

func (*DefaultLogger) Fatalf added in v1.0.70

func (l *DefaultLogger) Fatalf(format string, args ...interface{})

func (*DefaultLogger) Infof added in v1.0.70

func (l *DefaultLogger) Infof(format string, args ...interface{})

func (*DefaultLogger) Warnf added in v1.0.70

func (l *DefaultLogger) Warnf(format string, args ...interface{})

type Error

type Error struct {
	Code    float64
	Message string
}

Error comment

type GetInfo added in v1.0.16

type GetInfo struct {
	Version                      int32   `json:"version"`
	ProtocolVersion              int32   `json:"protocolversion"`
	WalletVersion                int32   `json:"walletversion"`
	Balance                      float64 `json:"balance"`
	InitComplete                 bool    `json:"initcomplete"`
	Blocks                       int32   `json:"blocks"`
	TimeOffset                   int64   `json:"timeoffset"`
	Connections                  int32   `json:"connections"`
	Proxy                        string  `json:"proxy"`
	Difficulty                   float64 `json:"difficulty"`
	TestNet                      bool    `json:"testnet"`
	STN                          bool    `json:"stn"`
	KeyPoolOldest                int64   `json:"keypoololdest"`
	KeyPoolSize                  int32   `json:"keypoolsize"`
	PayTXFee                     float64 `json:"paytxfee"`
	RelayFee                     float64 `json:"relayfee"`
	Errors                       string  `json:"errors"`
	MaxBlockSize                 int64   `json:"maxblocksize"`
	MaxMinedBlockSize            int64   `json:"maxminedblocksize"`
	MaxStackMemoryUsagePolicy    uint64  `json:"maxstackmemoryusagepolicy"`
	MaxStackMemoryUsageConsensus uint64  `json:"maxstackmemoryusageconsensus"`
}

GetInfo comment

type LocalAddress

type LocalAddress struct {
	Address string `json:"address"`
	Port    int    `json:"port"`
	Score   int    `json:"score"`
}

LocalAddress comment

type Logger added in v1.0.70

type Logger interface {
	// Debugf logs a message at debug level.
	Debugf(format string, args ...interface{})
	// Infof logs a message at info level.
	Infof(format string, args ...interface{})
	// Warnf logs a message at warn level.
	Warnf(format string, args ...interface{})
	// Errorf logs a message at error level.
	Errorf(format string, args ...interface{})
	// Fatalf logs a message at fatal level.
	Fatalf(format string, args ...interface{})
}

type MempoolEntry added in v1.0.74

type MempoolEntry struct {
	Size        int      `json:"size"`
	Fee         float64  `json:"fee"`
	ModifiedFee float64  `json:"modifiedfee"`
	Time        int      `json:"time"`
	Height      int      `json:"height"`
	Depends     []string `json:"depends"`
}

type MempoolInfo

type MempoolInfo struct {
	Size               int     `json:"size"`               // Current tx count
	JournalSize        int     `json:"journalsize"`        // Current tx count within the journal
	NonFinalSize       int     `json:"nonfinalsize"`       // Current non-final tx count
	Bytes              int     `json:"bytes"`              // Transaction size
	Usage              int     `json:"usage"`              // Total memory usage for the mempool
	UsageDisk          int     `json:"usagedisk"`          // Total disk usage for storing mempool transactions
	UsageCpfp          int     `json:"usagecpfp"`          // Total memory usage for the low paying transactions
	NonFinalUsage      int     `json:"nonfinalusage"`      // Total memory usage for the non-final mempool
	MaxMemPool         int     `json:"maxmempool"`         // Maximum memory usage for the mempool
	MaxMempoolSizeDisk int     `json:"maxmempoolsizedisk"` // Maximum disk usage for storing mempool transactions
	MaxMempoolSizeCpfp int     `json:"maxmempoolsizecpfp"` // Maximum memory usage for the low paying transactions
	MemPoolMinFree     float64 `json:"mempoolminfee"`      // Minimum fee (in BSV/kB) for tx to be accepted
}

MempoolInfo comment

type MiningCandidate

type MiningCandidate struct {
	ID                  string   `json:"id"`
	PreviousHash        string   `json:"prevhash"`
	CoinbaseValue       uint64   `json:"coinbaseValue"`
	Version             uint32   `json:"version"`
	Bits                string   `json:"nBits"`
	CurTime             uint64   `json:"time"`
	Height              uint32   `json:"height"`
	NumTx               uint32   `json:"num_tx"`
	SizeWithoutCoinbase uint64   `json:"sizeWithoutCoinbase"`
	MerkleProof         []string `json:"merkleProof"`
}

MiningCandidate comment

type MiningInfo

type MiningInfo struct {
	Blocks                int     `json:"blocks"`
	CurrentBlockSize      int     `json:"currentblocksize"`
	CurrentBlockTX        int     `json:"currentblocktx"`
	Difficulty            float64 `json:"difficulty"`
	BlocksPriorityPercent int     `json:"blockprioritypercentage"`
	Errors                string  `json:"errors"`
	NetworkHashPS         float64 `json:"networkhashps"`
	PooledTX              int     `json:"pooledtx"`
	Chain                 string  `json:"chain"`
}

MiningInfo comment

type NetTotals

type NetTotals struct {
	TotalBytesRecv int `json:"totalbytesrecv"`
	TotalBytesSent int `json:"totalbytessent"`
	TimeMillis     int `json:"timemillis"`
	UploadTarget   struct {
		TimeFrame             int  `json:"timeframe"`
		Target                int  `json:"target"`
		TargetReached         bool `json:"target_reached"`
		ServeHistoricalBlocks bool `json:"serve_historical_blocks"`
		BytesLeftInCycle      int  `json:"bytes_left_in_cycle"`
		TimeLeftInCycle       int  `json:"time_left_in_cycle"`
	} `json:"uploadtarget"`
}

NetTotals comment

type Network

type Network struct {
	Name                       string `json:"name"`
	Limited                    bool   `json:"limited"`
	Reachable                  bool   `json:"reachable"`
	Proxy                      string `json:"proxy"`
	ProxyRandmomizeCredentials bool   `json:"proxy_randomize_credentials"`
}

Network comment

type NetworkInfo

type NetworkInfo struct {
	Version                         int            `json:"version"`
	SubVersion                      string         `json:"subversion"`
	ProtocolVersion                 int            `json:"protocolversion"`
	LocalServices                   string         `json:"localservices"`
	LocalRelay                      bool           `json:"localrelay"`
	TimeOffset                      int            `json:"timeoffset"`
	TXPropagationFreq               int            `json:"txnpropagationfreq"`
	TXPropagationLen                int            `json:"txnpropagationqlen"`
	NetworkActive                   bool           `json:"networkactive"`
	Connections                     int            `json:"connections"`
	AddressCount                    int            `json:"addresscount"`
	Networks                        []Network      `json:"networks"`
	RelayFee                        float64        `json:"relayfee"`
	MinConsolidationFactor          int            `json:"minconsolidationfactor"`
	MinConsolidationInputMaturity   int            `json:"minconsolidationinputmaturity"`
	MaxConsolidationInputScriptSize int            `json:"maxconsolidationinputscriptsize"`
	AcceptNonStdConsolidationInput  bool           `json:"acceptnonstdconsolidationinput"`
	ExcessUTXOCharge                float64        `json:"excessutxocharge"`
	LocalAddresses                  []LocalAddress `json:"localaddresses"`
	Warnings                        string         `json:"warnings"`
}

NetworkInfo comment

type OpReturn

type OpReturn struct {
	Type   string   `json:"type"`
	Action string   `json:"action"`
	Text   string   `json:"text"`
	Parts  []string `json:"parts"`
}

OpReturn comment

type Option added in v1.0.81

type Option func(f *rpcClient)

type Peer

type Peer struct {
	ID             int     `json:"id"`
	Addr           string  `json:"addr"`
	AddrLocal      string  `json:"addrlocal"`
	Services       string  `json:"services"`
	RelayTXes      bool    `json:"relaytxes"`
	LastSend       int     `json:"lastsend"`
	LastRecv       int     `json:"lastrecv"`
	BytesSent      int     `json:"bytessent"`
	BytesRecv      int     `json:"bytesrecv"`
	ConnTime       int     `json:"conntime"`
	TimeOffset     int     `json:"timeoffset"`
	PingTime       float64 `json:"pingtime"`
	MinPing        float64 `json:"minping"`
	Version        int     `json:"version"`
	Subver         string  `json:"subver"`
	Inbound        bool    `json:"inbound"`
	AddNode        bool    `json:"addnode"`
	StartingHeight int     `json:"startingheight"`
	TXNInvSize     int     `json:"txninvsize"`
	Banscore       int     `json:"banscore"`
	SyncedHeaders  int     `json:"synced_headers"`
	SyncedBlocks   int     `json:"synced_blocks"`
	// "inflight": [],
	WhiteListed     bool      `json:"whitelisted"`
	BytesSendPerMsg BytesData `json:"bytessent_per_msg"`
	BytesRecvPerMsg BytesData `json:"bytesrecv_per_msg"`
}

Peer struct

type PeerInfo

type PeerInfo []Peer

PeerInfo comment

type RawMemPool

type RawMemPool []string

RawMemPool comment

type RawTransaction

type RawTransaction struct {
	Hex           string  `json:"hex,omitempty"`
	TxID          string  `json:"txid"`
	Hash          string  `json:"hash"`
	Version       int32   `json:"version"`
	Size          uint32  `json:"size"`
	LockTime      uint32  `json:"locktime"`
	Vin           []*Vin  `json:"vin"`
	Vout          []*Vout `json:"vout"`
	BlockHash     string  `json:"blockhash,omitempty"`
	Confirmations uint32  `json:"confirmations,omitempty"`
	Time          int64   `json:"time,omitempty"`
	Blocktime     int64   `json:"blocktime,omitempty"`
	BlockHeight   uint64  `json:"blockheight,omitempty"`
}

RawTransaction comment

type ScriptPubKey

type ScriptPubKey struct {
	ASM         string    `json:"asm"`
	Hex         string    `json:"hex"`
	ReqSigs     int64     `json:"reqSigs,omitempty"`
	Type        string    `json:"type"`
	Addresses   []string  `json:"addresses,omitempty"`
	OpReturn    *OpReturn `json:"opReturn,omitempty"`
	Tag         *Tag      `json:"tag,omitempty"`
	IsTruncated bool      `json:"isTruncated"`
}

ScriptPubKey Comment

type ScriptSig

type ScriptSig struct {
	ASM string `json:"asm"`
	Hex string `json:"hex"`
}

A ScriptSig represents a scriptsig

type Settings added in v1.0.77

type Settings struct {
	ExcessiveBlockSize              int     `json:"excessiveblocksize"`
	BlockMaxSize                    int     `json:"blockmaxsize"`
	MaxTxSizePolicy                 int     `json:"maxtxsizepolicy"`
	MaxOrphanTxSize                 int     `json:"maxorphantxsize"`
	DataCarrierSize                 int64   `json:"datacarriersize"`
	MaxScriptSizePolicy             int     `json:"maxscriptsizepolicy"`
	MaxOpsPerScriptPolicy           int64   `json:"maxopsperscriptpolicy"`
	MaxScriptNumLengthPolicy        int     `json:"maxscriptnumlengthpolicy"`
	MaxPubKeysPerMultisigPolicy     int64   `json:"maxpubkeyspermultisigpolicy"`
	MaxTxSigopsCountsPolicy         int64   `json:"maxtxsigopscountspolicy"`
	MaxStackMemoryUsagePolicy       int     `json:"maxstackmemoryusagepolicy"`
	MaxStackMemoryUsageConsensus    int     `json:"maxstackmemoryusageconsensus"`
	LimitAncestorCount              int     `json:"limitancestorcount"`
	LimitCPFPGroupMembersCount      int     `json:"limitcpfpgroupmemberscount"`
	MaxMempool                      int     `json:"maxmempool"`
	MaxMempoolSizedisk              int     `json:"maxmempoolsizedisk"`
	MempoolMaxPercentCPFP           int     `json:"mempoolmaxpercentcpfp"`
	AcceptNonStdOutputs             bool    `json:"acceptnonstdoutputs"`
	DataCarrier                     bool    `json:"datacarrier"`
	MinMiningTxFee                  float64 `json:"minminingtxfee"`
	MaxStdTxValidationDuration      int     `json:"maxstdtxvalidationduration"`
	MaxNonStdTxValidationDuration   int     `json:"maxnonstdtxvalidationduration"`
	MaxTxChainValidationBudget      int     `json:"maxtxchainvalidationbudget"`
	ValidationClockCpu              bool    `json:"validationclockcpu"`
	MinConsolidationFactor          int     `json:"minconsolidationfactor"`
	MaxConsolidationInputScriptSize int     `json:"maxconsolidationinputscriptsize"`
	MinConfConsolidationInput       int     `json:"minconfconsolidationinput"`
	MinConsolidationInputMaturity   int     `json:"minconsolidationinputmaturity"`
	AcceptNonStdConsolidationInput  bool    `json:"acceptnonstdconsolidationinput"`
}

type SignRawTransactionResponse added in v1.0.17

type SignRawTransactionResponse struct {
	Hex      string `json:"hex"`
	Complete bool   `json:"complete"`
}

SignRawTransactionResponse struct

type TXOut added in v1.0.51

type TXOut struct {
	BestBlock     string       `json:"bestblock"`
	Confirmations int          `json:"confirmations"`
	Value         float64      `json:"value"`
	ScriptPubKey  ScriptPubKey `json:"scriptPubKey"`
	Coinbase      bool         `json:"coinbase"`
}

type Tag added in v1.0.60

type Tag struct {
	Type   string `json:"type"`
	Action string `json:"action"`
}

Tag

type Tip added in v1.0.55

type Tip struct {
	Height    uint64 `json:"height"`
	Hash      string `json:"hash"`
	BranchLen uint32 `json:"branchlen"`
	Status    string `json:"status"`
}

type Transaction

type Transaction struct {
	TXID string `json:"txid"`
	Hash string `json:"hash"`
	Data string `json:"data"`
}

Transaction comment

type TxResponse added in v1.0.64

type TxResponse struct {
	TxID         string `json:"txid"`
	RejectReason string `json:"reject_reason"`
}

type UnspentTransaction added in v1.0.13

type UnspentTransaction struct {
	TXID          string  `json:"txid"`
	Vout          uint32  `json:"vout"`
	Address       string  `json:"address"`
	ScriptPubKey  string  `json:"scriptPubKey"`
	Amount        float64 `json:"amount"`
	Satoshis      uint64  `json:"satoshis"`
	Confirmations uint32  `json:"confirmations"`
}

UnspentTransaction type

type Utxo added in v1.0.17

type Utxo struct {
	TxID   string `json:"txid"`
	Vout   uint32 `json:"vout"`
	Height uint32 `json:"height"`
	Value  uint64 `json:"value"`
}

Utxo bitindex comment

type UtxoResponse added in v1.0.17

type UtxoResponse struct {
	Address string `json:"address"`
	Utxos   []Utxo `json:"utxos"`
	Balance uint64 `json:"balance"`
}

UtxoResponse comment

type Vin

type Vin struct {
	Coinbase  string    `json:"coinbase"`
	Txid      string    `json:"txid"`
	Vout      uint64    `json:"vout"`
	ScriptSig ScriptSig `json:"scriptSig"`
	Sequence  uint32    `json:"sequence"`
}

Vin represent an IN value

type Vout

type Vout struct {
	Value        float64      `json:"value"`
	N            int          `json:"n"`
	ScriptPubKey ScriptPubKey `json:"scriptPubKey"`
}

Vout represent an OUT value

type ZMQ added in v1.0.8

type ZMQ struct {
	// contains filtered or unexported fields
}

ZMQ struct

func NewZMQ added in v1.0.8

func NewZMQ(host string, port int, optionalLogger ...Logger) *ZMQ

func NewZMQWithContext added in v1.0.79

func NewZMQWithContext(ctx context.Context, host string, port int, optionalLogger ...Logger) *ZMQ

func (*ZMQ) Subscribe added in v1.0.8

func (zmq *ZMQ) Subscribe(topic string, ch chan []string) error

func (*ZMQ) Unsubscribe added in v1.0.8

func (zmq *ZMQ) Unsubscribe(topic string, ch chan []string) error

Directories

Path Synopsis
examples
zmq

Jump to

Keyboard shortcuts

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