chainntnfs/interface: stricter conf dispatch for txindex
This commit is contained in:
parent
50f7f7f1b7
commit
d5da18827e
@ -628,6 +628,28 @@ func ConfDetailsFromTxIndex(chainConn TxIndexConn, r ConfRequest,
|
|||||||
r.TxID, err)
|
r.TxID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deserialize the hex-encoded transaction to include it in the
|
||||||
|
// confirmation details.
|
||||||
|
rawTx, err := hex.DecodeString(rawTxRes.Hex)
|
||||||
|
if err != nil {
|
||||||
|
return nil, TxNotFoundIndex,
|
||||||
|
fmt.Errorf("unable to deserialize tx %v: %v",
|
||||||
|
r.TxID, err)
|
||||||
|
}
|
||||||
|
var tx wire.MsgTx
|
||||||
|
if err := tx.Deserialize(bytes.NewReader(rawTx)); err != nil {
|
||||||
|
return nil, TxNotFoundIndex,
|
||||||
|
fmt.Errorf("unable to deserialize tx %v: %v",
|
||||||
|
r.TxID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the transaction matches our confirmation request in terms of
|
||||||
|
// txid and pkscript.
|
||||||
|
if !r.MatchesTx(&tx) {
|
||||||
|
return nil, TxNotFoundIndex,
|
||||||
|
fmt.Errorf("unable to locate tx %v", r.TxID)
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we actually retrieved a transaction that is included in a
|
// Make sure we actually retrieved a transaction that is included in a
|
||||||
// block. If not, the transaction must be unconfirmed (in the mempool),
|
// block. If not, the transaction must be unconfirmed (in the mempool),
|
||||||
// and we'll return TxFoundMempool together with a nil TxConfirmation.
|
// and we'll return TxFoundMempool together with a nil TxConfirmation.
|
||||||
@ -659,21 +681,6 @@ func ConfDetailsFromTxIndex(chainConn TxIndexConn, r ConfRequest,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deserialize the hex-encoded transaction to include it in the
|
|
||||||
// confirmation details.
|
|
||||||
rawTx, err := hex.DecodeString(rawTxRes.Hex)
|
|
||||||
if err != nil {
|
|
||||||
return nil, TxNotFoundIndex,
|
|
||||||
fmt.Errorf("unable to deserialize tx %v: %v",
|
|
||||||
txHash, err)
|
|
||||||
}
|
|
||||||
var tx wire.MsgTx
|
|
||||||
if err := tx.Deserialize(bytes.NewReader(rawTx)); err != nil {
|
|
||||||
return nil, TxNotFoundIndex,
|
|
||||||
fmt.Errorf("unable to deserialize tx %v: %v",
|
|
||||||
txHash, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &TxConfirmation{
|
return &TxConfirmation{
|
||||||
Tx: &tx,
|
Tx: &tx,
|
||||||
BlockHash: blockHash,
|
BlockHash: blockHash,
|
||||||
|
@ -660,12 +660,29 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
|
|||||||
t.Fatalf("unable to register ntfn: %v", err)
|
t.Fatalf("unable to register ntfn: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We'll also register for a confirmation notification with the pkscript
|
||||||
|
// of a different transaction. This notification shouldn't fire since we
|
||||||
|
// match on both txid and pkscript.
|
||||||
|
var ntfn4 *chainntnfs.ConfirmationEvent
|
||||||
|
ntfn4, err = notifier.RegisterConfirmationsNtfn(
|
||||||
|
txid3, pkScript2, 1, uint32(currentHeight-1),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to register ntfn: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ntfn3.Confirmed:
|
case <-ntfn3.Confirmed:
|
||||||
case <-time.After(10 * time.Second):
|
case <-time.After(10 * time.Second):
|
||||||
t.Fatalf("confirmation notification never received")
|
t.Fatalf("confirmation notification never received")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ntfn4.Confirmed:
|
||||||
|
t.Fatalf("confirmation notification received")
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user