mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-96] Convert txid to pointer where possible (#279)
* [NOD-96] Convert txid to pointer where possible * [NOD-96] Make msgTx.TxID return a pointer * [NOD-96] observedTransaction.id -> observedTransaction.txID
This commit is contained in:
parent
1cc479dbf8
commit
ea5e18ea11
@ -274,7 +274,7 @@ func TestCalcSequenceLock(t *testing.T) {
|
||||
// output.
|
||||
unConfTx := wire.NewNativeMsgTx(wire.TxVersion, nil, []*wire.TxOut{{PkScript: nil, Value: 5}})
|
||||
unConfUtxo := wire.OutPoint{
|
||||
TxID: unConfTx.TxID(),
|
||||
TxID: *unConfTx.TxID(),
|
||||
Index: 0,
|
||||
}
|
||||
|
||||
@ -1012,7 +1012,7 @@ func TestValidateFeeTransaction(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{
|
||||
{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: cb1A.TxID(),
|
||||
TxID: *cb1A.TxID(),
|
||||
Index: 0,
|
||||
},
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
@ -1092,7 +1092,7 @@ func TestValidateFeeTransaction(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{
|
||||
{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: cb3.TxID(),
|
||||
TxID: *cb3.TxID(),
|
||||
Index: 0,
|
||||
},
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
@ -1133,7 +1133,7 @@ func TestValidateFeeTransaction(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{
|
||||
{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: cb3.TxID(),
|
||||
TxID: *cb3.TxID(),
|
||||
Index: 1,
|
||||
},
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
|
@ -193,7 +193,7 @@ func TestChainedTransactions(t *testing.T) {
|
||||
cbTx := block1.Transactions[0]
|
||||
|
||||
txIn := &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{TxID: cbTx.TxID(), Index: 0},
|
||||
PreviousOutPoint: wire.OutPoint{TxID: *cbTx.TxID(), Index: 0},
|
||||
SignatureScript: nil,
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
@ -204,7 +204,7 @@ func TestChainedTransactions(t *testing.T) {
|
||||
tx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
|
||||
|
||||
chainedTxIn := &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{TxID: tx.TxID(), Index: 0},
|
||||
PreviousOutPoint: wire.OutPoint{TxID: *tx.TxID(), Index: 0},
|
||||
SignatureScript: nil,
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
@ -235,7 +235,7 @@ func TestChainedTransactions(t *testing.T) {
|
||||
}
|
||||
|
||||
nonChainedTxIn := &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{TxID: cbTx.TxID(), Index: 0},
|
||||
PreviousOutPoint: wire.OutPoint{TxID: *cbTx.TxID(), Index: 0},
|
||||
SignatureScript: nil,
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
@ -296,7 +296,7 @@ func TestGasLimit(t *testing.T) {
|
||||
cbTxID := fundsBlock.Transactions[0].TxID()
|
||||
|
||||
tx1In := &wire.TxIn{
|
||||
PreviousOutPoint: *wire.NewOutPoint(&cbTxID, 0),
|
||||
PreviousOutPoint: *wire.NewOutPoint(cbTxID, 0),
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
tx1Out := &wire.TxOut{
|
||||
@ -306,7 +306,7 @@ func TestGasLimit(t *testing.T) {
|
||||
tx1 := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{tx1In}, []*wire.TxOut{tx1Out}, subnetworkID, 10000, []byte{})
|
||||
|
||||
tx2In := &wire.TxIn{
|
||||
PreviousOutPoint: *wire.NewOutPoint(&cbTxID, 1),
|
||||
PreviousOutPoint: *wire.NewOutPoint(cbTxID, 1),
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
tx2Out := &wire.TxOut{
|
||||
@ -335,7 +335,7 @@ func TestGasLimit(t *testing.T) {
|
||||
}
|
||||
|
||||
overflowGasTxIn := &wire.TxIn{
|
||||
PreviousOutPoint: *wire.NewOutPoint(&cbTxID, 1),
|
||||
PreviousOutPoint: *wire.NewOutPoint(cbTxID, 1),
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
overflowGasTxOut := &wire.TxOut{
|
||||
@ -366,7 +366,7 @@ func TestGasLimit(t *testing.T) {
|
||||
|
||||
nonExistentSubnetwork := &subnetworkid.SubnetworkID{123}
|
||||
nonExistentSubnetworkTxIn := &wire.TxIn{
|
||||
PreviousOutPoint: *wire.NewOutPoint(&cbTxID, 0),
|
||||
PreviousOutPoint: *wire.NewOutPoint(cbTxID, 0),
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
nonExistentSubnetworkTxOut := &wire.TxOut{
|
||||
|
@ -162,7 +162,7 @@ type spendableOut struct {
|
||||
func makeSpendableOutForTx(tx *wire.MsgTx, txOutIndex uint32) spendableOut {
|
||||
return spendableOut{
|
||||
prevOut: wire.OutPoint{
|
||||
TxID: tx.TxID(),
|
||||
TxID: *tx.TxID(),
|
||||
Index: txOutIndex,
|
||||
},
|
||||
amount: util.Amount(tx.TxOut[txOutIndex].Value),
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
func createTransaction(value uint64, originTx *wire.MsgTx, outputIndex uint32) *wire.MsgTx {
|
||||
txIn := &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: originTx.TxID(),
|
||||
TxID: *originTx.TxID(),
|
||||
Index: outputIndex,
|
||||
},
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
@ -74,7 +74,7 @@ func TestTxIndexConnectBlock(t *testing.T) {
|
||||
block3 := prepareAndProcessBlock([]*daghash.Hash{block2.BlockHash()}, []*wire.MsgTx{block3Tx}, "3")
|
||||
|
||||
block3TxID := block3Tx.TxID()
|
||||
block3TxNewAcceptedBlock, err := txIndex.BlockThatAcceptedTx(dag, &block3TxID)
|
||||
block3TxNewAcceptedBlock, err := txIndex.BlockThatAcceptedTx(dag, block3TxID)
|
||||
if err != nil {
|
||||
t.Errorf("TestTxIndexConnectBlock: TxAcceptedInBlock: %v", err)
|
||||
}
|
||||
@ -88,7 +88,7 @@ func TestTxIndexConnectBlock(t *testing.T) {
|
||||
block4 := prepareAndProcessBlock([]*daghash.Hash{block3.BlockHash()}, nil, "4")
|
||||
prepareAndProcessBlock([]*daghash.Hash{block3A.BlockHash(), block4.BlockHash()}, nil, "5")
|
||||
|
||||
block3TxAcceptedBlock, err := txIndex.BlockThatAcceptedTx(dag, &block3TxID)
|
||||
block3TxAcceptedBlock, err := txIndex.BlockThatAcceptedTx(dag, block3TxID)
|
||||
if err != nil {
|
||||
t.Errorf("TestTxIndexConnectBlock: TxAcceptedInBlock: %v", err)
|
||||
}
|
||||
@ -98,7 +98,7 @@ func TestTxIndexConnectBlock(t *testing.T) {
|
||||
"been accepted in block %v but instead got accepted in block %v", block3AHash, block3TxAcceptedBlock)
|
||||
}
|
||||
|
||||
region, err := txIndex.TxFirstBlockRegion(&block3TxID)
|
||||
region, err := txIndex.TxFirstBlockRegion(block3TxID)
|
||||
if err != nil {
|
||||
t.Fatalf("TestTxIndexConnectBlock: no block region was found for block3Tx")
|
||||
}
|
||||
|
@ -290,8 +290,7 @@ func (d *UTXODiff) clone() *UTXODiff {
|
||||
//RemoveTxOuts marks the transaction's outputs to removal
|
||||
func (d *UTXODiff) RemoveTxOuts(tx *wire.MsgTx) {
|
||||
for idx := range tx.TxOut {
|
||||
hash := tx.TxID()
|
||||
d.toRemove.add(*wire.NewOutPoint(&hash, uint32(idx)), nil)
|
||||
d.toRemove.add(*wire.NewOutPoint(tx.TxID(), uint32(idx)), nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -360,9 +359,8 @@ func diffFromTx(u UTXOSet, tx *wire.MsgTx, containingNode *blockNode) (*UTXODiff
|
||||
}
|
||||
}
|
||||
for i, txOut := range tx.TxOut {
|
||||
hash := tx.TxID()
|
||||
entry := NewUTXOEntry(txOut, isBlockReward, containingNode.height)
|
||||
outPoint := *wire.NewOutPoint(&hash, uint32(i))
|
||||
outPoint := *wire.NewOutPoint(tx.TxID(), uint32(i))
|
||||
diff.toAdd.add(outPoint, entry)
|
||||
}
|
||||
return diff, nil
|
||||
@ -415,8 +413,7 @@ func (fus *FullUTXOSet) AddTx(tx *wire.MsgTx, blockHeight uint64) bool {
|
||||
}
|
||||
|
||||
for i, txOut := range tx.TxOut {
|
||||
hash := tx.TxID()
|
||||
outPoint := *wire.NewOutPoint(&hash, uint32(i))
|
||||
outPoint := *wire.NewOutPoint(tx.TxID(), uint32(i))
|
||||
entry := NewUTXOEntry(txOut, isBlockReward, blockHeight)
|
||||
|
||||
fus.add(outPoint, entry)
|
||||
@ -519,8 +516,7 @@ func (dus *DiffUTXOSet) appendTx(tx *wire.MsgTx, blockHeight uint64, isBlockRewa
|
||||
}
|
||||
|
||||
for i, txOut := range tx.TxOut {
|
||||
hash := tx.TxID()
|
||||
outPoint := *wire.NewOutPoint(&hash, uint32(i))
|
||||
outPoint := *wire.NewOutPoint(tx.TxID(), uint32(i))
|
||||
entry := NewUTXOEntry(txOut, isBlockReward, blockHeight)
|
||||
|
||||
if dus.UTXODiff.toRemove.contains(outPoint) {
|
||||
|
@ -639,23 +639,23 @@ func TestDiffUTXOSet_addTx(t *testing.T) {
|
||||
|
||||
// transaction1 spends transaction0
|
||||
id1 := transaction0.TxID()
|
||||
outPoint1 := *wire.NewOutPoint(&id1, 0)
|
||||
txIn1 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: wire.OutPoint{TxID: id1, Index: 0}, Sequence: 0}
|
||||
outPoint1 := *wire.NewOutPoint(id1, 0)
|
||||
txIn1 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: wire.OutPoint{TxID: *id1, Index: 0}, Sequence: 0}
|
||||
txOut1 := &wire.TxOut{PkScript: []byte{1}, Value: 20}
|
||||
utxoEntry1 := NewUTXOEntry(txOut1, false, 1)
|
||||
transaction1 := wire.NewNativeMsgTx(1, []*wire.TxIn{txIn1}, []*wire.TxOut{txOut1})
|
||||
|
||||
// transaction2 spends transaction1
|
||||
id2 := transaction1.TxID()
|
||||
outPoint2 := *wire.NewOutPoint(&id2, 0)
|
||||
txIn2 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: wire.OutPoint{TxID: id2, Index: 0}, Sequence: 0}
|
||||
outPoint2 := *wire.NewOutPoint(id2, 0)
|
||||
txIn2 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: wire.OutPoint{TxID: *id2, Index: 0}, Sequence: 0}
|
||||
txOut2 := &wire.TxOut{PkScript: []byte{2}, Value: 30}
|
||||
utxoEntry2 := NewUTXOEntry(txOut2, false, 2)
|
||||
transaction2 := wire.NewNativeMsgTx(1, []*wire.TxIn{txIn2}, []*wire.TxOut{txOut2})
|
||||
|
||||
// outpoint3 is the outpoint for transaction2
|
||||
id3 := transaction2.TxID()
|
||||
outPoint3 := *wire.NewOutPoint(&id3, 0)
|
||||
outPoint3 := *wire.NewOutPoint(id3, 0)
|
||||
|
||||
// For each of the following test cases, we will:
|
||||
// 1. startSet.addTx() all the transactions in toAdd, in order, with the initial block height startHeight
|
||||
@ -797,7 +797,7 @@ func TestDiffFromTx(t *testing.T) {
|
||||
}
|
||||
fus.AddTx(cbTx, 1)
|
||||
node := &blockNode{height: 2} //Fake node
|
||||
cbOutpoint := wire.OutPoint{TxID: cbTx.TxID(), Index: 0}
|
||||
cbOutpoint := wire.OutPoint{TxID: *cbTx.TxID(), Index: 0}
|
||||
txIns := []*wire.TxIn{&wire.TxIn{
|
||||
PreviousOutPoint: cbOutpoint,
|
||||
SignatureScript: nil,
|
||||
@ -813,13 +813,13 @@ func TestDiffFromTx(t *testing.T) {
|
||||
t.Errorf("diffFromTx: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(diff.toAdd, utxoCollection{
|
||||
wire.OutPoint{TxID: tx.TxID(), Index: 0}: NewUTXOEntry(tx.TxOut[0], false, 2),
|
||||
wire.OutPoint{TxID: *tx.TxID(), Index: 0}: NewUTXOEntry(tx.TxOut[0], false, 2),
|
||||
}) {
|
||||
t.Errorf("diff.toAdd doesn't have the expected values")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(diff.toRemove, utxoCollection{
|
||||
wire.OutPoint{TxID: cbTx.TxID(), Index: 0}: NewUTXOEntry(cbTx.TxOut[0], true, 1),
|
||||
wire.OutPoint{TxID: *cbTx.TxID(), Index: 0}: NewUTXOEntry(cbTx.TxOut[0], true, 1),
|
||||
}) {
|
||||
t.Errorf("diff.toRemove doesn't have the expected values")
|
||||
}
|
||||
@ -922,10 +922,8 @@ func TestUTXOSetAddEntry(t *testing.T) {
|
||||
func TestUTXOSetRemoveTxOuts(t *testing.T) {
|
||||
tx0 := wire.NewNativeMsgTx(1, nil, []*wire.TxOut{{PkScript: []byte{1}, Value: 10}})
|
||||
tx1 := wire.NewNativeMsgTx(1, nil, []*wire.TxOut{{PkScript: []byte{2}, Value: 20}})
|
||||
hash0 := tx0.TxID()
|
||||
hash1 := tx1.TxID()
|
||||
outPoint0 := wire.NewOutPoint(&hash0, 0)
|
||||
outPoint1 := wire.NewOutPoint(&hash1, 0)
|
||||
outPoint0 := wire.NewOutPoint(tx0.TxID(), 0)
|
||||
outPoint1 := wire.NewOutPoint(tx1.TxID(), 0)
|
||||
|
||||
utxoDiff := NewUTXODiff()
|
||||
|
||||
|
@ -206,8 +206,7 @@ func (m *memWallet) ingestBlock(update *dagUpdate) {
|
||||
for _, tx := range update.filteredTxns {
|
||||
mtx := tx.MsgTx()
|
||||
isCoinbase := mtx.IsCoinBase()
|
||||
txID := mtx.TxID()
|
||||
m.evalOutputs(mtx.TxOut, &txID, isCoinbase, undo)
|
||||
m.evalOutputs(mtx.TxOut, mtx.TxID(), isCoinbase, undo)
|
||||
m.evalInputs(mtx.TxIn, undo)
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func NewSatoshiPerByte(fee util.Amount, size uint32) SatoshiPerByte {
|
||||
// additional data required for the fee estimation algorithm.
|
||||
type observedTransaction struct {
|
||||
// A transaction ID.
|
||||
id daghash.TxID
|
||||
txID *daghash.TxID
|
||||
|
||||
// The fee per byte of the transaction in satoshis.
|
||||
feeRate SatoshiPerByte
|
||||
@ -108,17 +108,19 @@ type observedTransaction struct {
|
||||
}
|
||||
|
||||
func (o *observedTransaction) Serialize(w io.Writer) {
|
||||
binary.Write(w, binary.BigEndian, o.id)
|
||||
binary.Write(w, binary.BigEndian, o.txID)
|
||||
binary.Write(w, binary.BigEndian, o.feeRate)
|
||||
binary.Write(w, binary.BigEndian, o.observed)
|
||||
binary.Write(w, binary.BigEndian, o.mined)
|
||||
}
|
||||
|
||||
func deserializeObservedTransaction(r io.Reader) (*observedTransaction, error) {
|
||||
ot := observedTransaction{}
|
||||
ot := observedTransaction{
|
||||
txID: &daghash.TxID{},
|
||||
}
|
||||
|
||||
// The first 32 bytes should be a hash.
|
||||
binary.Read(r, binary.BigEndian, &ot.id)
|
||||
binary.Read(r, binary.BigEndian, ot.txID)
|
||||
|
||||
// The next 8 are SatoshiPerByte
|
||||
binary.Read(r, binary.BigEndian, &ot.feeRate)
|
||||
@ -206,12 +208,12 @@ func (ef *FeeEstimator) ObserveTransaction(t *TxDesc) {
|
||||
return
|
||||
}
|
||||
|
||||
txID := *t.Tx.ID()
|
||||
if _, ok := ef.observed[txID]; !ok {
|
||||
txID := t.Tx.ID()
|
||||
if _, ok := ef.observed[*txID]; !ok {
|
||||
size := uint32(t.Tx.MsgTx().SerializeSize())
|
||||
|
||||
ef.observed[txID] = &observedTransaction{
|
||||
id: txID,
|
||||
ef.observed[*txID] = &observedTransaction{
|
||||
txID: txID,
|
||||
feeRate: NewSatoshiPerByte(util.Amount(t.Fee), size),
|
||||
observed: t.Height,
|
||||
mined: mining.UnminedHeight,
|
||||
@ -614,7 +616,7 @@ type observedTxSet []*observedTransaction
|
||||
func (q observedTxSet) Len() int { return len(q) }
|
||||
|
||||
func (q observedTxSet) Less(i, j int) bool {
|
||||
return strings.Compare(q[i].id.String(), q[j].id.String()) < 0
|
||||
return strings.Compare(q[i].txID.String(), q[j].txID.String()) < 0
|
||||
}
|
||||
|
||||
func (q observedTxSet) Swap(i, j int) {
|
||||
@ -716,7 +718,7 @@ func RestoreFeeEstimator(data FeeEstimatorState) (*FeeEstimator, error) {
|
||||
return nil, err
|
||||
}
|
||||
observed[i] = ot
|
||||
ef.observed[ot.id] = ot
|
||||
ef.observed[*ot.txID] = ot
|
||||
}
|
||||
|
||||
// Read bins.
|
||||
|
@ -253,7 +253,7 @@ func (p *poolHarness) CreateTxChain(firstOutput spendableOutpoint, numTxns uint3
|
||||
txChain = append(txChain, util.NewTx(tx))
|
||||
|
||||
// Next transaction uses outputs from this one.
|
||||
prevOutPoint = wire.OutPoint{TxID: tx.TxID(), Index: 0}
|
||||
prevOutPoint = wire.OutPoint{TxID: *tx.TxID(), Index: 0}
|
||||
}
|
||||
|
||||
return txChain, nil
|
||||
|
@ -200,7 +200,7 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
// tx is a regular transaction, and should not be filtered by the miner
|
||||
txIn := &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: template1CbTx.TxID(),
|
||||
TxID: *template1CbTx.TxID(),
|
||||
Index: 0,
|
||||
},
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
@ -214,7 +214,7 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
// We want to check that the miner filters non finalized transactions
|
||||
txIn = &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: template1CbTx.TxID(),
|
||||
TxID: *template1CbTx.TxID(),
|
||||
Index: 1,
|
||||
},
|
||||
Sequence: 0,
|
||||
@ -232,7 +232,7 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
// We want to check that the miner filters transactions with non-existing subnetwork id. (It should first push it to the priority queue, and then ignore it)
|
||||
txIn = &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: template1CbTx.TxID(),
|
||||
TxID: *template1CbTx.TxID(),
|
||||
Index: 2,
|
||||
},
|
||||
Sequence: 0,
|
||||
@ -247,7 +247,7 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
// We want to check that the miner doesn't filters transactions that do not exceed the subnetwork gas limit
|
||||
txIn = &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: template1CbTx.TxID(),
|
||||
TxID: *template1CbTx.TxID(),
|
||||
Index: 3,
|
||||
},
|
||||
Sequence: 0,
|
||||
@ -261,7 +261,7 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
// We want to check that the miner filters transactions that exceed the subnetwork gas limit. (It should first push it to the priority queue, and then ignore it)
|
||||
txIn = &wire.TxIn{
|
||||
PreviousOutPoint: wire.OutPoint{
|
||||
TxID: template1CbTx.TxID(),
|
||||
TxID: *template1CbTx.TxID(),
|
||||
Index: 4,
|
||||
},
|
||||
Sequence: 0,
|
||||
@ -317,10 +317,10 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
// Here we check that the miner's priorty queue has the expected transactions after filtering.
|
||||
popReturnedUnexpectedValue := false
|
||||
expectedPops := map[daghash.TxID]bool{
|
||||
tx.TxID(): false,
|
||||
subnetworkTx1.TxID(): false,
|
||||
subnetworkTx2.TxID(): false,
|
||||
nonExistingSubnetworkTx.TxID(): false,
|
||||
*tx.TxID(): false,
|
||||
*subnetworkTx1.TxID(): false,
|
||||
*subnetworkTx2.TxID(): false,
|
||||
*nonExistingSubnetworkTx.TxID(): false,
|
||||
}
|
||||
var popPatch *monkey.PatchGuard
|
||||
popPatch = monkey.Patch((*txPriorityQueue).Pop, func(pq *txPriorityQueue) interface{} {
|
||||
@ -365,12 +365,12 @@ func TestNewBlockTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
expectedTxs := map[daghash.TxID]bool{
|
||||
tx.TxID(): false,
|
||||
subnetworkTx1.TxID(): false,
|
||||
*tx.TxID(): false,
|
||||
*subnetworkTx1.TxID(): false,
|
||||
}
|
||||
|
||||
for _, tx := range template2.Block.Transactions[2:] {
|
||||
id := tx.TxID()
|
||||
id := *tx.TxID()
|
||||
if _, ok := expectedTxs[id]; !ok {
|
||||
t.Errorf("Unexpected tx %v in template2's candidate block", id)
|
||||
}
|
||||
|
@ -61,8 +61,7 @@ func newUTXOSet(sourceTxns []*wire.MsgTx, sourceTxHeights []uint64) blockdag.UTX
|
||||
func createTxIn(originTx *wire.MsgTx, outputIndex uint32) *wire.TxIn {
|
||||
var prevOut *wire.OutPoint
|
||||
if originTx != nil {
|
||||
originTxID := originTx.TxID()
|
||||
prevOut = wire.NewOutPoint(&originTxID, 0)
|
||||
prevOut = wire.NewOutPoint(originTx.TxID(), 0)
|
||||
} else {
|
||||
prevOut = &wire.OutPoint{
|
||||
TxID: daghash.TxID{},
|
||||
|
@ -1731,7 +1731,7 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
|
||||
txIndex := make(map[daghash.TxID]int64, numTx)
|
||||
for i, tx := range msgBlock.Transactions {
|
||||
txID := tx.TxID()
|
||||
txIndex[txID] = int64(i)
|
||||
txIndex[*txID] = int64(i)
|
||||
|
||||
// Skip the coinbase transaction.
|
||||
if i == 0 {
|
||||
|
@ -109,14 +109,13 @@ func ExampleSignTxOutput() {
|
||||
}
|
||||
txOut := wire.NewTxOut(100000000, pkScript)
|
||||
originTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
|
||||
originTxID := originTx.TxID()
|
||||
|
||||
// Create the transaction to redeem the fake transaction.
|
||||
|
||||
// Add the input(s) the redeeming transaction will spend. There is no
|
||||
// signature script at this point since it hasn't been created or signed
|
||||
// yet, hence nil is provided for it.
|
||||
prevOut = wire.NewOutPoint(&originTxID, 0)
|
||||
prevOut = wire.NewOutPoint(originTx.TxID(), 0)
|
||||
txIn = wire.NewTxIn(prevOut, nil)
|
||||
|
||||
// Ordinarily this would contain that actual destination of the funds,
|
||||
|
@ -221,8 +221,7 @@ func createSpendingTx(sigScript, pkScript []byte) *wire.MsgTx {
|
||||
txOut := wire.NewTxOut(0, pkScript)
|
||||
coinbaseTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
|
||||
|
||||
coinbaseTxID := coinbaseTx.TxID()
|
||||
outPoint = wire.NewOutPoint(&coinbaseTxID, 0)
|
||||
outPoint = wire.NewOutPoint(coinbaseTx.TxID(), 0)
|
||||
txIn = wire.NewTxIn(outPoint, sigScript)
|
||||
txOut = wire.NewTxOut(0, nil)
|
||||
spendingTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
|
||||
|
@ -326,8 +326,7 @@ func BuildBasicFilter(block *wire.MsgBlock) (*gcs.Filter, error) {
|
||||
for i, tx := range block.Transactions {
|
||||
// First we'll compute the bash of the transaction and add that
|
||||
// directly to the filter.
|
||||
txID := tx.TxID()
|
||||
b.AddTxID(&txID)
|
||||
b.AddTxID(tx.TxID())
|
||||
|
||||
// Skip the inputs for the coinbase transaction
|
||||
if i != 0 {
|
||||
|
@ -51,11 +51,10 @@ func RegisterSubnetworkForTest(dag *blockdag.BlockDAG, params *dagconfig.Params,
|
||||
}
|
||||
|
||||
fundsBlockCbTx := fundsBlock.Transactions()[0].MsgTx()
|
||||
fundsBlockCbTxID := fundsBlockCbTx.TxID()
|
||||
|
||||
// Create a block with a valid subnetwork registry transaction
|
||||
txIn := &wire.TxIn{
|
||||
PreviousOutPoint: *wire.NewOutPoint(&fundsBlockCbTxID, 0),
|
||||
PreviousOutPoint: *wire.NewOutPoint(fundsBlockCbTx.TxID(), 0),
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}
|
||||
txOut := &wire.TxOut{
|
||||
|
@ -60,8 +60,8 @@ func (t *Tx) ID() *daghash.TxID {
|
||||
|
||||
// Cache the hash and return it.
|
||||
id := t.msgTx.TxID()
|
||||
t.txID = &id
|
||||
return &id
|
||||
t.txID = id
|
||||
return id
|
||||
}
|
||||
|
||||
// Index returns the saved index of the transaction within a block. This value
|
||||
|
@ -340,7 +340,7 @@ func (msg *MsgTx) TxHash() *daghash.Hash {
|
||||
}
|
||||
|
||||
// TxID generates the Hash for the transaction without the signature script, gas and payload fields.
|
||||
func (msg *MsgTx) TxID() daghash.TxID {
|
||||
func (msg *MsgTx) TxID() *daghash.TxID {
|
||||
// Encode the transaction, replace signature script with zeroes, cut off
|
||||
// payload and calculate double sha256 on the result. Ignore the error
|
||||
// returns since the only way the encode could fail is being out of memory or
|
||||
@ -351,7 +351,8 @@ func (msg *MsgTx) TxID() daghash.TxID {
|
||||
}
|
||||
buf := bytes.NewBuffer(make([]byte, 0, msg.serializeSize(encodingFlags)))
|
||||
_ = msg.serialize(buf, encodingFlags)
|
||||
return daghash.TxID(daghash.DoubleHashH(buf.Bytes()))
|
||||
txID := daghash.TxID(daghash.DoubleHashH(buf.Bytes()))
|
||||
return &txID
|
||||
}
|
||||
|
||||
// Copy creates a deep copy of a transaction so that the original does not get
|
||||
|
Loading…
x
Reference in New Issue
Block a user