chainntnfs: update interface to use pkScript for conf notifications

This commit is contained in:
Olaoluwa Osuntokun 2018-05-30 22:02:17 -07:00
parent 0f98030186
commit 6387c9e085

@ -58,10 +58,10 @@ var (
testAddr = addrPk.AddressPubKeyHash() testAddr = addrPk.AddressPubKeyHash()
) )
func getTestTxId(miner *rpctest.Harness) (*chainhash.Hash, error) { func getTestTxIdAndScript(miner *rpctest.Harness) (*chainhash.Hash, []byte, error) {
script, err := txscript.PayToAddrScript(testAddr) script, err := txscript.PayToAddrScript(testAddr)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
outputs := []*wire.TxOut{ outputs := []*wire.TxOut{
@ -70,7 +70,13 @@ func getTestTxId(miner *rpctest.Harness) (*chainhash.Hash, error) {
PkScript: script, PkScript: script,
}, },
} }
return miner.SendOutputs(outputs, 10)
txid, err := miner.SendOutputs(outputs, 10)
if err != nil {
return nil, nil, err
}
return txid, script, nil
} }
func waitForMempoolTx(r *rpctest.Harness, txid *chainhash.Hash) error { func waitForMempoolTx(r *rpctest.Harness, txid *chainhash.Hash) error {
@ -116,7 +122,7 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
// We're spending from a coinbase output here, so we use the dedicated // We're spending from a coinbase output here, so we use the dedicated
// function. // function.
txid, err := getTestTxId(miner) txid, pkScript, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -134,8 +140,9 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
// Now that we have a txid, register a confirmation notification with // Now that we have a txid, register a confirmation notification with
// the chainntfn source. // the chainntfn source.
numConfs := uint32(1) numConfs := uint32(1)
confIntent, err := notifier.RegisterConfirmationsNtfn(txid, numConfs, confIntent, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -184,7 +191,7 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
// //
// Again, we'll begin by creating a fresh transaction, so we can obtain // Again, we'll begin by creating a fresh transaction, so we can obtain
// a fresh txid. // a fresh txid.
txid, err := getTestTxId(miner) txid, pkScript, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test addr: %v", err) t.Fatalf("unable to create test addr: %v", err)
} }
@ -200,8 +207,9 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
} }
numConfs := uint32(6) numConfs := uint32(6)
confIntent, err := notifier.RegisterConfirmationsNtfn(txid, numConfs, confIntent, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -242,12 +250,13 @@ func testBatchConfirmationNotification(miner *rpctest.Harness,
// verify they're each notified at the proper number of confirmations // verify they're each notified at the proper number of confirmations
// below. // below.
for i, numConfs := range confSpread { for i, numConfs := range confSpread {
txid, err := getTestTxId(miner) txid, pkScript, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test addr: %v", err) t.Fatalf("unable to create test addr: %v", err)
} }
confIntent, err := notifier.RegisterConfirmationsNtfn(txid, confIntent, err := notifier.RegisterConfirmationsNtfn(
numConfs, uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -303,7 +312,7 @@ func testBatchConfirmationNotification(miner *rpctest.Harness,
func createSpendableOutput(miner *rpctest.Harness, func createSpendableOutput(miner *rpctest.Harness,
t *testing.T) (*wire.OutPoint, []byte) { t *testing.T) (*wire.OutPoint, []byte) {
txid, err := getTestTxId(miner) txid, _, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test addr: %v", err) t.Fatalf("unable to create test addr: %v", err)
} }
@ -554,7 +563,7 @@ func testMultiClientConfirmationNotification(miner *rpctest.Harness,
// We'd like to test the case of a multiple clients registered to // We'd like to test the case of a multiple clients registered to
// receive a confirmation notification for the same transaction. // receive a confirmation notification for the same transaction.
txid, err := getTestTxId(miner) txid, pkScript, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -578,8 +587,9 @@ func testMultiClientConfirmationNotification(miner *rpctest.Harness,
// Register for a conf notification for the above generated txid with // Register for a conf notification for the above generated txid with
// numConfsClients distinct clients. // numConfsClients distinct clients.
for i := 0; i < numConfsClients; i++ { for i := 0; i < numConfsClients; i++ {
confClient, err := notifier.RegisterConfirmationsNtfn(txid, confClient, err := notifier.RegisterConfirmationsNtfn(
numConfs, uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register for confirmation: %v", err) t.Fatalf("unable to register for confirmation: %v", err)
} }
@ -620,7 +630,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
// spending from a coinbase output here, so we use the dedicated // spending from a coinbase output here, so we use the dedicated
// function. // function.
txid3, err := getTestTxId(miner) txid3, pkScript3, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -640,7 +650,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
t.Fatalf("unable to generate block: %v", err) t.Fatalf("unable to generate block: %v", err)
} }
txid1, err := getTestTxId(miner) txid1, pkScript1, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -650,7 +660,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
t.Fatalf("tx not relayed to miner: %v", err) t.Fatalf("tx not relayed to miner: %v", err)
} }
txid2, err := getTestTxId(miner) txid2, pkScript2, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -675,8 +685,9 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
// which is included in the last block. The height hint is the height before // which is included in the last block. The height hint is the height before
// the block is included. This notification should fire immediately since // the block is included. This notification should fire immediately since
// only 1 confirmation is required. // only 1 confirmation is required.
ntfn1, err := notifier.RegisterConfirmationsNtfn(txid1, 1, ntfn1, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid1, pkScript1, 1, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -713,8 +724,9 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
// Register a confirmation notification for tx2, requiring 3 confirmations. // Register a confirmation notification for tx2, requiring 3 confirmations.
// This transaction is only partially confirmed, so the notification should // This transaction is only partially confirmed, so the notification should
// not fire yet. // not fire yet.
ntfn2, err := notifier.RegisterConfirmationsNtfn(txid2, 3, ntfn2, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid2, pkScript2, 3, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -740,8 +752,9 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
// Finally register a confirmation notification for tx3, requiring 1 // Finally register a confirmation notification for tx3, requiring 1
// confirmation. Ensure that conf notifications do not refire on txs // confirmation. Ensure that conf notifications do not refire on txs
// 1 or 2. // 1 or 2.
ntfn3, err := notifier.RegisterConfirmationsNtfn(txid3, 1, ntfn3, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight-1)) txid3, pkScript3, 1, uint32(currentHeight-1),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -775,7 +788,7 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
// Create a transaction to be notified about. We'll register for // Create a transaction to be notified about. We'll register for
// notifications on this transaction but won't be prompt in checking them // notifications on this transaction but won't be prompt in checking them
txid, err := getTestTxId(miner) txid, pkScript, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -798,8 +811,9 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
t.Fatalf("unable to generate blocks: %v", err) t.Fatalf("unable to generate blocks: %v", err)
} }
firstConfIntent, err := notifier.RegisterConfirmationsNtfn(txid, numConfs, firstConfIntent, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -812,7 +826,7 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
// Now make another transaction, just because we haven't checked to see // Now make another transaction, just because we haven't checked to see
// if the first transaction has confirmed doesn't mean that we shouldn't // if the first transaction has confirmed doesn't mean that we shouldn't
// be able to see if this transaction confirms first // be able to see if this transaction confirms first
txid, err = getTestTxId(miner) txid, pkScript, err = getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -829,9 +843,9 @@ func testLazyNtfnConsumer(miner *rpctest.Harness,
numConfs = 1 numConfs = 1
secondConfIntent, err := notifier.RegisterConfirmationsNtfn(txid, numConfs, secondConfIntent, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }
@ -1150,7 +1164,7 @@ func testReorgConf(miner *rpctest.Harness, notifier chainntnfs.ChainNotifier,
t.Fatalf("unable to remove node: %v", err) t.Fatalf("unable to remove node: %v", err)
} }
txid, err := getTestTxId(miner) txid, pkScript, err := getTestTxIdAndScript(miner)
if err != nil { if err != nil {
t.Fatalf("unable to create test tx: %v", err) t.Fatalf("unable to create test tx: %v", err)
} }
@ -1168,8 +1182,9 @@ func testReorgConf(miner *rpctest.Harness, notifier chainntnfs.ChainNotifier,
// Now that we have a txid, register a confirmation notification with // Now that we have a txid, register a confirmation notification with
// the chainntfn source. // the chainntfn source.
numConfs := uint32(2) numConfs := uint32(2)
confIntent, err := notifier.RegisterConfirmationsNtfn(txid, numConfs, confIntent, err := notifier.RegisterConfirmationsNtfn(
uint32(currentHeight)) txid, pkScript, numConfs, uint32(currentHeight),
)
if err != nil { if err != nil {
t.Fatalf("unable to register ntfn: %v", err) t.Fatalf("unable to register ntfn: %v", err)
} }