bchain

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: AGPL-3.0 Imports: 20 Imported by: 50

Documentation

Index

Constants

View Source
const (
	// ChainBitcoinType is blockchain derived from bitcoin
	ChainBitcoinType = ChainType(iota)
	// ChainEthereumType is blockchain derived from ethereum
	ChainEthereumType
)
View Source
const (
	FungibleToken    = TokenType(iota) // ERC20
	NonFungibleToken                   // ERC721
	MultiToken                         // ERC1155
)

TokenType enumeration

View Source
const (
	P2PK = ScriptType(iota)
	P2PKH
	P2SHWPKH
	P2WPKH
	P2TR
)

ScriptType enumeration

View Source
const (
	CALL = EthereumInternalTransactionType(iota)
	CREATE
	SELFDESTRUCT
)

EthereumInternalTransactionType enumeration

Variables

View Source
var (
	// ErrBlockNotFound is returned when block is not found
	// either unknown hash or too high height
	// can be returned from GetBlockHash, GetBlockHeader, GetBlock
	ErrBlockNotFound = errors.New("Block not found")
	// ErrAddressMissing is returned if address is not specified
	// for example To address in ethereum can be missing in case of contract transaction
	ErrAddressMissing = errors.New("Address missing")
	// ErrTxidMissing is returned if txid is not specified
	// for example coinbase transactions in Bitcoin
	ErrTxidMissing = errors.New("Txid missing")
	// ErrTxNotFound is returned if transaction was not found
	ErrTxNotFound = errors.New("Tx not found")
)

errors with specific meaning returned by blockchain rpc

EthereumTokenTypeMap maps bchain.TokenType to TokenTypeName the map must match all bchain.TokenType to avoid index out of range panic

View Source
var File_bchain_tx_proto protoreflect.FileDescriptor

Functions

func AmountToDecimalString added in v0.2.0

func AmountToDecimalString(a *big.Int, d int) string

AmountToDecimalString converts amount in big.Int to string with decimal point in the place defined by the parameter d

Types

type AddrDescForOutpointFunc added in v0.2.2

type AddrDescForOutpointFunc func(outpoint Outpoint) (AddressDescriptor, *big.Int)

AddrDescForOutpointFunc returns address descriptor and value for given outpoint or nil if outpoint not found

type AddressAliasRecord added in v0.4.0

type AddressAliasRecord struct {
	Address string
	Name    string
}

AddressAliasRecord maps address to ENS name

type AddressDescriptor added in v0.1.0

type AddressDescriptor []byte

AddressDescriptor is an opaque type obtained by parser.GetAddrDesc* methods

func AddressDescriptorFromString added in v0.3.2

func AddressDescriptorFromString(s string) (AddressDescriptor, error)

AddressDescriptorFromString converts string created by AddressDescriptor.String to AddressDescriptor

func (AddressDescriptor) String added in v0.1.0

func (ad AddressDescriptor) String() string

type BaseChain added in v0.2.0

type BaseChain struct {
	Parser  BlockChainParser
	Testnet bool
	Network string
}

BaseChain is base type for bchain.BlockChain

func (*BaseChain) EthereumTypeEstimateGas added in v0.2.0

func (b *BaseChain) EthereumTypeEstimateGas(params map[string]interface{}) (uint64, error)

EthereumTypeEstimateGas is not supported

func (*BaseChain) EthereumTypeGetBalance added in v0.2.0

func (b *BaseChain) EthereumTypeGetBalance(addrDesc AddressDescriptor) (*big.Int, error)

EthereumTypeGetBalance is not supported

func (*BaseChain) EthereumTypeGetErc20ContractBalance added in v0.2.0

func (b *BaseChain) EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc AddressDescriptor) (*big.Int, error)

EthereumTypeGetErc20ContractBalance is not supported

func (*BaseChain) EthereumTypeGetNonce added in v0.2.0

func (b *BaseChain) EthereumTypeGetNonce(addrDesc AddressDescriptor) (uint64, error)

EthereumTypeGetNonce is not supported

func (*BaseChain) GetBlockRaw added in v0.4.0

func (b *BaseChain) GetBlockRaw(hash string) (string, error)

GetBlockRaw is not supported by default

func (*BaseChain) GetChainParser added in v0.2.0

func (b *BaseChain) GetChainParser() BlockChainParser

GetChainParser returns BlockChainParser

func (*BaseChain) GetContractInfo added in v0.4.0

func (b *BaseChain) GetContractInfo(contractDesc AddressDescriptor) (*ContractInfo, error)

GetContractInfo is not supported

func (*BaseChain) GetMempoolEntry added in v0.2.2

func (b *BaseChain) GetMempoolEntry(txid string) (*MempoolEntry, error)

GetMempoolEntry is not supported by default

func (*BaseChain) GetNetworkName added in v0.2.0

func (b *BaseChain) GetNetworkName() string

GetNetworkName returns network name

func (*BaseChain) GetTokenURI added in v0.4.0

func (p *BaseChain) GetTokenURI(contractDesc AddressDescriptor, tokenID *big.Int) (string, error)

GetContractInfo returns URI of non fungible or multi token defined by token id

func (*BaseChain) IsTestnet added in v0.2.0

