chainntnfs/neutrino: new neutrino API
This commit is contained in:
parent
146875ba65
commit
e0fd163096
@ -137,15 +137,12 @@ func (n *NeutrinoNotifier) Start() error {
|
|||||||
// start the auto-rescan from this point. Once a caller actually wishes
|
// start the auto-rescan from this point. Once a caller actually wishes
|
||||||
// to register a chain view, the rescan state will be rewound
|
// to register a chain view, the rescan state will be rewound
|
||||||
// accordingly.
|
// accordingly.
|
||||||
bestHeader, bestHeight, err := n.p2pNode.BlockHeaders.ChainTip()
|
startingPoint, err := n.p2pNode.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
startingPoint := &waddrmgr.BlockStamp{
|
|
||||||
Height: int32(bestHeight),
|
n.bestHeight = uint32(startingPoint.Height)
|
||||||
Hash: bestHeader.BlockHash(),
|
|
||||||
}
|
|
||||||
n.bestHeight = bestHeight
|
|
||||||
|
|
||||||
// Next, we'll create our set of rescan options. Currently it's
|
// Next, we'll create our set of rescan options. Currently it's
|
||||||
// required that a user MUST set an addr/outpoint/txid when creating a
|
// required that a user MUST set an addr/outpoint/txid when creating a
|
||||||
@ -165,7 +162,7 @@ func (n *NeutrinoNotifier) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n.txConfNotifier = chainntnfs.NewTxConfNotifier(
|
n.txConfNotifier = chainntnfs.NewTxConfNotifier(
|
||||||
bestHeight, reorgSafetyLimit, n.confirmHintCache,
|
n.bestHeight, reorgSafetyLimit, n.confirmHintCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
n.chainConn = &NeutrinoChainConn{n.p2pNode}
|
n.chainConn = &NeutrinoChainConn{n.p2pNode}
|
||||||
@ -476,20 +473,17 @@ out:
|
|||||||
"blocks, attempting to catch up")
|
"blocks, attempting to catch up")
|
||||||
}
|
}
|
||||||
|
|
||||||
header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(
|
hash, err := n.p2pNode.GetBlockHash(int64(n.bestHeight))
|
||||||
n.bestHeight,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chainntnfs.Log.Errorf("Unable to fetch header"+
|
chainntnfs.Log.Errorf("Unable to fetch block hash"+
|
||||||
"for height %d: %v", n.bestHeight, err)
|
"for height %d: %v", n.bestHeight, err)
|
||||||
n.heightMtx.Unlock()
|
n.heightMtx.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
hash := header.BlockHash()
|
|
||||||
notifierBestBlock := chainntnfs.BlockEpoch{
|
notifierBestBlock := chainntnfs.BlockEpoch{
|
||||||
Height: int32(n.bestHeight),
|
Height: int32(n.bestHeight),
|
||||||
Hash: &hash,
|
Hash: hash,
|
||||||
}
|
}
|
||||||
newBestBlock, err := chainntnfs.RewindChain(
|
newBestBlock, err := chainntnfs.RewindChain(
|
||||||
n.chainConn, n.txConfNotifier, notifierBestBlock,
|
n.chainConn, n.txConfNotifier, notifierBestBlock,
|
||||||
@ -536,17 +530,16 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
|
|
||||||
// First, we'll fetch the block header for this height so we
|
// First, we'll fetch the block header for this height so we
|
||||||
// can compute the current block hash.
|
// can compute the current block hash.
|
||||||
header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(scanHeight)
|
blockHash, err := n.p2pNode.GetBlockHash(int64(scanHeight))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to get header for height=%v: %v",
|
return nil, fmt.Errorf("unable to get header for height=%v: %v",
|
||||||
scanHeight, err)
|
scanHeight, err)
|
||||||
}
|
}
|
||||||
blockHash := header.BlockHash()
|
|
||||||
|
|
||||||
// With the hash computed, we can now fetch the basic filter
|
// With the hash computed, we can now fetch the basic filter
|
||||||
// for this height.
|
// for this height.
|
||||||
regFilter, err := n.p2pNode.GetCFilter(
|
regFilter, err := n.p2pNode.GetCFilter(
|
||||||
blockHash, wire.GCSFilterRegular,
|
*blockHash, wire.GCSFilterRegular,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to retrieve regular filter for "+
|
return nil, fmt.Errorf("unable to retrieve regular filter for "+
|
||||||
@ -562,7 +555,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
|
|
||||||
// In the case that the filter exists, we'll attempt to see if
|
// In the case that the filter exists, we'll attempt to see if
|
||||||
// any element in it matches our target public key script.
|
// any element in it matches our target public key script.
|
||||||
key := builder.DeriveKey(&blockHash)
|
key := builder.DeriveKey(blockHash)
|
||||||
match, err := regFilter.Match(key, pkScript)
|
match, err := regFilter.Match(key, pkScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to query filter: %v", err)
|
return nil, fmt.Errorf("unable to query filter: %v", err)
|
||||||
@ -577,7 +570,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
// In the case that we do have a match, we'll fetch the block
|
// In the case that we do have a match, we'll fetch the block
|
||||||
// from the network so we can find the positional data required
|
// from the network so we can find the positional data required
|
||||||
// to send the proper response.
|
// to send the proper response.
|
||||||
block, err := n.p2pNode.GetBlock(blockHash)
|
block, err := n.p2pNode.GetBlock(*blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to get block from network: %v", err)
|
return nil, fmt.Errorf("unable to get block from network: %v", err)
|
||||||
}
|
}
|
||||||
@ -585,7 +578,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
txHash := tx.Hash()
|
txHash := tx.Hash()
|
||||||
if txHash.IsEqual(targetHash) {
|
if txHash.IsEqual(targetHash) {
|
||||||
confDetails := chainntnfs.TxConfirmation{
|
confDetails := chainntnfs.TxConfirmation{
|
||||||
BlockHash: &blockHash,
|
BlockHash: blockHash,
|
||||||
BlockHeight: scanHeight,
|
BlockHeight: scanHeight,
|
||||||
TxIndex: uint32(j),
|
TxIndex: uint32(j),
|
||||||
}
|
}
|
||||||
@ -1085,11 +1078,7 @@ type NeutrinoChainConn struct {
|
|||||||
|
|
||||||
// GetBlockHeader returns the block header for a hash.
|
// GetBlockHeader returns the block header for a hash.
|
||||||
func (n *NeutrinoChainConn) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
|
func (n *NeutrinoChainConn) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
|
||||||
header, _, err := n.p2pNode.BlockHeaders.FetchHeader(blockHash)
|
return n.p2pNode.GetBlockHeader(blockHash)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return header, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockHeaderVerbose returns a verbose block header result for a hash. This
|
// GetBlockHeaderVerbose returns a verbose block header result for a hash. This
|
||||||
@ -1097,7 +1086,7 @@ func (n *NeutrinoChainConn) GetBlockHeader(blockHash *chainhash.Hash) (*wire.Blo
|
|||||||
func (n *NeutrinoChainConn) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (
|
func (n *NeutrinoChainConn) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (
|
||||||
*btcjson.GetBlockHeaderVerboseResult, error) {
|
*btcjson.GetBlockHeaderVerboseResult, error) {
|
||||||
|
|
||||||
_, height, err := n.p2pNode.BlockHeaders.FetchHeader(blockHash)
|
height, err := n.p2pNode.GetBlockHeight(blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1107,10 +1096,5 @@ func (n *NeutrinoChainConn) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (
|
|||||||
|
|
||||||
// GetBlockHash returns the hash from a block height.
|
// GetBlockHash returns the hash from a block height.
|
||||||
func (n *NeutrinoChainConn) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
|
func (n *NeutrinoChainConn) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
|
||||||
header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(uint32(blockHeight))
|
return n.p2pNode.GetBlockHash(blockHeight)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hash := header.BlockHash()
|
|
||||||
return &hash, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user