btc

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidValue = errors.New("Invalid value to marshal")

ErrInvalidValue is error returned by JSONMarshalerV1.Marshal if the passed structure contains invalid value

Functions

func GetChainParams

func GetChainParams(chain string) *chaincfg.Params

GetChainParams contains network parameters for the main Bitcoin network, the regression test Bitcoin network, the test Bitcoin network and the simulation test Bitcoin network, in this order

func InitWhatTheFee added in v0.3.0

func InitWhatTheFee(chain bchain.BlockChain, params string) error

InitWhatTheFee initializes https://whatthefee.io handler

func IsErrBlockNotFound added in v0.2.0

func IsErrBlockNotFound(err *bchain.RPCError) bool

IsErrBlockNotFound returns true if error means block was not found

func IsMissingTx added in v0.2.0

func IsMissingTx(err *bchain.RPCError) bool

IsMissingTx return true if error means missing tx

func NewBitcoinRPC

func NewBitcoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error)

NewBitcoinRPC returns new BitcoinRPC instance.

Types

type BitcoinParser

type BitcoinParser struct {
	*bchain.BaseParser
	Params                      *chaincfg.Params
	OutputScriptToAddressesFunc OutputScriptToAddressesFunc
	XPubMagic                   uint32
	XPubMagicSegwitP2sh         uint32
	XPubMagicSegwitNative       uint32
	Slip44                      uint32
	// contains filtered or unexported fields
}

BitcoinParser handle

func NewBitcoinParser

func NewBitcoinParser(params *chaincfg.Params, c *Configuration) *BitcoinParser

NewBitcoinParser returns new BitcoinParser instance

func (*BitcoinParser) AppendTxInput added in v0.3.4

func (p *BitcoinParser) AppendTxInput(txi *bchain.TxInput, buf []byte, varBuf []byte) []byte

func (*BitcoinParser) AppendTxOutput added in v0.3.4

func (p *BitcoinParser) AppendTxOutput(txo *bchain.TxOutput, buf []byte, varBuf []byte) []byte

func (*BitcoinParser) DerivationBasePath added in v0.2.1

func (p *BitcoinParser) DerivationBasePath(xpub string) (string, error)

DerivationBasePath returns base path of xpub

func (*BitcoinParser) DeriveAddressDescriptors added in v0.2.1

func (p *BitcoinParser) DeriveAddressDescriptors(xpub string, change uint32, indexes []uint32) ([]bchain.AddressDescriptor, error)

DeriveAddressDescriptors derives address descriptors from given xpub for listed indexes

func (*BitcoinParser) DeriveAddressDescriptorsFromTo added in v0.2.1

func (p *BitcoinParser) DeriveAddressDescriptorsFromTo(xpub string, change uint32, fromIndex uint32, toIndex uint32) ([]bchain.AddressDescriptor, error)

DeriveAddressDescriptorsFromTo derives address descriptors from given xpub for addresses in index range

func (*BitcoinParser) GetAddrDescFromAddress added in v0.1.0

func (p *BitcoinParser) GetAddrDescFromAddress(address string) (bchain.AddressDescriptor, error)

GetAddrDescFromAddress returns internal address representation (descriptor) of given address

func (*BitcoinParser) GetAddrDescFromVout added in v0.1.0

func (p *BitcoinParser) GetAddrDescFromVout(output *bchain.Vout) (bchain.AddressDescriptor, error)

GetAddrDescFromVout returns internal address representation (descriptor) of given transaction output

func (*BitcoinParser) GetAddressesFromAddrDesc added in v0.1.0

func (p *BitcoinParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error)

GetAddressesFromAddrDesc returns addresses for given address descriptor with flag if the addresses are searchable

func (*BitcoinParser) GetScriptFromAddrDesc added in v0.1.0

func (p *BitcoinParser) GetScriptFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]byte, error)

GetScriptFromAddrDesc returns output script for given address descriptor

func (*BitcoinParser) IsAddrDescIndexable added in v0.3.0

func (p *BitcoinParser) IsAddrDescIndexable(addrDesc bchain.AddressDescriptor) bool

IsAddrDescIndexable returns true if AddressDescriptor should be added to index empty or OP_RETURN scripts are not indexed

func (*BitcoinParser) MinimumCoinbaseConfirmations added in v0.3.4

func (p *BitcoinParser) MinimumCoinbaseConfirmations() int

MinimumCoinbaseConfirmations returns minimum number of confirmations a coinbase transaction must have before it can be spent

func (*BitcoinParser) PackAddrBalance added in v0.3.4

