chainntnfs/neutrinonotify: update neutrino backend to use new API

In this commit, we update the neutrino backend for the ChainNotifier to
use the new API which requires that callers pass the outpoint along with
the pkScript to be notified of any spends.
This commit is contained in:
Olaoluwa Osuntokun
2018-07-17 19:03:26 -07:00
parent 6781b17056
commit f87b1a94c5

View File

@@ -133,7 +133,7 @@ func (n *NeutrinoNotifier) Start() error {
// 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
// rescan. To get around this, we'll add a "zero" outpoint, that won't // rescan. To get around this, we'll add a "zero" outpoint, that won't
// actually be matched. // actually be matched.
var zeroHash chainhash.Hash var zeroInput neutrino.InputWithScript
rescanOptions := []neutrino.RescanOption{ rescanOptions := []neutrino.RescanOption{
neutrino.StartBlock(startingPoint), neutrino.StartBlock(startingPoint),
neutrino.QuitChan(n.quit), neutrino.QuitChan(n.quit),
@@ -143,11 +143,12 @@ func (n *NeutrinoNotifier) Start() error {
OnFilteredBlockDisconnected: n.onFilteredBlockDisconnected, OnFilteredBlockDisconnected: n.onFilteredBlockDisconnected,
}, },
), ),
neutrino.WatchTxIDs(zeroHash), neutrino.WatchInputs(zeroInput),
} }
n.txConfNotifier = chainntnfs.NewTxConfNotifier( n.txConfNotifier = chainntnfs.NewTxConfNotifier(
bestHeight, reorgSafetyLimit) bestHeight, reorgSafetyLimit,
)
// Finally, we'll create our rescan struct, start it, and launch all // Finally, we'll create our rescan struct, start it, and launch all
// the goroutines we need to operate this ChainNotifier instance. // the goroutines we need to operate this ChainNotifier instance.
@@ -599,7 +600,7 @@ type spendCancel struct {
// target outpoint has been detected, the details of the spending event will be // target outpoint has been detected, the details of the spending event will be
// sent across the 'Spend' channel. // sent across the 'Spend' channel.
func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
heightHint uint32) (*chainntnfs.SpendEvent, error) { pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
n.heightMtx.RLock() n.heightMtx.RLock()
currentHeight := n.bestHeight currentHeight := n.bestHeight
@@ -658,10 +659,15 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
break break
} }
inputToWatch := neutrino.InputWithScript{
OutPoint: *outpoint,
PkScript: pkScript,
}
// Before sending off the notification request, we'll attempt to see if // Before sending off the notification request, we'll attempt to see if
// this output is still spent or not at this point in the chain. // this output is still spent or not at this point in the chain.
spendReport, err := n.p2pNode.GetUtxo( spendReport, err := n.p2pNode.GetUtxo(
neutrino.WatchOutPoints(*outpoint), neutrino.WatchInputs(inputToWatch),
neutrino.StartBlock(&waddrmgr.BlockStamp{ neutrino.StartBlock(&waddrmgr.BlockStamp{
Height: int32(heightHint), Height: int32(heightHint),
}), }),
@@ -697,7 +703,7 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
// If the output is still unspent, then we'll update our rescan's // If the output is still unspent, then we'll update our rescan's
// filter, and send the request to the dispatcher goroutine. // filter, and send the request to the dispatcher goroutine.
rescanUpdate := []neutrino.UpdateOption{ rescanUpdate := []neutrino.UpdateOption{
neutrino.AddOutPoints(*outpoint), neutrino.AddInputs(inputToWatch),
neutrino.Rewind(currentHeight), neutrino.Rewind(currentHeight),
} }