Documentation ¶
Overview ¶
Package observer implements the Bitcoin chain observer
Index ¶
- Constants
- func GetSenderAddressByVin(rpcClient interfaces.BTCRPCClient, vin btcjson.Vin, net *chaincfg.Params) (string, error)
- type BTCBlockNHeader
- type BTCInboundEvent
- type Logger
- type Observer
- func (ob *Observer) BtcClient() interfaces.BTCRPCClient
- func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string, vote bool) (string, error)
- func (ob *Observer) ConfirmationsThreshold(amount *big.Int) int64
- func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent) bool
- func (ob *Observer) FetchUTXOs(ctx context.Context) error
- func (ob *Observer) GetBlockByNumberCached(blockNumber int64) (*BTCBlockNHeader, error)
- func (ob *Observer) GetChainParams() observertypes.ChainParams
- func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inbound *BTCInboundEvent) *crosschaintypes.MsgVoteInbound
- func (ob *Observer) GetPendingNonce() uint64
- func (ob *Observer) GetTxID(nonce uint64) string
- func (ob *Observer) IsOutboundProcessed(ctx context.Context, cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger) (bool, bool, error)
- func (ob *Observer) LoadBroadcastedTxMap() error
- func (ob *Observer) LoadDB(dbPath string) error
- func (ob *Observer) LoadLastBlockScanned() error
- func (ob *Observer) ObserveInbound(ctx context.Context) error
- func (ob *Observer) PostGasPrice(ctx context.Context) error
- func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error
- func (ob *Observer) SaveBroadcastedTx(txHash string, nonce uint64)
- func (ob *Observer) SelectUTXOs(ctx context.Context, amount float64, utxosToSpend uint16, nonce uint64, ...) ([]btcjson.ListUnspentResult, float64, uint16, float64, error)
- func (ob *Observer) SetChainParams(params observertypes.ChainParams)
- func (ob *Observer) Start(ctx context.Context)
- func (ob *Observer) WatchGasPrice(ctx context.Context) error
- func (ob *Observer) WatchInbound(ctx context.Context) error
- func (ob *Observer) WatchInboundTracker(ctx context.Context) error
- func (ob *Observer) WatchOutbound(ctx context.Context) error
- func (ob *Observer) WatchRPCStatus(_ context.Context) error
- func (ob *Observer) WatchUTXOs(ctx context.Context) error
- func (ob *Observer) WithBtcClient(client interfaces.BTCRPCClient)
Constants ¶
const ( // RegnetStartBlock is the hardcoded start block for regnet RegnetStartBlock = 100 // BigValueSats contains the threshold to determine a big value in Bitcoin represents 2 BTC BigValueSats = 200000000 // BigValueConfirmationCount represents the number of confirmation necessary for bigger values: 6 confirmations BigValueConfirmationCount = 6 )
Variables ¶
This section is empty.
Functions ¶
func GetSenderAddressByVin ¶
func GetSenderAddressByVin(rpcClient interfaces.BTCRPCClient, vin btcjson.Vin, net *chaincfg.Params) (string, error)
GetSenderAddressByVin get the sender address from the previous transaction TODO(revamp): move in upper package to separate file (e.g., rpc.go)
Types ¶
type BTCBlockNHeader ¶
type BTCBlockNHeader struct { Header *wire.BlockHeader Block *btcjson.GetBlockVerboseTxResult }
BTCBlockNHeader contains bitcoin block and the header
type BTCInboundEvent ¶
type BTCInboundEvent struct { // FromAddress is the first input address FromAddress string // ToAddress is the TSS address ToAddress string // Value is the amount of BTC Value float64 MemoBytes []byte BlockNumber uint64 TxHash string }
BTCInboundEvent represents an incoming transaction event TODO(revamp): Move to inbound
func FilterAndParseIncomingTx ¶
func FilterAndParseIncomingTx( rpcClient interfaces.BTCRPCClient, txs []btcjson.TxRawResult, blockNumber uint64, tssAddress string, logger zerolog.Logger, netParams *chaincfg.Params, depositorFee float64, ) ([]*BTCInboundEvent, error)
FilterAndParseIncomingTx given txs list returned by the "getblock 2" RPC command, return the txs that are relevant to us relevant tx must have the following vouts as the first two vouts: vout0: p2wpkh to the TSS address (targetAddress) vout1: OP_RETURN memo, base64 encoded
func GetBtcEvent ¶
func GetBtcEvent( rpcClient interfaces.BTCRPCClient, tx btcjson.TxRawResult, tssAddress string, blockNumber uint64, logger zerolog.Logger, netParams *chaincfg.Params, depositorFee float64, ) (*BTCInboundEvent, error)
GetBtcEvent either returns a valid BTCInboundEvent or nil Note: the caller should retry the tx on error (e.g., GetSenderAddressByVin failed) TODO(revamp): simplify this function
type Logger ¶
type Logger struct { // base.Logger contains a list of base observer loggers base.ObserverLogger // UTXOs is the logger for UTXOs management UTXOs zerolog.Logger }
Logger contains list of loggers used by Bitcoin chain observer
type Observer ¶
type Observer struct { // base.Observer implements the base chain observer base.Observer // contains filtered or unexported fields }
Observer is the Bitcoin chain observer
func NewObserver ¶
func NewObserver( chain chains.Chain, btcClient interfaces.BTCRPCClient, chainParams observertypes.ChainParams, zetacoreClient interfaces.ZetacoreClient, tss interfaces.TSSSigner, dbpath string, logger base.Logger, ts *metrics.TelemetryServer, ) (*Observer, error)
NewObserver returns a new Bitcoin chain observer
func (*Observer) BtcClient ¶
func (ob *Observer) BtcClient() interfaces.BTCRPCClient
BtcClient returns the btc client
func (*Observer) CheckReceiptForBtcTxHash ¶
func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string, vote bool) (string, error)
CheckReceiptForBtcTxHash checks the receipt for a btc tx hash
func (*Observer) ConfirmationsThreshold ¶
ConfirmationsThreshold returns number of required Bitcoin confirmations depending on sent BTC amount.
func (*Observer) DoesInboundContainsRestrictedAddress ¶
func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent) bool
DoesInboundContainsRestrictedAddress returns true if the inbound contains restricted addresses TODO(revamp): move all compliance related functions in a specific file
func (*Observer) FetchUTXOs ¶
FetchUTXOs fetches TSS-owned UTXOs from the Bitcoin node TODO(revamp): move to UTXO file
func (*Observer) GetBlockByNumberCached ¶
func (ob *Observer) GetBlockByNumberCached(blockNumber int64) (*BTCBlockNHeader, error)
GetBlockByNumberCached gets cached block (and header) by block number
func (*Observer) GetChainParams ¶
func (ob *Observer) GetChainParams() observertypes.ChainParams
GetChainParams returns the chain params for the observer Note: chain params is accessed concurrently
func (*Observer) GetInboundVoteMessageFromBtcEvent ¶
func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inbound *BTCInboundEvent) *crosschaintypes.MsgVoteInbound
GetInboundVoteMessageFromBtcEvent converts a BTCInboundEvent to a MsgVoteInbound to enable voting on the inbound on zetacore
func (*Observer) GetPendingNonce ¶
GetPendingNonce returns the artificial pending nonce Note: pending nonce is accessed concurrently
func (*Observer) IsOutboundProcessed ¶
func (ob *Observer) IsOutboundProcessed( ctx context.Context, cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger, ) (bool, bool, error)
IsOutboundProcessed returns isIncluded(or inMempool), isConfirmed, Error TODO(revamp): rename as it vote the outbound and doesn't only check if outbound is processed
func (*Observer) LoadBroadcastedTxMap ¶
LoadBroadcastedTxMap loads broadcasted transactions from the database
func (*Observer) LoadLastBlockScanned ¶
LoadLastBlockScanned loads the last scanned block from the database
func (*Observer) ObserveInbound ¶
ObserveInbound observes the Bitcoin chain for inbounds and post votes to zetacore TODO(revamp): simplify this function into smaller functions
func (*Observer) PostGasPrice ¶
PostGasPrice posts gas price to zetacore TODO(revamp): move to gas price file
func (*Observer) ProcessInboundTrackers ¶
ProcessInboundTrackers processes inbound trackers TODO(revamp): move inbound tracker logic in a specific file
func (*Observer) SaveBroadcastedTx ¶
SaveBroadcastedTx saves successfully broadcasted transaction TODO(revamp): move to db file
func (*Observer) SelectUTXOs ¶
func (ob *Observer) SelectUTXOs( ctx context.Context, amount float64, utxosToSpend uint16, nonce uint64, consolidateRank uint16, test bool, ) ([]btcjson.ListUnspentResult, float64, uint16, float64, error)
SelectUTXOs selects a sublist of utxos to be used as inputs.
Parameters:
- amount: The desired minimum total value of the selected UTXOs.
- utxos2Spend: The maximum number of UTXOs to spend.
- nonce: The nonce of the outbound transaction.
- consolidateRank: The rank below which UTXOs will be consolidated.
- test: true for unit test only.
Returns:
- a sublist (includes previous nonce-mark) of UTXOs or an error if the qualifying sublist cannot be found.
- the total value of the selected UTXOs.
- the number of consolidated UTXOs.
- the total value of the consolidated UTXOs.
TODO(revamp): move to utxo file
func (*Observer) SetChainParams ¶
func (ob *Observer) SetChainParams(params observertypes.ChainParams)
SetChainParams sets the chain params for the observer Note: chain params is accessed concurrently
func (*Observer) WatchGasPrice ¶
WatchGasPrice watches Bitcoin chain for gas rate and post to zetacore TODO(revamp): move ticker related functions to a specific file TODO(revamp): move inner logic in a separate function
func (*Observer) WatchInbound ¶
WatchInbound watches Bitcoin chain for inbounds on a ticker It starts a ticker and run ObserveInbound TODO(revamp): move all ticker related methods in the same file
func (*Observer) WatchInboundTracker ¶
WatchInboundTracker watches zetacore for bitcoin inbound trackers TODO(revamp): move all ticker related methods in the same file
func (*Observer) WatchOutbound ¶
WatchOutbound watches Bitcoin chain for outgoing txs status TODO(revamp): move ticker functions to a specific file TODO(revamp): move into a separate package
func (*Observer) WatchRPCStatus ¶
WatchRPCStatus watches the RPC status of the Bitcoin chain TODO(revamp): move ticker related functions to a specific file TODO(revamp): move inner logic in a separate function
func (*Observer) WatchUTXOs ¶
WatchUTXOs watches bitcoin chain for UTXOs owned by the TSS address TODO(revamp): move ticker related functions to a specific file
func (*Observer) WithBtcClient ¶
func (ob *Observer) WithBtcClient(client interfaces.BTCRPCClient)
WithBtcClient attaches a new btc client to the observer