func (p *BitcoinParser) PackAddrBalance(ab *bchain.AddrBalance, buf, varBuf []byte) []byte

func (*BitcoinParser) PackBlockInfo added in v0.3.4

func (p *BitcoinParser) PackBlockInfo(block *bchain.DbBlockInfo) ([]byte, error)

func (*BitcoinParser) PackOutpoints added in v0.3.4

func (p *BitcoinParser) PackOutpoints(outpoints []bchain.DbOutpoint) []byte

func (*BitcoinParser) PackTx

func (p *BitcoinParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error)

PackTx packs transaction to byte array

func (*BitcoinParser) PackTxAddresses added in v0.3.4

func (p *BitcoinParser) PackTxAddresses(ta *bchain.TxAddresses, buf []byte, varBuf []byte) []byte

func (*BitcoinParser) ParseBlock

func (p *BitcoinParser) ParseBlock(b []byte) (*bchain.Block, error)

ParseBlock parses raw block to our Block struct

func (*BitcoinParser) ParseTx

func (p *BitcoinParser) ParseTx(b []byte) (*bchain.Tx, error)

ParseTx parses byte array containing transaction and returns Tx struct

func (*BitcoinParser) TryParseOPReturn added in v0.2.2

func (p *BitcoinParser) TryParseOPReturn(script []byte) string

TryParseOPReturn tries to process OP_RETURN script and return its string representation

func (*BitcoinParser) TxFromMsgTx

func (p *BitcoinParser) TxFromMsgTx(t *wire.MsgTx, parseAddresses bool) bchain.Tx

TxFromMsgTx converts bitcoin wire Tx to bchain.Tx

func (*BitcoinParser) UnpackAddrBalance added in v0.3.4

func (p *BitcoinParser) UnpackAddrBalance(buf []byte, txidUnpackedLen int, detail bchain.AddressBalanceDetail) (*bchain.AddrBalance, error)

func (*BitcoinParser) UnpackBlockInfo added in v0.3.4

func (p *BitcoinParser) UnpackBlockInfo(buf []byte) (*bchain.DbBlockInfo, error)

func (*BitcoinParser) UnpackNOutpoints added in v0.3.4

func (p *BitcoinParser) UnpackNOutpoints(buf []byte) ([]bchain.DbOutpoint, int, error)

func (*BitcoinParser) UnpackTx

func (p *BitcoinParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error)

UnpackTx unpacks transaction from byte array

func (*BitcoinParser) UnpackTxAddresses added in v0.3.4

func (p *BitcoinParser) UnpackTxAddresses(buf []byte) (*bchain.TxAddresses, error)

func (*BitcoinParser) UnpackTxInput added in v0.3.4

func (p *BitcoinParser) UnpackTxInput(ti *bchain.TxInput, buf []byte) int

func (*BitcoinParser) UnpackTxOutput added in v0.3.4

func (p *BitcoinParser) UnpackTxOutput(to *bchain.TxOutput, buf []byte) int

type BitcoinRPC

type BitcoinRPC struct {
	*bchain.BaseChain

	Mempool     *bchain.MempoolBitcoinType
	ParseBlocks bool

	ChainConfig  *Configuration
	RPCMarshaler RPCMarshaler
	// contains filtered or unexported fields
}

BitcoinRPC is an interface to JSON-RPC bitcoind service.

func (*BitcoinRPC) Call

func (b *BitcoinRPC) Call(req interface{}, res interface{}) error

Call calls Backend RPC interface, using RPCMarshaler interface to marshall the request

func (*BitcoinRPC) CreateMempool added in v0.2.2

func (b *BitcoinRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error)

CreateMempool creates mempool if not already created, however does not initialize it

func (*BitcoinRPC) DecodeRawTransaction added in v0.3.4

func (b *BitcoinRPC) DecodeRawTransaction(hex string) (string, error)

getRawTransaction returns json as returned by backend, with all coin specific data

func (*BitcoinRPC) EstimateFee

func (b *BitcoinRPC) EstimateFee(blocks int) (big.Int, error)

EstimateFee returns fee estimation.

func (*BitcoinRPC) EstimateSmartFee

func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (big.Int, error)

EstimateSmartFee returns fee estimation

func (*BitcoinRPC) GetBestBlockHash

func (b *BitcoinRPC) GetBestBlockHash() (string, error)

GetBestBlockHash returns hash of the tip of the best-block-chain.

func (*BitcoinRPC) GetBestBlockHeight

func (b *BitcoinRPC) GetBestBlockHeight() (uint32, error)