func (b *BaseChain) IsTestnet() bool

IsTestnet returns true if the blockchain is testnet

type BaseMempool added in v0.2.2

type BaseMempool struct {
	OnNewTxAddr OnNewTxAddrFunc
	OnNewTx     OnNewTxFunc
	// contains filtered or unexported fields
}

BaseMempool is mempool base handle

func (*BaseMempool) GetAddrDescTransactions added in v0.2.2

func (m *BaseMempool) GetAddrDescTransactions(addrDesc AddressDescriptor) ([]Outpoint, error)

GetAddrDescTransactions returns slice of mempool transactions for given address descriptor, in reverse order

func (*BaseMempool) GetAllEntries added in v0.2.2

func (m *BaseMempool) GetAllEntries() MempoolTxidEntries

GetAllEntries returns all mempool entries sorted by fist seen time in descending order

func (*BaseMempool) GetTransactionTime added in v0.2.2

func (m *BaseMempool) GetTransactionTime(txid string) uint32

GetTransactionTime returns first seen time of a transaction

func (*BaseMempool) GetTransactions added in v0.2.2

func (m *BaseMempool) GetTransactions(address string) ([]Outpoint, error)

GetTransactions returns slice of mempool transactions for given address

type BaseParser

type BaseParser struct {
	BlockAddressesToKeep int
	AmountDecimalPoint   int
	AddressAliases       bool
}

BaseParser implements data parsing/handling functionality base for all other parsers

func (*BaseParser) AmountDecimals added in v0.2.0

func (p *BaseParser) AmountDecimals() int

AmountDecimals returns number of decimal places in amounts

func (*BaseParser) AmountToBigInt added in v0.1.0

func (p *BaseParser) AmountToBigInt(n common.JSONNumber) (big.Int, error)

AmountToBigInt converts amount in common.JSONNumber (string) to big.Int it uses string operations to avoid problems with rounding

func (*BaseParser) AmountToDecimalString added in v0.1.0

func (p *BaseParser) AmountToDecimalString(a *big.Int) string

AmountToDecimalString converts amount in big.Int to string with decimal point in the correct place

func (*BaseParser) DerivationBasePath added in v0.2.1

func (p *BaseParser) DerivationBasePath(descriptor *XpubDescriptor) (string, error)

DerivationBasePath is unsupported

func (*BaseParser) DeriveAddressDescriptors added in v0.2.1

func (p *BaseParser) DeriveAddressDescriptors(descriptor *XpubDescriptor, change uint32, indexes []uint32) ([]AddressDescriptor, error)

DeriveAddressDescriptors is unsupported

func (*BaseParser) DeriveAddressDescriptorsFromTo added in v0.2.1

func (p *BaseParser) DeriveAddressDescriptorsFromTo(descriptor *XpubDescriptor, change uint32, fromIndex uint32, toIndex uint32) ([]AddressDescriptor, error)

DeriveAddressDescriptorsFromTo is unsupported

func (*BaseParser) EthereumTypeGetTokenTransfersFromTx added in v0.4.0

func (p *BaseParser) EthereumTypeGetTokenTransfersFromTx(tx *Tx) (TokenTransfers, error)

EthereumTypeGetTokenTransfersFromTx is unsupported

func (*BaseParser) FormatAddressAlias added in v0.4.0

func (p *BaseParser) FormatAddressAlias(address string, name string) string

FormatAddressAlias makes possible to do coin specific formatting to an address alias

func (*BaseParser) GetAddrDescForUnknownInput added in v0.2.0

func (p *BaseParser) GetAddrDescForUnknownInput(tx *Tx, input int) AddressDescriptor

GetAddrDescForUnknownInput returns nil AddressDescriptor

func (*BaseParser) GetChainType added in v0.2.0

func (p *BaseParser) GetChainType() ChainType

GetChainType is type of the blockchain, default is ChainBitcoinType

func (*BaseParser) IsAddrDescIndexable added in v0.3.0

func (p *BaseParser) IsAddrDescIndexable(addrDesc AddressDescriptor) bool

IsAddrDescIndexable returns true if AddressDescriptor should be added to index by default all AddressDescriptors are indexable

func (*BaseParser) KeepBlockAddresses

func (p *BaseParser) KeepBlockAddresses() int

KeepBlockAddresses returns number of blocks which are to be kept in blockaddresses column

func (*BaseParser) MinimumCoinbaseConfirmations added in v0.3.2

func (p *BaseParser) MinimumCoinbaseConfirmations() int

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

func (*BaseParser) PackBlockHash

func (p *BaseParser) PackBlockHash(hash string) ([]byte, error)

PackBlockHash packs block hash to byte array

func (*BaseParser) PackTx

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

PackTx packs transaction to byte array using protobuf

func (*BaseParser) PackTxid

func (p *BaseParser) PackTxid(txid string) ([]byte, error)

PackTxid packs txid to byte array

func (*BaseParser) PackedTxidLen

func (p *BaseParser) PackedTxidLen() int

PackedTxidLen returns length in bytes of packed txid

func (*BaseParser) ParseBlock

func (p *BaseParser) ParseBlock(b []byte) (*Block, error)

