2017-05-16 05:20:44 +02:00
|
|
|
package chain
|
|
|
|
|
|
|
|
import (
|
2017-05-20 01:45:38 +02:00
|
|
|
"time"
|
|
|
|
|
2021-08-26 00:58:28 +02:00
|
|
|
"github.com/lbryio/lbcd/chaincfg/chainhash"
|
|
|
|
"github.com/lbryio/lbcd/wire"
|
|
|
|
btcutil "github.com/lbryio/lbcutil"
|
|
|
|
"github.com/lbryio/lbcwallet/waddrmgr"
|
|
|
|
"github.com/lbryio/lbcwallet/wtxmgr"
|
2017-05-16 05:20:44 +02:00
|
|
|
)
|
|
|
|
|
2019-05-14 22:17:58 +02:00
|
|
|
// isCurrentDelta is the delta duration we'll use from the present time to
|
|
|
|
// determine if a backend is considered "current", i.e. synced to the tip of
|
|
|
|
// the chain.
|
|
|
|
const isCurrentDelta = 2 * time.Hour
|
|
|
|
|
2017-11-10 01:13:40 +01:00
|
|
|
// BackEnds returns a list of the available back ends.
|
|
|
|
// TODO: Refactor each into a driver and use dynamic registration.
|
|
|
|
func BackEnds() []string {
|
|
|
|
return []string{
|
2021-08-25 23:03:05 +02:00
|
|
|
"lbrycrd",
|
|
|
|
"lbcd",
|
2017-11-10 01:13:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-16 05:20:44 +02:00
|
|
|
// Interface allows more than one backing blockchain source, such as a
|
2022-08-05 06:38:43 +02:00
|
|
|
//
|
|
|
|
// RPC chain server, or an SPV library, as long as we write a driver for
|
|
|
|
//
|
2017-05-16 05:20:44 +02:00
|
|
|
// it.
|
|
|
|
type Interface interface {
|
|
|
|
Start() error
|
|
|
|
Stop()
|
|
|
|
WaitForShutdown()
|
|
|
|
GetBestBlock() (*chainhash.Hash, int32, error)
|
|
|
|
GetBlock(*chainhash.Hash) (*wire.MsgBlock, error)
|
2017-07-12 01:13:10 +02:00
|
|
|
GetBlockHash(int64) (*chainhash.Hash, error)
|
2017-09-20 22:33:12 +02:00
|
|
|
GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error)
|
2019-05-14 22:17:58 +02:00
|
|
|
IsCurrent() bool
|
2018-03-21 02:03:11 +01:00
|
|
|
FilterBlocks(*FilterBlocksRequest) (*FilterBlocksResponse, error)
|
2017-05-16 05:20:44 +02:00
|
|
|
BlockStamp() (*waddrmgr.BlockStamp, error)
|
|
|
|
SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash, error)
|
2018-06-15 07:01:50 +02:00
|
|
|
Rescan(*chainhash.Hash, []btcutil.Address, map[wire.OutPoint]btcutil.Address) error
|
2017-05-16 05:20:44 +02:00
|
|
|
NotifyReceived([]btcutil.Address) error
|
|
|
|
NotifyBlocks() error
|
|
|
|
Notifications() <-chan interface{}
|
2017-11-10 01:13:40 +01:00
|
|
|
BackEnd() string
|
2017-05-16 05:20:44 +02:00
|
|
|
}
|
2017-05-20 01:45:38 +02:00
|
|
|
|
|
|
|
// Notification types. These are defined here and processed from from reading
|
|
|
|
// a notificationChan to avoid handling these notifications directly in
|
2017-08-25 02:30:43 +02:00
|
|
|
// rpcclient callbacks, which isn't very Go-like and doesn't allow
|
2017-05-20 01:45:38 +02:00
|
|
|
// blocking client calls.
|
|
|
|
type (
|
|
|
|
// ClientConnected is a notification for when a client connection is
|
|
|
|
// opened or reestablished to the chain server.
|
|
|
|
ClientConnected struct{}
|
|
|
|
|
|
|
|
// BlockConnected is a notification for a newly-attached block to the
|
|
|
|
// best chain.
|
|
|
|
BlockConnected wtxmgr.BlockMeta
|
|
|
|
|
2017-05-21 04:36:40 +02:00
|
|
|
// FilteredBlockConnected is an alternate notification that contains
|
|
|
|
// both block and relevant transaction information in one struct, which
|
|
|
|
// allows atomic updates.
|
|
|
|
FilteredBlockConnected struct {
|
|
|
|
Block *wtxmgr.BlockMeta
|
|
|
|
RelevantTxs []*wtxmgr.TxRecord
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:03:11 +01:00
|
|
|
// FilterBlocksRequest specifies a range of blocks and the set of
|
|
|
|
// internal and external addresses of interest, indexed by corresponding
|
|
|
|
// scoped-index of the child address. A global set of watched outpoints
|
|
|
|
// is also included to monitor for spends.
|
|
|
|
FilterBlocksRequest struct {
|
|
|
|
Blocks []wtxmgr.BlockMeta
|
|
|
|
ExternalAddrs map[waddrmgr.ScopedIndex]btcutil.Address
|
|
|
|
InternalAddrs map[waddrmgr.ScopedIndex]btcutil.Address
|
2018-06-15 07:03:31 +02:00
|
|
|
WatchedOutPoints map[wire.OutPoint]btcutil.Address
|
2018-03-21 02:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FilterBlocksResponse reports the set of all internal and external
|
|
|
|
// addresses found in response to a FilterBlockRequest, any outpoints
|
|
|
|
// found that correspond to those addresses, as well as the relevant
|
|
|
|
// transactions that can modify the wallet's balance. The index of the
|
|
|
|
// block within the FilterBlocksRequest is returned, such that the
|
|
|
|
// caller can reinitiate a request for the subsequent block after
|
|
|
|
// updating the addresses of interest.
|
|
|
|
FilterBlocksResponse struct {
|
|
|
|
BatchIndex uint32
|
|
|
|
BlockMeta wtxmgr.BlockMeta
|
|
|
|
FoundExternalAddrs map[waddrmgr.KeyScope]map[uint32]struct{}
|
|
|
|
FoundInternalAddrs map[waddrmgr.KeyScope]map[uint32]struct{}
|
2018-06-15 07:03:31 +02:00
|
|
|
FoundOutPoints map[wire.OutPoint]btcutil.Address
|
2018-03-21 02:03:11 +01:00
|
|
|
RelevantTxns []*wire.MsgTx
|
|
|
|
}
|
|
|
|
|
2017-05-20 01:45:38 +02:00
|
|
|
// BlockDisconnected is a notifcation that the block described by the
|
|
|
|
// BlockStamp was reorganized out of the best chain.
|
|
|
|
BlockDisconnected wtxmgr.BlockMeta
|
|
|
|
|
|
|
|
// RelevantTx is a notification for a transaction which spends wallet
|
|
|
|
// inputs or pays to a watched address.
|
|
|
|
RelevantTx struct {
|
|
|
|
TxRecord *wtxmgr.TxRecord
|
|
|
|
Block *wtxmgr.BlockMeta // nil if unmined
|
|
|
|
}
|
|
|
|
|
|
|
|
// RescanProgress is a notification describing the current status
|
|
|
|
// of an in-progress rescan.
|
|
|
|
RescanProgress struct {
|
|
|
|
Hash *chainhash.Hash
|
|
|
|
Height int32
|
|
|
|
Time time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
// RescanFinished is a notification that a previous rescan request
|
|
|
|
// has finished.
|
|
|
|
RescanFinished struct {
|
|
|
|
Hash *chainhash.Hash
|
|
|
|
Height int32
|
|
|
|
Time time.Time
|
|
|
|
}
|
|
|
|
)
|