GetBestBlockHeight returns height of the tip of the best-block-chain.

func (*BitcoinRPC) GetBlock

func (b *BitcoinRPC) GetBlock(hash string, height uint32) (*bchain.Block, error)

GetBlock returns block with given hash.

func (*BitcoinRPC) GetBlockFull

func (b *BitcoinRPC) GetBlockFull(hash string) (*bchain.Block, error)

GetBlockFull returns block with given hash

func (*BitcoinRPC) GetBlockHash

func (b *BitcoinRPC) GetBlockHash(height uint32) (string, error)

GetBlockHash returns hash of block in best-block-chain at given height.

func (*BitcoinRPC) GetBlockHeader

func (b *BitcoinRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error)

GetBlockHeader returns header of block with given hash.

func (*BitcoinRPC) GetBlockInfo added in v0.1.0

func (b *BitcoinRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error)

GetBlockInfo returns extended header (more info than in bchain.BlockHeader) with a list of txids

func (*BitcoinRPC) GetBlockRaw

func (b *BitcoinRPC) GetBlockRaw(hash string) ([]byte, error)

GetBlockRaw returns block with given hash as bytes

func (*BitcoinRPC) GetBlockWithoutHeader

func (b *BitcoinRPC) GetBlockWithoutHeader(hash string, height uint32) (*bchain.Block, error)

GetBlockWithoutHeader is an optimization - it does not call GetBlockHeader to get prev, next hashes instead it sets to header only block hash and height passed in parameters

func (*BitcoinRPC) GetChainInfo added in v0.1.0

func (b *BitcoinRPC) GetChainInfo() (*bchain.ChainInfo, error)

GetChainInfo returns information about the connected backend

func (*BitcoinRPC) GetChainTips added in v0.3.4

func (b *BitcoinRPC) GetChainTips() (string, error)

getRawTransaction returns json as returned by backend, with all coin specific data

func (*BitcoinRPC) GetCoinName

func (b *BitcoinRPC) GetCoinName() string

GetCoinName returns the coin name

func (*BitcoinRPC) GetMempoolEntry

func (b *BitcoinRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error)

GetMempoolEntry returns mempool data for given transaction

func (*BitcoinRPC) GetMempoolTransactions

func (b *BitcoinRPC) GetMempoolTransactions() ([]string, error)

GetMempoolTransactions returns transactions in mempool

func (*BitcoinRPC) GetSubversion

func (b *BitcoinRPC) GetSubversion() string

GetSubversion returns the backend subversion

func (*BitcoinRPC) GetTransaction

func (b *BitcoinRPC) GetTransaction(txid string) (*bchain.Tx, error)

GetTransaction returns a transaction by the transaction ID

func (*BitcoinRPC) GetTransactionForMempool

func (b *BitcoinRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error)

GetTransactionForMempool returns a transaction by the transaction ID It could be optimized for mempool, i.e. without block time and confirmations

func (*BitcoinRPC) GetTransactionSpecific added in v0.1.1

func (b *BitcoinRPC) GetTransactionSpecific(tx *bchain.Tx) (json.RawMessage, error)

GetTransactionSpecific returns json as returned by backend, with all coin specific data

func (*BitcoinRPC) Initialize

func (b *BitcoinRPC) Initialize() error

Initialize initializes BitcoinRPC instance.

func (*BitcoinRPC) InitializeMempool added in v0.2.2

func (b *BitcoinRPC) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOutpointFunc, onNewTxAddr bchain.OnNewTxAddrFunc, onNewTx bchain.OnNewTxFunc) error

InitializeMempool creates ZeroMQ subscription and sets AddrDescForOutpointFunc to the Mempool

func (*BitcoinRPC) SendRawTransaction

func (b *BitcoinRPC) SendRawTransaction(tx string) (string, error)

SendRawTransaction sends raw transaction

func (*BitcoinRPC) Shutdown

func (b *BitcoinRPC) Shutdown(ctx context.Context) error

Shutdown ZeroMQ and other resources

type BlockThin added in v0.1.0

type BlockThin struct {
	bchain.BlockHeader
	Txids []string `json:"tx"`
}

type CmdDecodeRawTransaction added in v0.3.4

type CmdDecodeRawTransaction struct {
	Method string `json:"method"`
	Params struct {
		Hex string `json:"hexstring"`
	} `json:"params"`
}

type CmdEstimateFee

type CmdEstimateFee struct {
	Method string `json:"method"`
	Params struct {
		Blocks int `json:"nblocks"`
	} `json:"params"`
}