ParseBlock parses raw block to our Block struct - currently not implemented

func (*BaseParser) ParseTx

func (p *BaseParser) ParseTx(b []byte) (*Tx, error)

ParseTx parses byte array containing transaction and returns Tx struct - currently not implemented

func (*BaseParser) ParseTxFromJson

func (p *BaseParser) ParseTxFromJson(msg json.RawMessage) (*Tx, error)

ParseTxFromJson parses JSON message containing transaction and returns Tx struct

func (*BaseParser) ParseXpub added in v0.4.0

func (p *BaseParser) ParseXpub(xpub string) (*XpubDescriptor, error)

ParseXpub is unsupported

func (*BaseParser) SupportsVSize added in v0.4.0

func (p *BaseParser) SupportsVSize() bool

SupportsVSize returns true if vsize of a transaction should be computed and returned by API

func (*BaseParser) UnpackBlockHash

func (p *BaseParser) UnpackBlockHash(buf []byte) (string, error)

UnpackBlockHash unpacks byte array to block hash

func (*BaseParser) UnpackTx

func (p *BaseParser) UnpackTx(buf []byte) (*Tx, uint32, error)

UnpackTx unpacks transaction from protobuf byte array

func (*BaseParser) UnpackTxid

func (p *BaseParser) UnpackTxid(buf []byte) (string, error)

UnpackTxid unpacks byte array to txid

func (*BaseParser) UseAddressAliases added in v0.4.0

func (p *BaseParser) UseAddressAliases() bool

UseAddressAliases returns true if address aliases are enabled

type Block

type Block struct {
	BlockHeader
	Txs              []Tx        `json:"tx"`
	CoinSpecificData interface{} `json:"-"`
}

Block is block header and list of transactions

type BlockChain

type BlockChain interface {
	// life-cycle methods
	// initialize the block chain connector
	Initialize() error
	// create mempool but do not initialize it
	CreateMempool(BlockChain) (Mempool, error)
	// initialize mempool, create ZeroMQ (or other) subscription
	InitializeMempool(AddrDescForOutpointFunc, OnNewTxAddrFunc, OnNewTxFunc) error
	// shutdown mempool, ZeroMQ and block chain connections
	Shutdown(ctx context.Context) error
	// chain info
	IsTestnet() bool
	GetNetworkName() string
	GetSubversion() string
	GetCoinName() string
	GetChainInfo() (*ChainInfo, error)
	// requests
	GetBestBlockHash() (string, error)
	GetBestBlockHeight() (uint32, error)
	GetBlockHash(height uint32) (string, error)
	GetBlockHeader(hash string) (*BlockHeader, error)
	GetBlock(hash string, height uint32) (*Block, error)
	GetBlockInfo(hash string) (*BlockInfo, error)
	GetBlockRaw(hash string) (string, error)
	GetMempoolTransactions() ([]string, error)
	GetTransaction(txid string) (*Tx, error)
	GetTransactionForMempool(txid string) (*Tx, error)
	GetTransactionSpecific(tx *Tx) (json.RawMessage, error)
	EstimateSmartFee(blocks int, conservative bool) (big.Int, error)
	EstimateFee(blocks int) (big.Int, error)
	SendRawTransaction(tx string) (string, error)
	GetMempoolEntry(txid string) (*MempoolEntry, error)
	GetContractInfo(contractDesc AddressDescriptor) (*ContractInfo, error)
	// parser
	GetChainParser() BlockChainParser
	// EthereumType specific
	EthereumTypeGetBalance(addrDesc AddressDescriptor) (*big.Int, error)
	EthereumTypeGetNonce(addrDesc AddressDescriptor) (uint64, error)
	EthereumTypeEstimateGas(params map[string]interface{}) (uint64, error)
	EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc AddressDescriptor) (*big.Int, error)
	GetTokenURI(contractDesc AddressDescriptor, tokenID *big.Int) (string, error)
}

BlockChain defines common interface to block chain daemon

type BlockChainParser

