From 396842ae40412b59b35d8513538c583e4ef80683 Mon Sep 17 00:00:00 2001 From: Svarog Date: Wed, 5 Jun 2019 16:23:57 +0300 Subject: [PATCH] [NOD-207] Rename any place that says 'OutPoint' to 'Outpoint' (#323) * [NOD-207] Rename any place that says 'OutPoint' to 'Outpoint' * [NOD-207] Fix any place that says output point --- blockdag/common_test.go | 2 +- blockdag/dag.go | 12 +- blockdag/dag_test.go | 38 ++--- blockdag/dagio.go | 18 +-- blockdag/external_dag_test.go | 14 +- blockdag/fees.go | 2 +- blockdag/fullblocktests/generate.go | 14 +- blockdag/fullblocktests/params.go | 2 +- blockdag/indexers/addrindex.go | 4 +- blockdag/indexers/txindex_test.go | 2 +- blockdag/scriptval.go | 12 +- blockdag/test_utils.go | 4 +- blockdag/utxodiffstore_test.go | 4 +- blockdag/utxoio.go | 30 ++-- blockdag/utxoset.go | 214 ++++++++++++++-------------- blockdag/utxoset_test.go | 184 ++++++++++++------------ blockdag/validate.go | 28 ++-- blockdag/validate_test.go | 36 ++--- btcjson/dagsvrwscmds.go | 10 +- btcjson/dagsvrwscmds_test.go | 4 +- cmd/addsubnetwork/addsubnetwork.go | 8 +- cmd/addsubnetwork/registrytx.go | 9 +- cmd/addsubnetwork/utxo.go | 19 +-- cmd/txgen/txloop.go | 21 +-- dagconfig/genesis.go | 2 +- database/testdata/generator.go | 2 +- integration/csv_test.go | 18 +-- integration/rpctest/blockgen.go | 2 +- integration/rpctest/memwallet.go | 24 ++-- mempool/mempool.go | 86 +++++------ mempool/mempool_test.go | 58 ++++---- mempool/policy.go | 2 +- mempool/policy_test.go | 10 +- mining/mining.go | 2 +- mining/mining_test.go | 10 +- mining/policy.go | 2 +- mining/policy_test.go | 6 +- netsync/manager.go | 2 +- rpcclient/notify.go | 24 ++-- rpcclient/wallet.go | 12 +- server/rpc/rpcserver.go | 20 +-- server/rpc/rpcserverhelp.go | 8 +- server/rpc/rpcwebsocket.go | 56 ++++---- txscript/engine_test.go | 8 +- txscript/example_test.go | 4 +- txscript/reference_test.go | 8 +- txscript/sign_test.go | 10 +- util/block_test.go | 8 +- util/bloom/filter.go | 30 ++-- util/bloom/filter_test.go | 28 ++-- util/bloom/test_coverage.txt | 8 +- util/coinset/coins.go | 2 +- util/coinset/coins_test.go | 2 +- util/gcs/builder/builder.go | 14 +- util/gcs/builder/builder_test.go | 26 ++-- util/testtools/testtools.go | 2 +- util/txsort/txsort.go | 6 +- wire/bench_test.go | 22 +-- wire/msgblock_test.go | 2 +- wire/msgtx.go | 48 +++---- wire/msgtx_test.go | 20 +-- 61 files changed, 644 insertions(+), 641 deletions(-) diff --git a/blockdag/common_test.go b/blockdag/common_test.go index 1a661523d..1069df0a7 100644 --- a/blockdag/common_test.go +++ b/blockdag/common_test.go @@ -155,7 +155,7 @@ func loadUTXOSet(filename string) (UTXOSet, error) { if err != nil { return nil, err } - utxoSet.utxoCollection[wire.OutPoint{TxID: txID, Index: index}] = entry + utxoSet.utxoCollection[wire.Outpoint{TxID: txID, Index: index}] = entry } return utxoSet, nil diff --git a/blockdag/dag.go b/blockdag/dag.go index cc999432e..43ba8b5a2 100644 --- a/blockdag/dag.go +++ b/blockdag/dag.go @@ -384,11 +384,11 @@ func (dag *BlockDAG) calcSequenceLock(node *blockNode, utxoSet UTXOSet, tx *util mTx := tx.MsgTx() for txInIndex, txIn := range mTx.TxIn { - entry, ok := utxoSet.Get(txIn.PreviousOutPoint) + entry, ok := utxoSet.Get(txIn.PreviousOutpoint) if !ok { str := fmt.Sprintf("output %s referenced from "+ "transaction %s:%d either does not exist or "+ - "has already been spent", txIn.PreviousOutPoint, + "has already been spent", txIn.PreviousOutpoint, tx.ID(), txInIndex) return sequenceLock, ruleError(ErrMissingTxOut, str) } @@ -925,8 +925,8 @@ func genesisPastUTXO(virtual *virtualBlock) UTXOSet { // set by creating a diff UTXO set with the virtual UTXO // set, and adding all of its entries in toRemove diff := NewUTXODiff() - for outPoint, entry := range virtual.utxoSet.utxoCollection { - diff.toRemove[outPoint] = entry + for outpoint, entry := range virtual.utxoSet.utxoCollection { + diff.toRemove[outpoint] = entry } genesisPastUTXO := UTXOSet(NewDiffUTXOSet(virtual.utxoSet, diff)) return genesisPastUTXO @@ -1188,8 +1188,8 @@ func (dag *BlockDAG) CalcPastMedianTime() time.Time { // // This function is safe for concurrent access. However, the returned entry (if // any) is NOT. -func (dag *BlockDAG) GetUTXOEntry(outPoint wire.OutPoint) (*UTXOEntry, bool) { - return dag.virtual.utxoSet.get(outPoint) +func (dag *BlockDAG) GetUTXOEntry(outpoint wire.Outpoint) (*UTXOEntry, bool) { + return dag.virtual.utxoSet.get(outpoint) } // BlockConfirmationsByHash returns the confirmations number for a block with the diff --git a/blockdag/dag_test.go b/blockdag/dag_test.go index 4ed6fde0d..d7232718a 100644 --- a/blockdag/dag_test.go +++ b/blockdag/dag_test.go @@ -253,7 +253,7 @@ func TestCalcSequenceLock(t *testing.T) { // that the sequence lock heights are always calculated from the same // point of view that they were originally calculated from for a given // utxo. That is to say, the height prior to it. - utxo := wire.OutPoint{ + utxo := wire.Outpoint{ TxID: *targetTx.ID(), Index: 0, } @@ -274,7 +274,7 @@ func TestCalcSequenceLock(t *testing.T) { // Add an additional transaction which will serve as our unconfirmed // output. unConfTx := wire.NewNativeMsgTx(wire.TxVersion, nil, []*wire.TxOut{{PkScript: nil, Value: 5}}) - unConfUtxo := wire.OutPoint{ + unConfUtxo := wire.Outpoint{ TxID: *unConfTx.TxID(), Index: 0, } @@ -296,7 +296,7 @@ func TestCalcSequenceLock(t *testing.T) { // should be disabled. { name: "single input, max sequence number", - tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutPoint: utxo, Sequence: wire.MaxTxInSequenceNum}}, nil), + tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutpoint: utxo, Sequence: wire.MaxTxInSequenceNum}}, nil), utxoSet: utxoSet, want: &SequenceLock{ Seconds: -1, @@ -311,7 +311,7 @@ func TestCalcSequenceLock(t *testing.T) { // the targeted block. { name: "single input, seconds lock time below time granularity", - tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutPoint: utxo, Sequence: LockTimeToSequence(true, 2)}}, nil), + tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 2)}}, nil), utxoSet: utxoSet, want: &SequenceLock{ Seconds: medianTime - 1, @@ -324,7 +324,7 @@ func TestCalcSequenceLock(t *testing.T) { // chain. { name: "single input, 1023 seconds after median time", - tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutPoint: utxo, Sequence: LockTimeToSequence(true, 1024)}}, nil), + tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 1024)}}, nil), utxoSet: utxoSet, want: &SequenceLock{ Seconds: medianTime + 1023, @@ -341,13 +341,13 @@ func TestCalcSequenceLock(t *testing.T) { name: "multiple varied inputs", tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 2560), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 4), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 5) | wire.SequenceLockTimeDisabled, }}, @@ -364,7 +364,7 @@ func TestCalcSequenceLock(t *testing.T) { // height of 2 meaning it can be included at height 3. { name: "single input, lock-time in blocks", - tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutPoint: utxo, Sequence: LockTimeToSequence(false, 3)}}, nil), + tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 3)}}, nil), utxoSet: utxoSet, want: &SequenceLock{ Seconds: -1, @@ -377,10 +377,10 @@ func TestCalcSequenceLock(t *testing.T) { { name: "two inputs, lock-times in seconds", tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 5120), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 2560), }}, nil), utxoSet: utxoSet, @@ -397,10 +397,10 @@ func TestCalcSequenceLock(t *testing.T) { name: "two inputs, lock-times in blocks", tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 1), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 11), }}, nil), @@ -417,16 +417,16 @@ func TestCalcSequenceLock(t *testing.T) { name: "four inputs, two lock-times in time, two lock-times in blocks", tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 2560), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(true, 6656), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 3), }, { - PreviousOutPoint: utxo, + PreviousOutpoint: utxo, Sequence: LockTimeToSequence(false, 9), }}, nil), @@ -444,7 +444,7 @@ func TestCalcSequenceLock(t *testing.T) { // after that. { name: "single input, unconfirmed, lock-time in blocks", - tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutPoint: unConfUtxo, Sequence: LockTimeToSequence(false, 2)}}, nil), + tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutpoint: unConfUtxo, Sequence: LockTimeToSequence(false, 2)}}, nil), utxoSet: utxoSet, mempool: true, want: &SequenceLock{ @@ -457,7 +457,7 @@ func TestCalcSequenceLock(t *testing.T) { // MTP of the *next* block. { name: "single input, unconfirmed, lock-time in seoncds", - tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutPoint: unConfUtxo, Sequence: LockTimeToSequence(true, 1024)}}, nil), + tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{PreviousOutpoint: unConfUtxo, Sequence: LockTimeToSequence(true, 1024)}}, nil), utxoSet: utxoSet, mempool: true, want: &SequenceLock{ diff --git a/blockdag/dagio.go b/blockdag/dagio.go index 71b0cd00c..c933684dd 100644 --- a/blockdag/dagio.go +++ b/blockdag/dagio.go @@ -203,7 +203,7 @@ var outpointKeyPool = sync.Pool{ // returned to the free list by using the recycleOutpointKey function when the // caller is done with it _unless_ the slice will need to live for longer than // the caller can calculate such as when used to write to the database. -func outpointKey(outpoint wire.OutPoint) *[]byte { +func outpointKey(outpoint wire.Outpoint) *[]byte { // A VLQ employs an MSB encoding, so they are useful not only to reduce // the amount of storage space, but also so iteration of UTXOs when // doing byte-wise comparisons will produce them in order. @@ -227,8 +227,8 @@ func recycleOutpointKey(key *[]byte) { // to the database. func dbPutUTXODiff(dbTx database.Tx, diff *UTXODiff) error { utxoBucket := dbTx.Metadata().Bucket(utxoSetBucketName) - for outPoint := range diff.toRemove { - key := outpointKey(outPoint) + for outpoint := range diff.toRemove { + key := outpointKey(outpoint) err := utxoBucket.Delete(*key) recycleOutpointKey(key) if err != nil { @@ -236,11 +236,11 @@ func dbPutUTXODiff(dbTx database.Tx, diff *UTXODiff) error { } } - for outPoint, entry := range diff.toAdd { + for outpoint, entry := range diff.toAdd { // Serialize and store the UTXO entry. serialized := serializeUTXOEntry(entry) - key := outpointKey(outPoint) + key := outpointKey(outpoint) err := utxoBucket.Put(*key, serialized) // NOTE: The key is intentionally not recycled here since the // database interface contract prohibits modifications. It will @@ -504,15 +504,15 @@ func (dag *BlockDAG) initDAGState() error { fullUTXOCollection := make(utxoCollection, utxoEntryCount) for ok := cursor.First(); ok; ok = cursor.Next() { - // Deserialize the outPoint - outPoint, err := deserializeOutPoint(cursor.Key()) + // Deserialize the outpoint + outpoint, err := deserializeOutpoint(cursor.Key()) if err != nil { // Ensure any deserialization errors are returned as database // corruption errors. if isDeserializeErr(err) { return database.Error{ ErrorCode: database.ErrCorruption, - Description: fmt.Sprintf("corrupt outPoint: %s", err), + Description: fmt.Sprintf("corrupt outpoint: %s", err), } } @@ -534,7 +534,7 @@ func (dag *BlockDAG) initDAGState() error { return err } - fullUTXOCollection[*outPoint] = entry + fullUTXOCollection[*outpoint] = entry } // Apply the loaded utxoCollection to the virtual block. diff --git a/blockdag/external_dag_test.go b/blockdag/external_dag_test.go index fb26f9c7d..bc86cd3ae 100644 --- a/blockdag/external_dag_test.go +++ b/blockdag/external_dag_test.go @@ -198,7 +198,7 @@ func TestChainedTransactions(t *testing.T) { t.Fatalf("Failed to build signature script: %s", err) } txIn := &wire.TxIn{ - PreviousOutPoint: wire.OutPoint{TxID: *cbTx.TxID(), Index: 0}, + PreviousOutpoint: wire.Outpoint{TxID: *cbTx.TxID(), Index: 0}, SignatureScript: signatureScript, Sequence: wire.MaxTxInSequenceNum, } @@ -209,7 +209,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: signatureScript, Sequence: wire.MaxTxInSequenceNum, } @@ -245,7 +245,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: signatureScript, Sequence: wire.MaxTxInSequenceNum, } @@ -316,7 +316,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, SignatureScript: signatureScript, } @@ -327,7 +327,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, SignatureScript: signatureScript, } @@ -357,7 +357,7 @@ func TestGasLimit(t *testing.T) { } overflowGasTxIn := &wire.TxIn{ - PreviousOutPoint: *wire.NewOutPoint(cbTxID, 1), + PreviousOutpoint: *wire.NewOutpoint(cbTxID, 1), Sequence: wire.MaxTxInSequenceNum, SignatureScript: signatureScript, } @@ -389,7 +389,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, SignatureScript: signatureScript, } diff --git a/blockdag/fees.go b/blockdag/fees.go index cc6bc8168..8b8403b32 100644 --- a/blockdag/fees.go +++ b/blockdag/fees.go @@ -183,7 +183,7 @@ func feeInputAndOutputForBlueBlock(blueBlock *blockNode, txsAcceptanceData Multi txIn := &wire.TxIn{ SignatureScript: []byte{}, - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID(*blueBlock.hash), Index: math.MaxUint32, }, diff --git a/blockdag/fullblocktests/generate.go b/blockdag/fullblocktests/generate.go index c6c8a60f6..09adeb619 100644 --- a/blockdag/fullblocktests/generate.go +++ b/blockdag/fullblocktests/generate.go @@ -153,7 +153,7 @@ func (b RejectedNonCanonicalBlock) FullBlockTestInstance() {} // spendableOut represents a transaction output that is spendable along with // additional metadata such as the block its in and how much it pays. type spendableOut struct { - prevOut wire.OutPoint + prevOut wire.Outpoint amount util.Amount } @@ -161,7 +161,7 @@ type spendableOut struct { // and transaction output index within the transaction. func makeSpendableOutForTx(tx *wire.MsgTx, txOutIndex uint32) spendableOut { return spendableOut{ - prevOut: wire.OutPoint{ + prevOut: wire.Outpoint{ TxID: *tx.TxID(), Index: txOutIndex, }, @@ -285,7 +285,7 @@ func (g *testGenerator) createCoinbaseTx(blockHeight uint64) *wire.MsgTx { txIn := &wire.TxIn{ // Coinbase transactions have no inputs, so previous outpoint is // zero hash and max index. - PreviousOutPoint: *wire.NewOutPoint(&daghash.TxID{}, + PreviousOutpoint: *wire.NewOutpoint(&daghash.TxID{}, wire.MaxPrevOutIndex), Sequence: wire.MaxTxInSequenceNum, SignatureScript: coinbaseScript, @@ -436,7 +436,7 @@ func additionalTx(tx *wire.MsgTx) func(*wire.MsgBlock) { // tests. func createSpendTx(spend *spendableOut, fee util.Amount) *wire.MsgTx { txIn := &wire.TxIn{ - PreviousOutPoint: spend.prevOut, + PreviousOutpoint: spend.prevOut, Sequence: wire.MaxTxInSequenceNum, SignatureScript: nil, } @@ -1532,8 +1532,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { g.nextBlock("b52", outs[14], func(b *wire.MsgBlock) { txID := newTxIDFromStr("00000000000000000000000000000000" + "00000000000000000123456789abcdef") - b.Transactions[1].TxIn[0].PreviousOutPoint.TxID = *txID - b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 0 + b.Transactions[1].TxIn[0].PreviousOutpoint.TxID = *txID + b.Transactions[1].TxIn[0].PreviousOutpoint.Index = 0 }) rejected(blockdag.ErrMissingTxOut) @@ -1689,7 +1689,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) { // \-> b58(17) g.setTip("b57") g.nextBlock("b58", outs[17], func(b *wire.MsgBlock) { - b.Transactions[1].TxIn[0].PreviousOutPoint.Index = 42 + b.Transactions[1].TxIn[0].PreviousOutpoint.Index = 42 }) rejected(blockdag.ErrMissingTxOut) diff --git a/blockdag/fullblocktests/params.go b/blockdag/fullblocktests/params.go index 93319a7c4..1329557d1 100644 --- a/blockdag/fullblocktests/params.go +++ b/blockdag/fullblocktests/params.go @@ -77,7 +77,7 @@ var ( Transactions: []*wire.MsgTx{{ Version: 1, TxIn: []*wire.TxIn{{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, diff --git a/blockdag/indexers/addrindex.go b/blockdag/indexers/addrindex.go index e52a96320..00a00a007 100644 --- a/blockdag/indexers/addrindex.go +++ b/blockdag/indexers/addrindex.go @@ -673,7 +673,7 @@ func (idx *AddrIndex) indexBlock(data writeIndexData, block *util.Block, dag *bl // The UTXO should always have the input since // the index contract requires it, however, be // safe and simply ignore any missing entries. - entry, ok := dag.GetUTXOEntry(txIn.PreviousOutPoint) + entry, ok := dag.GetUTXOEntry(txIn.PreviousOutpoint) if !ok { continue } @@ -842,7 +842,7 @@ func (idx *AddrIndex) AddUnconfirmedTx(tx *util.Tx, utxoSet blockdag.UTXOSet) { // transaction has already been validated and thus all inputs are // already known to exist. for _, txIn := range tx.MsgTx().TxIn { - entry, ok := utxoSet.Get(txIn.PreviousOutPoint) + entry, ok := utxoSet.Get(txIn.PreviousOutpoint) if !ok { // Ignore missing entries. This should never happen // in practice since the function comments specifically diff --git a/blockdag/indexers/txindex_test.go b/blockdag/indexers/txindex_test.go index a611c2dba..ba663d246 100644 --- a/blockdag/indexers/txindex_test.go +++ b/blockdag/indexers/txindex_test.go @@ -20,7 +20,7 @@ func createTransaction(t *testing.T, value uint64, originTx *wire.MsgTx, outputI t.Fatalf("Error creating signature script: %s", err) } txIn := &wire.TxIn{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: *originTx.TxID(), Index: outputIndex, }, diff --git a/blockdag/scriptval.go b/blockdag/scriptval.go index 522bd6477..3f7ab0a5b 100644 --- a/blockdag/scriptval.go +++ b/blockdag/scriptval.go @@ -55,12 +55,12 @@ out: case txVI := <-v.validateChan: // Ensure the referenced input utxo is available. txIn := txVI.txIn - entry, ok := v.utxoSet.Get(txIn.PreviousOutPoint) + entry, ok := v.utxoSet.Get(txIn.PreviousOutpoint) if !ok { str := fmt.Sprintf("unable to find unspent "+ "output %s referenced from "+ "transaction %s:%d", - txIn.PreviousOutPoint, txVI.tx.ID(), + txIn.PreviousOutpoint, txVI.tx.ID(), txVI.txInIndex) err := ruleError(ErrMissingTxOut, str) v.sendResult(err) @@ -78,7 +78,7 @@ out: "%s (input script bytes %x, prev "+ "output script bytes %x)", txVI.tx.ID(), txVI.txInIndex, - txIn.PreviousOutPoint, err, sigScript, pkScript) + txIn.PreviousOutpoint, err, sigScript, pkScript) err := ruleError(ErrScriptMalformed, str) v.sendResult(err) break out @@ -91,7 +91,7 @@ out: "%s (input script bytes %x, prev output "+ "script bytes %x)", txVI.tx.ID(), txVI.txInIndex, - txIn.PreviousOutPoint, err, sigScript, pkScript) + txIn.PreviousOutpoint, err, sigScript, pkScript) err := ruleError(ErrScriptValidation, str) v.sendResult(err) break out @@ -186,7 +186,7 @@ func ValidateTransactionScripts(tx *util.Tx, utxoSet UTXOSet, flags txscript.Scr txValItems := make([]*txValidateItem, 0, len(txIns)) for txInIdx, txIn := range txIns { // Skip block reward transactions. - if txIn.PreviousOutPoint.Index == math.MaxUint32 { + if txIn.PreviousOutpoint.Index == math.MaxUint32 { continue } @@ -216,7 +216,7 @@ func checkBlockScripts(block *blockNode, utxoSet UTXOSet, transactions []*util.T for _, tx := range transactions { for txInIdx, txIn := range tx.MsgTx().TxIn { // Skip block reward transactions. - if txIn.PreviousOutPoint.Index == math.MaxUint32 { + if txIn.PreviousOutpoint.Index == math.MaxUint32 { continue } diff --git a/blockdag/test_utils.go b/blockdag/test_utils.go index 3f1690a41..399149675 100644 --- a/blockdag/test_utils.go +++ b/blockdag/test_utils.go @@ -116,7 +116,7 @@ func createTxForTest(numInputs uint32, numOutputs uint32, outputValue uint64, su for i := uint32(0); i < numInputs; i++ { txIns = append(txIns, &wire.TxIn{ - PreviousOutPoint: *wire.NewOutPoint(&daghash.TxID{}, i), + PreviousOutpoint: *wire.NewOutpoint(&daghash.TxID{}, i), SignatureScript: []byte{}, Sequence: wire.MaxTxInSequenceNum, }) @@ -151,7 +151,7 @@ func createCoinbaseTxForTest(blockHeight uint64, numOutputs uint32, extraNonce i txIns := []*wire.TxIn{&wire.TxIn{ // Coinbase transactions have no inputs, so previous outpoint is // zero hash and max index. - PreviousOutPoint: *wire.NewOutPoint(&daghash.TxID{}, + PreviousOutpoint: *wire.NewOutpoint(&daghash.TxID{}, wire.MaxPrevOutIndex), SignatureScript: coinbaseScript, Sequence: wire.MaxTxInSequenceNum, diff --git a/blockdag/utxodiffstore_test.go b/blockdag/utxodiffstore_test.go index c7b3f7c14..ea1dff44d 100644 --- a/blockdag/utxodiffstore_test.go +++ b/blockdag/utxodiffstore_test.go @@ -40,8 +40,8 @@ func TestUTXODiffStore(t *testing.T) { // Add node's diff data to the utxoDiffStore and check if it's checked correctly. node := createNode() diff := NewUTXODiff() - diff.toAdd.add(wire.OutPoint{TxID: daghash.TxID{0x01}, Index: 0}, &UTXOEntry{amount: 1, pkScript: []byte{0x01}}) - diff.toRemove.add(wire.OutPoint{TxID: daghash.TxID{0x02}, Index: 0}, &UTXOEntry{amount: 2, pkScript: []byte{0x02}}) + diff.toAdd.add(wire.Outpoint{TxID: daghash.TxID{0x01}, Index: 0}, &UTXOEntry{amount: 1, pkScript: []byte{0x01}}) + diff.toRemove.add(wire.Outpoint{TxID: daghash.TxID{0x02}, Index: 0}, &UTXOEntry{amount: 2, pkScript: []byte{0x02}}) if err := dag.utxoDiffStore.setBlockDiff(node, diff); err != nil { t.Fatalf("setBlockDiff: unexpected error: %s", err) } diff --git a/blockdag/utxoio.go b/blockdag/utxoio.go index 81ed0576e..b856a037c 100644 --- a/blockdag/utxoio.go +++ b/blockdag/utxoio.go @@ -100,17 +100,17 @@ func deserializeDiffEntries(r io.Reader) (utxoCollection, error) { } collection := utxoCollection{} for i := uint64(0); i < count; i++ { - outPointSize, err := wire.ReadVarInt(r) + outpointSize, err := wire.ReadVarInt(r) if err != nil { return nil, err } - serializedOutPoint := make([]byte, outPointSize) - err = binary.Read(r, byteOrder, serializedOutPoint) + serializedOutpoint := make([]byte, outpointSize) + err = binary.Read(r, byteOrder, serializedOutpoint) if err != nil { return nil, err } - outPoint, err := deserializeOutPoint(serializedOutPoint) + outpoint, err := deserializeOutpoint(serializedOutpoint) if err != nil { return nil, err } @@ -128,7 +128,7 @@ func deserializeDiffEntries(r io.Reader) (utxoCollection, error) { if err != nil { return nil, err } - collection.add(*outPoint, utxoEntry) + collection.add(*outpoint, utxoEntry) } return collection, nil } @@ -179,8 +179,8 @@ func serializeUTXOCollection(w io.Writer, collection utxoCollection) error { if err != nil { return err } - for outPoint, utxoEntry := range collection { - err := serializeUTXO(w, utxoEntry, &outPoint) + for outpoint, utxoEntry := range collection { + err := serializeUTXO(w, utxoEntry, &outpoint) if err != nil { return err } @@ -212,14 +212,14 @@ func serializeMultiset(w io.Writer, ms *btcec.Multiset) error { } // serializeUTXO serializes a utxo entry-outpoint pair -func serializeUTXO(w io.Writer, entry *UTXOEntry, outPoint *wire.OutPoint) error { - serializedOutPoint := *outpointKey(*outPoint) - err := wire.WriteVarInt(w, uint64(len(serializedOutPoint))) +func serializeUTXO(w io.Writer, entry *UTXOEntry, outpoint *wire.Outpoint) error { + serializedOutpoint := *outpointKey(*outpoint) + err := wire.WriteVarInt(w, uint64(len(serializedOutpoint))) if err != nil { return err } - err = binary.Write(w, byteOrder, serializedOutPoint) + err = binary.Write(w, byteOrder, serializedOutpoint) if err != nil { return err } @@ -256,10 +256,10 @@ func serializeUTXOEntry(entry *UTXOEntry) []byte { return serialized } -// deserializeOutPoint decodes an outPoint from the passed serialized byte -// slice into a new wire.OutPoint using a format that is suitable for long- +// deserializeOutpoint decodes an outpoint from the passed serialized byte +// slice into a new wire.Outpoint using a format that is suitable for long- // term storage. this format is described in detail above. -func deserializeOutPoint(serialized []byte) (*wire.OutPoint, error) { +func deserializeOutpoint(serialized []byte) (*wire.Outpoint, error) { if len(serialized) <= daghash.HashSize { return nil, errDeserialize("unexpected end of data") } @@ -267,7 +267,7 @@ func deserializeOutPoint(serialized []byte) (*wire.OutPoint, error) { txID := daghash.TxID{} txID.SetBytes(serialized[:daghash.HashSize]) index, _ := deserializeVLQ(serialized[daghash.HashSize:]) - return wire.NewOutPoint(&txID, uint32(index)), nil + return wire.NewOutpoint(&txID, uint32(index)), nil } // deserializeUTXOEntry decodes a UTXO entry from the passed serialized byte diff --git a/blockdag/utxoset.go b/blockdag/utxoset.go index aa2d42c54..7814c17a8 100644 --- a/blockdag/utxoset.go +++ b/blockdag/utxoset.go @@ -77,15 +77,15 @@ const ( tfBlockReward txoFlags = 1 << iota ) -// utxoCollection represents a set of UTXOs indexed by their outPoints -type utxoCollection map[wire.OutPoint]*UTXOEntry +// utxoCollection represents a set of UTXOs indexed by their outpoints +type utxoCollection map[wire.Outpoint]*UTXOEntry func (uc utxoCollection) String() string { utxoStrings := make([]string, len(uc)) i := 0 - for outPoint, utxoEntry := range uc { - utxoStrings[i] = fmt.Sprintf("(%s, %d) => %d", outPoint.TxID, outPoint.Index, utxoEntry.amount) + for outpoint, utxoEntry := range uc { + utxoStrings[i] = fmt.Sprintf("(%s, %d) => %d", outpoint.TxID, outpoint.Index, utxoEntry.amount) i++ } @@ -96,33 +96,33 @@ func (uc utxoCollection) String() string { } // add adds a new UTXO entry to this collection -func (uc utxoCollection) add(outPoint wire.OutPoint, entry *UTXOEntry) { - uc[outPoint] = entry +func (uc utxoCollection) add(outpoint wire.Outpoint, entry *UTXOEntry) { + uc[outpoint] = entry } // remove removes a UTXO entry from this collection if it exists -func (uc utxoCollection) remove(outPoint wire.OutPoint) { - delete(uc, outPoint) +func (uc utxoCollection) remove(outpoint wire.Outpoint) { + delete(uc, outpoint) } -// get returns the UTXOEntry represented by provided outPoint, +// get returns the UTXOEntry represented by provided outpoint, // and a boolean value indicating if said UTXOEntry is in the set or not -func (uc utxoCollection) get(outPoint wire.OutPoint) (*UTXOEntry, bool) { - entry, ok := uc[outPoint] +func (uc utxoCollection) get(outpoint wire.Outpoint) (*UTXOEntry, bool) { + entry, ok := uc[outpoint] return entry, ok } // contains returns a boolean value indicating whether a UTXO entry is in the set -func (uc utxoCollection) contains(outPoint wire.OutPoint) bool { - _, ok := uc[outPoint] +func (uc utxoCollection) contains(outpoint wire.Outpoint) bool { + _, ok := uc[outpoint] return ok } // clone returns a clone of this collection func (uc utxoCollection) clone() utxoCollection { clone := utxoCollection{} - for outPoint, entry := range uc { - clone.add(outPoint, entry) + for outpoint, entry := range uc { + clone.add(outpoint, entry) } return clone @@ -187,40 +187,40 @@ func (d *UTXODiff) diffFrom(other *UTXODiff) (*UTXODiff, error) { // All transactions in d.toAdd: // If they are not in other.toAdd - should be added in result.toRemove // If they are in other.toRemove - base utxoSet is not the same - for outPoint, utxoEntry := range d.toAdd { - if !other.toAdd.contains(outPoint) { - result.toRemove.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range d.toAdd { + if !other.toAdd.contains(outpoint) { + result.toRemove.add(outpoint, utxoEntry) } - if other.toRemove.contains(outPoint) { - return nil, fmt.Errorf("diffFrom: outpoint %s both in d.toAdd and in other.toRemove", outPoint) + if other.toRemove.contains(outpoint) { + return nil, fmt.Errorf("diffFrom: outpoint %s both in d.toAdd and in other.toRemove", outpoint) } } // All transactions in d.toRemove: // If they are not in other.toRemove - should be added in result.toAdd // If they are in other.toAdd - base utxoSet is not the same - for outPoint, utxoEntry := range d.toRemove { - if !other.toRemove.contains(outPoint) { - result.toAdd.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range d.toRemove { + if !other.toRemove.contains(outpoint) { + result.toAdd.add(outpoint, utxoEntry) } - if other.toAdd.contains(outPoint) { + if other.toAdd.contains(outpoint) { return nil, errors.New("diffFrom: transaction both in d.toRemove and in other.toAdd") } } // All transactions in other.toAdd: // If they are not in d.toAdd - should be added in result.toAdd - for outPoint, utxoEntry := range other.toAdd { - if !d.toAdd.contains(outPoint) { - result.toAdd.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range other.toAdd { + if !d.toAdd.contains(outpoint) { + result.toAdd.add(outpoint, utxoEntry) } } // All transactions in other.toRemove: // If they are not in d.toRemove - should be added in result.toRemove - for outPoint, utxoEntry := range other.toRemove { - if !d.toRemove.contains(outPoint) { - result.toRemove.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range other.toRemove { + if !d.toRemove.contains(outpoint) { + result.toRemove.add(outpoint, utxoEntry) } } @@ -267,12 +267,12 @@ func (d *UTXODiff) WithDiff(diff *UTXODiff) (*UTXODiff, error) { // If they are not in diff.toRemove - should be added in result.toAdd // If they are in diff.toAdd - should throw an error // Otherwise - should be ignored - for outPoint, utxoEntry := range d.toAdd { - if !diff.toRemove.contains(outPoint) { - result.toAdd.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range d.toAdd { + if !diff.toRemove.contains(outpoint) { + result.toAdd.add(outpoint, utxoEntry) } - if diff.toAdd.contains(outPoint) { - return nil, ruleError(ErrWithDiff, fmt.Sprintf("WithDiff: outpoint %s both in d.toAdd and in other.toAdd", outPoint)) + if diff.toAdd.contains(outpoint) { + return nil, ruleError(ErrWithDiff, fmt.Sprintf("WithDiff: outpoint %s both in d.toAdd and in other.toAdd", outpoint)) } } @@ -280,28 +280,28 @@ func (d *UTXODiff) WithDiff(diff *UTXODiff) (*UTXODiff, error) { // If they are not in diff.toAdd - should be added in result.toRemove // If they are in diff.toRemove - should throw an error // Otherwise - should be ignored - for outPoint, utxoEntry := range d.toRemove { - if !diff.toAdd.contains(outPoint) { - result.toRemove.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range d.toRemove { + if !diff.toAdd.contains(outpoint) { + result.toRemove.add(outpoint, utxoEntry) } - if diff.toRemove.contains(outPoint) { + if diff.toRemove.contains(outpoint) { return nil, ruleError(ErrWithDiff, "WithDiff: transaction both in d.toRemove and in other.toRemove") } } // All transactions in diff.toAdd: // If they are not in d.toRemove - should be added in result.toAdd - for outPoint, utxoEntry := range diff.toAdd { - if !d.toRemove.contains(outPoint) { - result.toAdd.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range diff.toAdd { + if !d.toRemove.contains(outpoint) { + result.toAdd.add(outpoint, utxoEntry) } } // All transactions in diff.toRemove: // If they are not in d.toAdd - should be added in result.toRemove - for outPoint, utxoEntry := range diff.toRemove { - if !d.toAdd.contains(outPoint) { - result.toRemove.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range diff.toRemove { + if !d.toAdd.contains(outpoint) { + result.toRemove.add(outpoint, utxoEntry) } } @@ -321,17 +321,17 @@ func (d *UTXODiff) clone() *UTXODiff { } // AddEntry adds a UTXOEntry to the diff -func (d *UTXODiff) AddEntry(outPoint wire.OutPoint, entry *UTXOEntry) error { - if d.toRemove.contains(outPoint) { - d.toRemove.remove(outPoint) - } else if _, exists := d.toAdd[outPoint]; exists { - return fmt.Errorf("AddEntry: Cannot add outpoint %s twice", outPoint) +func (d *UTXODiff) AddEntry(outpoint wire.Outpoint, entry *UTXOEntry) error { + if d.toRemove.contains(outpoint) { + d.toRemove.remove(outpoint) + } else if _, exists := d.toAdd[outpoint]; exists { + return fmt.Errorf("AddEntry: Cannot add outpoint %s twice", outpoint) } else { - d.toAdd.add(outPoint, entry) + d.toAdd.add(outpoint, entry) } var err error - newMs, err := addUTXOToMultiset(d.diffMultiset, entry, &outPoint) + newMs, err := addUTXOToMultiset(d.diffMultiset, entry, &outpoint) if err != nil { return err } @@ -340,17 +340,17 @@ func (d *UTXODiff) AddEntry(outPoint wire.OutPoint, entry *UTXOEntry) error { } // RemoveEntry removes a UTXOEntry from the diff -func (d *UTXODiff) RemoveEntry(outPoint wire.OutPoint, entry *UTXOEntry) error { - if d.toAdd.contains(outPoint) { - d.toAdd.remove(outPoint) - } else if _, exists := d.toRemove[outPoint]; exists { - return fmt.Errorf("removeEntry: Cannot remove outpoint %s twice", outPoint) +func (d *UTXODiff) RemoveEntry(outpoint wire.Outpoint, entry *UTXOEntry) error { + if d.toAdd.contains(outpoint) { + d.toAdd.remove(outpoint) + } else if _, exists := d.toRemove[outpoint]; exists { + return fmt.Errorf("removeEntry: Cannot remove outpoint %s twice", outpoint) } else { - d.toRemove.add(outPoint, entry) + d.toRemove.add(outpoint, entry) } var err error - newMs, err := removeUTXOFromMultiset(d.diffMultiset, entry, &outPoint) + newMs, err := removeUTXOFromMultiset(d.diffMultiset, entry, &outpoint) if err != nil { return err } @@ -396,7 +396,7 @@ type UTXOSet interface { diffFromTx(tx *wire.MsgTx, node *blockNode) (*UTXODiff, error) AddTx(tx *wire.MsgTx, blockHeight uint64) (ok bool, err error) clone() UTXOSet - Get(outPoint wire.OutPoint) (*UTXOEntry, bool) + Get(outpoint wire.Outpoint) (*UTXOEntry, bool) Multiset() *btcec.Multiset WithTransactions(transactions []*wire.MsgTx, blockHeight uint64, ignoreDoubleSpends bool) (UTXOSet, error) } @@ -410,22 +410,22 @@ func diffFromTx(u UTXOSet, tx *wire.MsgTx, containingNode *blockNode) (*UTXODiff isBlockReward := tx.IsBlockReward() if !isBlockReward { for _, txIn := range tx.TxIn { - if entry, ok := u.Get(txIn.PreviousOutPoint); ok { - err := diff.RemoveEntry(txIn.PreviousOutPoint, entry) + if entry, ok := u.Get(txIn.PreviousOutpoint); ok { + err := diff.RemoveEntry(txIn.PreviousOutpoint, entry) if err != nil { return nil, err } } else { return nil, ruleError(ErrMissingTxOut, fmt.Sprintf( "Transaction %s is invalid because spends outpoint %s that is not in utxo set", - tx.TxID(), txIn.PreviousOutPoint)) + tx.TxID(), txIn.PreviousOutpoint)) } } } for i, txOut := range tx.TxOut { entry := NewUTXOEntry(txOut, isBlockReward, containingNode.height) - outPoint := *wire.NewOutPoint(tx.TxID(), uint32(i)) - err := diff.AddEntry(outPoint, entry) + outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i)) + err := diff.AddEntry(outpoint, entry) if err != nil { return nil, err } @@ -478,8 +478,8 @@ func (fus *FullUTXOSet) AddTx(tx *wire.MsgTx, blockHeight uint64) (isAccepted bo } for _, txIn := range tx.TxIn { - outPoint := *wire.NewOutPoint(&txIn.PreviousOutPoint.TxID, txIn.PreviousOutPoint.Index) - err := fus.removeAndUpdateMultiset(outPoint) + outpoint := *wire.NewOutpoint(&txIn.PreviousOutpoint.TxID, txIn.PreviousOutpoint.Index) + err := fus.removeAndUpdateMultiset(outpoint) if err != nil { return false, err } @@ -487,10 +487,10 @@ func (fus *FullUTXOSet) AddTx(tx *wire.MsgTx, blockHeight uint64) (isAccepted bo } for i, txOut := range tx.TxOut { - outPoint := *wire.NewOutPoint(tx.TxID(), uint32(i)) + outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i)) entry := NewUTXOEntry(txOut, isBlockReward, blockHeight) - err := fus.addAndUpdateMultiset(outPoint, entry) + err := fus.addAndUpdateMultiset(outpoint, entry) if err != nil { return false, err } @@ -507,8 +507,8 @@ func (fus *FullUTXOSet) diffFromTx(tx *wire.MsgTx, node *blockNode) (*UTXODiff, func (fus *FullUTXOSet) containsInputs(tx *wire.MsgTx) bool { for _, txIn := range tx.TxIn { - outPoint := *wire.NewOutPoint(&txIn.PreviousOutPoint.TxID, txIn.PreviousOutPoint.Index) - if !fus.contains(outPoint) { + outpoint := *wire.NewOutpoint(&txIn.PreviousOutpoint.TxID, txIn.PreviousOutpoint.Index) + if !fus.contains(outpoint) { return false } } @@ -521,9 +521,9 @@ func (fus *FullUTXOSet) clone() UTXOSet { return &FullUTXOSet{utxoCollection: fus.utxoCollection.clone(), UTXOMultiset: fus.UTXOMultiset.Clone()} } -// Get returns the UTXOEntry associated with the given OutPoint, and a boolean indicating if such entry was found -func (fus *FullUTXOSet) Get(outPoint wire.OutPoint) (*UTXOEntry, bool) { - utxoEntry, ok := fus.utxoCollection[outPoint] +// Get returns the UTXOEntry associated with the given Outpoint, and a boolean indicating if such entry was found +func (fus *FullUTXOSet) Get(outpoint wire.Outpoint) (*UTXOEntry, bool) { + utxoEntry, ok := fus.utxoCollection[outpoint] return utxoEntry, ok } @@ -533,9 +533,9 @@ func (fus *FullUTXOSet) Multiset() *btcec.Multiset { } // addAndUpdateMultiset adds a UTXOEntry to this utxoSet and updates its multiset accordingly -func (fus *FullUTXOSet) addAndUpdateMultiset(outPoint wire.OutPoint, entry *UTXOEntry) error { - fus.add(outPoint, entry) - newMs, err := addUTXOToMultiset(fus.UTXOMultiset, entry, &outPoint) +func (fus *FullUTXOSet) addAndUpdateMultiset(outpoint wire.Outpoint, entry *UTXOEntry) error { + fus.add(outpoint, entry) + newMs, err := addUTXOToMultiset(fus.UTXOMultiset, entry, &outpoint) if err != nil { return err } @@ -544,14 +544,14 @@ func (fus *FullUTXOSet) addAndUpdateMultiset(outPoint wire.OutPoint, entry *UTXO } // removeAndUpdateMultiset removes a UTXOEntry from this utxoSet and updates its multiset accordingly -func (fus *FullUTXOSet) removeAndUpdateMultiset(outPoint wire.OutPoint) error { - entry, ok := fus.Get(outPoint) +func (fus *FullUTXOSet) removeAndUpdateMultiset(outpoint wire.Outpoint) error { + entry, ok := fus.Get(outpoint) if !ok { - return fmt.Errorf("Couldn't find outpoint %s", outPoint) + return fmt.Errorf("Couldn't find outpoint %s", outpoint) } - fus.remove(outPoint) + fus.remove(outpoint) var err error - newMs, err := removeUTXOFromMultiset(fus.UTXOMultiset, entry, &outPoint) + newMs, err := removeUTXOFromMultiset(fus.UTXOMultiset, entry, &outpoint) if err != nil { return err } @@ -631,12 +631,12 @@ func (dus *DiffUTXOSet) AddTx(tx *wire.MsgTx, blockHeight uint64) (bool, error) func (dus *DiffUTXOSet) appendTx(tx *wire.MsgTx, blockHeight uint64, isBlockReward bool) error { if !isBlockReward { for _, txIn := range tx.TxIn { - outPoint := *wire.NewOutPoint(&txIn.PreviousOutPoint.TxID, txIn.PreviousOutPoint.Index) - entry, ok := dus.Get(outPoint) + outpoint := *wire.NewOutpoint(&txIn.PreviousOutpoint.TxID, txIn.PreviousOutpoint.Index) + entry, ok := dus.Get(outpoint) if !ok { - return fmt.Errorf("Couldn't find entry for outpoint %s", outPoint) + return fmt.Errorf("Couldn't find entry for outpoint %s", outpoint) } - err := dus.UTXODiff.RemoveEntry(outPoint, entry) + err := dus.UTXODiff.RemoveEntry(outpoint, entry) if err != nil { return err } @@ -644,10 +644,10 @@ func (dus *DiffUTXOSet) appendTx(tx *wire.MsgTx, blockHeight uint64, isBlockRewa } for i, txOut := range tx.TxOut { - outPoint := *wire.NewOutPoint(tx.TxID(), uint32(i)) + outpoint := *wire.NewOutpoint(tx.TxID(), uint32(i)) entry := NewUTXOEntry(txOut, isBlockReward, blockHeight) - err := dus.UTXODiff.AddEntry(outPoint, entry) + err := dus.UTXODiff.AddEntry(outpoint, entry) if err != nil { return err } @@ -657,10 +657,10 @@ func (dus *DiffUTXOSet) appendTx(tx *wire.MsgTx, blockHeight uint64, isBlockRewa func (dus *DiffUTXOSet) containsInputs(tx *wire.MsgTx) bool { for _, txIn := range tx.TxIn { - outPoint := *wire.NewOutPoint(&txIn.PreviousOutPoint.TxID, txIn.PreviousOutPoint.Index) - isInBase := dus.base.contains(outPoint) - isInDiffToAdd := dus.UTXODiff.toAdd.contains(outPoint) - isInDiffToRemove := dus.UTXODiff.toRemove.contains(outPoint) + outpoint := *wire.NewOutpoint(&txIn.PreviousOutpoint.TxID, txIn.PreviousOutpoint.Index) + isInBase := dus.base.contains(outpoint) + isInDiffToAdd := dus.UTXODiff.toAdd.contains(outpoint) + isInDiffToRemove := dus.UTXODiff.toRemove.contains(outpoint) if (!isInBase && !isInDiffToAdd) || isInDiffToRemove { return false } @@ -671,16 +671,16 @@ func (dus *DiffUTXOSet) containsInputs(tx *wire.MsgTx) bool { // meldToBase updates the base fullUTXOSet with all changes in diff func (dus *DiffUTXOSet) meldToBase() error { - for outPoint := range dus.UTXODiff.toRemove { - if _, ok := dus.base.Get(outPoint); ok { - dus.base.remove(outPoint) + for outpoint := range dus.UTXODiff.toRemove { + if _, ok := dus.base.Get(outpoint); ok { + dus.base.remove(outpoint) } else { - return fmt.Errorf("Couldn't remove outpoint %s because it doesn't exist in the DiffUTXOSet base", outPoint) + return fmt.Errorf("Couldn't remove outpoint %s because it doesn't exist in the DiffUTXOSet base", outpoint) } } - for outPoint, utxoEntry := range dus.UTXODiff.toAdd { - dus.base.add(outPoint, utxoEntry) + for outpoint, utxoEntry := range dus.UTXODiff.toAdd { + dus.base.add(outpoint, utxoEntry) } dus.base.UTXOMultiset = dus.base.UTXOMultiset.Union(dus.UTXODiff.diffMultiset) @@ -704,16 +704,16 @@ func (dus *DiffUTXOSet) clone() UTXOSet { return NewDiffUTXOSet(dus.base.clone().(*FullUTXOSet), dus.UTXODiff.clone()) } -// Get returns the UTXOEntry associated with provided outPoint in this UTXOSet. +// Get returns the UTXOEntry associated with provided outpoint in this UTXOSet. // Returns false in second output if this UTXOEntry was not found -func (dus *DiffUTXOSet) Get(outPoint wire.OutPoint) (*UTXOEntry, bool) { - if dus.UTXODiff.toRemove.contains(outPoint) { +func (dus *DiffUTXOSet) Get(outpoint wire.Outpoint) (*UTXOEntry, bool) { + if dus.UTXODiff.toRemove.contains(outpoint) { return nil, false } - if txOut, ok := dus.base.get(outPoint); ok { + if txOut, ok := dus.base.get(outpoint); ok { return txOut, true } - txOut, ok := dus.UTXODiff.toAdd.get(outPoint) + txOut, ok := dus.UTXODiff.toAdd.get(outpoint) return txOut, ok } @@ -737,18 +737,18 @@ func (dus *DiffUTXOSet) WithTransactions(transactions []*wire.MsgTx, blockHeight return UTXOSet(diffSet), nil } -func addUTXOToMultiset(ms *btcec.Multiset, entry *UTXOEntry, outPoint *wire.OutPoint) (*btcec.Multiset, error) { +func addUTXOToMultiset(ms *btcec.Multiset, entry *UTXOEntry, outpoint *wire.Outpoint) (*btcec.Multiset, error) { w := &bytes.Buffer{} - err := serializeUTXO(w, entry, outPoint) + err := serializeUTXO(w, entry, outpoint) if err != nil { return nil, err } return ms.Add(w.Bytes()), nil } -func removeUTXOFromMultiset(ms *btcec.Multiset, entry *UTXOEntry, outPoint *wire.OutPoint) (*btcec.Multiset, error) { +func removeUTXOFromMultiset(ms *btcec.Multiset, entry *UTXOEntry, outpoint *wire.Outpoint) (*btcec.Multiset, error) { w := &bytes.Buffer{} - err := serializeUTXO(w, entry, outPoint) + err := serializeUTXO(w, entry, outpoint) if err != nil { return nil, err } diff --git a/blockdag/utxoset_test.go b/blockdag/utxoset_test.go index 70dc6167d..0ae756eb5 100644 --- a/blockdag/utxoset_test.go +++ b/blockdag/utxoset_test.go @@ -15,8 +15,8 @@ import ( func TestUTXOCollection(t *testing.T) { txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111") - outPoint0 := *wire.NewOutPoint(txID0, 0) - outPoint1 := *wire.NewOutPoint(txID1, 0) + outpoint0 := *wire.NewOutpoint(txID0, 0) + outpoint1 := *wire.NewOutpoint(txID1, 0) utxoEntry0 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 10}, true, 0) utxoEntry1 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 20}, false, 1) @@ -36,15 +36,15 @@ func TestUTXOCollection(t *testing.T) { { name: "one member", collection: utxoCollection{ - outPoint0: utxoEntry1, + outpoint0: utxoEntry1, }, expectedString: "[ (0000000000000000000000000000000000000000000000000000000000000000, 0) => 20 ]", }, { name: "two members", collection: utxoCollection{ - outPoint0: utxoEntry0, - outPoint1: utxoEntry1, + outpoint0: utxoEntry0, + outpoint1: utxoEntry1, }, expectedString: "[ (0000000000000000000000000000000000000000000000000000000000000000, 0) => 10, (1111111111111111111111111111111111111111111111111111111111111111, 0) => 20 ]", }, @@ -74,8 +74,8 @@ func TestUTXOCollection(t *testing.T) { func TestUTXODiff(t *testing.T) { txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111") - outPoint0 := *wire.NewOutPoint(txID0, 0) - outPoint1 := *wire.NewOutPoint(txID1, 0) + outpoint0 := *wire.NewOutpoint(txID0, 0) + outpoint1 := *wire.NewOutpoint(txID1, 0) utxoEntry0 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 10}, true, 0) utxoEntry1 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 20}, false, 1) @@ -85,12 +85,12 @@ func TestUTXODiff(t *testing.T) { t.Errorf("new diff is not empty") } - err := diff.AddEntry(outPoint0, utxoEntry0) + err := diff.AddEntry(outpoint0, utxoEntry0) if err != nil { t.Fatalf("Error adding entry to utxo diff: %s", err) } - err = diff.RemoveEntry(outPoint1, utxoEntry1) + err = diff.RemoveEntry(outpoint1, utxoEntry1) if err != nil { t.Fatalf("Error adding entry to utxo diff: %s", err) } @@ -118,7 +118,7 @@ func TestUTXODiff(t *testing.T) { // Each test case represents a cell in the two tables outlined in the documentation for utxoDiff. func TestUTXODiffRules(t *testing.T) { txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") - outPoint0 := *wire.NewOutPoint(txID0, 0) + outpoint0 := *wire.NewOutpoint(txID0, 0) utxoEntry0 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 10}, true, 0) // For each of the following test cases, we will: @@ -136,11 +136,11 @@ func TestUTXODiffRules(t *testing.T) { { name: "one toAdd in this, one toAdd in other", this: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, other: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, expectedDiffFromResult: &UTXODiff{ @@ -152,12 +152,12 @@ func TestUTXODiffRules(t *testing.T) { { name: "one toAdd in this, one toRemove in other", this: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, other: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, expectedDiffFromResult: nil, expectedWithDiffResult: &UTXODiff{ @@ -168,7 +168,7 @@ func TestUTXODiffRules(t *testing.T) { { name: "one toAdd in this, empty other", this: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, other: &UTXODiff{ @@ -177,10 +177,10 @@ func TestUTXODiffRules(t *testing.T) { }, expectedDiffFromResult: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, expectedWithDiffResult: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, }, @@ -188,10 +188,10 @@ func TestUTXODiffRules(t *testing.T) { name: "one toRemove in this, one toAdd in other", this: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, other: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, expectedDiffFromResult: nil, @@ -204,11 +204,11 @@ func TestUTXODiffRules(t *testing.T) { name: "one toRemove in this, one toRemove in other", this: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, other: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, expectedDiffFromResult: &UTXODiff{ toAdd: utxoCollection{}, @@ -220,19 +220,19 @@ func TestUTXODiffRules(t *testing.T) { name: "one toRemove in this, empty other", this: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, other: &UTXODiff{ toAdd: utxoCollection{}, toRemove: utxoCollection{}, }, expectedDiffFromResult: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, expectedWithDiffResult: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, }, { @@ -242,15 +242,15 @@ func TestUTXODiffRules(t *testing.T) { toRemove: utxoCollection{}, }, other: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, expectedDiffFromResult: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, expectedWithDiffResult: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, }, @@ -262,15 +262,15 @@ func TestUTXODiffRules(t *testing.T) { }, other: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, expectedDiffFromResult: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, expectedWithDiffResult: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, }, { @@ -362,14 +362,14 @@ func addMultisetToDiff(t *testing.T, diff *UTXODiff) *UTXODiff { return nil } diffWithMs := NewUTXODiff() - for outPoint, entry := range diff.toAdd { - err := diffWithMs.AddEntry(outPoint, entry) + for outpoint, entry := range diff.toAdd { + err := diffWithMs.AddEntry(outpoint, entry) if err != nil { t.Fatalf("Error with diffWithMs.AddEntry: %s", err) } } - for outPoint, entry := range diff.toRemove { - err := diffWithMs.RemoveEntry(outPoint, entry) + for outpoint, entry := range diff.toRemove { + err := diffWithMs.RemoveEntry(outpoint, entry) if err != nil { t.Fatalf("Error with diffWithMs.removeEntry: %s", err) } @@ -382,8 +382,8 @@ func addMultisetToFullUTXOSet(t *testing.T, fus *FullUTXOSet) *FullUTXOSet { return nil } fusWithMs := NewFullUTXOSet() - for outPoint, entry := range fus.utxoCollection { - err := fusWithMs.addAndUpdateMultiset(outPoint, entry) + for outpoint, entry := range fus.utxoCollection { + err := fusWithMs.addAndUpdateMultiset(outpoint, entry) if err != nil { t.Fatalf("Error with diffWithMs.AddEntry: %s", err) } @@ -404,15 +404,15 @@ func addMultisetToDiffUTXOSet(t *testing.T, diffSet *DiffUTXOSet) *DiffUTXOSet { func TestFullUTXOSet(t *testing.T) { txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111") - outPoint0 := *wire.NewOutPoint(txID0, 0) - outPoint1 := *wire.NewOutPoint(txID1, 0) + outpoint0 := *wire.NewOutpoint(txID0, 0) + outpoint1 := *wire.NewOutpoint(txID1, 0) txOut0 := &wire.TxOut{PkScript: []byte{}, Value: 10} txOut1 := &wire.TxOut{PkScript: []byte{}, Value: 20} utxoEntry0 := NewUTXOEntry(txOut0, true, 0) utxoEntry1 := NewUTXOEntry(txOut1, false, 1) diff := addMultisetToDiff(t, &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, - toRemove: utxoCollection{outPoint1: utxoEntry1}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint1: utxoEntry1}, }) // Test fullUTXOSet creation @@ -435,14 +435,14 @@ func TestFullUTXOSet(t *testing.T) { } // Test fullUTXOSet addTx - txIn0 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: wire.OutPoint{TxID: *txID0, Index: 0}, Sequence: 0} + txIn0 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: wire.Outpoint{TxID: *txID0, Index: 0}, Sequence: 0} transaction0 := wire.NewNativeMsgTx(1, []*wire.TxIn{txIn0}, []*wire.TxOut{txOut0}) if isAccepted, err := emptySet.AddTx(transaction0, 0); err != nil { t.Errorf("AddTx unexpectedly failed: %s", err) } else if isAccepted { t.Errorf("addTx unexpectedly succeeded") } - emptySet = addMultisetToFullUTXOSet(t, &FullUTXOSet{utxoCollection: utxoCollection{outPoint0: utxoEntry0}}) + emptySet = addMultisetToFullUTXOSet(t, &FullUTXOSet{utxoCollection: utxoCollection{outpoint0: utxoEntry0}}) if isAccepted, err := emptySet.AddTx(transaction0, 0); err != nil { t.Errorf("addTx unexpectedly failed. Error: %s", err) } else if !isAccepted { @@ -468,15 +468,15 @@ func TestFullUTXOSet(t *testing.T) { func TestDiffUTXOSet(t *testing.T) { txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111") - outPoint0 := *wire.NewOutPoint(txID0, 0) - outPoint1 := *wire.NewOutPoint(txID1, 0) + outpoint0 := *wire.NewOutpoint(txID0, 0) + outpoint1 := *wire.NewOutpoint(txID1, 0) txOut0 := &wire.TxOut{PkScript: []byte{}, Value: 10} txOut1 := &wire.TxOut{PkScript: []byte{}, Value: 20} utxoEntry0 := NewUTXOEntry(txOut0, true, 0) utxoEntry1 := NewUTXOEntry(txOut1, false, 1) diff := addMultisetToDiff(t, &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, - toRemove: utxoCollection{outPoint1: utxoEntry1}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint1: utxoEntry1}, }) // Test diffUTXOSet creation @@ -543,19 +543,19 @@ func TestDiffUTXOSet(t *testing.T) { diffSet: &DiffUTXOSet{ base: NewFullUTXOSet(), UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint0: utxoEntry0}, + toAdd: utxoCollection{outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, }, expectedMeldSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint0: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint0: utxoEntry0}}, UTXODiff: &UTXODiff{ toAdd: utxoCollection{}, toRemove: utxoCollection{}, }, }, expectedString: "{Base: [ ], To Add: [ (0000000000000000000000000000000000000000000000000000000000000000, 0) => 10 ], To Remove: [ ], Multiset-Hash:da4768bd0359c3426268d6707c1fc17a68c45ef1ea734331b07568418234487f}", - expectedCollection: utxoCollection{outPoint0: utxoEntry0}, + expectedCollection: utxoCollection{outpoint0: utxoEntry0}, }, { name: "empty base, one member in diff toRemove", @@ -563,7 +563,7 @@ func TestDiffUTXOSet(t *testing.T) { base: NewFullUTXOSet(), UTXODiff: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, }, expectedMeldSet: nil, @@ -574,17 +574,17 @@ func TestDiffUTXOSet(t *testing.T) { { name: "one member in base toAdd, one member in diff toAdd", diffSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint0: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint0: utxoEntry0}}, UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint1: utxoEntry1}, + toAdd: utxoCollection{outpoint1: utxoEntry1}, toRemove: utxoCollection{}, }, }, expectedMeldSet: &DiffUTXOSet{ base: &FullUTXOSet{ utxoCollection: utxoCollection{ - outPoint0: utxoEntry0, - outPoint1: utxoEntry1, + outpoint0: utxoEntry0, + outpoint1: utxoEntry1, }, }, UTXODiff: &UTXODiff{ @@ -594,17 +594,17 @@ func TestDiffUTXOSet(t *testing.T) { }, expectedString: "{Base: [ (0000000000000000000000000000000000000000000000000000000000000000, 0) => 10 ], To Add: [ (1111111111111111111111111111111111111111111111111111111111111111, 0) => 20 ], To Remove: [ ], Multiset-Hash:556cc61fd4d7e74d7807ca2298c5320375a6a20310a18920e54667220924baff}", expectedCollection: utxoCollection{ - outPoint0: utxoEntry0, - outPoint1: utxoEntry1, + outpoint0: utxoEntry0, + outpoint1: utxoEntry1, }, }, { name: "one member in base toAdd, same one member in diff toRemove", diffSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint0: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint0: utxoEntry0}}, UTXODiff: &UTXODiff{ toAdd: utxoCollection{}, - toRemove: utxoCollection{outPoint0: utxoEntry0}, + toRemove: utxoCollection{outpoint0: utxoEntry0}, }, }, expectedMeldSet: &DiffUTXOSet{ @@ -725,30 +725,30 @@ func TestUTXOSetDiffRules(t *testing.T) { func TestDiffUTXOSet_addTx(t *testing.T) { // transaction0 is coinbase. As such, it has exactly one input with hash zero and MaxUInt32 index txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") - txIn0 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: wire.OutPoint{TxID: *txID0, Index: math.MaxUint32}, Sequence: 0} + txIn0 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: wire.Outpoint{TxID: *txID0, Index: math.MaxUint32}, Sequence: 0} txOut0 := &wire.TxOut{PkScript: []byte{0}, Value: 10} utxoEntry0 := NewUTXOEntry(txOut0, true, 0) transaction0 := wire.NewNativeMsgTx(1, []*wire.TxIn{txIn0}, []*wire.TxOut{txOut0}) // transaction1 spends transaction0 id1 := transaction0.TxID() - outPoint1 := *wire.NewOutPoint(id1, 0) - txIn1 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutPoint: outPoint1, Sequence: 0} + outpoint1 := *wire.NewOutpoint(id1, 0) + txIn1 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: outpoint1, 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: outPoint2, Sequence: 0} + outpoint2 := *wire.NewOutpoint(id2, 0) + txIn2 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: outpoint2, 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 @@ -768,7 +768,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) { expectedSet: &DiffUTXOSet{ base: &FullUTXOSet{utxoCollection: utxoCollection{}}, UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint1: utxoEntry0}, + toAdd: utxoCollection{outpoint1: utxoEntry0}, toRemove: utxoCollection{}, }, }, @@ -789,7 +789,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) { { name: "add transaction to set with its input in base", startSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint1: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint1: utxoEntry0}}, UTXODiff: &UTXODiff{ toAdd: utxoCollection{}, toRemove: utxoCollection{}, @@ -798,10 +798,10 @@ func TestDiffUTXOSet_addTx(t *testing.T) { startHeight: 1, toAdd: []*wire.MsgTx{transaction1}, expectedSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint1: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint1: utxoEntry0}}, UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint2: utxoEntry1}, - toRemove: utxoCollection{outPoint1: utxoEntry0}, + toAdd: utxoCollection{outpoint2: utxoEntry1}, + toRemove: utxoCollection{outpoint1: utxoEntry0}, }, }, }, @@ -810,7 +810,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) { startSet: &DiffUTXOSet{ base: NewFullUTXOSet(), UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint1: utxoEntry0}, + toAdd: utxoCollection{outpoint1: utxoEntry0}, toRemove: utxoCollection{}, }, }, @@ -819,7 +819,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) { expectedSet: &DiffUTXOSet{ base: NewFullUTXOSet(), UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint2: utxoEntry1}, + toAdd: utxoCollection{outpoint2: utxoEntry1}, toRemove: utxoCollection{}, }, }, @@ -829,8 +829,8 @@ func TestDiffUTXOSet_addTx(t *testing.T) { startSet: &DiffUTXOSet{ base: NewFullUTXOSet(), UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint1: utxoEntry0}, - toRemove: utxoCollection{outPoint2: utxoEntry1}, + toAdd: utxoCollection{outpoint1: utxoEntry0}, + toRemove: utxoCollection{outpoint2: utxoEntry1}, }, }, startHeight: 1, @@ -846,7 +846,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) { { name: "add two transactions, one spending the other, to set with the first input in base", startSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint1: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint1: utxoEntry0}}, UTXODiff: &UTXODiff{ toAdd: utxoCollection{}, toRemove: utxoCollection{}, @@ -855,10 +855,10 @@ func TestDiffUTXOSet_addTx(t *testing.T) { startHeight: 1, toAdd: []*wire.MsgTx{transaction1, transaction2}, expectedSet: &DiffUTXOSet{ - base: &FullUTXOSet{utxoCollection: utxoCollection{outPoint1: utxoEntry0}}, + base: &FullUTXOSet{utxoCollection: utxoCollection{outpoint1: utxoEntry0}}, UTXODiff: &UTXODiff{ - toAdd: utxoCollection{outPoint3: utxoEntry2}, - toRemove: utxoCollection{outPoint1: utxoEntry0}, + toAdd: utxoCollection{outpoint3: utxoEntry2}, + toRemove: utxoCollection{outpoint1: utxoEntry0}, }, }, }, @@ -902,9 +902,9 @@ func TestDiffFromTx(t *testing.T) { t.Fatalf("AddTx unexpectedly didn't add tx %s", cbTx.TxID()) } 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, + PreviousOutpoint: cbOutpoint, SignatureScript: nil, Sequence: wire.MaxTxInSequenceNum, }} @@ -918,20 +918,20 @@ 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") } //Test that we get an error if we don't have the outpoint inside the utxo set invalidTxIns := []*wire.TxIn{&wire.TxIn{ - PreviousOutPoint: wire.OutPoint{TxID: daghash.TxID{}, Index: 0}, + PreviousOutpoint: wire.Outpoint{TxID: daghash.TxID{}, Index: 0}, SignatureScript: nil, Sequence: wire.MaxTxInSequenceNum, }} @@ -981,8 +981,8 @@ func (dus *DiffUTXOSet) collection() (utxoCollection, error) { func TestUTXOSetAddEntry(t *testing.T) { txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000") txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111") - outPoint0 := wire.NewOutPoint(txID0, 0) - outPoint1 := wire.NewOutPoint(txID1, 0) + outpoint0 := wire.NewOutpoint(txID0, 0) + outpoint1 := wire.NewOutpoint(txID1, 0) utxoEntry0 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 10}, true, 0) utxoEntry1 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 20}, false, 1) @@ -990,35 +990,35 @@ func TestUTXOSetAddEntry(t *testing.T) { tests := []struct { name string - outPointToAdd *wire.OutPoint + outpointToAdd *wire.Outpoint utxoEntryToAdd *UTXOEntry expectedUTXODiff *UTXODiff expectedError string }{ { name: "add an entry", - outPointToAdd: outPoint0, + outpointToAdd: outpoint0, utxoEntryToAdd: utxoEntry0, expectedUTXODiff: &UTXODiff{ - toAdd: utxoCollection{*outPoint0: utxoEntry0}, + toAdd: utxoCollection{*outpoint0: utxoEntry0}, toRemove: utxoCollection{}, }, }, { name: "add another entry", - outPointToAdd: outPoint1, + outpointToAdd: outpoint1, utxoEntryToAdd: utxoEntry1, expectedUTXODiff: &UTXODiff{ - toAdd: utxoCollection{*outPoint0: utxoEntry0, *outPoint1: utxoEntry1}, + toAdd: utxoCollection{*outpoint0: utxoEntry0, *outpoint1: utxoEntry1}, toRemove: utxoCollection{}, }, }, { name: "add first entry again", - outPointToAdd: outPoint0, + outpointToAdd: outpoint0, utxoEntryToAdd: utxoEntry0, expectedUTXODiff: &UTXODiff{ - toAdd: utxoCollection{*outPoint0: utxoEntry0, *outPoint1: utxoEntry1}, + toAdd: utxoCollection{*outpoint0: utxoEntry0, *outpoint1: utxoEntry1}, toRemove: utxoCollection{}, }, expectedError: "AddEntry: Cannot add outpoint 0000000000000000000000000000000000000000000000000000000000000000:0 twice", @@ -1027,7 +1027,7 @@ func TestUTXOSetAddEntry(t *testing.T) { for _, test := range tests { expectedUTXODiff := addMultisetToDiff(t, test.expectedUTXODiff) - err := utxoDiff.AddEntry(*test.outPointToAdd, test.utxoEntryToAdd) + err := utxoDiff.AddEntry(*test.outpointToAdd, test.utxoEntryToAdd) errString := "" if err != nil { errString = err.Error() diff --git a/blockdag/validate.go b/blockdag/validate.go index e3fb94a9f..fb147012d 100644 --- a/blockdag/validate.go +++ b/blockdag/validate.go @@ -49,9 +49,9 @@ const ( MaxOutputsPerBlock = wire.MaxBlockPayload / wire.MinTxOutPayload ) -// isNullOutpoint determines whether or not a previous transaction output point +// isNullOutpoint determines whether or not a previous transaction outpoint // is set. -func isNullOutpoint(outpoint *wire.OutPoint) bool { +func isNullOutpoint(outpoint *wire.Outpoint) bool { if outpoint.Index == math.MaxUint32 && outpoint.TxID == daghash.ZeroTxID { return true } @@ -206,13 +206,13 @@ func CheckTransactionSanity(tx *util.Tx, subnetworkID *subnetworkid.SubnetworkID } // Check for duplicate transaction inputs. - existingTxOut := make(map[wire.OutPoint]struct{}) + existingTxOut := make(map[wire.Outpoint]struct{}) for _, txIn := range msgTx.TxIn { - if _, exists := existingTxOut[txIn.PreviousOutPoint]; exists { + if _, exists := existingTxOut[txIn.PreviousOutpoint]; exists { return ruleError(ErrDuplicateTxInputs, "transaction "+ "contains duplicate inputs") } - existingTxOut[txIn.PreviousOutPoint] = struct{}{} + existingTxOut[txIn.PreviousOutpoint] = struct{}{} } // Coinbase script length must be between min and max length. @@ -228,7 +228,7 @@ func CheckTransactionSanity(tx *util.Tx, subnetworkID *subnetworkid.SubnetworkID // Previous transaction outputs referenced by the inputs to this // transaction must not be null. for _, txIn := range msgTx.TxIn { - if isNullOutpoint(&txIn.PreviousOutPoint) { + if isNullOutpoint(&txIn.PreviousOutpoint) { return ruleError(ErrBadTxInput, "transaction "+ "input refers to previous output that "+ "is null") @@ -364,11 +364,11 @@ func CountP2SHSigOps(tx *util.Tx, isBlockReward bool, utxoSet UTXOSet) (int, err totalSigOps := 0 for txInIndex, txIn := range msgTx.TxIn { // Ensure the referenced input transaction is available. - entry, ok := utxoSet.Get(txIn.PreviousOutPoint) + entry, ok := utxoSet.Get(txIn.PreviousOutpoint) if !ok { str := fmt.Sprintf("output %s referenced from "+ "transaction %s:%d either does not exist or "+ - "has already been spent", txIn.PreviousOutPoint, + "has already been spent", txIn.PreviousOutpoint, tx.ID(), txInIndex) return 0, ruleError(ErrMissingTxOut, str) } @@ -393,7 +393,7 @@ func CountP2SHSigOps(tx *util.Tx, isBlockReward bool, utxoSet UTXOSet) (int, err if totalSigOps < lastSigOps { str := fmt.Sprintf("the public key script from output "+ "%s contains too many signature operations - "+ - "overflow", txIn.PreviousOutPoint) + "overflow", txIn.PreviousOutpoint) return 0, ruleError(ErrTooManySigOps, str) } } @@ -852,9 +852,9 @@ func ensureNoDuplicateTx(block *blockNode, utxoSet UTXOSet, transactions []*util.Tx) error { // Fetch utxos for all of the transaction ouputs in this block. // Typically, there will not be any utxos for any of the outputs. - fetchSet := make(map[wire.OutPoint]struct{}) + fetchSet := make(map[wire.Outpoint]struct{}) for _, tx := range transactions { - prevOut := wire.OutPoint{TxID: *tx.ID()} + prevOut := wire.Outpoint{TxID: *tx.ID()} for txOutIdx := range tx.MsgTx().TxOut { prevOut.Index = uint32(txOutIdx) fetchSet[prevOut] = struct{}{} @@ -899,11 +899,11 @@ func CheckTransactionInputsAndCalulateFee(tx *util.Tx, txHeight uint64, utxoSet var totalSatoshiIn uint64 for txInIndex, txIn := range tx.MsgTx().TxIn { // Ensure the referenced input transaction is available. - entry, ok := utxoSet.Get(txIn.PreviousOutPoint) + entry, ok := utxoSet.Get(txIn.PreviousOutpoint) if !ok { str := fmt.Sprintf("output %s referenced from "+ "transaction %s:%d either does not exist or "+ - "has already been spent", txIn.PreviousOutPoint, + "has already been spent", txIn.PreviousOutpoint, tx.ID(), txInIndex) return 0, ruleError(ErrMissingTxOut, str) } @@ -977,7 +977,7 @@ func validateBlockRewardMaturity(dagParams *dagconfig.Params, entry *UTXOEntry, str := fmt.Sprintf("tried to spend block reward "+ "transaction output %s from chain-height %d "+ "at chain-height %d before required maturity "+ - "of %d blocks", txIn.PreviousOutPoint, + "of %d blocks", txIn.PreviousOutpoint, originChainHeight, txChainHeight, dagParams.BlockRewardMaturity) return ruleError(ErrImmatureSpend, str) diff --git a/blockdag/validate_test.go b/blockdag/validate_test.go index 3f95599cf..d6aa3aaca 100644 --- a/blockdag/validate_test.go +++ b/blockdag/validate_test.go @@ -243,7 +243,7 @@ func TestCheckBlockSanity(t *testing.T) { Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, @@ -270,7 +270,7 @@ func TestCheckBlockSanity(t *testing.T) { Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60, 0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac, @@ -340,7 +340,7 @@ func TestCheckBlockSanity(t *testing.T) { Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d, 0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27, @@ -409,7 +409,7 @@ func TestCheckBlockSanity(t *testing.T) { Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73, 0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac, @@ -481,7 +481,7 @@ func TestCheckBlockSanity(t *testing.T) { // and handled properly. func TestCheckSerializedHeight(t *testing.T) { // Create an empty coinbase template to be used in the tests below. - coinbaseOutpoint := wire.NewOutPoint(&daghash.TxID{}, math.MaxUint32) + coinbaseOutpoint := wire.NewOutpoint(&daghash.TxID{}, math.MaxUint32) coinbaseTx := wire.NewNativeMsgTx(1, []*wire.TxIn{wire.NewTxIn(coinbaseOutpoint, nil)}, nil) // Expected rule errors. @@ -680,7 +680,7 @@ func TestCheckTransactionSanity(t *testing.T) { {"duplicate inputs", 2, 1, 1, *subnetworkid.SubnetworkIDNative, nil, - func(tx *wire.MsgTx) { tx.TxIn[1].PreviousOutPoint.Index = 0 }, + func(tx *wire.MsgTx) { tx.TxIn[1].PreviousOutpoint.Index = 0 }, ruleError(ErrDuplicateTxInputs, "")}, {"non-zero gas in DAGCoin", 1, 1, 0, *subnetworkid.SubnetworkIDNative, @@ -779,7 +779,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, @@ -806,7 +806,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{ 0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95, 0xd9, 0xc6, 0x41, 0xf3, 0xb8, 0xee, 0xc2, 0xf3, @@ -818,7 +818,7 @@ var Block100000 = wire.MsgBlock{ Sequence: math.MaxUint64, }, { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{ 0x4b, 0xb0, 0x75, 0x35, 0xdf, 0xd5, 0x8e, 0x0b, 0x3c, 0xd6, 0x4f, 0xd7, 0x15, 0x52, 0x80, 0x87, @@ -836,7 +836,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60, 0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac, @@ -906,7 +906,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d, 0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27, @@ -975,7 +975,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73, 0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac, @@ -1076,7 +1076,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, @@ -1110,7 +1110,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{ 0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95, 0xd9, 0xc6, 0x41, 0xf3, 0xb8, 0xee, 0xc2, 0xf3, @@ -1122,7 +1122,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{ Sequence: math.MaxUint64, }, { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{ 0x4b, 0xb0, 0x75, 0x35, 0xdf, 0xd5, 0x8e, 0x0b, 0x3c, 0xd6, 0x4f, 0xd7, 0x15, 0x52, 0x80, 0x87, @@ -1140,7 +1140,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60, 0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac, @@ -1212,7 +1212,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d, 0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27, @@ -1281,7 +1281,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73, 0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac, diff --git a/btcjson/dagsvrwscmds.go b/btcjson/dagsvrwscmds.go index a5b9ecb80..bdf74eed6 100644 --- a/btcjson/dagsvrwscmds.go +++ b/btcjson/dagsvrwscmds.go @@ -80,9 +80,9 @@ func NewStopNotifyNewTransactionsCmd() *StopNotifyNewTransactionsCmd { return &StopNotifyNewTransactionsCmd{} } -// OutPoint describes a transaction outpoint that will be marshalled to and +// Outpoint describes a transaction outpoint that will be marshalled to and // from JSON. -type OutPoint struct { +type Outpoint struct { TxID string `json:"txid"` Index uint32 `json:"index"` } @@ -95,7 +95,7 @@ type OutPoint struct { type LoadTxFilterCmd struct { Reload bool Addresses []string - OutPoints []OutPoint + Outpoints []Outpoint } // NewLoadTxFilterCmd returns a new instance which can be used to issue a @@ -103,11 +103,11 @@ type LoadTxFilterCmd struct { // // NOTE: This is a btcd extension ported from github.com/decred/dcrd/dcrjson // and requires a websocket connection. -func NewLoadTxFilterCmd(reload bool, addresses []string, outPoints []OutPoint) *LoadTxFilterCmd { +func NewLoadTxFilterCmd(reload bool, addresses []string, outpoints []Outpoint) *LoadTxFilterCmd { return &LoadTxFilterCmd{ Reload: reload, Addresses: addresses, - OutPoints: outPoints, + Outpoints: outpoints, } } diff --git a/btcjson/dagsvrwscmds_test.go b/btcjson/dagsvrwscmds_test.go index 5a9ad942e..01770ee58 100644 --- a/btcjson/dagsvrwscmds_test.go +++ b/btcjson/dagsvrwscmds_test.go @@ -121,7 +121,7 @@ func TestDAGSvrWsCmds(t *testing.T) { }, staticCmd: func() interface{} { addrs := []string{"1Address"} - ops := []btcjson.OutPoint{{ + ops := []btcjson.Outpoint{{ TxID: "0000000000000000000000000000000000000000000000000000000000000123", Index: 0, }} @@ -131,7 +131,7 @@ func TestDAGSvrWsCmds(t *testing.T) { unmarshalled: &btcjson.LoadTxFilterCmd{ Reload: false, Addresses: []string{"1Address"}, - OutPoints: []btcjson.OutPoint{{TxID: "0000000000000000000000000000000000000000000000000000000000000123", Index: 0}}, + Outpoints: []btcjson.Outpoint{{TxID: "0000000000000000000000000000000000000000000000000000000000000123", Index: 0}}, }, }, { diff --git a/cmd/addsubnetwork/addsubnetwork.go b/cmd/addsubnetwork/addsubnetwork.go index 576aa383f..2c9cff4ae 100644 --- a/cmd/addsubnetwork/addsubnetwork.go +++ b/cmd/addsubnetwork/addsubnetwork.go @@ -31,16 +31,16 @@ func main() { } log.Infof("Connected to server %s", cfg.RPCServer) - fundingOutPoint, fundingTx, err := findUnspentTXO(cfg, client, addrPubKeyHash) + fundingOutpoint, fundingTx, err := findUnspentTXO(cfg, client, addrPubKeyHash) if err != nil { panic(fmt.Errorf("error finding unspent transactions: %s", err)) } - if fundingOutPoint == nil || fundingTx == nil { + if fundingOutpoint == nil || fundingTx == nil { panic(fmt.Errorf("could not find any unspent transactions this for key")) } - log.Infof("Found transaction to spend: %s:%d", fundingOutPoint.TxID, fundingOutPoint.Index) + log.Infof("Found transaction to spend: %s:%d", fundingOutpoint.TxID, fundingOutpoint.Index) - registryTx, err := buildSubnetworkRegistryTx(cfg, fundingOutPoint, fundingTx, privateKey) + registryTx, err := buildSubnetworkRegistryTx(cfg, fundingOutpoint, fundingTx, privateKey) if err != nil { panic(fmt.Errorf("error building subnetwork registry tx: %s", err)) } diff --git a/cmd/addsubnetwork/registrytx.go b/cmd/addsubnetwork/registrytx.go index c9cd6cbde..9efadaf61 100644 --- a/cmd/addsubnetwork/registrytx.go +++ b/cmd/addsubnetwork/registrytx.go @@ -2,15 +2,16 @@ package main import ( "fmt" + "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/btcec" "github.com/daglabs/btcd/txscript" "github.com/daglabs/btcd/wire" ) -func buildSubnetworkRegistryTx(cfg *config, fundingOutPoint *wire.OutPoint, fundingTx *wire.MsgTx, privateKey *btcec.PrivateKey) (*wire.MsgTx, error) { +func buildSubnetworkRegistryTx(cfg *config, fundingOutpoint *wire.Outpoint, fundingTx *wire.MsgTx, privateKey *btcec.PrivateKey) (*wire.MsgTx, error) { txIn := &wire.TxIn{ - PreviousOutPoint: *fundingOutPoint, + PreviousOutpoint: *fundingOutpoint, Sequence: wire.MaxTxInSequenceNum, } pkScript, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript) @@ -19,11 +20,11 @@ func buildSubnetworkRegistryTx(cfg *config, fundingOutPoint *wire.OutPoint, fund } txOut := &wire.TxOut{ PkScript: pkScript, - Value: fundingTx.TxOut[fundingOutPoint.Index].Value - cfg.RegistryTxFee, + Value: fundingTx.TxOut[fundingOutpoint.Index].Value - cfg.RegistryTxFee, } registryTx := wire.NewRegistryMsgTx(1, []*wire.TxIn{txIn}, []*wire.TxOut{txOut}, cfg.GasLimit) - SignatureScript, err := txscript.SignatureScript(registryTx, 0, fundingTx.TxOut[fundingOutPoint.Index].PkScript, + SignatureScript, err := txscript.SignatureScript(registryTx, 0, fundingTx.TxOut[fundingOutpoint.Index].PkScript, txscript.SigHashAll, privateKey, true) if err != nil { return nil, fmt.Errorf("failed to build signature script: %s", err) diff --git a/cmd/addsubnetwork/utxo.go b/cmd/addsubnetwork/utxo.go index 948632f14..28359f8af 100644 --- a/cmd/addsubnetwork/utxo.go +++ b/cmd/addsubnetwork/utxo.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/rpcclient" "github.com/daglabs/btcd/util" @@ -15,20 +16,20 @@ const ( minConfirmations = 10 ) -func findUnspentTXO(cfg *config, client *rpcclient.Client, addrPubKeyHash *util.AddressPubKeyHash) (*wire.OutPoint, *wire.MsgTx, error) { +func findUnspentTXO(cfg *config, client *rpcclient.Client, addrPubKeyHash *util.AddressPubKeyHash) (*wire.Outpoint, *wire.MsgTx, error) { txs, err := collectTransactions(client, addrPubKeyHash) if err != nil { return nil, nil, err } utxos := buildUTXOs(txs) - for outPoint, tx := range utxos { + for outpoint, tx := range utxos { // Skip TXOs that can't pay for registration - if tx.TxOut[outPoint.Index].Value < cfg.RegistryTxFee { + if tx.TxOut[outpoint.Index].Value < cfg.RegistryTxFee { continue } - return &outPoint, tx, nil + return &outpoint, tx, nil } return nil, nil, nil @@ -95,17 +96,17 @@ func isTxMatured(tx *wire.MsgTx, confirmations uint64) bool { return confirmations >= activeNetParams.BlockRewardMaturity } -func buildUTXOs(txs []*wire.MsgTx) map[wire.OutPoint]*wire.MsgTx { - utxos := make(map[wire.OutPoint]*wire.MsgTx) +func buildUTXOs(txs []*wire.MsgTx) map[wire.Outpoint]*wire.MsgTx { + utxos := make(map[wire.Outpoint]*wire.MsgTx) for _, tx := range txs { for i := range tx.TxOut { - outPoint := wire.NewOutPoint(tx.TxID(), uint32(i)) - utxos[*outPoint] = tx + outpoint := wire.NewOutpoint(tx.TxID(), uint32(i)) + utxos[*outpoint] = tx } } for _, tx := range txs { for _, input := range tx.TxIn { - delete(utxos, input.PreviousOutPoint) + delete(utxos, input.PreviousOutpoint) } } return utxos diff --git a/cmd/txgen/txloop.go b/cmd/txgen/txloop.go index 179541bf6..db031c438 100644 --- a/cmd/txgen/txloop.go +++ b/cmd/txgen/txloop.go @@ -4,13 +4,14 @@ import ( "bytes" "encoding/hex" "fmt" + "math/rand" + "time" + "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/txscript" "github.com/daglabs/btcd/util" "github.com/daglabs/btcd/util/daghash" "github.com/daglabs/btcd/wire" - "math/rand" - "time" ) const ( @@ -37,7 +38,7 @@ type walletTransaction struct { confirmed bool } -type utxoSet map[wire.OutPoint]*wire.TxOut +type utxoSet map[wire.Outpoint]*wire.TxOut func isDust(value uint64) bool { return value < minSpendableAmount+minTxFee @@ -189,8 +190,8 @@ func createTx(walletUTXOSet utxoSet, outputs []*wire.TxOut, feeRate uint64) (*wi // signTx signs a transaction func signTx(walletUTXOSet utxoSet, tx *wire.MsgTx) error { for i, txIn := range tx.TxIn { - outPoint := txIn.PreviousOutPoint - prevOut := walletUTXOSet[outPoint] + outpoint := txIn.PreviousOutpoint + prevOut := walletUTXOSet[outpoint] sigScript, err := txscript.SignatureScript(tx, i, prevOut.PkScript, txscript.SigHashAll, privateKey, true) @@ -214,13 +215,13 @@ func fundTx(walletUTXOSet utxoSet, tx *wire.MsgTx, amount uint64, feeRate uint64 isFunded := false - for outPoint, output := range walletUTXOSet { + for outpoint, output := range walletUTXOSet { amountSelected += output.Value // Add the selected output to the transaction, updating the // current tx size while accounting for the size of the future // sigScript. - tx.AddTxIn(wire.NewTxIn(&outPoint, nil)) + tx.AddTxIn(wire.NewTxIn(&outpoint, nil)) txSize = tx.SerializeSize() + spendSize*len(tx.TxIn) // Calculate the fee required for the txn at this point @@ -280,14 +281,14 @@ func checkConfirmations(client *txgenClient, walletTxs map[daghash.TxID]*walletT func removeTxInsFromUTXOSet(walletUTXOSet utxoSet, tx *wire.MsgTx) { for _, txIn := range tx.TxIn { - delete(walletUTXOSet, txIn.PreviousOutPoint) + delete(walletUTXOSet, txIn.PreviousOutpoint) } } func addTxOutsToUTXOSet(walletUTXOSet utxoSet, tx *wire.MsgTx) { for i, txOut := range tx.TxOut { - outPoint := wire.OutPoint{TxID: *tx.TxID(), Index: uint32(i)} - walletUTXOSet[outPoint] = txOut + outpoint := wire.Outpoint{TxID: *tx.TxID(), Index: uint32(i)} + walletUTXOSet[outpoint] = txOut } } diff --git a/dagconfig/genesis.go b/dagconfig/genesis.go index bf7d4a37f..2b4169398 100644 --- a/dagconfig/genesis.go +++ b/dagconfig/genesis.go @@ -14,7 +14,7 @@ import ( var genesisTxIns = []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, diff --git a/database/testdata/generator.go b/database/testdata/generator.go index d31ca7e85..97971b59d 100644 --- a/database/testdata/generator.go +++ b/database/testdata/generator.go @@ -107,7 +107,7 @@ func printUsage() { var genesisCoinbaseTxIns = []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, diff --git a/integration/csv_test.go b/integration/csv_test.go index 0e4b96974..f28c75438 100644 --- a/integration/csv_test.go +++ b/integration/csv_test.go @@ -27,7 +27,7 @@ import ( // makeTestOutput creates an on-chain output paying to a freshly generated // p2pkh output with the specified amount. func makeTestOutput(r *rpctest.Harness, t *testing.T, - amt util.Amount) (*btcec.PrivateKey, *wire.OutPoint, []byte, error) { + amt util.Amount) (*btcec.PrivateKey, *wire.Outpoint, []byte, error) { // Create a fresh key, then send some coins to an address spendable by // that key. @@ -76,7 +76,7 @@ func makeTestOutput(r *rpctest.Harness, t *testing.T, outputIndex = 1 } - utxo := &wire.OutPoint{ + utxo := &wire.Outpoint{ TxID: fundTx.TxID(), Index: outputIndex, } @@ -131,7 +131,7 @@ func TestBIP0113(t *testing.T) { // past. tx := wire.NewMsgTx(1) tx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *testOutput, + PreviousOutpoint: *testOutput, }) tx.AddTxOut(&wire.TxOut{ PkScript: addrScript, @@ -193,7 +193,7 @@ func TestBIP0113(t *testing.T) { // MTP. tx = wire.NewMsgTx(1) tx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *testOutput, + PreviousOutpoint: *testOutput, }) tx.AddTxOut(&wire.TxOut{ PkScript: addrScript, @@ -238,7 +238,7 @@ func TestBIP0113(t *testing.T) { // pkScript with the specified time-lock. func createCSVOutput(r *rpctest.Harness, t *testing.T, numSatoshis util.Amount, timeLock int64, - isSeconds bool) ([]byte, *wire.OutPoint, *wire.MsgTx, error) { + isSeconds bool) ([]byte, *wire.Outpoint, *wire.MsgTx, error) { // Convert the time-lock to the proper sequence lock based according to // if the lock is seconds or time based. @@ -281,7 +281,7 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T, outputIndex = 1 } - utxo := &wire.OutPoint{ + utxo := &wire.Outpoint{ TxID: tx.TxID(), Index: outputIndex, } @@ -292,13 +292,13 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T, // spendCSVOutput spends an output previously created by the createCSVOutput // function. The sigScript is a trivial push of OP_TRUE followed by the // redeemScript to pass P2SH evaluation. -func spendCSVOutput(redeemScript []byte, csvUTXO *wire.OutPoint, +func spendCSVOutput(redeemScript []byte, csvUTXO *wire.Outpoint, sequence uint64, targetOutput *wire.TxOut, txVersion int32) (*wire.MsgTx, error) { tx := wire.NewMsgTx(txVersion) tx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *csvUTXO, + PreviousOutpoint: *csvUTXO, Sequence: sequence, }) tx.AddTxOut(targetOutput) @@ -396,7 +396,7 @@ func TestBIP0068AndCsv(t *testing.T) { const numTests = 7 type csvOutput struct { RedeemScript []byte - Utxo *wire.OutPoint + Utxo *wire.Outpoint Timelock int64 } var spendableInputs [numTests]csvOutput diff --git a/integration/rpctest/blockgen.go b/integration/rpctest/blockgen.go index da02ca018..d201f05ad 100644 --- a/integration/rpctest/blockgen.go +++ b/integration/rpctest/blockgen.go @@ -108,7 +108,7 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight uint64, txIns := []*wire.TxIn{&wire.TxIn{ // Coinbase transactions have no inputs, so previous outpoint is // zero hash and max index. - PreviousOutPoint: *wire.NewOutPoint(&daghash.TxID{}, + PreviousOutpoint: *wire.NewOutpoint(&daghash.TxID{}, wire.MaxPrevOutIndex), SignatureScript: coinbaseScript, Sequence: wire.MaxTxInSequenceNum, diff --git a/integration/rpctest/memwallet.go b/integration/rpctest/memwallet.go index bcb6041f5..ee7483457 100644 --- a/integration/rpctest/memwallet.go +++ b/integration/rpctest/memwallet.go @@ -61,8 +61,8 @@ type dagUpdate struct { // created for each new block received, then stored in a log in order to // properly handle block re-orgs. type undoEntry struct { - utxosDestroyed map[wire.OutPoint]*utxo - utxosCreated []wire.OutPoint + utxosDestroyed map[wire.Outpoint]*utxo + utxosCreated []wire.Outpoint } // memWallet is a simple in-memory wallet whose purpose is to provide basic @@ -87,7 +87,7 @@ type memWallet struct { addrs map[uint32]util.Address // utxos is the set of utxos spendable by the wallet. - utxos map[wire.OutPoint]*utxo + utxos map[wire.Outpoint]*utxo // reorgJournal is a map storing an undo entry for each new block // received. Once a block is disconnected, the undo entry for the @@ -148,7 +148,7 @@ func newMemWallet(net *dagconfig.Params, harnessID uint32) (*memWallet, error) { hdIndex: 1, hdRoot: hdRoot, addrs: addrs, - utxos: make(map[wire.OutPoint]*utxo), + utxos: make(map[wire.Outpoint]*utxo), dagUpdateSignal: make(chan struct{}), reorgJournal: make(map[uint64]*undoEntry), }, nil @@ -201,7 +201,7 @@ func (m *memWallet) ingestBlock(update *dagUpdate) { // the wallet as a result. m.currentHeight = update.blockHeight undo := &undoEntry{ - utxosDestroyed: make(map[wire.OutPoint]*utxo), + utxosDestroyed: make(map[wire.Outpoint]*utxo), } for _, tx := range update.filteredTxns { mtx := tx.MsgTx() @@ -264,7 +264,7 @@ func (m *memWallet) evalOutputs(outputs []*wire.TxOut, txID *daghash.TxID, maturityHeight = m.currentHeight + m.net.BlockRewardMaturity } - op := wire.OutPoint{TxID: *txID, Index: uint32(i)} + op := wire.Outpoint{TxID: *txID, Index: uint32(i)} m.utxos[op] = &utxo{ value: util.Amount(output.Value), keyIndex: keyIndex, @@ -280,7 +280,7 @@ func (m *memWallet) evalOutputs(outputs []*wire.TxOut, txID *daghash.TxID, // wallet which are spent by an input. func (m *memWallet) evalInputs(inputs []*wire.TxIn, undo *undoEntry) { for _, txIn := range inputs { - op := txIn.PreviousOutPoint + op := txIn.PreviousOutpoint oldUtxo, ok := m.utxos[op] if !ok { continue @@ -351,7 +351,7 @@ func (m *memWallet) fundTx(tx *wire.MsgTx, amt util.Amount, feeRate util.Amount) txSize int ) - for outPoint, utxo := range m.utxos { + for outpoint, utxo := range m.utxos { // Skip any outputs that are still currently immature or are // currently locked. if !utxo.isMature(m.currentHeight) || utxo.isLocked { @@ -363,7 +363,7 @@ func (m *memWallet) fundTx(tx *wire.MsgTx, amt util.Amount, feeRate util.Amount) // Add the selected output to the transaction, updating the // current tx size while accounting for the size of the future // sigScript. - tx.AddTxIn(wire.NewTxIn(&outPoint, nil)) + tx.AddTxIn(wire.NewTxIn(&outpoint, nil)) txSize = tx.SerializeSize() + spendSize*len(tx.TxIn) // Calculate the fee required for the txn at this point @@ -445,8 +445,8 @@ func (m *memWallet) CreateTransaction(outputs []*wire.TxOut, feeRate util.Amount // potential double spend. spentOutputs := make([]*utxo, 0, len(tx.TxIn)) for i, txIn := range tx.TxIn { - outPoint := txIn.PreviousOutPoint - utxo := m.utxos[outPoint] + outpoint := txIn.PreviousOutpoint + utxo := m.utxos[outpoint] extendedKey, err := m.hdRoot.Child(utxo.keyIndex) if err != nil { @@ -489,7 +489,7 @@ func (m *memWallet) UnlockOutputs(inputs []*wire.TxIn) { defer m.Unlock() for _, input := range inputs { - utxo, ok := m.utxos[input.PreviousOutPoint] + utxo, ok := m.utxos[input.PreviousOutpoint] if !ok { continue } diff --git a/mempool/mempool.go b/mempool/mempool.go index 79ce1a92b..119a8189d 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -175,10 +175,10 @@ type TxPool struct { cfg Config pool map[daghash.TxID]*TxDesc depends map[daghash.TxID]*TxDesc - dependsByPrev map[wire.OutPoint]map[daghash.TxID]*TxDesc + dependsByPrev map[wire.Outpoint]map[daghash.TxID]*TxDesc orphans map[daghash.TxID]*orphanTx - orphansByPrev map[wire.OutPoint]map[daghash.TxID]*util.Tx - outpoints map[wire.OutPoint]*util.Tx + orphansByPrev map[wire.Outpoint]map[daghash.TxID]*util.Tx + outpoints map[wire.Outpoint]*util.Tx pennyTotal float64 // exponentially decaying total for penny spends. lastPennyUnix int64 // unix time of last ``penny spend'' @@ -208,21 +208,21 @@ func (mp *TxPool) removeOrphan(tx *util.Tx, removeRedeemers bool) { // Remove the reference from the previous orphan index. for _, txIn := range otx.tx.MsgTx().TxIn { - orphans, exists := mp.orphansByPrev[txIn.PreviousOutPoint] + orphans, exists := mp.orphansByPrev[txIn.PreviousOutpoint] if exists { delete(orphans, *txID) // Remove the map entry altogether if there are no // longer any orphans which depend on it. if len(orphans) == 0 { - delete(mp.orphansByPrev, txIn.PreviousOutPoint) + delete(mp.orphansByPrev, txIn.PreviousOutpoint) } } } // Remove any orphans that redeem outputs from this one if requested. if removeRedeemers { - prevOut := wire.OutPoint{TxID: *txID} + prevOut := wire.Outpoint{TxID: *txID} for txOutIdx := range tx.MsgTx().TxOut { prevOut.Index = uint32(txOutIdx) for _, orphan := range mp.orphansByPrev[prevOut] { @@ -335,11 +335,11 @@ func (mp *TxPool) addOrphan(tx *util.Tx, tag Tag) { expiration: time.Now().Add(orphanTTL), } for _, txIn := range tx.MsgTx().TxIn { - if _, exists := mp.orphansByPrev[txIn.PreviousOutPoint]; !exists { - mp.orphansByPrev[txIn.PreviousOutPoint] = + if _, exists := mp.orphansByPrev[txIn.PreviousOutpoint]; !exists { + mp.orphansByPrev[txIn.PreviousOutpoint] = make(map[daghash.TxID]*util.Tx) } - mp.orphansByPrev[txIn.PreviousOutPoint][*tx.ID()] = tx + mp.orphansByPrev[txIn.PreviousOutpoint][*tx.ID()] = tx } log.Debugf("Stored orphan transaction %s (total: %d)", tx.ID(), @@ -384,7 +384,7 @@ func (mp *TxPool) maybeAddOrphan(tx *util.Tx, tag Tag) error { func (mp *TxPool) removeOrphanDoubleSpends(tx *util.Tx) { msgTx := tx.MsgTx() for _, txIn := range msgTx.TxIn { - for _, orphan := range mp.orphansByPrev[txIn.PreviousOutPoint] { + for _, orphan := range mp.orphansByPrev[txIn.PreviousOutpoint] { mp.removeOrphan(orphan, true) } } @@ -527,7 +527,7 @@ func (mp *TxPool) removeTransaction(tx *util.Tx, removeDependants bool, restoreI if removeDependants { // Remove any transactions which rely on this one. for i := uint32(0); i < uint32(len(tx.MsgTx().TxOut)); i++ { - prevOut := wire.OutPoint{TxID: *txID, Index: i} + prevOut := wire.Outpoint{TxID: *txID, Index: i} if txRedeemer, exists := mp.outpoints[prevOut]; exists { err := mp.removeTransaction(txRedeemer, true, false) if err != nil { @@ -595,10 +595,10 @@ func (mp *TxPool) removeTransactionWithDiff(tx *util.Tx, diff *blockdag.UTXODiff // removeTransactionUTXOEntriesFromDiff removes tx's UTXOEntries from the diff func (mp *TxPool) removeTransactionUTXOEntriesFromDiff(tx *util.Tx, diff *blockdag.UTXODiff) error { for idx := range tx.MsgTx().TxOut { - outPoint := *wire.NewOutPoint(tx.ID(), uint32(idx)) - entry, exists := mp.mpUTXOSet.Get(outPoint) + outpoint := *wire.NewOutpoint(tx.ID(), uint32(idx)) + entry, exists := mp.mpUTXOSet.Get(outpoint) if exists { - err := diff.RemoveEntry(outPoint, entry) + err := diff.RemoveEntry(outpoint, entry) if err != nil { return err } @@ -612,24 +612,24 @@ func (mp *TxPool) removeTransactionUTXOEntriesFromDiff(tx *util.Tx, diff *blockd func (mp *TxPool) markTransactionOutputsUnspent(tx *util.Tx, diff *blockdag.UTXODiff, restoreInputs bool) error { for _, txIn := range tx.MsgTx().TxIn { if restoreInputs { - if prevTxDesc, exists := mp.pool[txIn.PreviousOutPoint.TxID]; exists { - prevOut := prevTxDesc.Tx.MsgTx().TxOut[txIn.PreviousOutPoint.Index] + if prevTxDesc, exists := mp.pool[txIn.PreviousOutpoint.TxID]; exists { + prevOut := prevTxDesc.Tx.MsgTx().TxOut[txIn.PreviousOutpoint.Index] entry := blockdag.NewUTXOEntry(prevOut, false, blockdag.UnminedChainHeight) - err := diff.AddEntry(txIn.PreviousOutPoint, entry) + err := diff.AddEntry(txIn.PreviousOutpoint, entry) if err != nil { return err } } - if prevTxDesc, exists := mp.depends[txIn.PreviousOutPoint.TxID]; exists { - prevOut := prevTxDesc.Tx.MsgTx().TxOut[txIn.PreviousOutPoint.Index] + if prevTxDesc, exists := mp.depends[txIn.PreviousOutpoint.TxID]; exists { + prevOut := prevTxDesc.Tx.MsgTx().TxOut[txIn.PreviousOutpoint.Index] entry := blockdag.NewUTXOEntry(prevOut, false, blockdag.UnminedChainHeight) - err := diff.AddEntry(txIn.PreviousOutPoint, entry) + err := diff.AddEntry(txIn.PreviousOutpoint, entry) if err != nil { return err } } } - delete(mp.outpoints, txIn.PreviousOutPoint) + delete(mp.outpoints, txIn.PreviousOutpoint) } return nil } @@ -637,7 +637,7 @@ func (mp *TxPool) markTransactionOutputsUnspent(tx *util.Tx, diff *blockdag.UTXO // processRemovedTransactionDependencies processes the dependencies of a // transaction tx that was just now removed from the mempool func (mp *TxPool) processRemovedTransactionDependencies(tx *util.Tx) { - prevOut := wire.OutPoint{TxID: *tx.ID()} + prevOut := wire.Outpoint{TxID: *tx.ID()} for txOutIdx := range tx.MsgTx().TxOut { // Skip to the next available output if there are none. prevOut.Index = uint32(txOutIdx) @@ -697,7 +697,7 @@ func (mp *TxPool) RemoveDoubleSpends(tx *util.Tx) { mp.mtx.Lock() defer mp.mtx.Unlock() for _, txIn := range tx.MsgTx().TxIn { - if txRedeemer, ok := mp.outpoints[txIn.PreviousOutPoint]; ok { + if txRedeemer, ok := mp.outpoints[txIn.PreviousOutpoint]; ok { if !txRedeemer.ID().IsEqual(tx.ID()) { mp.removeTransaction(txRedeemer, true, false) } @@ -710,7 +710,7 @@ func (mp *TxPool) RemoveDoubleSpends(tx *util.Tx) { // helper for maybeAcceptTransaction. // // This function MUST be called with the mempool lock held (for writes). -func (mp *TxPool) addTransaction(tx *util.Tx, height uint64, fee uint64, parentsInPool []*wire.OutPoint) (*TxDesc, error) { +func (mp *TxPool) addTransaction(tx *util.Tx, height uint64, fee uint64, parentsInPool []*wire.Outpoint) (*TxDesc, error) { // Add the transaction to the pool and mark the referenced outpoints // as spent by the pool. txD := &TxDesc{ @@ -729,16 +729,16 @@ func (mp *TxPool) addTransaction(tx *util.Tx, height uint64, fee uint64, parents mp.pool[*tx.ID()] = txD } else { mp.depends[*tx.ID()] = txD - for _, previousOutPoint := range parentsInPool { - if _, exists := mp.dependsByPrev[*previousOutPoint]; !exists { - mp.dependsByPrev[*previousOutPoint] = make(map[daghash.TxID]*TxDesc) + for _, previousOutpoint := range parentsInPool { + if _, exists := mp.dependsByPrev[*previousOutpoint]; !exists { + mp.dependsByPrev[*previousOutpoint] = make(map[daghash.TxID]*TxDesc) } - mp.dependsByPrev[*previousOutPoint][*tx.ID()] = txD + mp.dependsByPrev[*previousOutpoint][*tx.ID()] = txD } } for _, txIn := range tx.MsgTx().TxIn { - mp.outpoints[txIn.PreviousOutPoint] = tx + mp.outpoints[txIn.PreviousOutpoint] = tx } if isAccepted, err := mp.mpUTXOSet.AddTx(tx.MsgTx(), blockdag.UnminedChainHeight); err != nil { return nil, err @@ -769,10 +769,10 @@ func (mp *TxPool) addTransaction(tx *util.Tx, height uint64, fee uint64, parents // This function MUST be called with the mempool lock held (for reads). func (mp *TxPool) checkPoolDoubleSpend(tx *util.Tx) error { for _, txIn := range tx.MsgTx().TxIn { - if txR, exists := mp.outpoints[txIn.PreviousOutPoint]; exists { + if txR, exists := mp.outpoints[txIn.PreviousOutpoint]; exists { str := fmt.Sprintf("output %s already spent by "+ "transaction %s in the memory pool", - txIn.PreviousOutPoint, txR.ID()) + txIn.PreviousOutpoint, txR.ID()) return txRuleError(wire.RejectDuplicate, str) } } @@ -783,7 +783,7 @@ func (mp *TxPool) checkPoolDoubleSpend(tx *util.Tx) error { // CheckSpend checks whether the passed outpoint is already spent by a // transaction in the mempool. If that's the case the spending transaction will // be returned, if not nil will be returned. -func (mp *TxPool) CheckSpend(op wire.OutPoint) *util.Tx { +func (mp *TxPool) CheckSpend(op wire.Outpoint) *util.Tx { mp.mtx.RLock() txR := mp.outpoints[op] mp.mtx.RUnlock() @@ -920,7 +920,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu // Don't allow the transaction if it exists in the DAG and is // not already fully spent. - prevOut := wire.OutPoint{TxID: *txID} + prevOut := wire.Outpoint{TxID: *txID} for txOutIdx := range tx.MsgTx().TxOut { prevOut.Index = uint32(txOutIdx) _, ok := mp.mpUTXOSet.Get(prevOut) @@ -935,18 +935,18 @@ func (mp *TxPool) maybeAcceptTransaction(tx *util.Tx, isNew, rateLimit, rejectDu // is not handled by this function, and the caller should use // maybeAddOrphan if this behavior is desired. var missingParents []*daghash.TxID - var parentsInPool []*wire.OutPoint + var parentsInPool []*wire.Outpoint for _, txIn := range tx.MsgTx().TxIn { - if _, ok := mp.mpUTXOSet.Get(txIn.PreviousOutPoint); !ok { + if _, ok := mp.mpUTXOSet.Get(txIn.PreviousOutpoint); !ok { // Must make a copy of the hash here since the iterator // is replaced and taking its address directly would // result in all of the entries pointing to the same // memory location and thus all be the final hash. - txIDCopy := txIn.PreviousOutPoint.TxID + txIDCopy := txIn.PreviousOutpoint.TxID missingParents = append(missingParents, &txIDCopy) } - if mp.isTransactionInPool(&txIn.PreviousOutPoint.TxID) { - parentsInPool = append(parentsInPool, &txIn.PreviousOutPoint) + if mp.isTransactionInPool(&txIn.PreviousOutpoint.TxID) { + parentsInPool = append(parentsInPool, &txIn.PreviousOutpoint) } } if len(missingParents) > 0 { @@ -1142,7 +1142,7 @@ func (mp *TxPool) processOrphans(acceptedTx *util.Tx) []*TxDesc { firstElement := processList.Remove(processList.Front()) processItem := firstElement.(*util.Tx) - prevOut := wire.OutPoint{TxID: *processItem.ID()} + prevOut := wire.Outpoint{TxID: *processItem.ID()} for txOutIdx := range processItem.MsgTx().TxOut { // Look up all orphans that redeem the output that is // now available. This will typically only be one, but @@ -1401,7 +1401,7 @@ func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseRe Depends: make([]string, 0), } for _, txIn := range tx.MsgTx().TxIn { - txID := &txIn.PreviousOutPoint.TxID + txID := &txIn.PreviousOutpoint.TxID if mp.haveTransaction(txID) { mpd.Depends = append(mpd.Depends, txID.String()) @@ -1462,11 +1462,11 @@ func New(cfg *Config) *TxPool { cfg: *cfg, pool: make(map[daghash.TxID]*TxDesc), depends: make(map[daghash.TxID]*TxDesc), - dependsByPrev: make(map[wire.OutPoint]map[daghash.TxID]*TxDesc), + dependsByPrev: make(map[wire.Outpoint]map[daghash.TxID]*TxDesc), orphans: make(map[daghash.TxID]*orphanTx), - orphansByPrev: make(map[wire.OutPoint]map[daghash.TxID]*util.Tx), + orphansByPrev: make(map[wire.Outpoint]map[daghash.TxID]*util.Tx), nextExpireScan: time.Now().Add(orphanExpireScanInterval), - outpoints: make(map[wire.OutPoint]*util.Tx), + outpoints: make(map[wire.Outpoint]*util.Tx), mpUTXOSet: mpUTXO, } } diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 5e2ff9860..efe6508ed 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -83,7 +83,7 @@ func calcSequenceLock(tx *util.Tx, // spendableOutpoint is a convenience type that houses a particular utxo and the // amount associated with it. type spendableOutpoint struct { - outPoint wire.OutPoint + outpoint wire.Outpoint amount util.Amount } @@ -92,7 +92,7 @@ type spendableOutpoint struct { // transactions. func txOutToSpendableOutpoint(tx *util.Tx, outputNum uint32) spendableOutpoint { return spendableOutpoint{ - outPoint: wire.OutPoint{TxID: *tx.ID(), Index: outputNum}, + outpoint: wire.Outpoint{TxID: *tx.ID(), Index: outputNum}, amount: util.Amount(tx.MsgTx().TxOut[outputNum].Value), } } @@ -126,7 +126,7 @@ func (p *poolHarness) CreateCoinbaseTx(blockHeight uint64, numOutputs uint32) (* txIns := []*wire.TxIn{&wire.TxIn{ // Coinbase transactions have no inputs, so previous outpoint is // zero hash and max index. - PreviousOutPoint: *wire.NewOutPoint(&daghash.TxID{}, + PreviousOutpoint: *wire.NewOutpoint(&daghash.TxID{}, wire.MaxPrevOutIndex), SignatureScript: coinbaseScript, Sequence: wire.MaxTxInSequenceNum, @@ -169,7 +169,7 @@ func (p *poolHarness) CreateSignedTxForSubnetwork(inputs []spendableOutpoint, nu txIns := []*wire.TxIn{} for _, input := range inputs { txIns = append(txIns, &wire.TxIn{ - PreviousOutPoint: input.outPoint, + PreviousOutpoint: input.outpoint, SignatureScript: p.signatureScript, Sequence: wire.MaxTxInSequenceNum, }) @@ -213,14 +213,14 @@ func (p *poolHarness) CreateSignedTx(inputs []spendableOutpoint, numOutputs uint // amount of the previous one and as such does not include any fees. func (p *poolHarness) CreateTxChain(firstOutput spendableOutpoint, numTxns uint32) ([]*util.Tx, error) { txChain := make([]*util.Tx, 0, numTxns) - prevOutPoint := firstOutput.outPoint + prevOutpoint := firstOutput.outpoint spendableAmount := firstOutput.amount for i := uint32(0); i < numTxns; i++ { // Create the transaction using the previous transaction output // and paying the full amount to the payment address associated // with the harness. txIn := &wire.TxIn{ - PreviousOutPoint: prevOutPoint, + PreviousOutpoint: prevOutpoint, SignatureScript: p.signatureScript, Sequence: wire.MaxTxInSequenceNum, } @@ -233,7 +233,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 @@ -446,7 +446,7 @@ func testPoolMembership(tc *testContext, tx *util.Tx, inOrphanPool, inTxPool boo func (p *poolHarness) createTx(outpoint spendableOutpoint, fee uint64, numOutputs int64) (*util.Tx, error) { txIns := []*wire.TxIn{&wire.TxIn{ - PreviousOutPoint: outpoint.outPoint, + PreviousOutpoint: outpoint.outpoint, SignatureScript: nil, Sequence: wire.MaxTxInSequenceNum, }} @@ -496,7 +496,7 @@ func TestProcessTransaction(t *testing.T) { orphanedTx, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{}, Index: 1}, + outpoint: wire.Outpoint{TxID: daghash.TxID{}, Index: 1}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -610,7 +610,7 @@ func TestProcessTransaction(t *testing.T) { if err != nil { t.Fatalf("NewShaHashFromStr: unexpected error: %v", err) } - dummyPrevOut := wire.OutPoint{TxID: *dummyPrevOutTxID, Index: 1} + dummyPrevOut := wire.Outpoint{TxID: *dummyPrevOutTxID, Index: 1} dummySigScript := bytes.Repeat([]byte{0x00}, 65) addrHash := [20]byte{0x01} @@ -631,7 +631,7 @@ func TestProcessTransaction(t *testing.T) { } txIns := []*wire.TxIn{{ - PreviousOutPoint: wire.OutPoint{TxID: *p2shTx.ID(), Index: 0}, + PreviousOutpoint: wire.Outpoint{TxID: *p2shTx.ID(), Index: 0}, SignatureScript: wrappedP2SHNonStdSigScript, Sequence: wire.MaxTxInSequenceNum, }} @@ -675,7 +675,7 @@ func TestProcessTransaction(t *testing.T) { //Checks that a transaction with no outputs will not get rejected noOutsTx := util.NewTx(wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: dummyPrevOut, + PreviousOutpoint: dummyPrevOut, SignatureScript: dummySigScript, Sequence: wire.MaxTxInSequenceNum, }}, @@ -739,7 +739,7 @@ func TestProcessTransaction(t *testing.T) { harness.txPool.cfg.Policy.DisableRelayPriority = true txIns = []*wire.TxIn{{ - PreviousOutPoint: spendableOuts[5].outPoint, + PreviousOutpoint: spendableOuts[5].outpoint, SignatureScript: []byte{02, 01}, //Unparsable script Sequence: wire.MaxTxInSequenceNum, }} @@ -888,7 +888,7 @@ func TestFetchTransaction(t *testing.T) { orphanedTx, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{1}, Index: 1}, + outpoint: wire.Outpoint{TxID: daghash.TxID{1}, Index: 1}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1051,7 +1051,7 @@ func TestOrphanExpiration(t *testing.T) { expiredTx, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{}, Index: 0}, + outpoint: wire.Outpoint{TxID: daghash.TxID{}, Index: 0}, }}, 1) harness.txPool.ProcessTransaction(expiredTx, true, false, 0) @@ -1059,7 +1059,7 @@ func TestOrphanExpiration(t *testing.T) { tx1, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{1}, Index: 0}, + outpoint: wire.Outpoint{TxID: daghash.TxID{1}, Index: 0}, }}, 1) harness.txPool.ProcessTransaction(tx1, true, false, 0) @@ -1074,7 +1074,7 @@ func TestOrphanExpiration(t *testing.T) { tx2, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{2}, Index: 0}, + outpoint: wire.Outpoint{TxID: daghash.TxID{2}, Index: 0}, }}, 1) harness.txPool.ProcessTransaction(tx2, true, false, 0) @@ -1098,7 +1098,7 @@ func TestMaxOrphanTxSize(t *testing.T) { tx, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{}, Index: 0}, + outpoint: wire.Outpoint{TxID: daghash.TxID{}, Index: 0}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1248,7 +1248,7 @@ func TestRemoveOrphansByTag(t *testing.T) { orphanedTx1, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{1}, Index: 1}, + outpoint: wire.Outpoint{TxID: daghash.TxID{1}, Index: 1}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1257,7 +1257,7 @@ func TestRemoveOrphansByTag(t *testing.T) { false, 1) orphanedTx2, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{2}, Index: 2}, + outpoint: wire.Outpoint{TxID: daghash.TxID{2}, Index: 2}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1266,7 +1266,7 @@ func TestRemoveOrphansByTag(t *testing.T) { false, 1) orphanedTx3, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{3}, Index: 3}, + outpoint: wire.Outpoint{TxID: daghash.TxID{3}, Index: 3}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1276,7 +1276,7 @@ func TestRemoveOrphansByTag(t *testing.T) { orphanedTx4, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{4}, Index: 4}, + outpoint: wire.Outpoint{TxID: daghash.TxID{4}, Index: 4}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1338,7 +1338,7 @@ func TestBasicOrphanRemoval(t *testing.T) { // and ensure the state of all other orphans are unaffected. nonChainedOrphanTx, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(5000000000), - outPoint: wire.OutPoint{TxID: daghash.TxID{}, Index: 0}, + outpoint: wire.Outpoint{TxID: daghash.TxID{}, Index: 0}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1530,7 +1530,7 @@ func TestCheckSpend(t *testing.T) { // The mempool is empty, so none of the spendable outputs should have a // spend there. for _, op := range outputs { - spend := harness.txPool.CheckSpend(op.outPoint) + spend := harness.txPool.CheckSpend(op.outpoint) if spend != nil { t.Fatalf("Unexpeced spend found in pool: %v", spend) } @@ -1554,7 +1554,7 @@ func TestCheckSpend(t *testing.T) { // The first tx in the chain should be the spend of the spendable // output. - op := outputs[0].outPoint + op := outputs[0].outpoint spend := harness.txPool.CheckSpend(op) if spend != chainedTxns[0] { t.Fatalf("expected %v to be spent by %v, instead "+ @@ -1563,7 +1563,7 @@ func TestCheckSpend(t *testing.T) { // Now all but the last tx should be spent by the next. for i := 0; i < len(chainedTxns)-1; i++ { - op = wire.OutPoint{ + op = wire.Outpoint{ TxID: *chainedTxns[i].ID(), Index: 0, } @@ -1576,7 +1576,7 @@ func TestCheckSpend(t *testing.T) { } // The last tx should have no spend. - op = wire.OutPoint{ + op = wire.Outpoint{ TxID: *chainedTxns[txChainLength-1].ID(), Index: 0, } @@ -1715,7 +1715,7 @@ func TestHandleNewBlock(t *testing.T) { txID := blockTx1.ID() orphanTx, err := harness.CreateSignedTx([]spendableOutpoint{{ amount: util.Amount(2500000000), - outPoint: wire.OutPoint{TxID: *txID, Index: 0}, + outpoint: wire.Outpoint{TxID: *txID, Index: 0}, }}, 1) if err != nil { t.Fatalf("unable to create signed tx: %v", err) @@ -1822,7 +1822,7 @@ var dummyBlock = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, diff --git a/mempool/policy.go b/mempool/policy.go index 5d95ab729..09bd66b50 100644 --- a/mempool/policy.go +++ b/mempool/policy.go @@ -94,7 +94,7 @@ func checkInputsStandard(tx *util.Tx, utxoSet blockdag.UTXOSet) error { // It is safe to elide existence and index checks here since // they have already been checked prior to calling this // function. - entry, _ := utxoSet.Get(txIn.PreviousOutPoint) + entry, _ := utxoSet.Get(txIn.PreviousOutpoint) originPkScript := entry.PkScript() switch txscript.GetScriptClass(originPkScript) { case txscript.ScriptHashTy: diff --git a/mempool/policy_test.go b/mempool/policy_test.go index 993cfa012..7adbc6ea6 100644 --- a/mempool/policy_test.go +++ b/mempool/policy_test.go @@ -283,10 +283,10 @@ func TestCheckTransactionStandard(t *testing.T) { if err != nil { t.Fatalf("NewShaHashFromStr: unexpected error: %v", err) } - dummyPrevOut := wire.OutPoint{TxID: *prevOutTxID, Index: 1} + dummyPrevOut := wire.Outpoint{TxID: *prevOutTxID, Index: 1} dummySigScript := bytes.Repeat([]byte{0x00}, 65) dummyTxIn := wire.TxIn{ - PreviousOutPoint: dummyPrevOut, + PreviousOutpoint: dummyPrevOut, SignatureScript: dummySigScript, Sequence: wire.MaxTxInSequenceNum, } @@ -327,7 +327,7 @@ func TestCheckTransactionStandard(t *testing.T) { { name: "Transaction is not finalized", tx: wire.NewNativeMsgTxWithLocktime(1, []*wire.TxIn{{ - PreviousOutPoint: dummyPrevOut, + PreviousOutpoint: dummyPrevOut, SignatureScript: dummySigScript, Sequence: 0, }}, []*wire.TxOut{&dummyTxOut}, 300001), @@ -349,7 +349,7 @@ func TestCheckTransactionStandard(t *testing.T) { { name: "Signature script size is too large", tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: dummyPrevOut, + PreviousOutpoint: dummyPrevOut, SignatureScript: bytes.Repeat([]byte{0x00}, maxStandardSigScriptSize+1), Sequence: wire.MaxTxInSequenceNum, @@ -361,7 +361,7 @@ func TestCheckTransactionStandard(t *testing.T) { { name: "Signature script that does more than push data", tx: wire.NewNativeMsgTx(1, []*wire.TxIn{{ - PreviousOutPoint: dummyPrevOut, + PreviousOutpoint: dummyPrevOut, SignatureScript: []byte{ txscript.OpCheckSigVerify}, Sequence: wire.MaxTxInSequenceNum, diff --git a/mining/mining.go b/mining/mining.go index 6a6e5ba47..aebd12267 100644 --- a/mining/mining.go +++ b/mining/mining.go @@ -250,7 +250,7 @@ func CreateCoinbaseTx(params *dagconfig.Params, coinbaseScript []byte, nextBlock txIn := &wire.TxIn{ // Coinbase transactions have no inputs, so previous outpoint is // zero hash and max index. - PreviousOutPoint: *wire.NewOutPoint(&daghash.TxID{}, + PreviousOutpoint: *wire.NewOutpoint(&daghash.TxID{}, wire.MaxPrevOutIndex), SignatureScript: coinbaseScript, Sequence: wire.MaxTxInSequenceNum, diff --git a/mining/mining_test.go b/mining/mining_test.go index 16efaee1d..899867ff5 100644 --- a/mining/mining_test.go +++ b/mining/mining_test.go @@ -204,7 +204,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{ + PreviousOutpoint: wire.Outpoint{ TxID: *template1CbTx.TxID(), Index: 0, }, @@ -219,7 +219,7 @@ func TestNewBlockTemplate(t *testing.T) { // We want to check that the miner filters non finalized transactions txIn = &wire.TxIn{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: *template1CbTx.TxID(), Index: 1, }, @@ -238,7 +238,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{ + PreviousOutpoint: wire.Outpoint{ TxID: *template1CbTx.TxID(), Index: 2, }, @@ -254,7 +254,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{ + PreviousOutpoint: wire.Outpoint{ TxID: *template1CbTx.TxID(), Index: 3, }, @@ -269,7 +269,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{ + PreviousOutpoint: wire.Outpoint{ TxID: *template1CbTx.TxID(), Index: 4, }, diff --git a/mining/policy.go b/mining/policy.go index eb828a473..b5a40f8bb 100644 --- a/mining/policy.go +++ b/mining/policy.go @@ -52,7 +52,7 @@ func calcInputValueAge(tx *wire.MsgTx, utxoSet blockdag.UTXOSet, nextBlockHeight for _, txIn := range tx.TxIn { // Don't attempt to accumulate the total input age if the // referenced transaction output doesn't exist. - entry, ok := utxoSet.Get(txIn.PreviousOutPoint) + entry, ok := utxoSet.Get(txIn.PreviousOutpoint) if ok { // Inputs with dependencies currently in the mempool // have their block height set to a special constant. diff --git a/mining/policy_test.go b/mining/policy_test.go index 7aae66f9f..7b915db2f 100644 --- a/mining/policy_test.go +++ b/mining/policy_test.go @@ -63,11 +63,11 @@ func newUTXOSet(sourceTxns []*wire.MsgTx, sourceTxHeights []uint64) blockdag.UTX } func createTxIn(originTx *wire.MsgTx, outputIndex uint32) *wire.TxIn { - var prevOut *wire.OutPoint + var prevOut *wire.Outpoint if originTx != nil { - prevOut = wire.NewOutPoint(originTx.TxID(), 0) + prevOut = wire.NewOutpoint(originTx.TxID(), 0) } else { - prevOut = &wire.OutPoint{ + prevOut = &wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xFFFFFFFF, } diff --git a/netsync/manager.go b/netsync/manager.go index a7dec9010..12c3e6703 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -880,7 +880,7 @@ func (sm *SyncManager) haveInventory(invVect *wire.InvVect) (bool, error) { // checked because the vast majority of transactions consist of // two outputs where one is some form of "pay-to-somebody-else" // and the other is a change output. - prevOut := wire.OutPoint{TxID: daghash.TxID(*invVect.Hash)} + prevOut := wire.Outpoint{TxID: daghash.TxID(*invVect.Hash)} for i := uint32(0); i < 2; i++ { prevOut.Index = i entry, ok := sm.dag.GetUTXOEntry(prevOut) diff --git a/rpcclient/notify.go b/rpcclient/notify.go index d90009fa9..4f6c548c7 100644 --- a/rpcclient/notify.go +++ b/rpcclient/notify.go @@ -639,10 +639,10 @@ func (c *Client) NotifyBlocks() error { return c.NotifyBlocksAsync().Receive() } -// newOutPointFromWire constructs the btcjson representation of a transaction +// newOutpointFromWire constructs the btcjson representation of a transaction // outpoint from the wire type. -func newOutPointFromWire(op *wire.OutPoint) btcjson.OutPoint { - return btcjson.OutPoint{ +func newOutpointFromWire(op *wire.Outpoint) btcjson.Outpoint { + return btcjson.Outpoint{ TxID: op.TxID.String(), Index: op.Index, } @@ -723,21 +723,21 @@ func (r FutureLoadTxFilterResult) Receive() error { // NOTE: This is a btcd extension ported from github.com/decred/dcrrpcclient // and requires a websocket connection. func (c *Client) LoadTxFilterAsync(reload bool, addresses []util.Address, - outPoints []wire.OutPoint) FutureLoadTxFilterResult { + outpoints []wire.Outpoint) FutureLoadTxFilterResult { addrStrs := make([]string, len(addresses)) for i, a := range addresses { addrStrs[i] = a.EncodeAddress() } - outPointObjects := make([]btcjson.OutPoint, len(outPoints)) - for i := range outPoints { - outPointObjects[i] = btcjson.OutPoint{ - TxID: outPoints[i].TxID.String(), - Index: outPoints[i].Index, + outpointObjects := make([]btcjson.Outpoint, len(outpoints)) + for i := range outpoints { + outpointObjects[i] = btcjson.Outpoint{ + TxID: outpoints[i].TxID.String(), + Index: outpoints[i].Index, } } - cmd := btcjson.NewLoadTxFilterCmd(reload, addrStrs, outPointObjects) + cmd := btcjson.NewLoadTxFilterCmd(reload, addrStrs, outpointObjects) return c.sendCmd(cmd) } @@ -747,6 +747,6 @@ func (c *Client) LoadTxFilterAsync(reload bool, addresses []util.Address, // // NOTE: This is a btcd extension ported from github.com/decred/dcrrpcclient // and requires a websocket connection. -func (c *Client) LoadTxFilter(reload bool, addresses []util.Address, outPoints []wire.OutPoint) error { - return c.LoadTxFilterAsync(reload, addresses, outPoints).Receive() +func (c *Client) LoadTxFilter(reload bool, addresses []util.Address, outpoints []wire.Outpoint) error { + return c.LoadTxFilterAsync(reload, addresses, outpoints).Receive() } diff --git a/rpcclient/wallet.go b/rpcclient/wallet.go index 40a88ea26..005bd63ee 100644 --- a/rpcclient/wallet.go +++ b/rpcclient/wallet.go @@ -331,7 +331,7 @@ func (r FutureLockUnspentResult) Receive() error { // returned instance. // // See LockUnspent for the blocking version and more details. -func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockUnspentResult { +func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.Outpoint) FutureLockUnspentResult { outputs := make([]btcjson.TransactionInput, len(ops)) for i, op := range ops { outputs[i] = btcjson.TransactionInput{ @@ -360,7 +360,7 @@ func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockU // reversed (that is, LockUnspent(true, ...) locked the outputs), it has been // left as unlock to keep compatibility with the reference client API and to // avoid confusion for those who are already familiar with the lockunspent RPC. -func (c *Client) LockUnspent(unlock bool, ops []*wire.OutPoint) error { +func (c *Client) LockUnspent(unlock bool, ops []*wire.Outpoint) error { return c.LockUnspentAsync(unlock, ops).Receive() } @@ -370,7 +370,7 @@ type FutureListLockUnspentResult chan *response // Receive waits for the response promised by the future and returns the result // of all currently locked unspent outputs. -func (r FutureListLockUnspentResult) Receive() ([]*wire.OutPoint, error) { +func (r FutureListLockUnspentResult) Receive() ([]*wire.Outpoint, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -384,13 +384,13 @@ func (r FutureListLockUnspentResult) Receive() ([]*wire.OutPoint, error) { } // Create a slice of outpoints from the transaction input structs. - ops := make([]*wire.OutPoint, len(inputs)) + ops := make([]*wire.Outpoint, len(inputs)) for i, input := range inputs { txID, err := daghash.NewTxIDFromStr(input.TxID) if err != nil { return nil, err } - ops[i] = wire.NewOutPoint(txID, input.Vout) + ops[i] = wire.NewOutpoint(txID, input.Vout) } return ops, nil @@ -409,7 +409,7 @@ func (c *Client) ListLockUnspentAsync() FutureListLockUnspentResult { // ListLockUnspent returns a slice of outpoints for all unspent outputs marked // as locked by a wallet. Unspent outputs may be marked locked using // LockOutput. -func (c *Client) ListLockUnspent() ([]*wire.OutPoint, error) { +func (c *Client) ListLockUnspent() ([]*wire.Outpoint, error) { return c.ListLockUnspentAsync().Receive() } diff --git a/server/rpc/rpcserver.go b/server/rpc/rpcserver.go index be2545569..d098f8ce8 100644 --- a/server/rpc/rpcserver.go +++ b/server/rpc/rpcserver.go @@ -555,7 +555,7 @@ func handleCreateRawTransaction(s *Server, cmd interface{}, closeChan <-chan str return nil, rpcDecodeHexError(input.TxID) } - prevOut := wire.NewOutPoint(txID, input.Vout) + prevOut := wire.NewOutpoint(txID, input.Vout) txIn := wire.NewTxIn(prevOut, []byte{}) if c.LockTime != nil && *c.LockTime != 0 { txIn.Sequence = wire.MaxTxInSequenceNum - 1 @@ -679,8 +679,8 @@ func createVinList(mtx *wire.MsgTx) []btcjson.Vin { disbuf, _ := txscript.DisasmString(txIn.SignatureScript) vinEntry := &vinList[i] - vinEntry.TxID = txIn.PreviousOutPoint.TxID.String() - vinEntry.Vout = txIn.PreviousOutPoint.Index + vinEntry.TxID = txIn.PreviousOutpoint.TxID.String() + vinEntry.Vout = txIn.PreviousOutpoint.Index vinEntry.Sequence = txIn.Sequence vinEntry.ScriptSig = &btcjson.ScriptSig{ Asm: disbuf, @@ -1766,7 +1766,7 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld // when multiple inputs reference the same transaction. dependsMap := make(map[int64]struct{}) for _, txIn := range tx.TxIn { - if idx, ok := txIndex[txIn.PreviousOutPoint.TxID]; ok { + if idx, ok := txIndex[txIn.PreviousOutpoint.TxID]; ok { dependsMap[idx] = struct{}{} } } @@ -2746,7 +2746,7 @@ func handleGetTxOut(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte isCoinbase = mtx.IsCoinBase() isInMempool = true } else { - out := wire.OutPoint{TxID: *txID, Index: c.Vout} + out := wire.Outpoint{TxID: *txID, Index: c.Vout} entry, ok := s.cfg.DAG.GetUTXOEntry(out) if !ok { return nil, rpcNoTxInfoError(txID) @@ -2876,13 +2876,13 @@ type retrievedTx struct { // fetchInputTxos fetches the outpoints from all transactions referenced by the // inputs to the passed transaction by checking the transaction mempool first // then the transaction index for those already mined into blocks. -func fetchInputTxos(s *Server, tx *wire.MsgTx) (map[wire.OutPoint]wire.TxOut, error) { +func fetchInputTxos(s *Server, tx *wire.MsgTx) (map[wire.Outpoint]wire.TxOut, error) { mp := s.cfg.TxMemPool - originOutputs := make(map[wire.OutPoint]wire.TxOut) + originOutputs := make(map[wire.Outpoint]wire.TxOut) for txInIndex, txIn := range tx.TxIn { // Attempt to fetch and use the referenced transaction from the // memory pool. - origin := &txIn.PreviousOutPoint + origin := &txIn.PreviousOutpoint originTx, err := mp.FetchTransaction(&origin.TxID) if err == nil { txOuts := originTx.MsgTx().TxOut @@ -2989,7 +2989,7 @@ func createVinListPrevOut(s *Server, mtx *wire.MsgTx, chainParams *dagconfig.Par // Lookup all of the referenced transaction outputs needed to populate the // previous output information if requested. Fee transactions do not contain // valid inputs: block hash instead of transaction ID. - var originOutputs map[wire.OutPoint]wire.TxOut + var originOutputs map[wire.Outpoint]wire.TxOut if !mtx.IsFeeTransaction() && (vinExtra || len(filterAddrMap) > 0) { var err error originOutputs, err = fetchInputTxos(s, mtx) @@ -3007,7 +3007,7 @@ func createVinListPrevOut(s *Server, mtx *wire.MsgTx, chainParams *dagconfig.Par // Create the basic input entry without the additional optional // previous output details which will be added later if // requested and available. - prevOut := &txIn.PreviousOutPoint + prevOut := &txIn.PreviousOutpoint vinEntry := btcjson.VinPrevOut{ TxID: prevOut.TxID.String(), Vout: prevOut.Index, diff --git a/server/rpc/rpcserverhelp.go b/server/rpc/rpcserverhelp.go index 602e2c4d3..0c6993223 100644 --- a/server/rpc/rpcserverhelp.go +++ b/server/rpc/rpcserverhelp.go @@ -624,15 +624,15 @@ var helpDescsEnUS = map[string]string{ // StopNotifyNewTransactionsCmd help. "stopNotifyNewTransactions--synopsis": "Stop sending either a txaccepted or a txacceptedverbose notification when a new transaction is accepted into the mempool.", - // OutPoint help. - "outPoint-txid": "The hex-encoded bytes of the outPoint transaction ID", - "outPoint-index": "The index of the outPoint", + // Outpoint help. + "outpoint-txid": "The hex-encoded bytes of the outpoint transaction ID", + "outpoint-index": "The index of the outpoint", // LoadTxFilterCmd help. "loadTxFilter--synopsis": "Load, add to, or reload a websocket client's transaction filter for mempool transactions, new blocks and rescanBlocks.", "loadTxFilter-reload": "Load a new filter instead of adding data to an existing one", "loadTxFilter-addresses": "Array of addresses to add to the transaction filter", - "loadTxFilter-outPoints": "Array of outpoints to add to the transaction filter", + "loadTxFilter-outpoints": "Array of outpoints to add to the transaction filter", // RescanBlocks help. "rescanBlocks--synopsis": "Rescan blocks for transactions matching the loaded transaction filter.", diff --git a/server/rpc/rpcwebsocket.go b/server/rpc/rpcwebsocket.go index f1036698f..a4e1dd9f9 100644 --- a/server/rpc/rpcwebsocket.go +++ b/server/rpc/rpcwebsocket.go @@ -249,28 +249,28 @@ type wsClientFilter struct { otherAddresses map[string]struct{} // Outpoints of unspent outputs. - unspent map[wire.OutPoint]struct{} + unspent map[wire.Outpoint]struct{} } // newWSClientFilter creates a new, empty wsClientFilter struct to be used // for a websocket client. // // NOTE: This extension was ported from github.com/decred/dcrd -func newWSClientFilter(addresses []string, unspentOutPoints []wire.OutPoint, params *dagconfig.Params) *wsClientFilter { +func newWSClientFilter(addresses []string, unspentOutpoints []wire.Outpoint, params *dagconfig.Params) *wsClientFilter { filter := &wsClientFilter{ pubKeyHashes: map[[ripemd160.Size]byte]struct{}{}, scriptHashes: map[[ripemd160.Size]byte]struct{}{}, compressedPubKeys: map[[33]byte]struct{}{}, uncompressedPubKeys: map[[65]byte]struct{}{}, otherAddresses: map[string]struct{}{}, - unspent: make(map[wire.OutPoint]struct{}, len(unspentOutPoints)), + unspent: make(map[wire.Outpoint]struct{}, len(unspentOutpoints)), } for _, s := range addresses { filter.addAddressStr(s, params) } - for i := range unspentOutPoints { - filter.addUnspentOutPoint(&unspentOutPoints[i]) + for i := range unspentOutpoints { + filter.addUnspentOutpoint(&unspentOutpoints[i]) } return filter @@ -404,27 +404,27 @@ func (f *wsClientFilter) removeAddressStr(s string, params *dagconfig.Params) { } } -// addUnspentOutPoint adds an outpoint to the wsClientFilter. +// addUnspentOutpoint adds an outpoint to the wsClientFilter. // // NOTE: This extension was ported from github.com/decred/dcrd -func (f *wsClientFilter) addUnspentOutPoint(op *wire.OutPoint) { +func (f *wsClientFilter) addUnspentOutpoint(op *wire.Outpoint) { f.unspent[*op] = struct{}{} } -// existsUnspentOutPoint returns true if the passed outpoint has been added to +// existsUnspentOutpoint returns true if the passed outpoint has been added to // the wsClientFilter. // // NOTE: This extension was ported from github.com/decred/dcrd -func (f *wsClientFilter) existsUnspentOutPoint(op *wire.OutPoint) bool { +func (f *wsClientFilter) existsUnspentOutpoint(op *wire.Outpoint) bool { _, ok := f.unspent[*op] return ok } -// removeUnspentOutPoint removes the passed outpoint, if it exists, from the +// removeUnspentOutpoint removes the passed outpoint, if it exists, from the // wsClientFilter. // // NOTE: This extension was ported from github.com/decred/dcrd -func (f *wsClientFilter) removeUnspentOutPoint(op *wire.OutPoint) { +func (f *wsClientFilter) removeUnspentOutpoint(op *wire.Outpoint) { delete(f.unspent, *op) } @@ -571,7 +571,7 @@ func (m *wsNotificationManager) subscribedClients(tx *util.Tx, continue } filter.mu.Lock() - if filter.existsUnspentOutPoint(&input.PreviousOutPoint) { + if filter.existsUnspentOutpoint(&input.PreviousOutpoint) { subscribed[quitChan] = struct{}{} } filter.mu.Unlock() @@ -597,11 +597,11 @@ func (m *wsNotificationManager) subscribedClients(tx *util.Tx, for _, a := range addrs { if filter.existsAddress(a) { subscribed[quitChan] = struct{}{} - op := wire.OutPoint{ + op := wire.Outpoint{ TxID: *tx.ID(), Index: uint32(i), } - filter.addUnspentOutPoint(&op) + filter.addUnspentOutpoint(&op) } } filter.mu.Unlock() @@ -1397,18 +1397,18 @@ func handleWebsocketHelp(wsc *wsClient, icmd interface{}) (interface{}, error) { func handleLoadTxFilter(wsc *wsClient, icmd interface{}) (interface{}, error) { cmd := icmd.(*btcjson.LoadTxFilterCmd) - outPoints := make([]wire.OutPoint, len(cmd.OutPoints)) - for i := range cmd.OutPoints { - txID, err := daghash.NewTxIDFromStr(cmd.OutPoints[i].TxID) + outpoints := make([]wire.Outpoint, len(cmd.Outpoints)) + for i := range cmd.Outpoints { + txID, err := daghash.NewTxIDFromStr(cmd.Outpoints[i].TxID) if err != nil { return nil, &btcjson.RPCError{ Code: btcjson.ErrRPCInvalidParameter, Message: err.Error(), } } - outPoints[i] = wire.OutPoint{ + outpoints[i] = wire.Outpoint{ TxID: *txID, - Index: cmd.OutPoints[i].Index, + Index: cmd.Outpoints[i].Index, } } @@ -1416,7 +1416,7 @@ func handleLoadTxFilter(wsc *wsClient, icmd interface{}) (interface{}, error) { wsc.Lock() if cmd.Reload || wsc.filterData == nil { - wsc.filterData = newWSClientFilter(cmd.Addresses, outPoints, + wsc.filterData = newWSClientFilter(cmd.Addresses, outpoints, params) wsc.Unlock() } else { @@ -1426,8 +1426,8 @@ func handleLoadTxFilter(wsc *wsClient, icmd interface{}) (interface{}, error) { for _, a := range cmd.Addresses { wsc.filterData.addAddressStr(a, params) } - for i := range outPoints { - wsc.filterData.addUnspentOutPoint(&outPoints[i]) + for i := range outpoints { + wsc.filterData.addUnspentOutpoint(&outpoints[i]) } wsc.filterData.mu.Unlock() } @@ -1520,15 +1520,15 @@ func handleStopNotifyNewTransactions(wsc *wsClient, icmd interface{}) (interface } // deserializeOutpoints deserializes each serialized outpoint. -func deserializeOutpoints(serializedOuts []btcjson.OutPoint) ([]*wire.OutPoint, error) { - outpoints := make([]*wire.OutPoint, 0, len(serializedOuts)) +func deserializeOutpoints(serializedOuts []btcjson.Outpoint) ([]*wire.Outpoint, error) { + outpoints := make([]*wire.Outpoint, 0, len(serializedOuts)) for i := range serializedOuts { txID, err := daghash.NewTxIDFromStr(serializedOuts[i].TxID) if err != nil { return nil, rpcDecodeHexError(serializedOuts[i].TxID) } index := serializedOuts[i].Index - outpoints = append(outpoints, wire.NewOutPoint(txID, index)) + outpoints = append(outpoints, wire.NewOutpoint(txID, index)) } return outpoints, nil @@ -1553,7 +1553,7 @@ func rescanBlockFilter(filter *wsClientFilter, block *util.Block, params *dagcon // Scan inputs if not a coinbase transaction. if !msgTx.IsCoinBase() { for _, input := range msgTx.TxIn { - if !filter.existsUnspentOutPoint(&input.PreviousOutPoint) { + if !filter.existsUnspentOutpoint(&input.PreviousOutpoint) { continue } if !added { @@ -1577,11 +1577,11 @@ func rescanBlockFilter(filter *wsClientFilter, block *util.Block, params *dagcon continue } - op := wire.OutPoint{ + op := wire.Outpoint{ TxID: *tx.ID(), Index: uint32(i), } - filter.addUnspentOutPoint(&op) + filter.addUnspentOutpoint(&op) if !added { transactions = append( diff --git a/txscript/engine_test.go b/txscript/engine_test.go index 7e509368d..5871c59b2 100644 --- a/txscript/engine_test.go +++ b/txscript/engine_test.go @@ -27,7 +27,7 @@ func TestBadPC(t *testing.T) { // tx with almost empty scripts. txIns := []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, @@ -97,7 +97,7 @@ func TestCheckErrorCondition(t *testing.T) { for i, test := range tests { func() { txIns := []*wire.TxIn{{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, @@ -392,7 +392,7 @@ func TestDisasmPC(t *testing.T) { // tx with almost empty scripts. txIns := []*wire.TxIn{{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, @@ -452,7 +452,7 @@ func TestDisasmScript(t *testing.T) { // tx with almost empty scripts. txIns := []*wire.TxIn{{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc9, 0x97, 0xa5, 0xe5, 0x6e, 0x10, 0x41, 0x02, diff --git a/txscript/example_test.go b/txscript/example_test.go index 20b612380..b6dc9a203 100644 --- a/txscript/example_test.go +++ b/txscript/example_test.go @@ -100,7 +100,7 @@ func ExampleSignTxOutput() { // For this example, create a fake transaction that represents what // would ordinarily be the real transaction that is being spent. It // contains a single output that pays to address in the amount of 1 BTC. - prevOut := wire.NewOutPoint(&daghash.TxID{}, ^uint32(0)) + prevOut := wire.NewOutpoint(&daghash.TxID{}, ^uint32(0)) txIn := wire.NewTxIn(prevOut, []byte{txscript.Op0, txscript.Op0}) pkScript, err := txscript.PayToAddrScript(addr) if err != nil { @@ -115,7 +115,7 @@ func ExampleSignTxOutput() { // 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(originTx.TxID(), 0) + prevOut = wire.NewOutpoint(originTx.TxID(), 0) txIn = wire.NewTxIn(prevOut, nil) // Ordinarily this would contain that actual destination of the funds, diff --git a/txscript/reference_test.go b/txscript/reference_test.go index 307203999..0245ac028 100644 --- a/txscript/reference_test.go +++ b/txscript/reference_test.go @@ -216,13 +216,13 @@ func parseExpectedResult(expected string) ([]ErrorCode, error) { // signature and public key scripts. func createSpendingTx(sigScript, pkScript []byte) *wire.MsgTx { - outPoint := wire.NewOutPoint(&daghash.TxID{}, ^uint32(0)) - txIn := wire.NewTxIn(outPoint, []byte{Op0, Op0}) + outpoint := wire.NewOutpoint(&daghash.TxID{}, ^uint32(0)) + txIn := wire.NewTxIn(outpoint, []byte{Op0, Op0}) txOut := wire.NewTxOut(0, pkScript) coinbaseTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut}) - outPoint = wire.NewOutPoint(coinbaseTx.TxID(), 0) - txIn = wire.NewTxIn(outPoint, sigScript) + 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}) diff --git a/txscript/sign_test.go b/txscript/sign_test.go index 4a7412da2..ba71e3f63 100644 --- a/txscript/sign_test.go +++ b/txscript/sign_test.go @@ -101,21 +101,21 @@ func TestSignTxOutput(t *testing.T) { } txIns := []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0, }, Sequence: 4294967295, }, { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 1, }, Sequence: 4294967295, }, { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 2, }, @@ -1361,7 +1361,7 @@ type tstSigScript struct { scriptAtWrongIndex bool } -var coinbaseOutPoint = &wire.OutPoint{ +var coinbaseOutpoint = &wire.Outpoint{ Index: (1 << 32) - 1, } @@ -1621,7 +1621,7 @@ nexttest: txIns := []*wire.TxIn{} for range sigScriptTests[i].inputs { - txIns = append(txIns, wire.NewTxIn(coinbaseOutPoint, nil)) + txIns = append(txIns, wire.NewTxIn(coinbaseOutpoint, nil)) } tx := wire.NewNativeMsgTx(wire.TxVersion, txIns, txOuts) diff --git a/util/block_test.go b/util/block_test.go index bfb25e859..e9e65142b 100644 --- a/util/block_test.go +++ b/util/block_test.go @@ -346,7 +346,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, @@ -381,7 +381,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60, 0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac, @@ -451,7 +451,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d, 0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27, @@ -520,7 +520,7 @@ var Block100000 = wire.MsgBlock{ Version: 1, TxIn: []*wire.TxIn{ { - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: daghash.TxID([32]byte{ 0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73, 0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac, diff --git a/util/bloom/filter.go b/util/bloom/filter.go index 324d64bfc..7a98d3cd3 100644 --- a/util/bloom/filter.go +++ b/util/bloom/filter.go @@ -161,11 +161,11 @@ func (bf *Filter) Matches(data []byte) bool { return match } -// matchesOutPoint returns true if the bloom filter might contain the passed +// matchesOutpoint returns true if the bloom filter might contain the passed // outpoint and false if it definitely does not. // // This function MUST be called with the filter lock held. -func (bf *Filter) matchesOutPoint(outpoint *wire.OutPoint) bool { +func (bf *Filter) matchesOutpoint(outpoint *wire.Outpoint) bool { // Serialize var buf [daghash.HashSize + 4]byte copy(buf[:], outpoint.TxID[:]) @@ -174,13 +174,13 @@ func (bf *Filter) matchesOutPoint(outpoint *wire.OutPoint) bool { return bf.matches(buf[:]) } -// MatchesOutPoint returns true if the bloom filter might contain the passed +// MatchesOutpoint returns true if the bloom filter might contain the passed // outpoint and false if it definitely does not. // // This function is safe for concurrent access. -func (bf *Filter) MatchesOutPoint(outpoint *wire.OutPoint) bool { +func (bf *Filter) MatchesOutpoint(outpoint *wire.Outpoint) bool { bf.mtx.Lock() - match := bf.matchesOutPoint(outpoint) + match := bf.matchesOutpoint(outpoint) bf.mtx.Unlock() return match } @@ -224,10 +224,10 @@ func (bf *Filter) AddHash(hash *daghash.Hash) { bf.mtx.Unlock() } -// addOutPoint adds the passed transaction outpoint to the bloom filter. +// addOutpoint adds the passed transaction outpoint to the bloom filter. // // This function MUST be called with the filter lock held. -func (bf *Filter) addOutPoint(outpoint *wire.OutPoint) { +func (bf *Filter) addOutpoint(outpoint *wire.Outpoint) { // Serialize var buf [daghash.HashSize + 4]byte copy(buf[:], outpoint.TxID[:]) @@ -236,12 +236,12 @@ func (bf *Filter) addOutPoint(outpoint *wire.OutPoint) { bf.add(buf[:]) } -// AddOutPoint adds the passed transaction outpoint to the bloom filter. +// AddOutpoint adds the passed transaction outpoint to the bloom filter. // // This function is safe for concurrent access. -func (bf *Filter) AddOutPoint(outpoint *wire.OutPoint) { +func (bf *Filter) AddOutpoint(outpoint *wire.Outpoint) { bf.mtx.Lock() - bf.addOutPoint(outpoint) + bf.addOutpoint(outpoint) bf.mtx.Unlock() } @@ -253,13 +253,13 @@ func (bf *Filter) AddOutPoint(outpoint *wire.OutPoint) { func (bf *Filter) maybeAddOutpoint(pkScript []byte, outTxID *daghash.TxID, outIdx uint32) { switch bf.msgFilterLoad.Flags { case wire.BloomUpdateAll: - outpoint := wire.NewOutPoint(outTxID, outIdx) - bf.addOutPoint(outpoint) + outpoint := wire.NewOutpoint(outTxID, outIdx) + bf.addOutpoint(outpoint) case wire.BloomUpdateP2PubkeyOnly: class := txscript.GetScriptClass(pkScript) if class == txscript.PubKeyTy || class == txscript.MultiSigTy { - outpoint := wire.NewOutPoint(outTxID, outIdx) - bf.addOutPoint(outpoint) + outpoint := wire.NewOutpoint(outTxID, outIdx) + bf.addOutpoint(outpoint) } } } @@ -311,7 +311,7 @@ func (bf *Filter) matchTxAndUpdate(tx *util.Tx) bool { // Check if the filter matches any outpoints this transaction spends or // any any data elements in the signature scripts of any of the inputs. for _, txin := range tx.MsgTx().TxIn { - if bf.matchesOutPoint(&txin.PreviousOutPoint) { + if bf.matchesOutpoint(&txin.PreviousOutpoint) { return true } diff --git a/util/bloom/filter_test.go b/util/bloom/filter_test.go index 8e490f98b..671ad8121 100644 --- a/util/bloom/filter_test.go +++ b/util/bloom/filter_test.go @@ -420,8 +420,8 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } - outpoint := wire.NewOutPoint(txID, 0) - f.AddOutPoint(outpoint) + outpoint := wire.NewOutpoint(txID, 0) + f.AddOutpoint(outpoint) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match outpoint %s", inputStr) } @@ -457,8 +457,8 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } - outpoint = wire.NewOutPoint(txID, 1) - f.AddOutPoint(outpoint) + outpoint = wire.NewOutpoint(txID, 1) + f.AddOutpoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } @@ -470,8 +470,8 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } - outpoint = wire.NewOutPoint(txID, 0) - f.AddOutPoint(outpoint) + outpoint = wire.NewOutpoint(txID, 0) + f.AddOutpoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } @@ -506,9 +506,9 @@ func TestFilterInsertUpdateNone(t *testing.T) { t.Errorf("TestFilterInsertUpdateNone NewHashFromStr failed: %v", err) return } - outpoint := wire.NewOutPoint(txID, 0) + outpoint := wire.NewOutpoint(txID, 0) - if f.MatchesOutPoint(outpoint) { + if f.MatchesOutpoint(outpoint) { t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr) return } @@ -519,9 +519,9 @@ func TestFilterInsertUpdateNone(t *testing.T) { t.Errorf("TestFilterInsertUpdateNone NewHashFromStr failed: %v", err) return } - outpoint = wire.NewOutPoint(txID, 0) + outpoint = wire.NewOutpoint(txID, 0) - if f.MatchesOutPoint(outpoint) { + if f.MatchesOutpoint(outpoint) { t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr) return } @@ -836,8 +836,8 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) { t.Errorf("TestMerkleBlockP2PubKeyOnly NewHashFromStr failed: %v", err) return } - outpoint := wire.NewOutPoint(txID, 0) - if !f.MatchesOutPoint(outpoint) { + outpoint := wire.NewOutpoint(txID, 0) + if !f.MatchesOutpoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly didn't match the generation "+ "outpoint %s", inputStr) return @@ -850,8 +850,8 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) { t.Errorf("TestMerkleBlockP2PubKeyOnly NewHashFromStr failed: %v", err) return } - outpoint = wire.NewOutPoint(txID, 0) - if f.MatchesOutPoint(outpoint) { + outpoint = wire.NewOutpoint(txID, 0) + if f.MatchesOutpoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly matched outpoint %s", inputStr) return } diff --git a/util/bloom/test_coverage.txt b/util/bloom/test_coverage.txt index e503f26fe..60b4fbe56 100644 --- a/util/bloom/test_coverage.txt +++ b/util/bloom/test_coverage.txt @@ -4,18 +4,18 @@ github.com/conformal/btcutil/bloom/merkleblock.go NewMerkleBlock 100.00% (19 github.com/conformal/btcutil/bloom/merkleblock.go merkleBlock.traverseAndBuild 100.00% (10/10) github.com/conformal/btcutil/bloom/merkleblock.go merkleBlock.calcHash 100.00% (8/8) github.com/conformal/btcutil/bloom/filter.go Filter.maybeAddOutpoint 100.00% (7/7) -github.com/conformal/btcutil/bloom/filter.go Filter.addOutPoint 100.00% (4/4) +github.com/conformal/btcutil/bloom/filter.go Filter.addOutpoint 100.00% (4/4) github.com/conformal/btcutil/bloom/filter.go Filter.IsLoaded 100.00% (4/4) github.com/conformal/btcutil/bloom/filter.go Filter.MsgFilterLoad 100.00% (4/4) -github.com/conformal/btcutil/bloom/filter.go Filter.matchesOutPoint 100.00% (4/4) -github.com/conformal/btcutil/bloom/filter.go Filter.MatchesOutPoint 100.00% (4/4) +github.com/conformal/btcutil/bloom/filter.go Filter.matchesOutpoint 100.00% (4/4) +github.com/conformal/btcutil/bloom/filter.go Filter.MatchesOutpoint 100.00% (4/4) github.com/conformal/btcutil/bloom/filter.go Filter.MatchTxAndUpdate 100.00% (4/4) github.com/conformal/btcutil/bloom/filter.go Filter.Matches 100.00% (4/4) github.com/conformal/btcutil/bloom/filter.go Filter.Add 100.00% (3/3) github.com/conformal/btcutil/bloom/filter.go Filter.Reload 100.00% (3/3) github.com/conformal/btcutil/bloom/filter.go Filter.Unload 100.00% (3/3) github.com/conformal/btcutil/bloom/filter.go Filter.AddShaHash 100.00% (3/3) -github.com/conformal/btcutil/bloom/filter.go Filter.AddOutPoint 100.00% (3/3) +github.com/conformal/btcutil/bloom/filter.go Filter.AddOutpoint 100.00% (3/3) github.com/conformal/btcutil/bloom/filter.go minUint32 100.00% (3/3) github.com/conformal/btcutil/bloom/filter.go Filter.hash 100.00% (2/2) github.com/conformal/btcutil/bloom/merkleblock.go merkleBlock.calcTreeWidth 100.00% (1/1) diff --git a/util/coinset/coins.go b/util/coinset/coins.go index a5c3b0007..1d2177b75 100644 --- a/util/coinset/coins.go +++ b/util/coinset/coins.go @@ -130,7 +130,7 @@ func NewMsgTxWithInputCoins(txVersion int32, inputCoins Coins) *wire.MsgTx { txIn := make([]*wire.TxIn, len(coins)) for i, coin := range coins { txIn[i] = &wire.TxIn{ - PreviousOutPoint: wire.OutPoint{ + PreviousOutpoint: wire.Outpoint{ TxID: *coin.ID(), Index: coin.Index(), }, diff --git a/util/coinset/coins_test.go b/util/coinset/coins_test.go index 72373d6ad..d3788ba1d 100644 --- a/util/coinset/coins_test.go +++ b/util/coinset/coins_test.go @@ -118,7 +118,7 @@ func TestCoinSet(t *testing.T) { if len(mtx.TxIn) != 1 { t.Errorf("Expected only 1 TxIn, got %d", len(mtx.TxIn)) } - op := mtx.TxIn[0].PreviousOutPoint + op := mtx.TxIn[0].PreviousOutpoint if !op.TxID.IsEqual(coins[1].ID()) || op.Index != coins[1].Index() { t.Errorf("Expected the second coin to be added as input to mtx") } diff --git a/util/gcs/builder/builder.go b/util/gcs/builder/builder.go index 73eadca81..18ca4c1fa 100644 --- a/util/gcs/builder/builder.go +++ b/util/gcs/builder/builder.go @@ -57,10 +57,10 @@ func DeriveKey(keyHash *daghash.Hash) [gcs.KeySize]byte { return key } -// OutPointToFilterEntry is a utility function that derives a filter entry from -// a wire.OutPoint in a standardized way for use with both building and +// OutpointToFilterEntry is a utility function that derives a filter entry from +// a wire.Outpoint in a standardized way for use with both building and // querying filters. -func OutPointToFilterEntry(outpoint wire.OutPoint) []byte { +func OutpointToFilterEntry(outpoint wire.Outpoint) []byte { // Size of the hash plus size of int32 index data := make([]byte, daghash.HashSize+4) copy(data[:], outpoint.TxID.CloneBytes()[:]) @@ -166,15 +166,15 @@ func (b *GCSBuilder) AddEntries(data [][]byte) *GCSBuilder { return b } -// AddOutPoint adds a wire.OutPoint to the list of entries to be included in +// AddOutpoint adds a wire.Outpoint to the list of entries to be included in // the GCS filter when it's built. -func (b *GCSBuilder) AddOutPoint(outpoint wire.OutPoint) *GCSBuilder { +func (b *GCSBuilder) AddOutpoint(outpoint wire.Outpoint) *GCSBuilder { // Do nothing if the builder's already errored out. if b.err != nil { return b } - return b.AddEntry(OutPointToFilterEntry(outpoint)) + return b.AddEntry(OutpointToFilterEntry(outpoint)) } // AddHash adds a daghash.Hash to the list of entries to be included in the @@ -333,7 +333,7 @@ func BuildBasicFilter(block *wire.MsgBlock) (*gcs.Filter, error) { // Each each txin, we'll add a serialized version of // the txid:index to the filters data slices. for _, txIn := range tx.TxIn { - b.AddOutPoint(txIn.PreviousOutPoint) + b.AddOutpoint(txIn.PreviousOutpoint) } } diff --git a/util/gcs/builder/builder_test.go b/util/gcs/builder/builder_test.go index e0ad0186d..33754ec45 100644 --- a/util/gcs/builder/builder_test.go +++ b/util/gcs/builder/builder_test.go @@ -55,8 +55,8 @@ func TestUseBlockHash(t *testing.T) { t.Fatalf("Hash from string failed: %s", err.Error()) } - // wire.OutPoint - outPoint := wire.OutPoint{ + // wire.Outpoint + outpoint := wire.Outpoint{ TxID: *txID, Index: 4321, } @@ -84,11 +84,11 @@ func TestUseBlockHash(t *testing.T) { hex.EncodeToString(key[:]), hex.EncodeToString(testKey[:])) } - BuilderTest(b, txID, builder.DefaultP, outPoint, addrBytes, t) + BuilderTest(b, txID, builder.DefaultP, outpoint, addrBytes, t) // Create a GCSBuilder with a key hash and non-default P and test it. b = builder.WithKeyTxIDP(txID, 30) - BuilderTest(b, txID, 30, outPoint, addrBytes, t) + BuilderTest(b, txID, 30, outpoint, addrBytes, t) // Create a GCSBuilder with a random key, set the key from a hash // manually, check that the key is correct, and test it. @@ -104,7 +104,7 @@ func TestUseBlockHash(t *testing.T) { hex.EncodeToString(key[:]), hex.EncodeToString(testKey[:])) } - BuilderTest(b, txID, builder.DefaultP, outPoint, addrBytes, t) + BuilderTest(b, txID, builder.DefaultP, outpoint, addrBytes, t) // Create a GCSBuilder with a random key and test it. b = builder.WithRandomKey() @@ -114,7 +114,7 @@ func TestUseBlockHash(t *testing.T) { err.Error()) } t.Logf("Random Key 1: %s", hex.EncodeToString(key1[:])) - BuilderTest(b, txID, builder.DefaultP, outPoint, addrBytes, t) + BuilderTest(b, txID, builder.DefaultP, outpoint, addrBytes, t) // Create a GCSBuilder with a random key and non-default P and test it. b = builder.WithRandomKeyP(30) @@ -127,7 +127,7 @@ func TestUseBlockHash(t *testing.T) { if key2 == key1 { t.Fatalf("Random keys are the same!") } - BuilderTest(b, txID, 30, outPoint, addrBytes, t) + BuilderTest(b, txID, 30, outpoint, addrBytes, t) // Create a GCSBuilder with a known key and test it. b = builder.WithKey(testKey) @@ -141,7 +141,7 @@ func TestUseBlockHash(t *testing.T) { hex.EncodeToString(key[:]), hex.EncodeToString(testKey[:])) } - BuilderTest(b, txID, builder.DefaultP, outPoint, addrBytes, t) + BuilderTest(b, txID, builder.DefaultP, outpoint, addrBytes, t) // Create a GCSBuilder with a known key and non-default P and test it. b = builder.WithKeyP(testKey, 30) @@ -155,13 +155,13 @@ func TestUseBlockHash(t *testing.T) { hex.EncodeToString(key[:]), hex.EncodeToString(testKey[:])) } - BuilderTest(b, txID, 30, outPoint, addrBytes, t) + BuilderTest(b, txID, 30, outpoint, addrBytes, t) // Create a GCSBuilder with a known key and too-high P and ensure error // works throughout all functions that use it. b = builder.WithRandomKeyP(33).SetKeyFromTxID(txID).SetKey(testKey) b.SetP(30).AddEntry(txID.CloneBytes()).AddEntries(contents) - b.AddOutPoint(outPoint).AddTxID(txID).AddScript(addrBytes) + b.AddOutpoint(outpoint).AddTxID(txID).AddScript(addrBytes) _, err = b.Key() if err != gcs.ErrPTooBig { t.Fatalf("No error on P too big!") @@ -173,7 +173,7 @@ func TestUseBlockHash(t *testing.T) { } func BuilderTest(b *builder.GCSBuilder, txID *daghash.TxID, p uint8, - outPoint wire.OutPoint, addrBytes []byte, t *testing.T) { + outpoint wire.Outpoint, addrBytes []byte, t *testing.T) { key, err := b.Key() if err != nil { @@ -220,8 +220,8 @@ func BuilderTest(b *builder.GCSBuilder, txID *daghash.TxID, p uint8, t.Fatal("Filter didn't match when it should have!") } - // Add a wire.OutPoint, build a filter, and test matches - b.AddOutPoint(outPoint) + // Add a wire.Outpoint, build a filter, and test matches + b.AddOutpoint(outpoint) f, err = b.Build() if err != nil { t.Fatalf("Filter build failed: %s", err.Error()) diff --git a/util/testtools/testtools.go b/util/testtools/testtools.go index 18fc0ad99..4edfb9ec5 100644 --- a/util/testtools/testtools.go +++ b/util/testtools/testtools.go @@ -59,7 +59,7 @@ func RegisterSubnetworkForTest(dag *blockdag.BlockDAG, params *dagconfig.Params, return nil, fmt.Errorf("Failed to build signature script: %s", err) } txIn := &wire.TxIn{ - PreviousOutPoint: *wire.NewOutPoint(fundsBlockCbTx.TxID(), 0), + PreviousOutpoint: *wire.NewOutpoint(fundsBlockCbTx.TxID(), 0), Sequence: wire.MaxTxInSequenceNum, SignatureScript: signatureScript, } diff --git a/util/txsort/txsort.go b/util/txsort/txsort.go index 7df02d41c..c5bcb1f71 100644 --- a/util/txsort/txsort.go +++ b/util/txsort/txsort.go @@ -69,10 +69,10 @@ func (s sortableInputSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } // First sort based on input hash (reversed / rpc-style), then index. func (s sortableInputSlice) Less(i, j int) bool { // Input hashes are the same, so compare the index. - iTxID := s[i].PreviousOutPoint.TxID - jTxID := s[j].PreviousOutPoint.TxID + iTxID := s[i].PreviousOutpoint.TxID + jTxID := s[j].PreviousOutpoint.TxID if iTxID == jTxID { - return s[i].PreviousOutPoint.Index < s[j].PreviousOutPoint.Index + return s[i].PreviousOutpoint.Index < s[j].PreviousOutpoint.Index } // At this point, the hashes are not equal, so reverse them to diff --git a/wire/bench_test.go b/wire/bench_test.go index 0e49ca142..7e5c5fa63 100644 --- a/wire/bench_test.go +++ b/wire/bench_test.go @@ -21,7 +21,7 @@ import ( // the main network, regression test network, and test network (version 3). var genesisCoinbaseTxIns = []*TxIn{ { - PreviousOutPoint: OutPoint{ + PreviousOutpoint: Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, @@ -172,9 +172,9 @@ func BenchmarkWriteVarStr10(b *testing.B) { } } -// BenchmarkReadOutPoint performs a benchmark on how long it takes to read a -// transaction output point. -func BenchmarkReadOutPoint(b *testing.B) { +// BenchmarkReadOutpoint performs a benchmark on how long it takes to read a +// transaction outpoint. +func BenchmarkReadOutpoint(b *testing.B) { buf := []byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -183,22 +183,22 @@ func BenchmarkReadOutPoint(b *testing.B) { 0xff, 0xff, 0xff, 0xff, // Previous output index } r := bytes.NewReader(buf) - var op OutPoint + var op Outpoint for i := 0; i < b.N; i++ { r.Seek(0, 0) - readOutPoint(r, 0, 0, &op) + readOutpoint(r, 0, 0, &op) } } -// BenchmarkWriteOutPoint performs a benchmark on how long it takes to write a -// transaction output point. -func BenchmarkWriteOutPoint(b *testing.B) { - op := &OutPoint{ +// BenchmarkWriteOutpoint performs a benchmark on how long it takes to write a +// transaction outpoint. +func BenchmarkWriteOutpoint(b *testing.B) { + op := &Outpoint{ TxID: daghash.TxID{}, Index: 0, } for i := 0; i < b.N; i++ { - writeOutPoint(ioutil.Discard, 0, 0, op) + writeOutpoint(ioutil.Discard, 0, 0, op) } } diff --git a/wire/msgblock_test.go b/wire/msgblock_test.go index 82b47a339..0992bafd9 100644 --- a/wire/msgblock_test.go +++ b/wire/msgblock_test.go @@ -516,7 +516,7 @@ var blockOne = MsgBlock{ NewNativeMsgTx(1, []*TxIn{ { - PreviousOutPoint: OutPoint{ + PreviousOutpoint: Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, diff --git a/wire/msgtx.go b/wire/msgtx.go index 2e8d4b1f9..a3ed299f6 100644 --- a/wire/msgtx.go +++ b/wire/msgtx.go @@ -58,7 +58,7 @@ const ( defaultTxInOutAlloc = 15 // minTxInPayload is the minimum payload size for a transaction input. - // PreviousOutPoint.TxID + PreviousOutPoint.Index 4 bytes + Varint for + // PreviousOutpoint.TxID + PreviousOutpoint.Index 4 bytes + Varint for // SignatureScript length 1 byte + Sequence 4 bytes. minTxInPayload = 9 + daghash.HashSize @@ -168,24 +168,24 @@ func (c scriptFreeList) Return(buf []byte) { // the number of allocations. var scriptPool scriptFreeList = make(chan []byte, freeListMaxItems) -// OutPoint defines a bitcoin data type that is used to track previous +// Outpoint defines a bitcoin data type that is used to track previous // transaction outputs. -type OutPoint struct { +type Outpoint struct { TxID daghash.TxID Index uint32 } -// NewOutPoint returns a new bitcoin transaction outpoint point with the +// NewOutpoint returns a new bitcoin transaction outpoint point with the // provided hash and index. -func NewOutPoint(txID *daghash.TxID, index uint32) *OutPoint { - return &OutPoint{ +func NewOutpoint(txID *daghash.TxID, index uint32) *Outpoint { + return &Outpoint{ TxID: *txID, Index: index, } } -// String returns the OutPoint in the human-readable form "txID:index". -func (o OutPoint) String() string { +// String returns the Outpoint in the human-readable form "txID:index". +func (o Outpoint) String() string { // Allocate enough for ID string, colon, and 10 digits. Although // at the time of writing, the number of digits can be no greater than // the length of the decimal representation of maxTxOutPerMessage, the @@ -201,7 +201,7 @@ func (o OutPoint) String() string { // TxIn defines a bitcoin transaction input. type TxIn struct { - PreviousOutPoint OutPoint + PreviousOutpoint Outpoint SignatureScript []byte Sequence uint64 } @@ -230,9 +230,9 @@ func serializeSignatureScriptSize(signatureScript []byte, encodingFlags txEncodi // NewTxIn returns a new bitcoin transaction input with the provided // previous outpoint point and signature script with a default sequence of // MaxTxInSequenceNum. -func NewTxIn(prevOut *OutPoint, signatureScript []byte) *TxIn { +func NewTxIn(prevOut *Outpoint, signatureScript []byte) *TxIn { return &TxIn{ - PreviousOutPoint: *prevOut, + PreviousOutpoint: *prevOut, SignatureScript: signatureScript, Sequence: MaxTxInSequenceNum, } @@ -301,7 +301,7 @@ func (msg *MsgTx) IsCoinBase() bool { // The previous output of a coinbase must have a max value index and // a zero TxID. - prevOut := &msg.TxIn[0].PreviousOutPoint + prevOut := &msg.TxIn[0].PreviousOutpoint return prevOut.Index == math.MaxUint32 && prevOut.TxID == daghash.ZeroTxID } @@ -313,7 +313,7 @@ func (msg *MsgTx) IsFeeTransaction() bool { for _, txIn := range msg.TxIn { // The previous output of a fee transaction have a max value index and // a non-zero TxID (to differentiate from coinbase). - prevOut := txIn.PreviousOutPoint + prevOut := txIn.PreviousOutpoint if prevOut.Index != math.MaxUint32 || prevOut.TxID == daghash.ZeroTxID { return false } @@ -378,10 +378,10 @@ func (msg *MsgTx) Copy() *MsgTx { // Deep copy the old TxIn data. for _, oldTxIn := range msg.TxIn { // Deep copy the old previous outpoint. - oldOutPoint := oldTxIn.PreviousOutPoint - newOutPoint := OutPoint{} - newOutPoint.TxID.SetBytes(oldOutPoint.TxID[:]) - newOutPoint.Index = oldOutPoint.Index + oldOutpoint := oldTxIn.PreviousOutpoint + newOutpoint := Outpoint{} + newOutpoint.TxID.SetBytes(oldOutpoint.TxID[:]) + newOutpoint.Index = oldOutpoint.Index // Deep copy the old signature script. var newScript []byte @@ -394,7 +394,7 @@ func (msg *MsgTx) Copy() *MsgTx { // Create new txIn with the deep copied data. newTxIn := TxIn{ - PreviousOutPoint: newOutPoint, + PreviousOutpoint: newOutpoint, SignatureScript: newScript, Sequence: oldTxIn.Sequence, } @@ -908,8 +908,8 @@ func NewRegistryMsgTx(version int32, txIn []*TxIn, txOut []*TxOut, gasLimit uint return NewSubnetworkMsgTx(version, txIn, txOut, subnetworkid.SubnetworkIDRegistry, 0, payload) } -// readOutPoint reads the next sequence of bytes from r as an OutPoint. -func readOutPoint(r io.Reader, pver uint32, version int32, op *OutPoint) error { +// readOutpoint reads the next sequence of bytes from r as an Outpoint. +func readOutpoint(r io.Reader, pver uint32, version int32, op *Outpoint) error { _, err := io.ReadFull(r, op.TxID[:]) if err != nil { return err @@ -919,9 +919,9 @@ func readOutPoint(r io.Reader, pver uint32, version int32, op *OutPoint) error { return err } -// writeOutPoint encodes op to the bitcoin protocol encoding for an OutPoint +// writeOutpoint encodes op to the bitcoin protocol encoding for an Outpoint // to w. -func writeOutPoint(w io.Writer, pver uint32, version int32, op *OutPoint) error { +func writeOutpoint(w io.Writer, pver uint32, version int32, op *Outpoint) error { _, err := w.Write(op.TxID[:]) if err != nil { return err @@ -964,7 +964,7 @@ func readScript(r io.Reader, pver uint32, maxAllowed uint32, fieldName string) ( // readTxIn reads the next sequence of bytes from r as a transaction input // (TxIn). func readTxIn(r io.Reader, pver uint32, version int32, ti *TxIn) error { - err := readOutPoint(r, pver, version, &ti.PreviousOutPoint) + err := readOutpoint(r, pver, version, &ti.PreviousOutpoint) if err != nil { return err } @@ -981,7 +981,7 @@ func readTxIn(r io.Reader, pver uint32, version int32, ti *TxIn) error { // writeTxIn encodes ti to the bitcoin protocol encoding for a transaction // input (TxIn) to w. func writeTxIn(w io.Writer, pver uint32, version int32, ti *TxIn, encodingFlags txEncoding) error { - err := writeOutPoint(w, pver, version, &ti.PreviousOutPoint) + err := writeOutpoint(w, pver, version, &ti.PreviousOutpoint) if err != nil { return err } diff --git a/wire/msgtx_test.go b/wire/msgtx_test.go index 6ca33011c..9af87bfd1 100644 --- a/wire/msgtx_test.go +++ b/wire/msgtx_test.go @@ -45,31 +45,31 @@ func TestTx(t *testing.T) { maxPayload, wantPayload) } - // Ensure we get the same transaction output point data back out. + // Ensure we get the same transaction outpoint data back out. // NOTE: This is a block hash and made up index, but we're only // testing package functionality. prevOutIndex := uint32(1) - prevOut := NewOutPoint(txID, prevOutIndex) + prevOut := NewOutpoint(txID, prevOutIndex) if !prevOut.TxID.IsEqual(txID) { - t.Errorf("NewOutPoint: wrong ID - got %v, want %v", + t.Errorf("NewOutpoint: wrong ID - got %v, want %v", spew.Sprint(&prevOut.TxID), spew.Sprint(txID)) } if prevOut.Index != prevOutIndex { - t.Errorf("NewOutPoint: wrong index - got %v, want %v", + t.Errorf("NewOutpoint: wrong index - got %v, want %v", prevOut.Index, prevOutIndex) } prevOutStr := fmt.Sprintf("%s:%d", txID.String(), prevOutIndex) if s := prevOut.String(); s != prevOutStr { - t.Errorf("OutPoint.String: unexpected result - got %v, "+ + t.Errorf("Outpoint.String: unexpected result - got %v, "+ "want %v", s, prevOutStr) } // Ensure we get the same transaction input back out. sigScript := []byte{0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62} txIn := NewTxIn(prevOut, sigScript) - if !reflect.DeepEqual(&txIn.PreviousOutPoint, prevOut) { + if !reflect.DeepEqual(&txIn.PreviousOutpoint, prevOut) { t.Errorf("NewTxIn: wrong prev outpoint - got %v, want %v", - spew.Sprint(&txIn.PreviousOutPoint), + spew.Sprint(&txIn.PreviousOutpoint), spew.Sprint(prevOut)) } if !bytes.Equal(txIn.SignatureScript, sigScript) { @@ -138,7 +138,7 @@ func TestTxHashAndID(t *testing.T) { // First transaction from block 113875. txIn := &TxIn{ - PreviousOutPoint: OutPoint{ + PreviousOutpoint: Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, }, @@ -192,7 +192,7 @@ func TestTxHashAndID(t *testing.T) { } payload := []byte{1, 2, 3} txIns := []*TxIn{&TxIn{ - PreviousOutPoint: OutPoint{ + PreviousOutpoint: Outpoint{ Index: 0, TxID: daghash.TxID{1, 2, 3}, }, @@ -845,7 +845,7 @@ func underlyingArrayAddress(buf []byte) uint64 { // multiTx is a MsgTx with an input and output and used in various tests. var multiTxIns = []*TxIn{ { - PreviousOutPoint: OutPoint{ + PreviousOutpoint: Outpoint{ TxID: daghash.TxID{}, Index: 0xffffffff, },