type CmdEstimateSmartFee

type CmdEstimateSmartFee struct {
	Method string `json:"method"`
	Params struct {
		ConfTarget   int    `json:"conf_target"`
		EstimateMode string `json:"estimate_mode"`
	} `json:"params"`
}

type CmdGetBestBlockHash

type CmdGetBestBlockHash struct {
	Method string `json:"method"`
}

type CmdGetBlock

type CmdGetBlock struct {
	Method string `json:"method"`
	Params struct {
		BlockHash string `json:"blockhash"`
		Verbosity int    `json:"verbosity"`
	} `json:"params"`
}

type CmdGetBlockChainInfo

type CmdGetBlockChainInfo struct {
	Method string `json:"method"`
}

type CmdGetBlockCount

type CmdGetBlockCount struct {
	Method string `json:"method"`
}

type CmdGetBlockHash

type CmdGetBlockHash struct {
	Method string `json:"method"`
	Params struct {
		Height uint32 `json:"height"`
	} `json:"params"`
}

type CmdGetBlockHeader

type CmdGetBlockHeader struct {
	Method string `json:"method"`
	Params struct {
		BlockHash string `json:"blockhash"`
		Verbose   bool   `json:"verbose"`
	} `json:"params"`
}

type CmdGetChainTips added in v0.3.4

type CmdGetChainTips struct {
	Method string `json:"method"`
}

type CmdGetMempool

type CmdGetMempool struct {
	Method string `json:"method"`
}

type CmdGetMempoolEntry

type CmdGetMempoolEntry struct {
	Method string   `json:"method"`
	Params []string `json:"params"`
}

type CmdGetNetworkInfo added in v0.1.0

type CmdGetNetworkInfo struct {
	Method string `json:"method"`
}

type CmdGetRawTransaction

type CmdGetRawTransaction struct {
	Method string `json:"method"`
	Params struct {
		Txid    string `json:"txid"`
		Verbose bool   `json:"verbose"`
	} `json:"params"`
}

type CmdSendRawTransaction

type CmdSendRawTransaction struct {
	Method string   `json:"method"`
	Params []string `json:"params"`
}

type Configuration

type Configuration struct {
	CoinName                     string `json:"coin_name"`
	CoinShortcut                 string `json:"coin_shortcut"`
	RPCURL                       string `json:"rpc_url"`
	RPCUser                      string `json:"rpc_user"`
	RPCPass                      string `json:"rpc_pass"`
	RPCTimeout                   int    `json:"rpc_timeout"`
	Parse                        bool   `json:"parse"`
	MessageQueueBinding          string `json:"message_queue_binding"`
	Subversion                   string `json:"subversion"`
	BlockAddressesToKeep         int    `json:"block_addresses_to_keep"`
	MempoolWorkers               int    `json:"mempool_workers"`
	MempoolSubWorkers            int    `json:"mempool_sub_workers"`
	AddressFormat                string `json:"address_format"`
	SupportsEstimateFee          bool   `json:"supports_estimate_fee"`
	SupportsEstimateSmartFee     bool   `json:"supports_estimate_smart_fee"`
	XPubMagic                    uint32 `json:"xpub_magic,omitempty"`
	XPubMagicSegwitP2sh          uint32 `json:"xpub_magic_segwit_p2sh,omitempty"`
	XPubMagicSegwitNative        uint32 `json:"xpub_magic_segwit_native,omitempty"`
	Slip44                       uint32 `json:"slip44,omitempty"`
	AlternativeEstimateFee       string `json:"alternative_estimate_fee,omitempty"`
	AlternativeEstimateFeeParams string `json:"alternative_estimate_fee_params,omitempty"`
	MinimumCoinbaseConfirmations int    `json:"minimumCoinbaseConfirmations,omitempty"`
}

Configuration represents json config file

type JSONMarshalerV1

type JSONMarshalerV1 struct{}

JSONMarshalerV1 is used for marshalling requests to legacy Bitcoin Type RPC interfaces

func (JSONMarshalerV1) Marshal

func (JSONMarshalerV1) Marshal(v interface{}) ([]byte, error)

Marshal converts struct passed by parameter to JSON

type JSONMarshalerV2

type JSONMarshalerV2 struct{}

JSONMarshalerV2 is used for marshalling requests to newer Bitcoin Type RPC interfaces

func (JSONMarshalerV2) Marshal

func (JSONMarshalerV2) Marshal(v interface{}) ([]byte, error)

Marshal converts struct passed by parameter to JSON