type BlockChainParser interface {
	// type of the blockchain
	GetChainType() ChainType
	// KeepBlockAddresses returns number of blocks which are to be kept in blockTxs column
	// to be used for rollbacks
	KeepBlockAddresses() int
	// AmountDecimals returns number of decimal places in coin amounts
	AmountDecimals() int
	// UseAddressAliases returns true if address aliases are enabled
	UseAddressAliases() bool
	// MinimumCoinbaseConfirmations returns minimum number of confirmations a coinbase transaction must have before it can be spent
	MinimumCoinbaseConfirmations() int
	// SupportsVSize returns true if vsize of a transaction should be computed and returned by API
	SupportsVSize() bool
	// AmountToDecimalString converts amount in big.Int to string with decimal point in the correct place
	AmountToDecimalString(a *big.Int) string
	// AmountToBigInt converts amount in common.JSONNumber (string) to big.Int
	// it uses string operations to avoid problems with rounding
	AmountToBigInt(n common.JSONNumber) (big.Int, error)
	// address descriptor conversions
	GetAddrDescFromVout(output *Vout) (AddressDescriptor, error)
	GetAddrDescFromAddress(address string) (AddressDescriptor, error)
	GetAddressesFromAddrDesc(addrDesc AddressDescriptor) ([]string, bool, error)
	GetScriptFromAddrDesc(addrDesc AddressDescriptor) ([]byte, error)
	IsAddrDescIndexable(addrDesc AddressDescriptor) bool
	// transactions
	PackedTxidLen() int
	PackTxid(txid string) ([]byte, error)
	UnpackTxid(buf []byte) (string, error)
	ParseTx(b []byte) (*Tx, error)
	ParseTxFromJson(json.RawMessage) (*Tx, error)
	PackTx(tx *Tx, height uint32, blockTime int64) ([]byte, error)
	UnpackTx(buf []byte) (*Tx, uint32, error)
	GetAddrDescForUnknownInput(tx *Tx, input int) AddressDescriptor
	// blocks
	PackBlockHash(hash string) ([]byte, error)
	UnpackBlockHash(buf []byte) (string, error)
	ParseBlock(b []byte) (*Block, error)
	// xpub
	ParseXpub(xpub string) (*XpubDescriptor, error)
	DerivationBasePath(descriptor *XpubDescriptor) (string, error)
	DeriveAddressDescriptors(descriptor *XpubDescriptor, change uint32, indexes []uint32) ([]AddressDescriptor, error)
	DeriveAddressDescriptorsFromTo(descriptor *XpubDescriptor, change uint32, fromIndex uint32, toIndex uint32) ([]AddressDescriptor, error)
	// EthereumType specific
	EthereumTypeGetTokenTransfersFromTx(tx *Tx) (TokenTransfers, error)
	// AddressAlias
	FormatAddressAlias(address string, name string) string
}

BlockChainParser defines common interface to parsing and conversions of block chain data

type BlockHeader

type BlockHeader struct {
	Hash          string `json:"hash"`
	Prev          string `json:"previousblockhash"`
	Next          string `json:"nextblockhash"`
	Height        uint32 `json:"height"`
	Confirmations int    `json:"confirmations"`
	Size          int    `json:"size"`
	Time          int64  `json:"time,omitempty"`
}

BlockHeader contains limited data (as needed for indexing) from backend block header

type BlockInfo added in v0.1.0

type BlockInfo struct {
	BlockHeader
	Version    common.JSONNumber `json:"version"`
	MerkleRoot string            `json:"merkleroot"`
	Nonce      common.JSONNumber `json:"nonce"`
	Bits       string            `json:"bits"`
	Difficulty common.JSONNumber `json:"difficulty"`
	Txids      []string          `json:"tx,omitempty"`
}

BlockInfo contains extended block header data and a list of block txids

type ChainInfo added in v0.1.0

type ChainInfo struct {
	Chain            string      `json:"chain"`
	Blocks           int         `json:"blocks"`
	Headers          int         `json:"headers"`
	Bestblockhash    string      `json:"bestblockhash"`
	Difficulty       string      `json:"difficulty"`
	SizeOnDisk       int64       `json:"size_on_disk"`
	Version          string      `json:"version"`
	Subversion       string      `json:"subversion"`
	ProtocolVersion  string      `json:"protocolversion"`
	Timeoffset       float64     `json:"timeoffset"`
	Warnings         string      `json:"warnings"`
	ConsensusVersion string      `json:"consensus_version,omitempty"`
	Consensus        interface{} `json:"consensus,omitempty"`
}

ChainInfo is used to get information about blockchain

type ChainType added in v0.2.0

type ChainType int

ChainType is type of the blockchain

type ContractInfo added in v0.4.0

type ContractInfo struct {
	Type              TokenTypeName `json:"type"`
	Contract          string        `json:"contract"`
	Name              string        `json:"name"`
	Symbol            string        `json:"symbol"`
	Decimals          int           `json:"decimals"`
	CreatedInBlock    uint32        `json:"createdInBlock,omitempty"`
	DestructedInBlock uint32        `json:"destructedInBlock,omitempty"`
}

ContractInfo contains info about ERC20 contract

type EVMClient added in v0.4.0

