diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index ca1bd214..eab0a5ea 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -369,15 +369,22 @@ out: // the notification subscriber. if clients, ok := b.spendNotifications[prevOut]; ok { spenderSha := newSpend.tx.Hash() - for _, ntfn := range clients { - spendDetails := &chainntnfs.SpendDetail{ - SpentOutPoint: ntfn.targetOutpoint, - SpenderTxHash: spenderSha, - // TODO(roasbeef): copy tx? - SpendingTx: spendingTx.MsgTx(), - SpenderInputIndex: uint32(i), - } + spendDetails := &chainntnfs.SpendDetail{ + SpentOutPoint: &prevOut, + SpenderTxHash: spenderSha, + SpendingTx: spendingTx.MsgTx(), + SpenderInputIndex: uint32(i), + } + // TODO(roasbeef): after change to + // loadfilter, only notify on block + // inclusion? + if newSpend.details != nil { + spendDetails.SpendingHeight = newSpend.details.Height + } else { + spendDetails.SpendingHeight = currentHeight + } + for _, ntfn := range clients { chainntnfs.Log.Infof("Dispatching "+ "spend notification for "+ "outpoint=%v", ntfn.targetOutpoint) diff --git a/chainntnfs/interface_test.go b/chainntnfs/interface_test.go index 0d2fadfb..045510f3 100644 --- a/chainntnfs/interface_test.go +++ b/chainntnfs/interface_test.go @@ -287,6 +287,11 @@ func testSpendNotification(miner *rpctest.Harness, t.Fatalf("unable to brodacst tx: %v", err) } + _, currentHeight, err = miner.Node.GetBestBlock() + if err != nil { + t.Fatalf("unable to get current height: %v", err) + } + // Now we mine a single block, which should include our spend. The // notification should also be sent off. if _, err := miner.Node.Generate(1); err != nil { @@ -308,7 +313,7 @@ func testSpendNotification(miner *rpctest.Harness, case ntfn := <-spentNtfn: // We've received the spend nftn. So now verify all the // fields have been set properly. - if ntfn.SpentOutPoint != outpoint { + if *ntfn.SpentOutPoint != *outpoint { t.Fatalf("ntfn includes wrong output, reports "+ "%v instead of %v", ntfn.SpentOutPoint, outpoint) @@ -323,6 +328,11 @@ func testSpendNotification(miner *rpctest.Harness, "index, reports %v, should be %v", ntfn.SpenderInputIndex, 0) } + if ntfn.SpendingHeight != currentHeight { + t.Fatalf("ntfn has wrong spending height: "+ + "expected %v, got %v", currentHeight, + ntfn.SpendingHeight) + } case <-time.After(2 * time.Second): t.Fatalf("spend ntfn never received") }