type OutputScriptToAddressesFunc

type OutputScriptToAddressesFunc func(script []byte) ([]string, bool, error)

OutputScriptToAddressesFunc converts ScriptPubKey to bitcoin addresses

type RPCMarshaler

type RPCMarshaler interface {
	Marshal(v interface{}) ([]byte, error)
}

RPCMarshaler is used for marshalling requests to Bitcoin Type RPC interfaces

type ResDecodeRawTransaction added in v0.3.4

type ResDecodeRawTransaction struct {
	Error  *bchain.RPCError `json:"error"`
	Result json.RawMessage  `json:"result"`
}

decoderawtransaction

type ResEstimateFee

type ResEstimateFee struct {
	Error  *bchain.RPCError  `json:"error"`
	Result common.JSONNumber `json:"result"`
}

type ResEstimateSmartFee

type ResEstimateSmartFee struct {
	Error  *bchain.RPCError `json:"error"`
	Result struct {
		Feerate common.JSONNumber `json:"feerate"`
		Blocks  int               `json:"blocks"`
	} `json:"result"`
}

type ResGetBestBlockHash

type ResGetBestBlockHash struct {
	Error  *bchain.RPCError `json:"error"`
	Result string           `json:"result"`
}

type ResGetBlockChainInfo

type ResGetBlockChainInfo struct {
	Error  *bchain.RPCError `json:"error"`
	Result struct {
		Chain         string            `json:"chain"`
		Blocks        int               `json:"blocks"`
		Headers       int               `json:"headers"`
		Bestblockhash string            `json:"bestblockhash"`
		Difficulty    common.JSONNumber `json:"difficulty"`
		SizeOnDisk    int64             `json:"size_on_disk"`
		Warnings      string            `json:"warnings"`
	} `json:"result"`
}

type ResGetBlockCount

type ResGetBlockCount struct {
	Error  *bchain.RPCError `json:"error"`
	Result uint32           `json:"result"`
}

type ResGetBlockFull

type ResGetBlockFull struct {
	Error  *bchain.RPCError `json:"error"`
	Result bchain.Block     `json:"result"`
}

type ResGetBlockHash

type ResGetBlockHash struct {
	Error  *bchain.RPCError `json:"error"`
	Result string           `json:"result"`
}

type ResGetBlockHeader

type ResGetBlockHeader struct {
	Error  *bchain.RPCError   `json:"error"`
	Result bchain.BlockHeader `json:"result"`
}

type ResGetBlockInfo added in v0.1.0

type ResGetBlockInfo struct {
	Error  *bchain.RPCError `json:"error"`
	Result bchain.BlockInfo `json:"result"`
}

type ResGetBlockRaw

type ResGetBlockRaw struct {
	Error  *bchain.RPCError `json:"error"`
	Result string           `json:"result"`
}

type ResGetBlockThin

type ResGetBlockThin struct {
	Error  *bchain.RPCError `json:"error"`
	Result BlockThin        `json:"result"`
}

type ResGetChainTips added in v0.3.4

type ResGetChainTips struct {
	Error  *bchain.RPCError `json:"error"`
	Result json.RawMessage  `json:"result"`
}

getchaintips

type ResGetMempool

type ResGetMempool struct {
	Error  *bchain.RPCError `json:"error"`
	Result []string         `json:"result"`
}

type ResGetMempoolEntry

type ResGetMempoolEntry struct {
	Error  *bchain.RPCError     `json:"error"`
	Result *bchain.MempoolEntry `json:"result"`
}

type ResGetNetworkInfo added in v0.1.0

type ResGetNetworkInfo struct {
	Error  *bchain.RPCError `json:"error"`
	Result struct {
		Version         common.JSONNumber `json:"version"`
		Subversion      common.JSONNumber `json:"subversion"`
		ProtocolVersion common.JSONNumber `json:"protocolversion"`
		Timeoffset      float64           `json:"timeoffset"`
		Warnings        string            `json:"warnings"`
	} `json:"result"`
}

type ResGetRawTransaction

type ResGetRawTransaction struct {
	Error  *bchain.RPCError `json:"error"`
	Result json.RawMessage  `json:"result"`
}

type ResGetRawTransactionNonverbose

type ResGetRawTransactionNonverbose struct {
	Error  *bchain.RPCError `json:"error"`
	Result string           `json:"result"`
}

type ResSendRawTransaction

type ResSendRawTransaction struct {
	Error  *bchain.RPCError `json:"error"`
	Result string           `json:"result"`
}

Jump to

Keyboard shortcuts

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