type EVMClient interface {
	NetworkID(ctx context.Context) (*big.Int, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (EVMHeader, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	EstimateGas(ctx context.Context, msg interface{}) (uint64, error)
	BalanceAt(ctx context.Context, addrDesc AddressDescriptor, blockNumber *big.Int) (*big.Int, error)
	NonceAt(ctx context.Context, addrDesc AddressDescriptor, blockNumber *big.Int) (uint64, error)
}

EVMClient provides the necessary client functionality for evm chain sync

type EVMClientSubscription added in v0.4.0

type EVMClientSubscription interface {
	Err() <-chan error
	Unsubscribe()
}

EVMClientSubscription provides interaction with an evm client subscription

type EVMHash added in v0.4.0

type EVMHash interface {
	Hex() string
}

EVMHash provides access to the necessary hash data for evm chain sync

type EVMHeader added in v0.4.0

type EVMHeader interface {
	Hash() string
	Number() *big.Int
	Difficulty() *big.Int
}

EVMHeader provides access to the necessary header data for evm chain sync

type EVMNewBlockSubscriber added in v0.4.0

type EVMNewBlockSubscriber interface {
	EVMSubscriber
	Read() (EVMHeader, bool)
}

EVMNewBlockSubscriber provides interaction with a new block subscription channel

type EVMNewTxSubscriber added in v0.4.0

type EVMNewTxSubscriber interface {
	EVMSubscriber
	Read() (EVMHash, bool)
}

EVMNewBlockSubscriber provides interaction with a new tx subscription channel

type EVMRPCClient added in v0.4.0

type EVMRPCClient interface {
	EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (EVMClientSubscription, error)
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	Close()
}

EVMRPCClient provides the necessary rpc functionality for evm chain sync

type EVMSubscriber added in v0.4.0

type EVMSubscriber interface {
	Channel() interface{}
	Close()
}

EVMSubscriber provides interaction with a subscription channel

type EthereumBlockSpecificData added in v0.4.0

type EthereumBlockSpecificData struct {
	InternalDataError   string
	AddressAliasRecords []AddressAliasRecord
	Contracts           []ContractInfo
}

EthereumBlockSpecificData contain data specific for Ethereum block

type EthereumInternalData added in v0.4.0

type EthereumInternalData struct {
	Type      EthereumInternalTransactionType `json:"type"`
	Contract  string                          `json:"contract,omitempty"`
	Transfers []EthereumInternalTransfer      `json:"transfers,omitempty"`
	Error     string
}

EthereumInternalTransaction contains internal transfers

type EthereumInternalTransactionType added in v0.4.0

type EthereumInternalTransactionType int

EthereumInternalTransactionType - type of ethereum transaction from internal data

type EthereumInternalTransfer added in v0.4.0

type EthereumInternalTransfer struct {
	Type  EthereumInternalTransactionType `json:"type"`
	From  string                          `json:"from"`
	To    string                          `json:"to"`
	Value big.Int                         `json:"value"`
}

EthereumInternalTransfer contains data about internal transfer

type EthereumParsedInputData added in v0.4.0

type EthereumParsedInputData struct {
	MethodId string                     `json:"methodId"`
	Name     string                     `json:"name"`
	Function string                     `json:"function,omitempty"`
	Params   []EthereumParsedInputParam `json:"params,omitempty"`
}

type EthereumParsedInputParam added in v0.4.0

type EthereumParsedInputParam struct {
	Type   string   `json:"type"`
	Values []string `json:"values,omitempty"`
}

type EthereumSpecificData added in v0.4.0

type EthereumSpecificData struct {
	Tx           *RpcTransaction       `json:"tx"`
	InternalData *EthereumInternalData `json:"internalData,omitempty"`
	Receipt      *RpcReceipt           `json:"receipt,omitempty"`
}

EthereumSpecificData contains data specific to Ethereum transactions

type FourByteSignature added in v0.4.0

type FourByteSignature struct {
	// stored in DB
	Name       string
	Parameters []string
	// processed from DB data and stored only in cache
	DecamelName      string
	Function         string
	ParsedParameters []abi.Type
}

type MQ

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

MQ is message queue listener handle

func NewMQ

func NewMQ(binding string, callback func(NotificationType)) (*MQ, error)

NewMQ creates new Bitcoind ZeroMQ listener callback function receives messages

func (*MQ) Shutdown

func (mq *MQ) Shutdown(ctx context.Context) error

Shutdown stops listening to the ZeroMQ and closes the connection

type Mempool added in v0.2.2

type Mempool interface {
	Resync() (int, error)
	GetTransactions(address string) ([]Outpoint, error)
	GetAddrDescTransactions(addrDesc AddressDescriptor) ([]Outpoint, error)
	GetAllEntries() MempoolTxidEntries
	GetTransactionTime(txid string) uint32
}

Mempool defines common interface to mempool

type MempoolBitcoinType added in v0.2.0

type MempoolBitcoinType struct {
	BaseMempool

	AddrDescForOutpoint AddrDescForOutpointFunc
	// contains filtered or unexported fields
}

MempoolBitcoinType is mempool handle.

func NewMempoolBitcoinType added in v0.2.0

func NewMempoolBitcoinType(chain BlockChain, workers int, subworkers int) *MempoolBitcoinType

NewMempoolBitcoinType creates new mempool handler. For now there is no cleanup of sync routines, the expectation is that the mempool is created only once per process

func (*MempoolBitcoinType) Resync added in v0.2.0

func (m *MempoolBitcoinType) Resync() (int, error)

Resync gets mempool transactions and maps outputs to transactions. Resync is not reentrant, it should be called from a single thread. Read operations (GetTransactions) are safe.

type MempoolEntry

type MempoolEntry struct {
	Size            uint32 `json:"size"`
	FeeSat          big.Int
	Fee             common.JSONNumber `json:"fee"`
	ModifiedFeeSat  big.Int
	ModifiedFee     common.JSONNumber `json:"modifiedfee"`
	Time            uint64            `json:"time"`
	Height          uint32            `json:"height"`
	DescendantCount uint32            `json:"descendantcount"`
	DescendantSize  uint32            `json:"descendantsize"`
	DescendantFees  uint32            `json:"descendantfees"`
	AncestorCount   uint32            `json:"ancestorcount"`
	AncestorSize    uint32            `json:"ancestorsize"`
	AncestorFees    uint32            `json:"ancestorfees"`
	Depends         []string          `json:"depends"`
}

MempoolEntry is used to get data about mempool entry

type MempoolEthereumType added in v0.2.0

type MempoolEthereumType struct {
	BaseMempool
	// contains filtered or unexported fields
}

MempoolEthereumType is mempool handle of EthereumType chains

func NewMempoolEthereumType added in v0.2.0

func NewMempoolEthereumType(chain BlockChain, mempoolTxTimeoutHours int, queryBackendOnResync bool) *MempoolEthereumType

NewMempoolEthereumType creates new mempool handler.

func (*MempoolEthereumType) AddTransactionToMempool added in v0.2.2

func (m *MempoolEthereumType) AddTransactionToMempool(txid string)

AddTransactionToMempool adds transactions to mempool

func (*MempoolEthereumType) RemoveTransactionFromMempool added in v0.2.2

func (m *MempoolEthereumType) RemoveTransactionFromMempool(txid string)

RemoveTransactionFromMempool removes transaction from mempool

func (*MempoolEthereumType) Resync added in v0.2.0

func (m *MempoolEthereumType) Resync() (int, error)

Resync ethereum type removes timed out transactions and returns number of transactions in mempool. Transactions are added/removed by AddTransactionToMempool/RemoveTransactionFromMempool methods

type MempoolTx added in v0.3.4

type MempoolTx struct {
	Hex              string         `json:"hex"`
	Txid             string         `json:"txid"`
	Version          int32          `json:"version"`
	LockTime         uint32         `json:"locktime"`
	VSize            int64          `json:"vsize,omitempty"`
	Vin              []MempoolVin   `json:"vin"`
	Vout             []Vout         `json:"vout"`
	Blocktime        int64          `json:"blocktime,omitempty"`
	TokenTransfers   TokenTransfers `json:"-"`
	CoinSpecificData interface{}    `json:"-"`
}

MempoolTx is blockchain transaction in mempool optimized for onNewTx notification

type MempoolTxidEntries added in v0.2.2

type MempoolTxidEntries []MempoolTxidEntry

MempoolTxidEntries is array of MempoolTxidEntry

func (MempoolTxidEntries) Len added in v0.2.2

func (a MempoolTxidEntries) Len() int

func (MempoolTxidEntries) Less added in v0.2.2

func (a MempoolTxidEntries) Less(i, j int) bool

func (MempoolTxidEntries) Swap added in v0.2.2

func (a MempoolTxidEntries) Swap(i, j int)

type MempoolTxidEntry added in v0.2.2

type MempoolTxidEntry struct {
	Txid string
	Time uint32
}

MempoolTxidEntry contains mempool txid with first seen time

type MempoolVin added in v0.3.4

type MempoolVin struct {
	Vin
	AddrDesc AddressDescriptor `json:"-"`
	ValueSat big.Int
}

MempoolVin contains data about tx input

type MultiTokenValue added in v0.4.0

type MultiTokenValue struct {
	Id    big.Int
	Value big.Int
}

type NotificationType

type NotificationType int

NotificationType is type of notification

const (
	// NotificationUnknown is unknown
	NotificationUnknown NotificationType = iota
	// NotificationNewBlock message is sent when there is a new block to be imported
	NotificationNewBlock NotificationType = iota
	// NotificationNewTx message is sent when there is a new mempool transaction
	NotificationNewTx NotificationType = iota
)

type OnNewBlockFunc

type OnNewBlockFunc func(hash string, height uint32)

OnNewBlockFunc is used to send notification about a new block

type OnNewTxAddrFunc

type OnNewTxAddrFunc func(tx *Tx, desc AddressDescriptor)

OnNewTxAddrFunc is used to send notification about a new transaction/address

type OnNewTxFunc added in v0.3.4

type OnNewTxFunc func(tx *MempoolTx)

OnNewTxFunc is used to send notification about a new transaction/address

type Outpoint added in v0.2.0

type Outpoint struct {
	Txid string
	Vout int32
}

Outpoint is txid together with output (or input) index

type ProtoTransaction

type ProtoTransaction struct {
	Txid      []byte                       `protobuf:"bytes,1,opt,name=Txid,proto3" json:"Txid,omitempty"`
	Hex       []byte                       `protobuf:"bytes,2,opt,name=Hex,proto3" json:"Hex,omitempty"`
	Blocktime uint64                       `protobuf:"varint,3,opt,name=Blocktime,proto3" json:"Blocktime,omitempty"`
	Locktime  uint32                       `protobuf:"varint,4,opt,name=Locktime,proto3" json:"Locktime,omitempty"`
	Height    uint32                       `protobuf:"varint,5,opt,name=Height,proto3" json:"Height,omitempty"`
	Vin       []*ProtoTransaction_VinType  `protobuf:"bytes,6,rep,name=Vin,proto3" json:"Vin,omitempty"`
	Vout      []*ProtoTransaction_VoutType `protobuf:"bytes,7,rep,name=Vout,proto3" json:"Vout,omitempty"`
	Version   int32                        `protobuf:"varint,8,opt,name=Version,proto3" json:"Version,omitempty"`
	VSize     int64                        `protobuf:"varint,9,opt,name=VSize,proto3" json:"VSize,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoTransaction) Descriptor deprecated

func (*ProtoTransaction) Descriptor() ([]byte, []int)

Deprecated: Use ProtoTransaction.ProtoReflect.Descriptor instead.

func (*ProtoTransaction) GetBlocktime

func (x *ProtoTransaction) GetBlocktime() uint64

func (*ProtoTransaction) GetHeight

func (x *ProtoTransaction) GetHeight() uint32

func (*ProtoTransaction) GetHex

func (x *ProtoTransaction) GetHex() []byte

func (*ProtoTransaction) GetLocktime

func (x *ProtoTransaction) GetLocktime() uint32

func (*ProtoTransaction) GetTxid

func (x *ProtoTransaction) GetTxid() []byte

func (*ProtoTransaction) GetVSize added in v0.4.0

func (x *ProtoTransaction) GetVSize() int64

func (*ProtoTransaction) GetVersion added in v0.2.0

func (x *ProtoTransaction) GetVersion() int32

func (*ProtoTransaction) GetVin

func (*ProtoTransaction) GetVout

func (*ProtoTransaction) ProtoMessage

func (*ProtoTransaction) ProtoMessage()

func (*ProtoTransaction) ProtoReflect added in v0.4.0

func (x *ProtoTransaction) ProtoReflect() protoreflect.Message

func (*ProtoTransaction) Reset

func (x *ProtoTransaction) Reset()

func (*ProtoTransaction) String

func (x *ProtoTransaction) String() string

type ProtoTransaction_VinType

type ProtoTransaction_VinType struct {
	Coinbase     string   `protobuf:"bytes,1,opt,name=Coinbase,proto3" json:"Coinbase,omitempty"`
	Txid         []byte   `protobuf:"bytes,2,opt,name=Txid,proto3" json:"Txid,omitempty"`
	Vout         uint32   `protobuf:"varint,3,opt,name=Vout,proto3" json:"Vout,omitempty"`
	ScriptSigHex []byte   `protobuf:"bytes,4,opt,name=ScriptSigHex,proto3" json:"ScriptSigHex,omitempty"`
	Sequence     uint32   `protobuf:"varint,5,opt,name=Sequence,proto3" json:"Sequence,omitempty"`
	Addresses    []string `protobuf:"bytes,6,rep,name=Addresses,proto3" json:"Addresses,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoTransaction_VinType) Descriptor deprecated

func (*ProtoTransaction_VinType) Descriptor() ([]byte, []int)

Deprecated: Use ProtoTransaction_VinType.ProtoReflect.Descriptor instead.

func (*ProtoTransaction_VinType) GetAddresses

func (x *ProtoTransaction_VinType) GetAddresses() []string

func (*ProtoTransaction_VinType) GetCoinbase

func (x *ProtoTransaction_VinType) GetCoinbase() string

func (*ProtoTransaction_VinType) GetScriptSigHex

func (x *ProtoTransaction_VinType) GetScriptSigHex() []byte

func (*ProtoTransaction_VinType) GetSequence

func (x *ProtoTransaction_VinType) GetSequence() uint32

func (*ProtoTransaction_VinType) GetTxid

func (x *ProtoTransaction_VinType) GetTxid() []byte

func (*ProtoTransaction_VinType) GetVout

func (x *ProtoTransaction_VinType) GetVout() uint32

func (*ProtoTransaction_VinType) ProtoMessage

func (*ProtoTransaction_VinType) ProtoMessage()

func (*ProtoTransaction_VinType) ProtoReflect added in v0.4.0

func (x *ProtoTransaction_VinType) ProtoReflect() protoreflect.Message

func (*ProtoTransaction_VinType) Reset

func (x *ProtoTransaction_VinType) Reset()

func (*ProtoTransaction_VinType) String

func (x *ProtoTransaction_VinType) String() string

type ProtoTransaction_VoutType

type ProtoTransaction_VoutType struct {
	ValueSat        []byte   `protobuf:"bytes,1,opt,name=ValueSat,proto3" json:"ValueSat,omitempty"`
	N               uint32   `protobuf:"varint,2,opt,name=N,proto3" json:"N,omitempty"`
	ScriptPubKeyHex []byte   `protobuf:"bytes,3,opt,name=ScriptPubKeyHex,proto3" json:"ScriptPubKeyHex,omitempty"`
	Addresses       []string `protobuf:"bytes,4,rep,name=Addresses,proto3" json:"Addresses,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoTransaction_VoutType) Descriptor deprecated

func (*ProtoTransaction_VoutType) Descriptor() ([]byte, []int)

Deprecated: Use ProtoTransaction_VoutType.ProtoReflect.Descriptor instead.

func (*ProtoTransaction_VoutType) GetAddresses

func (x *ProtoTransaction_VoutType) GetAddresses() []string

func (*ProtoTransaction_VoutType) GetN

func (*ProtoTransaction_VoutType) GetScriptPubKeyHex

func (x *ProtoTransaction_VoutType) GetScriptPubKeyHex() []byte

func (*ProtoTransaction_VoutType) GetValueSat added in v0.1.0

func (x *ProtoTransaction_VoutType) GetValueSat() []byte

func (*ProtoTransaction_VoutType) ProtoMessage

func (*ProtoTransaction_VoutType) ProtoMessage()

func (*ProtoTransaction_VoutType) ProtoReflect added in v0.4.0

func (*ProtoTransaction_VoutType) Reset

func (x *ProtoTransaction_VoutType) Reset()

func (*ProtoTransaction_VoutType) String

func (x *ProtoTransaction_VoutType) String() string

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError defines rpc error returned by backend

func (*RPCError) Error

func (e *RPCError) Error() string

type RpcLog added in v0.4.0

type RpcLog struct {
	Address string   `json:"address"`
	Topics  []string `json:"topics"`
	Data    string   `json:"data"`
}

RpcLog is returned by eth_getLogs

type RpcReceipt added in v0.4.0

type RpcReceipt struct {
	GasUsed string    `json:"gasUsed"`
	Status  string    `json:"status"`
	Logs    []*RpcLog `json:"logs"`
}

RpcLog is returned by eth_getTransactionReceipt

type RpcTransaction added in v0.4.0

type RpcTransaction struct {
	AccountNonce     string `json:"nonce"`
	GasPrice         string `json:"gasPrice"`
	GasLimit         string `json:"gas"`
	To               string `json:"to"` // nil means contract creation
	Value            string `json:"value"`
	Payload          string `json:"input"`
	Hash             string `json:"hash"`
	BlockNumber      string `json:"blockNumber"`
	BlockHash        string `json:"blockHash,omitempty"`
	From             string `json:"from"`
	TransactionIndex string `json:"transactionIndex"`
}

RpcTransaction is returned by eth_getTransactionByHash

type ScriptPubKey

type ScriptPubKey struct {
	// Asm       string   `json:"asm"`
	Hex string `json:"hex,omitempty"`
	// Type      string   `json:"type"`
	Addresses []string `json:"addresses"`
}

ScriptPubKey contains data about output script

type ScriptSig

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

ScriptSig contains data about input script

type ScriptType added in v0.4.0

type ScriptType int

ScriptType - type of output script parsed from xpub (descriptor)

type TokenTransfer added in v0.4.0

type TokenTransfer struct {
	Type             TokenType
	Contract         string
	From             string
	To               string
	Value            big.Int
	MultiTokenValues []MultiTokenValue
}

TokenTransfer contains a single token transfer

type TokenTransfers added in v0.4.0

type TokenTransfers []*TokenTransfer

TokenTransfers is array of TokenTransfer

func (TokenTransfers) Len added in v0.4.0

func (a TokenTransfers) Len() int

func (TokenTransfers) Less added in v0.4.0

func (a TokenTransfers) Less(i, j int) bool

func (TokenTransfers) Swap added in v0.4.0

func (a TokenTransfers) Swap(i, j int)

type TokenType added in v0.4.0

type TokenType int

TokenType - type of token

type TokenTypeName added in v0.4.0

type TokenTypeName string

TokenTypeName specifies type of token

const (
	UnknownTokenType TokenTypeName = ""

	// XPUBAddressTokenType is address derived from xpub
	XPUBAddressTokenType TokenTypeName = "XPUBAddress"
)

Token types

const (
	ERC20TokenType   TokenTypeName = "ERC20"
	ERC771TokenType  TokenTypeName = "ERC721"
	ERC1155TokenType TokenTypeName = "ERC1155"
)

Ethereum token type names

type Tx

type Tx struct {
	Hex         string `json:"hex"`
	Txid        string `json:"txid"`
	Version     int32  `json:"version"`
	LockTime    uint32 `json:"locktime"`
	VSize       int64  `json:"vsize,omitempty"`
	Vin         []Vin  `json:"vin"`
	Vout        []Vout `json:"vout"`
	BlockHeight uint32 `json:"blockHeight,omitempty"`
	// BlockHash     string `json:"blockhash,omitempty"`
	Confirmations    uint32      `json:"confirmations,omitempty"`
	Time             int64       `json:"time,omitempty"`
	Blocktime        int64       `json:"blocktime,omitempty"`
	CoinSpecificData interface{} `json:"-"`
}

Tx is blockchain transaction unnecessary fields are commented out to avoid overhead

type Vin

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

Vin contains data about tx input

type Vout

type Vout struct {
	ValueSat     big.Int
	JsonValue    common.JSONNumber `json:"value"`
	N            uint32            `json:"n"`
	ScriptPubKey ScriptPubKey      `json:"scriptPubKey"`
}

Vout contains data about tx output

type XpubDescriptor added in v0.4.0

type XpubDescriptor struct {
	XpubDescriptor string // The whole descriptor
	Xpub           string // Xpub part of the descriptor
	Type           ScriptType
	Bip            string
	ChangeIndexes  []uint32
	ExtKey         interface{} // extended key parsed from xpub, usually of type *hdkeychain.ExtendedKey
}

XpubDescriptor contains parsed data from xpub descriptor

Directories

Path Synopsis
bch
btc
btg
dcr
eth
Package eth is a generated protocol buffer package.
Package eth is a generated protocol buffer package.
flo
grs
zec

Jump to

Keyboard shortcuts

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