[NOD-314] change pkscript to scriptpubkey (#400)

* [NOD-314] Change everywhere PkScript to ScriptPubKey

* [NOD-314] Change everywhere PkScript to ScriptPubKey

* [NOD-314] Rename pkPops -> scriptPubKeyPops
This commit is contained in:
Ori Newman 2019-09-15 11:09:36 +03:00 committed by Svarog
parent 90bda69931
commit a789680db1
59 changed files with 628 additions and 628 deletions

View File

@ -24,7 +24,7 @@ type transactionResponse struct {
type transactionOutputResponse struct {
TransactionID string `json:"transactionId,omitempty"`
Value uint64 `json:"value"`
PkScript string `json:"pkScript"`
ScriptPubKey string `json:"scriptPubKey"`
Address string `json:"address,omitempty"`
AcceptingBlockHash string `json:"acceptingBlockHash,omitempty"`
AcceptingBlockBlueScore uint64 `json:"acceptingBlockBlueScore,omitempty"`
@ -75,9 +75,9 @@ func convertTxModelToTxResponse(tx *models.Transaction) *transactionResponse {
}
for i, txOut := range tx.TransactionOutputs {
txRes.Outputs[i] = &transactionOutputResponse{
Value: txOut.Value,
PkScript: hex.EncodeToString(txOut.PkScript),
Address: txOut.Address.Address,
Value: txOut.Value,
ScriptPubKey: hex.EncodeToString(txOut.ScriptPubKey),
Address: txOut.Address.Address,
}
}
for i, txIn := range tx.TransactionInputs {

View File

@ -82,7 +82,7 @@ func GetUTXOsByAddressHandler(address string) (interface{}, *utils.HandlerError)
for i, utxo := range utxos {
UTXOsResponses[i] = &transactionOutputResponse{
Value: utxo.TransactionOutput.Value,
PkScript: hex.EncodeToString(utxo.TransactionOutput.PkScript),
ScriptPubKey: hex.EncodeToString(utxo.TransactionOutput.ScriptPubKey),
AcceptingBlockHash: utxo.AcceptingBlock.BlockHash,
AcceptingBlockBlueScore: utxo.AcceptingBlock.BlueScore,
}

View File

@ -4,7 +4,7 @@ CREATE TABLE `transaction_outputs`
`transaction_id` BIGINT UNSIGNED NOT NULL,
`index` INT UNSIGNED NOT NULL,
`value` BIGINT UNSIGNED NOT NULL,
`pk_script` BLOB NOT NULL,
`script_pub_key` BLOB NOT NULL,
`address_id` BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX `idx_transaction_outputs_transaction_id` (`transaction_id`),

View File

@ -85,7 +85,7 @@ type TransactionOutput struct {
Transaction Transaction
Index uint32
Value uint64
PkScript []byte
ScriptPubKey []byte
AddressID uint64
Address Address
}

View File

@ -179,7 +179,7 @@ func (dag *BlockDAG) findPreviousCheckpoint() (*blockNode, error) {
func isNonstandardTransaction(tx *util.Tx) bool {
// Check all of the output public key scripts for non-standard scripts.
for _, txOut := range tx.MsgTx().TxOut {
scriptClass := txscript.GetScriptClass(txOut.PkScript)
scriptClass := txscript.GetScriptClass(txOut.ScriptPubKey)
if scriptClass == txscript.NonStandardTy {
return true
}

View File

@ -130,11 +130,11 @@ func (node *blockNode) validateCoinbaseTransaction(dag *BlockDAG, block *util.Bl
return nil
}
blockCoinbaseTx := block.CoinbaseTransaction().MsgTx()
pkScript, extraData, err := DeserializeCoinbasePayload(blockCoinbaseTx)
scriptPubKey, extraData, err := DeserializeCoinbasePayload(blockCoinbaseTx)
if err != nil {
return err
}
expectedCoinbaseTransaction, err := node.expectedCoinbaseTransaction(dag, txsAcceptanceData, pkScript, extraData)
expectedCoinbaseTransaction, err := node.expectedCoinbaseTransaction(dag, txsAcceptanceData, scriptPubKey, extraData)
if err != nil {
return err
}
@ -147,7 +147,7 @@ func (node *blockNode) validateCoinbaseTransaction(dag *BlockDAG, block *util.Bl
}
// expectedCoinbaseTransaction returns the coinbase transaction for the current block
func (node *blockNode) expectedCoinbaseTransaction(dag *BlockDAG, txsAcceptanceData MultiBlockTxsAcceptanceData, pkScript []byte, extraData []byte) (*util.Tx, error) {
func (node *blockNode) expectedCoinbaseTransaction(dag *BlockDAG, txsAcceptanceData MultiBlockTxsAcceptanceData, scriptPubKey []byte, extraData []byte) (*util.Tx, error) {
bluesFeeData, err := node.getBluesFeeData(dag)
if err != nil {
return nil, err
@ -166,7 +166,7 @@ func (node *blockNode) expectedCoinbaseTransaction(dag *BlockDAG, txsAcceptanceD
txOuts = append(txOuts, txOut)
}
}
payload, err := SerializeCoinbasePayload(pkScript, extraData)
payload, err := SerializeCoinbasePayload(scriptPubKey, extraData)
if err != nil {
return nil, err
}
@ -175,14 +175,14 @@ func (node *blockNode) expectedCoinbaseTransaction(dag *BlockDAG, txsAcceptanceD
return util.NewTx(sortedCoinbaseTx), nil
}
// SerializeCoinbasePayload builds the coinbase payload based on the provided pkScript and extra data.
func SerializeCoinbasePayload(pkScript []byte, extraData []byte) ([]byte, error) {
// SerializeCoinbasePayload builds the coinbase payload based on the provided scriptPubKey and extra data.
func SerializeCoinbasePayload(scriptPubKey []byte, extraData []byte) ([]byte, error) {
w := &bytes.Buffer{}
err := wire.WriteVarInt(w, uint64(len(pkScript)))
err := wire.WriteVarInt(w, uint64(len(scriptPubKey)))
if err != nil {
return nil, err
}
_, err = w.Write(pkScript)
_, err = w.Write(scriptPubKey)
if err != nil {
return nil, err
}
@ -193,15 +193,15 @@ func SerializeCoinbasePayload(pkScript []byte, extraData []byte) ([]byte, error)
return w.Bytes(), nil
}
// DeserializeCoinbasePayload deserialize the coinbase payload to its component (pkScript and extra data).
func DeserializeCoinbasePayload(tx *wire.MsgTx) (pkScript []byte, extraData []byte, err error) {
// DeserializeCoinbasePayload deserialize the coinbase payload to its component (scriptPubKey and extra data).
func DeserializeCoinbasePayload(tx *wire.MsgTx) (scriptPubKey []byte, extraData []byte, err error) {
r := bytes.NewReader(tx.Payload)
pkScriptLen, err := wire.ReadVarInt(r)
scriptPubKeyLen, err := wire.ReadVarInt(r)
if err != nil {
return nil, nil, err
}
pkScript = make([]byte, pkScriptLen)
_, err = r.Read(pkScript)
scriptPubKey = make([]byte, scriptPubKeyLen)
_, err = r.Read(scriptPubKey)
if err != nil {
return nil, nil, err
}
@ -212,7 +212,7 @@ func DeserializeCoinbasePayload(tx *wire.MsgTx) (pkScript []byte, extraData []by
return nil, nil, err
}
}
return pkScript, extraData, nil
return scriptPubKey, extraData, nil
}
// feeInputAndOutputForBlueBlock calculates the input and output that should go into the coinbase transaction of blueBlock
@ -264,15 +264,15 @@ func coinbaseInputAndOutputForBlueBlock(dag *BlockDAG, blueBlock *blockNode,
return txIn, nil, nil
}
// the PkScript for the coinbase is parsed from the coinbase payload
pkScript, _, err := DeserializeCoinbasePayload(blockTxsAcceptanceData[0].Tx.MsgTx())
// the ScriptPubKey for the coinbase is parsed from the coinbase payload
scriptPubKey, _, err := DeserializeCoinbasePayload(blockTxsAcceptanceData[0].Tx.MsgTx())
if err != nil {
return nil, nil, err
}
txOut := &wire.TxOut{
Value: totalReward,
PkScript: pkScript,
Value: totalReward,
ScriptPubKey: scriptPubKey,
}
return txIn, txOut, nil

View File

@ -241,27 +241,27 @@ func isPubKey(script []byte) (bool, []byte) {
// compressedScriptSize returns the number of bytes the passed script would take
// when encoded with the domain specific compression algorithm described above.
func compressedScriptSize(pkScript []byte) int {
func compressedScriptSize(scriptPubKey []byte) int {
// Pay-to-pubkey-hash script.
if valid, _ := isPubKeyHash(pkScript); valid {
if valid, _ := isPubKeyHash(scriptPubKey); valid {
return 21
}
// Pay-to-script-hash script.
if valid, _ := isScriptHash(pkScript); valid {
if valid, _ := isScriptHash(scriptPubKey); valid {
return 21
}
// Pay-to-pubkey (compressed or uncompressed) script.
if valid, _ := isPubKey(pkScript); valid {
if valid, _ := isPubKey(scriptPubKey); valid {
return 33
}
// When none of the above special cases apply, encode the script as is
// preceded by the sum of its size and the number of special cases
// encoded as a variable length quantity.
return serializeSizeVLQ(uint64(len(pkScript)+numSpecialScripts)) +
len(pkScript)
return serializeSizeVLQ(uint64(len(scriptPubKey)+numSpecialScripts)) +
len(scriptPubKey)
}
// decodeCompressedScriptSize treats the passed serialized bytes as a compressed
@ -296,23 +296,23 @@ func decodeCompressedScriptSize(serialized []byte) int {
// target byte slice. The target byte slice must be at least large enough to
// handle the number of bytes returned by the compressedScriptSize function or
// it will panic.
func putCompressedScript(target, pkScript []byte) int {
func putCompressedScript(target, scriptPubKey []byte) int {
// Pay-to-pubkey-hash script.
if valid, hash := isPubKeyHash(pkScript); valid {
if valid, hash := isPubKeyHash(scriptPubKey); valid {
target[0] = cstPayToPubKeyHash
copy(target[1:21], hash)
return 21
}
// Pay-to-script-hash script.
if valid, hash := isScriptHash(pkScript); valid {
if valid, hash := isScriptHash(scriptPubKey); valid {
target[0] = cstPayToScriptHash
copy(target[1:21], hash)
return 21
}
// Pay-to-pubkey (compressed or uncompressed) script.
if valid, serializedPubKey := isPubKey(pkScript); valid {
if valid, serializedPubKey := isPubKey(scriptPubKey); valid {
pubKeyFormat := serializedPubKey[0]
switch pubKeyFormat {
case 0x02, 0x03:
@ -331,10 +331,10 @@ func putCompressedScript(target, pkScript []byte) int {
// When none of the above special cases apply, encode the unmodified
// script preceded by the sum of its size and the number of special
// cases encoded as a variable length quantity.
encodedSize := uint64(len(pkScript) + numSpecialScripts)
encodedSize := uint64(len(scriptPubKey) + numSpecialScripts)
vlqSizeLen := putVLQ(target, encodedSize)
copy(target[vlqSizeLen:], pkScript)
return vlqSizeLen + len(pkScript)
copy(target[vlqSizeLen:], scriptPubKey)
return vlqSizeLen + len(scriptPubKey)
}
// decompressScript returns the original script obtained by decompressing the
@ -344,50 +344,50 @@ func putCompressedScript(target, pkScript []byte) int {
// NOTE: The script parameter must already have been proven to be long enough
// to contain the number of bytes returned by decodeCompressedScriptSize or it
// will panic. This is acceptable since it is only an internal function.
func decompressScript(compressedPkScript []byte) []byte {
func decompressScript(compressedScriptPubKey []byte) []byte {
// In practice this function will not be called with a zero-length or
// nil script since the nil script encoding includes the length, however
// the code below assumes the length exists, so just return nil now if
// the function ever ends up being called with a nil script in the
// future.
if len(compressedPkScript) == 0 {
if len(compressedScriptPubKey) == 0 {
return nil
}
// Decode the script size and examine it for the special cases.
encodedScriptSize, bytesRead := deserializeVLQ(compressedPkScript)
encodedScriptSize, bytesRead := deserializeVLQ(compressedScriptPubKey)
switch encodedScriptSize {
// Pay-to-pubkey-hash script. The resulting script is:
// <OP_DUP><OP_HASH160><20 byte hash><OP_EQUALVERIFY><OP_CHECKSIG>
case cstPayToPubKeyHash:
pkScript := make([]byte, 25)
pkScript[0] = txscript.OpDup
pkScript[1] = txscript.OpHash160
pkScript[2] = txscript.OpData20
copy(pkScript[3:], compressedPkScript[bytesRead:bytesRead+20])
pkScript[23] = txscript.OpEqualVerify
pkScript[24] = txscript.OpCheckSig
return pkScript
scriptPubKey := make([]byte, 25)
scriptPubKey[0] = txscript.OpDup
scriptPubKey[1] = txscript.OpHash160
scriptPubKey[2] = txscript.OpData20
copy(scriptPubKey[3:], compressedScriptPubKey[bytesRead:bytesRead+20])
scriptPubKey[23] = txscript.OpEqualVerify
scriptPubKey[24] = txscript.OpCheckSig
return scriptPubKey
// Pay-to-script-hash script. The resulting script is:
// <OP_HASH160><20 byte script hash><OP_EQUAL>
case cstPayToScriptHash:
pkScript := make([]byte, 23)
pkScript[0] = txscript.OpHash160
pkScript[1] = txscript.OpData20
copy(pkScript[2:], compressedPkScript[bytesRead:bytesRead+20])
pkScript[22] = txscript.OpEqual
return pkScript
scriptPubKey := make([]byte, 23)
scriptPubKey[0] = txscript.OpHash160
scriptPubKey[1] = txscript.OpData20
copy(scriptPubKey[2:], compressedScriptPubKey[bytesRead:bytesRead+20])
scriptPubKey[22] = txscript.OpEqual
return scriptPubKey
// Pay-to-compressed-pubkey script. The resulting script is:
// <OP_DATA_33><33 byte compressed pubkey><OP_CHECKSIG>
case cstPayToPubKeyComp2, cstPayToPubKeyComp3:
pkScript := make([]byte, 35)
pkScript[0] = txscript.OpData33
pkScript[1] = byte(encodedScriptSize)
copy(pkScript[2:], compressedPkScript[bytesRead:bytesRead+32])
pkScript[34] = txscript.OpCheckSig
return pkScript
scriptPubKey := make([]byte, 35)
scriptPubKey[0] = txscript.OpData33
scriptPubKey[1] = byte(encodedScriptSize)
copy(scriptPubKey[2:], compressedScriptPubKey[bytesRead:bytesRead+32])
scriptPubKey[34] = txscript.OpCheckSig
return scriptPubKey
// Pay-to-uncompressed-pubkey script. The resulting script is:
// <OP_DATA_65><65 byte uncompressed pubkey><OP_CHECKSIG>
@ -398,26 +398,26 @@ func decompressScript(compressedPkScript []byte) []byte {
// encoding ensures it is valid before compressing to this type.
compressedKey := make([]byte, 33)
compressedKey[0] = byte(encodedScriptSize - 2)
copy(compressedKey[1:], compressedPkScript[1:])
copy(compressedKey[1:], compressedScriptPubKey[1:])
key, err := btcec.ParsePubKey(compressedKey, btcec.S256())
if err != nil {
return nil
}
pkScript := make([]byte, 67)
pkScript[0] = txscript.OpData65
copy(pkScript[1:], key.SerializeUncompressed())
pkScript[66] = txscript.OpCheckSig
return pkScript
scriptPubKey := make([]byte, 67)
scriptPubKey[0] = txscript.OpData65
copy(scriptPubKey[1:], key.SerializeUncompressed())
scriptPubKey[66] = txscript.OpCheckSig
return scriptPubKey
}
// When none of the special cases apply, the script was encoded using
// the general format, so reduce the script size by the number of
// special cases and return the unmodified script.
scriptSize := int(encodedScriptSize - numSpecialScripts)
pkScript := make([]byte, scriptSize)
copy(pkScript, compressedPkScript[bytesRead:bytesRead+scriptSize])
return pkScript
scriptPubKey := make([]byte, scriptSize)
copy(scriptPubKey, compressedScriptPubKey[bytesRead:bytesRead+scriptSize])
return scriptPubKey
}
// -----------------------------------------------------------------------------
@ -543,9 +543,9 @@ func decompressTxOutAmount(amount uint64) uint64 {
// compressedTxOutSize returns the number of bytes the passed transaction output
// fields would take when encoded with the format described above.
func compressedTxOutSize(amount uint64, pkScript []byte) int {
func compressedTxOutSize(amount uint64, scriptPubKey []byte) int {
return serializeSizeVLQ(compressTxOutAmount(amount)) +
compressedScriptSize(pkScript)
compressedScriptSize(scriptPubKey)
}
// putCompressedTxOut compresses the passed amount and script according to their
@ -553,9 +553,9 @@ func compressedTxOutSize(amount uint64, pkScript []byte) int {
// passed target byte slice with the format described above. The target byte
// slice must be at least large enough to handle the number of bytes returned by
// the compressedTxOutSize function or it will panic.
func putCompressedTxOut(target []byte, amount uint64, pkScript []byte) int {
func putCompressedTxOut(target []byte, amount uint64, scriptPubKey []byte) int {
offset := putVLQ(target, compressTxOutAmount(amount))
offset += putCompressedScript(target[offset:], pkScript)
offset += putCompressedScript(target[offset:], scriptPubKey)
return offset
}

View File

@ -333,29 +333,29 @@ func TestCompressedTxOut(t *testing.T) {
t.Parallel()
tests := []struct {
name string
amount uint64
pkScript []byte
compressed []byte
name string
amount uint64
scriptPubKey []byte
compressed []byte
}{
{
name: "pay-to-pubkey-hash dust",
amount: 546,
pkScript: hexToBytes("76a9141018853670f9f3b0582c5b9ee8ce93764ac32b9388ac"),
compressed: hexToBytes("a52f001018853670f9f3b0582c5b9ee8ce93764ac32b93"),
name: "pay-to-pubkey-hash dust",
amount: 546,
scriptPubKey: hexToBytes("76a9141018853670f9f3b0582c5b9ee8ce93764ac32b9388ac"),
compressed: hexToBytes("a52f001018853670f9f3b0582c5b9ee8ce93764ac32b93"),
},
{
name: "pay-to-pubkey uncompressed 1 BTC",
amount: 100000000,
pkScript: hexToBytes("4104192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b40d45264838c0bd96852662ce6a847b197376830160c6d2eb5e6a4c44d33f453eac"),
compressed: hexToBytes("0904192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"),
name: "pay-to-pubkey uncompressed 1 BTC",
amount: 100000000,
scriptPubKey: hexToBytes("4104192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b40d45264838c0bd96852662ce6a847b197376830160c6d2eb5e6a4c44d33f453eac"),
compressed: hexToBytes("0904192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"),
},
}
for _, test := range tests {
// Ensure the function to calculate the serialized size without
// actually serializing the txout is calculated properly.
gotSize := compressedTxOutSize(test.amount, test.pkScript)
gotSize := compressedTxOutSize(test.amount, test.scriptPubKey)
if gotSize != len(test.compressed) {
t.Errorf("compressedTxOutSize (%s): did not get "+
"expected size - got %d, want %d", test.name,
@ -366,7 +366,7 @@ func TestCompressedTxOut(t *testing.T) {
// Ensure the txout compresses to the expected value.
gotCompressed := make([]byte, gotSize)
gotBytesWritten := putCompressedTxOut(gotCompressed,
test.amount, test.pkScript)
test.amount, test.scriptPubKey)
if !bytes.Equal(gotCompressed, test.compressed) {
t.Errorf("compressTxOut (%s): did not get expected "+
"bytes - got %x, want %x", test.name,
@ -396,10 +396,10 @@ func TestCompressedTxOut(t *testing.T) {
test.name, gotAmount, test.amount)
continue
}
if !bytes.Equal(gotScript, test.pkScript) {
if !bytes.Equal(gotScript, test.scriptPubKey) {
t.Errorf("decodeCompressedTxOut (%s): did not get "+
"expected script - got %x, want %x",
test.name, gotScript, test.pkScript)
test.name, gotScript, test.scriptPubKey)
continue
}
if gotBytesRead != len(test.compressed) {

View File

@ -792,22 +792,22 @@ func (dag *BlockDAG) IsKnownFinalizedBlock(blockHash *daghash.Hash) bool {
// NextBlockCoinbaseTransaction prepares the coinbase transaction for the next mined block
//
// This function CAN'T be called with the DAG lock held.
func (dag *BlockDAG) NextBlockCoinbaseTransaction(pkScript []byte, extraData []byte) (*util.Tx, error) {
func (dag *BlockDAG) NextBlockCoinbaseTransaction(scriptPubKey []byte, extraData []byte) (*util.Tx, error) {
dag.dagLock.RLock()
defer dag.dagLock.RUnlock()
return dag.NextBlockCoinbaseTransactionNoLock(pkScript, extraData)
return dag.NextBlockCoinbaseTransactionNoLock(scriptPubKey, extraData)
}
// NextBlockCoinbaseTransactionNoLock prepares the coinbase transaction for the next mined block
//
// This function MUST be called with the DAG read-lock held
func (dag *BlockDAG) NextBlockCoinbaseTransactionNoLock(pkScript []byte, extraData []byte) (*util.Tx, error) {
func (dag *BlockDAG) NextBlockCoinbaseTransactionNoLock(scriptPubKey []byte, extraData []byte) (*util.Tx, error) {
txsAcceptanceData, err := dag.TxsAcceptedByVirtual()
if err != nil {
return nil, err
}
return dag.virtual.blockNode.expectedCoinbaseTransaction(dag, txsAcceptanceData, pkScript, extraData)
return dag.virtual.blockNode.expectedCoinbaseTransaction(dag, txsAcceptanceData, scriptPubKey, extraData)
}
// NextAcceptedIDMerkleRoot prepares the acceptedIDMerkleRoot for the next mined block

View File

@ -256,7 +256,7 @@ func TestCalcSequenceLock(t *testing.T) {
// Create a utxo view with a fake utxo for the inputs used in the
// transactions created below. This utxo is added such that it has an
// age of 4 blocks.
msgTx := wire.NewNativeMsgTx(wire.TxVersion, nil, []*wire.TxOut{{PkScript: nil, Value: 10}})
msgTx := wire.NewNativeMsgTx(wire.TxVersion, nil, []*wire.TxOut{{ScriptPubKey: nil, Value: 10}})
targetTx := util.NewTx(msgTx)
utxoSet := NewFullUTXOSet()
blueScore := uint64(numBlocksToGenerate) - 4
@ -291,7 +291,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}})
unConfTx := wire.NewNativeMsgTx(wire.TxVersion, nil, []*wire.TxOut{{ScriptPubKey: nil, Value: 5}})
unConfUtxo := wire.Outpoint{
TxID: *unConfTx.TxID(),
Index: 0,

View File

@ -52,7 +52,7 @@ func TestUtxoSerialization(t *testing.T) {
name: "blue score 1, coinbase",
entry: &UTXOEntry{
amount: 5000000000,
pkScript: hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
scriptPubKey: hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
blockBlueScore: 1,
packedFlags: tfCoinbase,
},
@ -64,7 +64,7 @@ func TestUtxoSerialization(t *testing.T) {
name: "blue score 100001, not coinbase",
entry: &UTXOEntry{
amount: 1000000,
pkScript: hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
scriptPubKey: hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
blockBlueScore: 100001,
packedFlags: 0,
},
@ -99,10 +99,10 @@ func TestUtxoSerialization(t *testing.T) {
continue
}
if !bytes.Equal(utxoEntry.PkScript(), test.entry.PkScript()) {
if !bytes.Equal(utxoEntry.ScriptPubKey(), test.entry.ScriptPubKey()) {
t.Errorf("deserializeUTXOEntry #%d (%s) mismatched "+
"scripts: got %x, want %x", i, test.name,
utxoEntry.PkScript(), test.entry.PkScript())
utxoEntry.ScriptPubKey(), test.entry.ScriptPubKey())
continue
}
if utxoEntry.BlockBlueScore() != test.entry.BlockBlueScore() {

View File

@ -236,8 +236,8 @@ func TestChainedTransactions(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}
txOut := &wire.TxOut{
PkScript: blockdag.OpTrueScript,
Value: uint64(1),
ScriptPubKey: blockdag.OpTrueScript,
Value: uint64(1),
}
tx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
@ -247,13 +247,13 @@ func TestChainedTransactions(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}
pkScript, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
scriptPubKey, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
if err != nil {
t.Fatalf("Failed to build public key script: %s", err)
}
chainedTxOut := &wire.TxOut{
PkScript: pkScript,
Value: uint64(1),
ScriptPubKey: scriptPubKey,
Value: uint64(1),
}
chainedTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{chainedTxIn}, []*wire.TxOut{chainedTxOut})
@ -287,8 +287,8 @@ func TestChainedTransactions(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}
nonChainedTxOut := &wire.TxOut{
PkScript: pkScript,
Value: uint64(1),
ScriptPubKey: scriptPubKey,
Value: uint64(1),
}
nonChainedTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{nonChainedTxIn}, []*wire.TxOut{nonChainedTxOut})
@ -357,7 +357,7 @@ func TestGasLimit(t *testing.T) {
t.Fatalf("Failed to build signature script: %s", err)
}
pkScript, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
scriptPubKey, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
if err != nil {
t.Fatalf("Failed to build public key script: %s", err)
}
@ -368,8 +368,8 @@ func TestGasLimit(t *testing.T) {
SignatureScript: signatureScript,
}
tx1Out := &wire.TxOut{
Value: cbTxs[0].TxOut[0].Value,
PkScript: pkScript,
Value: cbTxs[0].TxOut[0].Value,
ScriptPubKey: scriptPubKey,
}
tx1 := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{tx1In}, []*wire.TxOut{tx1Out}, subnetworkID, 10000, []byte{})
@ -379,8 +379,8 @@ func TestGasLimit(t *testing.T) {
SignatureScript: signatureScript,
}
tx2Out := &wire.TxOut{
Value: cbTxs[1].TxOut[0].Value,
PkScript: pkScript,
Value: cbTxs[1].TxOut[0].Value,
ScriptPubKey: scriptPubKey,
}
tx2 := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{tx2In}, []*wire.TxOut{tx2Out}, subnetworkID, 10000, []byte{})
@ -413,8 +413,8 @@ func TestGasLimit(t *testing.T) {
SignatureScript: signatureScript,
}
overflowGasTxOut := &wire.TxOut{
Value: cbTxs[2].TxOut[0].Value,
PkScript: pkScript,
Value: cbTxs[2].TxOut[0].Value,
ScriptPubKey: scriptPubKey,
}
overflowGasTx := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{overflowGasTxIn}, []*wire.TxOut{overflowGasTxOut},
subnetworkID, math.MaxUint64, []byte{})
@ -445,8 +445,8 @@ func TestGasLimit(t *testing.T) {
SignatureScript: signatureScript,
}
nonExistentSubnetworkTxOut := &wire.TxOut{
Value: cbTxs[3].TxOut[0].Value,
PkScript: pkScript,
Value: cbTxs[3].TxOut[0].Value,
ScriptPubKey: scriptPubKey,
}
nonExistentSubnetworkTx := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{nonExistentSubnetworkTxIn},
[]*wire.TxOut{nonExistentSubnetworkTxOut}, nonExistentSubnetwork, 1, []byte{})

View File

@ -294,8 +294,8 @@ func (g *testGenerator) createCoinbaseTx(blueScore uint64) *wire.MsgTx {
SignatureScript: coinbaseScript,
}
txOut := &wire.TxOut{
Value: blockdag.CalcBlockSubsidy(blueScore, g.params),
PkScript: opTrueScript,
Value: blockdag.CalcBlockSubsidy(blueScore, g.params),
ScriptPubKey: opTrueScript,
}
return wire.NewNativeMsgTx(1, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
}
@ -410,9 +410,9 @@ func additionalSpendFee(fee util.Amount) func(*wire.MsgBlock) {
// replaceSpendScript returns a function that itself takes a block and modifies
// it by replacing the public key script of the spending transaction.
func replaceSpendScript(pkScript []byte) func(*wire.MsgBlock) {
func replaceSpendScript(scriptPubKey []byte) func(*wire.MsgBlock) {
return func(b *wire.MsgBlock) {
b.Transactions[1].TxOut[0].PkScript = pkScript
b.Transactions[1].TxOut[0].ScriptPubKey = scriptPubKey
}
}
@ -684,7 +684,7 @@ func countBlockSigOps(block *wire.MsgBlock) int {
totalSigOps += numSigOps
}
for _, txOut := range tx.TxOut {
numSigOps := txscript.GetSigOpCount(txOut.PkScript)
numSigOps := txscript.GetSigOpCount(txOut.ScriptPubKey)
totalSigOps += numSigOps
}
}
@ -777,7 +777,7 @@ func (g *testGenerator) assertTipBlockTxOutOpReturn(txIndex, txOutIndex uint32)
}
txOut := tx.TxOut[txOutIndex]
if txOut.PkScript[0] != txscript.OpReturn {
if txOut.ScriptPubKey[0] != txscript.OpReturn {
panic(fmt.Sprintf("transaction index %d output %d in block %q "+
"(height %d) is not an OP_RETURN", txIndex, txOutIndex,
g.tipName, g.tipHeight))
@ -1314,7 +1314,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
fill := maxBlockSigOps - (txnsNeeded * redeemScriptSigOps) + 1
finalTx := b.Transactions[len(b.Transactions)-1]
tx := createSpendTxForTx(finalTx, lowFee)
tx.TxOut[0].PkScript = repeatOpcode(txscript.OpCheckSig, fill)
tx.TxOut[0].ScriptPubKey = repeatOpcode(txscript.OpCheckSig, fill)
b.AddTransaction(tx)
})
rejected(blockdag.ErrTooManySigOps)
@ -1348,7 +1348,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
}
finalTx := b.Transactions[len(b.Transactions)-1]
tx := createSpendTxForTx(finalTx, lowFee)
tx.TxOut[0].PkScript = repeatOpcode(txscript.OpCheckSig, fill)
tx.TxOut[0].ScriptPubKey = repeatOpcode(txscript.OpCheckSig, fill)
b.AddTransaction(tx)
})
accepted()

View File

@ -90,7 +90,7 @@ var (
}},
TxOut: []*wire.TxOut{{
Value: 0,
PkScript: fromHex("4104678afdb0fe5548271967f1" +
ScriptPubKey: fromHex("4104678afdb0fe5548271967f1" +
"a67130b7105cd6a828e03909a67962e0ea1f" +
"61deb649f6bc3f4cef38c4f35504e51ec138" +
"c4f35504e51ec112de5c384df7ba0b8d578a" +

View File

@ -620,13 +620,13 @@ func (idx *AddrIndex) Create(dbTx database.Tx) error {
// stored in the order they appear in the block.
type writeIndexData map[[addrKeySize]byte][]int
// indexPkScript extracts all standard addresses from the passed public key
// indexScriptPubKey extracts all standard addresses from the passed public key
// script and maps each of them to the associated transaction using the passed
// map.
func (idx *AddrIndex) indexPkScript(data writeIndexData, pkScript []byte, txIdx int) {
func (idx *AddrIndex) indexScriptPubKey(data writeIndexData, scriptPubKey []byte, txIdx int) {
// Nothing to index if the script is non-standard or otherwise doesn't
// contain any addresses.
_, addrs, _, err := txscript.ExtractPkScriptAddrs(pkScript,
_, addrs, _, err := txscript.ExtractScriptPubKeyAddrs(scriptPubKey,
idx.dagParams)
if err != nil || len(addrs) == 0 {
return
@ -672,12 +672,12 @@ func (idx *AddrIndex) indexBlock(data writeIndexData, block *util.Block, dag *bl
continue
}
idx.indexPkScript(data, entry.PkScript(), txIdx)
idx.indexScriptPubKey(data, entry.ScriptPubKey(), txIdx)
}
}
for _, txOut := range tx.MsgTx().TxOut {
idx.indexPkScript(data, txOut.PkScript, txIdx)
idx.indexScriptPubKey(data, txOut.ScriptPubKey, txIdx)
}
}
}
@ -787,11 +787,11 @@ func (idx *AddrIndex) TxRegionsForAddress(dbTx database.Tx, addr util.Address, n
// script to the transaction.
//
// This function is safe for concurrent access.
func (idx *AddrIndex) indexUnconfirmedAddresses(pkScript []byte, tx *util.Tx) {
func (idx *AddrIndex) indexUnconfirmedAddresses(scriptPubKey []byte, tx *util.Tx) {
// The error is ignored here since the only reason it can fail is if the
// script fails to parse and it was already validated before being
// admitted to the mempool.
_, addresses, _, _ := txscript.ExtractPkScriptAddrs(pkScript,
_, addresses, _, _ := txscript.ExtractScriptPubKeyAddrs(scriptPubKey,
idx.dagParams)
for _, addr := range addresses {
// Ignore unsupported address types.
@ -843,12 +843,12 @@ func (idx *AddrIndex) AddUnconfirmedTx(tx *util.Tx, utxoSet blockdag.UTXOSet) {
// call out all inputs must be available.
continue
}
idx.indexUnconfirmedAddresses(entry.PkScript(), tx)
idx.indexUnconfirmedAddresses(entry.ScriptPubKey(), tx)
}
// Index addresses of all created outputs.
for _, txOut := range tx.MsgTx().TxOut {
idx.indexUnconfirmedAddresses(txOut.PkScript, tx)
idx.indexUnconfirmedAddresses(txOut.ScriptPubKey, tx)
}
}

View File

@ -68,8 +68,8 @@ out:
// Create a new script engine for the script pair.
sigScript := txIn.SignatureScript
pkScript := entry.PkScript()
vm, err := txscript.NewEngine(pkScript, txVI.tx.MsgTx(),
scriptPubKey := entry.ScriptPubKey()
vm, err := txscript.NewEngine(scriptPubKey, txVI.tx.MsgTx(),
txVI.txInIndex, v.flags, v.sigCache)
if err != nil {
str := fmt.Sprintf("failed to parse input "+
@ -77,7 +77,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, scriptPubKey)
err := ruleError(ErrScriptMalformed, str)
v.sendResult(err)
break out
@ -90,7 +90,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, scriptPubKey)
err := ruleError(ErrScriptValidation, str)
v.sendResult(err)
break out

View File

@ -138,8 +138,8 @@ func createTxForTest(numInputs uint32, numOutputs uint32, outputValue uint64, su
for i := uint32(0); i < numOutputs; i++ {
txOuts = append(txOuts, &wire.TxOut{
PkScript: OpTrueScript,
Value: outputValue,
ScriptPubKey: OpTrueScript,
Value: outputValue,
})
}

View File

@ -39,8 +39,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, scriptPubKey: []byte{0x01}})
diff.toRemove.add(wire.Outpoint{TxID: daghash.TxID{0x02}, Index: 0}, &UTXOEntry{amount: 2, scriptPubKey: []byte{0x02}})
if err := dag.utxoDiffStore.setBlockDiff(node, diff); err != nil {
t.Fatalf("setBlockDiff: unexpected error: %s", err)
}

View File

@ -244,14 +244,14 @@ func serializeUTXOEntry(entry *UTXOEntry) []byte {
// Calculate the size needed to serialize the entry.
size := serializeSizeVLQ(headerCode) +
compressedTxOutSize(uint64(entry.Amount()), entry.PkScript())
compressedTxOutSize(uint64(entry.Amount()), entry.ScriptPubKey())
// Serialize the header code followed by the compressed unspent
// transaction output.
serialized := make([]byte, size)
offset := putVLQ(serialized, headerCode)
offset += putCompressedTxOut(serialized[offset:], uint64(entry.Amount()),
entry.PkScript())
entry.ScriptPubKey())
return serialized
}
@ -288,7 +288,7 @@ func deserializeUTXOEntry(serialized []byte) (*UTXOEntry, error) {
blockBlueScore := code >> 1
// Decode the compressed unspent transaction output.
amount, pkScript, _, err := decodeCompressedTxOut(serialized[offset:])
amount, scriptPubKey, _, err := decodeCompressedTxOut(serialized[offset:])
if err != nil {
return nil, errDeserialize(fmt.Sprintf("unable to decode "+
"UTXO: %s", err))
@ -296,7 +296,7 @@ func deserializeUTXOEntry(serialized []byte) (*UTXOEntry, error) {
entry := &UTXOEntry{
amount: amount,
pkScript: pkScript,
scriptPubKey: scriptPubKey,
blockBlueScore: blockBlueScore,
packedFlags: 0,
}

View File

@ -31,7 +31,7 @@ type UTXOEntry struct {
// lot of these in memory, so a few extra bytes of padding adds up.
amount uint64
pkScript []byte // The public key script for the output.
scriptPubKey []byte // The public key script for the output.
blockBlueScore uint64 // Blue score of the block accepting the tx.
// packedFlags contains additional info about output such as whether it
@ -57,9 +57,9 @@ func (entry *UTXOEntry) Amount() uint64 {
return entry.amount
}
// PkScript returns the public key script for the output.
func (entry *UTXOEntry) PkScript() []byte {
return entry.pkScript
// ScriptPubKey returns the public key script for the output.
func (entry *UTXOEntry) ScriptPubKey() []byte {
return entry.scriptPubKey
}
// IsUnaccepted returns true iff this UTXOEntry has been included in a block
@ -81,7 +81,7 @@ const (
func NewUTXOEntry(txOut *wire.TxOut, isCoinbase bool, blockBlueScore uint64) *UTXOEntry {
entry := &UTXOEntry{
amount: txOut.Value,
pkScript: txOut.PkScript,
scriptPubKey: txOut.ScriptPubKey,
blockBlueScore: blockBlueScore,
}

View File

@ -17,8 +17,8 @@ func TestUTXOCollection(t *testing.T) {
txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111")
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)
utxoEntry0 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 10}, true, 0)
utxoEntry1 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 20}, false, 1)
// For each of the following test cases, we will:
// .String() the given collection and compare it to expectedString
@ -76,8 +76,8 @@ func TestUTXODiff(t *testing.T) {
txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111")
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)
utxoEntry0 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 10}, true, 0)
utxoEntry1 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 20}, false, 1)
// Test utxoDiff creation
diff := NewUTXODiff()
@ -119,8 +119,8 @@ func TestUTXODiff(t *testing.T) {
func TestUTXODiffRules(t *testing.T) {
txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000")
outpoint0 := *wire.NewOutpoint(txID0, 0)
utxoEntry1 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 10}, true, 10)
utxoEntry2 := NewUTXOEntry(&wire.TxOut{PkScript: []byte{}, Value: 10}, true, 20)
utxoEntry1 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 10}, true, 10)
utxoEntry2 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 10}, true, 20)
// For each of the following test cases, we will:
// this.diffFrom(other) and compare it to expectedDiffFromResult
@ -537,8 +537,8 @@ func TestFullUTXOSet(t *testing.T) {
txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111")
outpoint0 := *wire.NewOutpoint(txID0, 0)
outpoint1 := *wire.NewOutpoint(txID1, 0)
txOut0 := &wire.TxOut{PkScript: []byte{}, Value: 10}
txOut1 := &wire.TxOut{PkScript: []byte{}, Value: 20}
txOut0 := &wire.TxOut{ScriptPubKey: []byte{}, Value: 10}
txOut1 := &wire.TxOut{ScriptPubKey: []byte{}, Value: 20}
utxoEntry0 := NewUTXOEntry(txOut0, true, 0)
utxoEntry1 := NewUTXOEntry(txOut1, false, 1)
diff := addMultisetToDiff(t, &UTXODiff{
@ -601,8 +601,8 @@ func TestDiffUTXOSet(t *testing.T) {
txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111")
outpoint0 := *wire.NewOutpoint(txID0, 0)
outpoint1 := *wire.NewOutpoint(txID1, 0)
txOut0 := &wire.TxOut{PkScript: []byte{}, Value: 10}
txOut1 := &wire.TxOut{PkScript: []byte{}, Value: 20}
txOut0 := &wire.TxOut{ScriptPubKey: []byte{}, Value: 10}
txOut1 := &wire.TxOut{ScriptPubKey: []byte{}, Value: 20}
utxoEntry0 := NewUTXOEntry(txOut0, true, 0)
utxoEntry1 := NewUTXOEntry(txOut1, false, 1)
diff := addMultisetToDiff(t, &UTXODiff{
@ -857,7 +857,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) {
// coinbaseTX 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}
txOut0 := &wire.TxOut{PkScript: []byte{0}, Value: 10}
txOut0 := &wire.TxOut{ScriptPubKey: []byte{0}, Value: 10}
utxoEntry0 := NewUTXOEntry(txOut0, true, 0)
coinbaseTX := wire.NewSubnetworkMsgTx(1, []*wire.TxIn{txIn0}, []*wire.TxOut{txOut0}, subnetworkid.SubnetworkIDCoinbase, 0, nil)
@ -865,7 +865,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) {
id1 := coinbaseTX.TxID()
outpoint1 := *wire.NewOutpoint(id1, 0)
txIn1 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: outpoint1, Sequence: 0}
txOut1 := &wire.TxOut{PkScript: []byte{1}, Value: 20}
txOut1 := &wire.TxOut{ScriptPubKey: []byte{1}, Value: 20}
utxoEntry1 := NewUTXOEntry(txOut1, false, 1)
transaction1 := wire.NewNativeMsgTx(1, []*wire.TxIn{txIn1}, []*wire.TxOut{txOut1})
@ -873,7 +873,7 @@ func TestDiffUTXOSet_addTx(t *testing.T) {
id2 := transaction1.TxID()
outpoint2 := *wire.NewOutpoint(id2, 0)
txIn2 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: outpoint2, Sequence: 0}
txOut2 := &wire.TxOut{PkScript: []byte{2}, Value: 30}
txOut2 := &wire.TxOut{ScriptPubKey: []byte{2}, Value: 30}
utxoEntry2 := NewUTXOEntry(txOut2, false, 2)
transaction2 := wire.NewNativeMsgTx(1, []*wire.TxIn{txIn2}, []*wire.TxOut{txOut2})
@ -1027,7 +1027,7 @@ func TestDiffFromTx(t *testing.T) {
txID0, _ := daghash.NewTxIDFromStr("0000000000000000000000000000000000000000000000000000000000000000")
txIn0 := &wire.TxIn{SignatureScript: []byte{}, PreviousOutpoint: wire.Outpoint{TxID: *txID0, Index: math.MaxUint32}, Sequence: 0}
txOut0 := &wire.TxOut{PkScript: []byte{0}, Value: 10}
txOut0 := &wire.TxOut{ScriptPubKey: []byte{0}, Value: 10}
cbTx := wire.NewSubnetworkMsgTx(1, []*wire.TxIn{txIn0}, []*wire.TxOut{txOut0}, subnetworkid.SubnetworkIDCoinbase, 0, nil)
if isAccepted, err := fus.AddTx(cbTx, 1); err != nil {
t.Fatalf("AddTx unexpectedly failed. Error: %s", err)
@ -1042,8 +1042,8 @@ func TestDiffFromTx(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}}
txOuts := []*wire.TxOut{{
PkScript: OpTrueScript,
Value: uint64(1),
ScriptPubKey: OpTrueScript,
Value: uint64(1),
}}
tx := wire.NewNativeMsgTx(wire.TxVersion, txIns, txOuts)
diff, err := fus.diffFromTx(tx, acceptingBlueScore)
@ -1069,8 +1069,8 @@ func TestDiffFromTx(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}}
invalidTxOuts := []*wire.TxOut{{
PkScript: OpTrueScript,
Value: uint64(1),
ScriptPubKey: OpTrueScript,
Value: uint64(1),
}}
invalidTx := wire.NewNativeMsgTx(wire.TxVersion, invalidTxIns, invalidTxOuts)
_, err = fus.diffFromTx(invalidTx, acceptingBlueScore)
@ -1116,8 +1116,8 @@ func TestUTXOSetAddEntry(t *testing.T) {
txID1, _ := daghash.NewTxIDFromStr("1111111111111111111111111111111111111111111111111111111111111111")
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)
utxoEntry0 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 10}, true, 0)
utxoEntry1 := NewUTXOEntry(&wire.TxOut{ScriptPubKey: []byte{}, Value: 20}, false, 1)
utxoDiff := NewUTXODiff()

View File

@ -27,9 +27,9 @@ const (
baseSubsidy = 50 * util.SatoshiPerBitcoin
// the following are used when calculating a transaction's mass
massPerTxByte = 1
massPerPKScriptByte = 10
massPerSigOp = 10000
massPerTxByte = 1
massPerScriptPubKeyByte = 10
massPerSigOp = 10000
)
// isNullOutpoint determines whether or not a previous transaction outpoint
@ -302,7 +302,7 @@ func CountSigOps(tx *util.Tx) int {
// Accumulate the number of signature operations in all transaction
// outputs.
for _, txOut := range msgTx.TxOut {
numSigOps := txscript.GetSigOpCount(txOut.PkScript)
numSigOps := txscript.GetSigOpCount(txOut.ScriptPubKey)
totalSigOps += numSigOps
}
@ -336,15 +336,15 @@ func CountP2SHSigOps(tx *util.Tx, isCoinbase bool, utxoSet UTXOSet) (int, error)
// We're only interested in pay-to-script-hash types, so skip
// this input if it's not one.
pkScript := entry.PkScript()
if !txscript.IsPayToScriptHash(pkScript) {
scriptPubKey := entry.ScriptPubKey()
if !txscript.IsPayToScriptHash(scriptPubKey) {
continue
}
// Count the precise number of signature operations in the
// referenced public key script.
sigScript := txIn.SignatureScript
numSigOps := txscript.GetPreciseSigOpCount(sigScript, pkScript,
numSigOps := txscript.GetPreciseSigOpCount(sigScript, scriptPubKey,
true)
// We could potentially overflow the accumulator so check for
@ -412,9 +412,9 @@ func CalcTxMass(tx *util.Tx, utxoSet UTXOSet) (uint64, error) {
return uint64(txSize * massPerTxByte), nil
}
pkScriptSize := 0
scriptPubKeySize := 0
for _, txOut := range tx.MsgTx().TxOut {
pkScriptSize += len(txOut.PkScript)
scriptPubKeySize += len(txOut.ScriptPubKey)
}
sigOpsCount := 0
@ -431,14 +431,14 @@ func CalcTxMass(tx *util.Tx, utxoSet UTXOSet) (uint64, error) {
// Count the precise number of signature operations in the
// referenced public key script.
pkScript := entry.PkScript()
scriptPubKey := entry.ScriptPubKey()
sigScript := txIn.SignatureScript
isP2SH := txscript.IsPayToScriptHash(pkScript)
sigOpsCount += txscript.GetPreciseSigOpCount(sigScript, pkScript, isP2SH)
isP2SH := txscript.IsPayToScriptHash(scriptPubKey)
sigOpsCount += txscript.GetPreciseSigOpCount(sigScript, scriptPubKey, isP2SH)
}
return uint64(txSize*massPerTxByte +
pkScriptSize*massPerPKScriptByte +
scriptPubKeySize*massPerScriptPubKeyByte +
sigOpsCount*massPerSigOp), nil
}

View File

@ -267,7 +267,7 @@ func TestCheckBlockSanity(t *testing.T) {
TxOut: []*wire.TxOut{
{
Value: 0x12a05f200, // 5000000000
PkScript: []byte{
ScriptPubKey: []byte{
0x51,
},
},
@ -317,7 +317,7 @@ func TestCheckBlockSanity(t *testing.T) {
TxOut: []*wire.TxOut{
{
Value: 0x2123e300, // 556000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -330,7 +330,7 @@ func TestCheckBlockSanity(t *testing.T) {
},
{
Value: 0x108e20f00, // 4444000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -386,7 +386,7 @@ func TestCheckBlockSanity(t *testing.T) {
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -399,7 +399,7 @@ func TestCheckBlockSanity(t *testing.T) {
},
{
Value: 0x11d260c0, // 299000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -456,7 +456,7 @@ func TestCheckBlockSanity(t *testing.T) {
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -786,7 +786,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x12a05f200, // 5000000000
PkScript: []byte{
ScriptPubKey: []byte{
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49,
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
@ -875,7 +875,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x2123e300, // 556000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -888,7 +888,7 @@ var Block100000 = wire.MsgBlock{
},
{
Value: 0x108e20f00, // 4444000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -944,7 +944,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -957,7 +957,7 @@ var Block100000 = wire.MsgBlock{
},
{
Value: 0x11d260c0, // 299000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -1014,7 +1014,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -1093,7 +1093,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x12a05f200, // 5000000000
PkScript: []byte{
ScriptPubKey: []byte{
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49,
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
@ -1182,7 +1182,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x2123e300, // 556000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -1195,7 +1195,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
},
{
Value: 0x108e20f00, // 4444000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -1253,7 +1253,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -1266,7 +1266,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
},
{
Value: 0x11d260c0, // 299000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -1323,7 +1323,7 @@ var BlockWithWrongTxOrder = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20

View File

@ -13,12 +13,12 @@ func buildSubnetworkRegistryTx(cfg *config, fundingOutpoint *wire.Outpoint, fund
Sequence: wire.MaxTxInSequenceNum,
}
txOut := &wire.TxOut{
PkScript: fundingTx.TxOut[fundingOutpoint.Index].PkScript,
Value: fundingTx.TxOut[fundingOutpoint.Index].Value - cfg.RegistryTxFee,
ScriptPubKey: fundingTx.TxOut[fundingOutpoint.Index].ScriptPubKey,
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].ScriptPubKey,
txscript.SigHashAll, privateKey, true)
if err != nil {
return nil, fmt.Errorf("failed to build signature script: %s", err)

View File

@ -26,8 +26,8 @@ const (
// spendSize is the largest number of bytes of a sigScript
// which spends a p2pkh output: OP_DATA_73 <sig> OP_DATA_33 <pubkey>
spendSize uint64 = 1 + 73 + 1 + 33
// Value 8 bytes + serialized varint size for the length of PkScript +
// PkScript bytes.
// Value 8 bytes + serialized varint size for the length of ScriptPubKey +
// ScriptPubKey bytes.
outputSize uint64 = 8 + 1 + 25
txLifeSpan = 1000
@ -55,8 +55,8 @@ func isDust(value uint64) bool {
var (
random = rand.New(rand.NewSource(time.Now().UnixNano()))
primaryPkScript []byte
secondaryPkScript []byte
primaryScriptPubKey []byte
secondaryScriptPubKey []byte
sentToSecondaryAddress bool
)
@ -64,15 +64,15 @@ var (
func txLoop(client *txgenClient, cfg *config) error {
filterAddresses := []util.Address{p2pkhAddress}
var err error
primaryPkScript, err = txscript.PayToAddrScript(p2pkhAddress)
primaryScriptPubKey, err = txscript.PayToAddrScript(p2pkhAddress)
if err != nil {
return fmt.Errorf("failed to generate primaryPkScript to address: %s", err)
return fmt.Errorf("failed to generate primaryScriptPubKey to address: %s", err)
}
if secondaryAddress != nil {
secondaryPkScript, err = txscript.PayToAddrScript(secondaryAddress)
secondaryScriptPubKey, err = txscript.PayToAddrScript(secondaryAddress)
if err != nil {
return fmt.Errorf("failed to generate primaryPkScript to address: %s", err)
return fmt.Errorf("failed to generate primaryScriptPubKey to address: %s", err)
}
filterAddresses = append(filterAddresses, secondaryAddress)
@ -214,8 +214,8 @@ func randomWithAverageTarget(target uint64, allowZero bool) uint64 {
}
func createRandomTxFromFunds(walletUTXOSet utxoSet, cfg *config, gasLimitMap map[subnetworkid.SubnetworkID]uint64, funds uint64) (tx *wire.MsgTx, isSecondaryAddress bool, err error) {
if secondaryPkScript != nil && !sentToSecondaryAddress && funds > minSecondaryTxAmount {
tx, err = createTx(walletUTXOSet, minSecondaryTxAmount, cfg.AverageFeeRate, 1, 1, subnetworkid.SubnetworkIDNative, 0, 0, secondaryPkScript)
if secondaryScriptPubKey != nil && !sentToSecondaryAddress && funds > minSecondaryTxAmount {
tx, err = createTx(walletUTXOSet, minSecondaryTxAmount, cfg.AverageFeeRate, 1, 1, subnetworkid.SubnetworkIDNative, 0, 0, secondaryScriptPubKey)
if err != nil {
return nil, false, err
}
@ -254,7 +254,7 @@ func createRandomTxFromFunds(walletUTXOSet utxoSet, cfg *config, gasLimitMap map
if amount > funds-minTxFee {
amount = funds - minTxFee
}
tx, err = createTx(walletUTXOSet, amount, feeRate, targetNumberOfOutputs, targetNumberOfInputs, chosenSubnetwork, payloadSize, gas, primaryPkScript)
tx, err = createTx(walletUTXOSet, amount, feeRate, targetNumberOfOutputs, targetNumberOfInputs, chosenSubnetwork, payloadSize, gas, primaryScriptPubKey)
if err != nil {
return nil, false, err
}
@ -281,7 +281,7 @@ func enqueueTransactions(client *txgenClient, blockAdded *blockAddedMsg, walletU
}
func createTx(walletUTXOSet utxoSet, minAmount uint64, feeRate uint64, targetNumberOfOutputs uint64, targetNumberOfInputs uint64,
subnetworkdID *subnetworkid.SubnetworkID, payloadSize uint64, gas uint64, pkScript []byte) (*wire.MsgTx, error) {
subnetworkdID *subnetworkid.SubnetworkID, payloadSize uint64, gas uint64, scriptPubKey []byte) (*wire.MsgTx, error) {
var tx *wire.MsgTx
if subnetworkdID.IsEqual(subnetworkid.SubnetworkIDNative) {
tx = wire.NewNativeMsgTx(wire.TxVersion, nil, nil)
@ -307,8 +307,8 @@ func createTx(walletUTXOSet utxoSet, minAmount uint64, feeRate uint64, targetNum
for i := uint64(0); i < numOuts; i++ {
tx.AddTxOut(&wire.TxOut{
Value: funds / numOuts,
PkScript: pkScript,
Value: funds / numOuts,
ScriptPubKey: scriptPubKey,
})
}
@ -328,7 +328,7 @@ func signTx(walletUTXOSet utxoSet, tx *wire.MsgTx) error {
outpoint := txIn.PreviousOutpoint
prevOut := walletUTXOSet[outpoint]
sigScript, err := txscript.SignatureScript(tx, i, prevOut.PkScript,
sigScript, err := txscript.SignatureScript(tx, i, prevOut.ScriptPubKey,
txscript.SigHashAll, privateKey, true)
if err != nil {
return fmt.Errorf("Failed to sign transaction: %s", err)
@ -410,7 +410,7 @@ func removeTxInsFromUTXOSet(walletUTXOSet utxoSet, tx *wire.MsgTx) {
func addTxOutsToUTXOSet(walletUTXOSet utxoSet, tx *wire.MsgTx) {
for i, txOut := range tx.TxOut {
if bytes.Equal(txOut.PkScript, primaryPkScript) {
if bytes.Equal(txOut.ScriptPubKey, primaryScriptPubKey) {
outpoint := wire.Outpoint{TxID: *tx.TxID(), Index: uint32(i)}
walletUTXOSet[outpoint] = txOut
}

View File

@ -129,7 +129,7 @@ var genesisCoinbaseTxIns = []*wire.TxIn{
var genesisCoinbaseTxOuts = []*wire.TxOut{
{
Value: 0x12a05f200,
PkScript: []byte{
ScriptPubKey: []byte{
0x41, 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, /* |A.g....U| */
0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, /* |H'.g..q0| */
0xb7, 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, /* |..\..(.9| */

View File

@ -36,7 +36,7 @@ func makeTestOutput(r *rpctest.Harness, t *testing.T,
return nil, nil, nil, err
}
// Using the key created above, generate a pkScript which it's able to
// Using the key created above, generate a scriptPubKey which it's able to
// spend.
a, err := util.NewAddressPubKey(key.PubKey().SerializeCompressed(), r.ActiveNet)
if err != nil {
@ -46,7 +46,7 @@ func makeTestOutput(r *rpctest.Harness, t *testing.T,
if err != nil {
return nil, nil, nil, err
}
output := &wire.TxOut{PkScript: selfAddrScript, Value: 1e8}
output := &wire.TxOut{ScriptPubKey: selfAddrScript, Value: 1e8}
// Next, create and broadcast a transaction paying to the output.
fundTx, err := r.CreateTransaction([]*wire.TxOut{output}, 10)
@ -70,7 +70,7 @@ func makeTestOutput(r *rpctest.Harness, t *testing.T,
// generated above, this is needed in order to create a proper utxo for
// this output.
var outputIndex uint32
if bytes.Equal(fundTx.TxOut[0].PkScript, selfAddrScript) {
if bytes.Equal(fundTx.TxOut[0].ScriptPubKey, selfAddrScript) {
outputIndex = 0
} else {
outputIndex = 1
@ -109,7 +109,7 @@ func TestBIP0113(t *testing.T) {
// Create a fresh output for usage within the test below.
const outputValue = util.SatoshiPerBitcoin
outputKey, testOutput, testPkScript, err := makeTestOutput(r, t,
outputKey, testOutput, testScriptPubKey, err := makeTestOutput(r, t,
outputValue)
if err != nil {
t.Fatalf("unable to create test output: %v", err)
@ -134,8 +134,8 @@ func TestBIP0113(t *testing.T) {
PreviousOutpoint: *testOutput,
})
tx.AddTxOut(&wire.TxOut{
PkScript: addrScript,
Value: outputValue - 1000,
ScriptPubKey: addrScript,
Value: outputValue - 1000,
})
// We set the lock-time of the transaction to just one minute after the
@ -146,7 +146,7 @@ func TestBIP0113(t *testing.T) {
}
tx.LockTime = chainInfo.MedianTime + 1
sigScript, err := txscript.SignatureScript(tx, 0, testPkScript,
sigScript, err := txscript.SignatureScript(tx, 0, testScriptPubKey,
txscript.SigHashAll, outputKey, true)
if err != nil {
t.Fatalf("unable to generate sig: %v", err)
@ -183,7 +183,7 @@ func TestBIP0113(t *testing.T) {
medianTimePast := chainInfo.MedianTime
// Create another test output to be spent shortly below.
outputKey, testOutput, testPkScript, err = makeTestOutput(r, t,
outputKey, testOutput, testScriptPubKey, err = makeTestOutput(r, t,
outputValue)
if err != nil {
t.Fatalf("unable to create test output: %v", err)
@ -196,11 +196,11 @@ func TestBIP0113(t *testing.T) {
PreviousOutpoint: *testOutput,
})
tx.AddTxOut(&wire.TxOut{
PkScript: addrScript,
Value: outputValue - 1000,
ScriptPubKey: addrScript,
Value: outputValue - 1000,
})
tx.LockTime = medianTimePast + timeLockDelta
sigScript, err = txscript.SignatureScript(tx, 0, testPkScript,
sigScript, err = txscript.SignatureScript(tx, 0, testScriptPubKey,
txscript.SigHashAll, outputKey, true)
if err != nil {
t.Fatalf("unable to generate sig: %v", err)
@ -235,7 +235,7 @@ func TestBIP0113(t *testing.T) {
}
// createCSVOutput creates an output paying to a trivially redeemable CSV
// pkScript with the specified time-lock.
// scriptPubKey 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) {
@ -265,8 +265,8 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T,
return nil, nil, nil, err
}
output := &wire.TxOut{
PkScript: p2shScript,
Value: int64(numSatoshis),
ScriptPubKey: p2shScript,
Value: int64(numSatoshis),
}
// Finally create a valid transaction which creates the output crafted
@ -277,7 +277,7 @@ func createCSVOutput(r *rpctest.Harness, t *testing.T,
}
var outputIndex uint32
if !bytes.Equal(tx.TxOut[0].PkScript, p2shScript) {
if !bytes.Equal(tx.TxOut[0].ScriptPubKey, p2shScript) {
outputIndex = 1
}
@ -366,7 +366,7 @@ func TestBIP0068AndCsv(t *testing.T) {
}
harnessScript, err := txscript.PayToAddrScript(harnessAddr)
if err != nil {
t.Fatalf("unable to generate pkScript: %v", err)
t.Fatalf("unable to generate scriptPubKey: %v", err)
}
const (
@ -375,8 +375,8 @@ func TestBIP0068AndCsv(t *testing.T) {
)
sweepOutput := &wire.TxOut{
Value: outputAmt - 5000,
PkScript: harnessScript,
Value: outputAmt - 5000,
ScriptPubKey: harnessScript,
}
// With the height at 104 we need 200 blocks to be mined after the

View File

@ -100,7 +100,7 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlueScore uint64,
net *dagconfig.Params) (*util.Tx, error) {
// Create the script to pay to the provided payment address.
pkScript, err := txscript.PayToAddrScript(addr)
scriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
return nil, err
}
@ -116,8 +116,8 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlueScore uint64,
txOuts := []*wire.TxOut{}
if len(mineTo) == 0 {
txOuts = append(txOuts, &wire.TxOut{
Value: blockdag.CalcBlockSubsidy(nextBlueScore, net),
PkScript: pkScript,
Value: blockdag.CalcBlockSubsidy(nextBlueScore, net),
ScriptPubKey: scriptPubKey,
})
} else {
for i := range mineTo {

View File

@ -36,7 +36,7 @@ var (
// height of the transaction is recorded in order to properly observe the
// maturity period of direct coinbase outputs.
type utxo struct {
pkScript []byte
scriptPubKey []byte
value util.Amount
keyIndex uint32
maturityHeight uint64
@ -246,13 +246,13 @@ func (m *memWallet) evalOutputs(outputs []*wire.TxOut, txID *daghash.TxID,
isCoinbase bool, undo *undoEntry) {
for i, output := range outputs {
pkScript := output.PkScript
scriptPubKey := output.ScriptPubKey
// Scan all the addresses we currently control to see if the
// output is paying to us.
for keyIndex, addr := range m.addrs {
pkHash := addr.ScriptAddress()
if !bytes.Contains(pkScript, pkHash) {
if !bytes.Contains(scriptPubKey, pkHash) {
continue
}
@ -269,7 +269,7 @@ func (m *memWallet) evalOutputs(outputs []*wire.TxOut, txID *daghash.TxID,
value: util.Amount(output.Value),
keyIndex: keyIndex,
maturityHeight: maturityHeight,
pkScript: pkScript,
scriptPubKey: scriptPubKey,
}
undo.utxosCreated = append(undo.utxosCreated, op)
}
@ -383,13 +383,13 @@ func (m *memWallet) fundTx(tx *wire.MsgTx, amt util.Amount, feeRate util.Amount)
if err != nil {
return err
}
pkScript, err := txscript.PayToAddrScript(addr)
scriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
return err
}
changeOutput := &wire.TxOut{
Value: uint64(changeVal),
PkScript: pkScript,
Value: uint64(changeVal),
ScriptPubKey: scriptPubKey,
}
tx.AddTxOut(changeOutput)
}
@ -458,7 +458,7 @@ func (m *memWallet) CreateTransaction(outputs []*wire.TxOut, feeRate util.Amount
return nil, err
}
sigScript, err := txscript.SignatureScript(tx, i, utxo.pkScript,
sigScript, err := txscript.SignatureScript(tx, i, utxo.scriptPubKey,
txscript.SigHashAll, privKey, true)
if err != nil {
return nil, err

View File

@ -32,7 +32,7 @@ func testSendOutputs(r *Harness, t *testing.T) {
// coinbase outputs.
addrScript, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("unable to generate pkscript to addr: %v", err)
t.Fatalf("unable to generate scriptPubKey to addr: %v", err)
}
output := wire.NewTxOut(int64(amt), addrScript)
txid, err := r.SendOutputs([]*wire.TxOut{output}, 10)
@ -203,7 +203,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
addr, err := r.NewAddress()
addrScript, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("unable to generate pkscript to addr: %v", err)
t.Fatalf("unable to generate scriptPubKey to addr: %v", err)
}
output := wire.NewTxOut(5e8, addrScript)
testTx, err := r.CreateTransaction([]*wire.TxOut{output}, 10)
@ -331,11 +331,11 @@ func testGenerateAndSubmitBlock(r *Harness, t *testing.T) {
if err != nil {
t.Fatalf("unable to generate new address: %v", err)
}
pkScript, err := txscript.PayToAddrScript(addr)
scriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("unable to create script: %v", err)
}
output := wire.NewTxOut(util.SatoshiPerBitcoin, pkScript)
output := wire.NewTxOut(util.SatoshiPerBitcoin, scriptPubKey)
const numTxns = 5
txns := make([]*util.Tx, 0, numTxns)
@ -398,11 +398,11 @@ func testGenerateAndSubmitBlockWithCustomCoinbaseOutputs(r *Harness,
if err != nil {
t.Fatalf("unable to generate new address: %v", err)
}
pkScript, err := txscript.PayToAddrScript(addr)
scriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("unable to create script: %v", err)
}
output := wire.NewTxOut(util.SatoshiPerBitcoin, pkScript)
output := wire.NewTxOut(util.SatoshiPerBitcoin, scriptPubKey)
const numTxns = 5
txns := make([]*util.Tx, 0, numTxns)
@ -419,8 +419,8 @@ func testGenerateAndSubmitBlockWithCustomCoinbaseOutputs(r *Harness,
// time, and a burn output.
block, err := r.GenerateAndSubmitBlockWithCustomCoinbaseOutputs(txns,
-1, time.Time{}, []wire.TxOut{{
Value: 0,
PkScript: []byte{},
Value: 0,
ScriptPubKey: []byte{},
}})
if err != nil {
t.Fatalf("unable to generate block: %v", err)
@ -445,8 +445,8 @@ func testGenerateAndSubmitBlockWithCustomCoinbaseOutputs(r *Harness,
targetBlockVersion := int32(1337)
block, err = r.GenerateAndSubmitBlockWithCustomCoinbaseOutputs(nil,
targetBlockVersion, timestamp, []wire.TxOut{{
Value: 0,
PkScript: []byte{},
Value: 0,
ScriptPubKey: []byte{},
}})
if err != nil {
t.Fatalf("unable to generate block: %v", err)
@ -516,12 +516,12 @@ func testMemWalletLockedOutputs(r *Harness, t *testing.T) {
if err != nil {
t.Fatalf("unable to generate new address: %v", err)
}
pkScript, err := txscript.PayToAddrScript(addr)
scriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("unable to create script: %v", err)
}
outputAmt := util.Amount(50 * util.SatoshiPerBitcoin)
output := wire.NewTxOut(int64(outputAmt), pkScript)
output := wire.NewTxOut(int64(outputAmt), scriptPubKey)
tx, err := r.CreateTransaction([]*wire.TxOut{output}, 10)
if err != nil {
t.Fatalf("unable to create transaction: %v", err)

View File

@ -147,8 +147,8 @@ func (p *poolHarness) CreateCoinbaseTx(blueScore uint64, numOutputs uint32) (*ut
amount = amountPerOutput + remainder
}
txOuts = append(txOuts, &wire.TxOut{
PkScript: p.payScript,
Value: amount,
ScriptPubKey: p.payScript,
Value: amount,
})
}
@ -188,8 +188,8 @@ func (p *poolHarness) CreateSignedTxForSubnetwork(inputs []spendableOutpoint, nu
amount = amountPerOutput + remainder
}
txOuts = append(txOuts, &wire.TxOut{
PkScript: p.payScript,
Value: amount,
ScriptPubKey: p.payScript,
Value: amount,
})
}
@ -231,8 +231,8 @@ func (p *poolHarness) CreateTxChain(firstOutput spendableOutpoint, numTxns uint3
Sequence: wire.MaxTxInSequenceNum,
}
txOut := &wire.TxOut{
PkScript: p.payScript,
Value: uint64(spendableAmount),
ScriptPubKey: p.payScript,
Value: uint64(spendableAmount),
}
tx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
@ -307,7 +307,7 @@ func (tc *testContext) mineTransactions(transactions []*util.Tx, numberOfBlocks
// outputs so the caller can easily create new valid transactions which build
// off of it.
func newPoolHarness(t *testing.T, dagParams *dagconfig.Params, numOutputs uint32, dbName string) (*testContext, []spendableOutpoint, func(), error) {
pkScript, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
scriptPubKey, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
if err != nil {
return nil, nil, nil, err
}
@ -337,7 +337,7 @@ func newPoolHarness(t *testing.T, dagParams *dagconfig.Params, numOutputs uint32
chain := &fakeChain{}
harness := &poolHarness{
signatureScript: signatureScript,
payScript: pkScript,
payScript: scriptPubKey,
dagParams: &params,
chain: chain,
@ -470,8 +470,8 @@ func (p *poolHarness) createTx(outpoint spendableOutpoint, fee uint64, numOutput
amountPerOutput := (uint64(outpoint.amount) - fee) / uint64(numOutputs)
for i := int64(0); i < numOutputs; i++ {
txOuts = append(txOuts, &wire.TxOut{
PkScript: p.payScript,
Value: amountPerOutput,
ScriptPubKey: p.payScript,
Value: amountPerOutput,
})
}
tx := wire.NewNativeMsgTx(wire.TxVersion, txIns, txOuts)
@ -606,14 +606,14 @@ func TestProcessTransaction(t *testing.T) {
t.Fatalf("Script: error creating nonStdSigScript: %v", err)
}
p2shPKScript, err := txscript.NewScriptBuilder().
p2shScriptPubKey, err := txscript.NewScriptBuilder().
AddOp(txscript.OpHash160).
AddData(util.Hash160(nonStdSigScript)).
AddOp(txscript.OpEqual).
Script()
if err != nil {
t.Fatalf("Script: error creating p2shPKScript: %v", err)
t.Fatalf("Script: error creating p2shScriptPubKey: %v", err)
}
wrappedP2SHNonStdSigScript, err := txscript.NewScriptBuilder().AddData(nonStdSigScript).Script()
@ -634,11 +634,11 @@ func TestProcessTransaction(t *testing.T) {
if err != nil {
t.Fatalf("NewAddressPubKeyHash: unexpected error: %v", err)
}
dummyPkScript, err := txscript.PayToAddrScript(addr)
dummyScriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("PayToAddrScript: unexpected error: %v", err)
}
p2shTx := util.NewTx(wire.NewNativeMsgTx(1, nil, []*wire.TxOut{{Value: 5000000000, PkScript: p2shPKScript}}))
p2shTx := util.NewTx(wire.NewNativeMsgTx(1, nil, []*wire.TxOut{{Value: 5000000000, ScriptPubKey: p2shScriptPubKey}}))
if isAccepted, err := harness.txPool.mpUTXOSet.AddTx(p2shTx.MsgTx(), curHeight+1); err != nil {
t.Fatalf("AddTx unexpectedly failed. Error: %s", err)
} else if !isAccepted {
@ -651,8 +651,8 @@ func TestProcessTransaction(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}}
txOuts := []*wire.TxOut{{
Value: 5000000000,
PkScript: dummyPkScript,
Value: 5000000000,
ScriptPubKey: dummyScriptPubKey,
}}
nonStdSigScriptTx := util.NewTx(wire.NewNativeMsgTx(1, txIns, txOuts))
_, err = harness.txPool.ProcessTransaction(nonStdSigScriptTx, true, 0)
@ -728,8 +728,8 @@ func TestProcessTransaction(t *testing.T) {
Sequence: wire.MaxTxInSequenceNum,
}}
txOuts = []*wire.TxOut{{
Value: 1,
PkScript: dummyPkScript,
Value: 1,
ScriptPubKey: dummyScriptPubKey,
}}
tx = util.NewTx(wire.NewNativeMsgTx(1, txIns, txOuts))
_, err = harness.txPool.ProcessTransaction(tx, true, 0)
@ -1776,7 +1776,7 @@ var dummyBlock = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x12a05f200, // 5000000000
PkScript: []byte{
ScriptPubKey: []byte{
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49,
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,

View File

@ -90,11 +90,11 @@ func checkInputsStandard(tx *util.Tx, utxoSet blockdag.UTXOSet) error {
// they have already been checked prior to calling this
// function.
entry, _ := utxoSet.Get(txIn.PreviousOutpoint)
originPkScript := entry.PkScript()
switch txscript.GetScriptClass(originPkScript) {
originScriptPubKey := entry.ScriptPubKey()
switch txscript.GetScriptClass(originScriptPubKey) {
case txscript.ScriptHashTy:
numSigOps := txscript.GetPreciseSigOpCount(
txIn.SignatureScript, originPkScript, true)
txIn.SignatureScript, originScriptPubKey, true)
if numSigOps > maxStandardP2SHSigOps {
str := fmt.Sprintf("transaction input #%d has "+
"%d signature operations which is more "+
@ -120,7 +120,7 @@ func checkInputsStandard(tx *util.Tx, utxoSet blockdag.UTXOSet) error {
// minimum transaction relay fee, it is considered dust.
func isDust(txOut *wire.TxOut, minRelayTxFee util.Amount) bool {
// Unspendable outputs are considered dust.
if txscript.IsUnspendable(txOut.PkScript) {
if txscript.IsUnspendable(txOut.ScriptPubKey) {
return true
}
@ -250,7 +250,7 @@ func checkTransactionStandard(tx *util.Tx, blueScore uint64,
// None of the output public key scripts can be a non-standard script or
// be "dust".
for i, txOut := range msgTx.TxOut {
scriptClass := txscript.GetScriptClass(txOut.PkScript)
scriptClass := txscript.GetScriptClass(txOut.ScriptPubKey)
if scriptClass == txscript.NonStandardTy {
str := fmt.Sprintf("transaction output %d: non-standard script form", i)
return txRuleError(wire.RejectNonstandard, str)

View File

@ -94,7 +94,7 @@ func TestCalcMinRequiredTxRelayFee(t *testing.T) {
// TestDust tests the isDust API.
func TestDust(t *testing.T) {
pkScript := []byte{0x76, 0xa9, 0x21, 0x03, 0x2f, 0x7e, 0x43,
scriptPubKey := []byte{0x76, 0xa9, 0x21, 0x03, 0x2f, 0x7e, 0x43,
0x0a, 0xa4, 0xc9, 0xd1, 0x59, 0x43, 0x7e, 0x84, 0xb9,
0x75, 0xdc, 0x76, 0xd9, 0x00, 0x3b, 0xf0, 0x92, 0x2c,
0xf3, 0xaa, 0x45, 0x28, 0x46, 0x4b, 0xab, 0x78, 0x0d,
@ -109,48 +109,48 @@ func TestDust(t *testing.T) {
{
// Any value is allowed with a zero relay fee.
"zero value with zero relay fee",
wire.TxOut{Value: 0, PkScript: pkScript},
wire.TxOut{Value: 0, ScriptPubKey: scriptPubKey},
0,
false,
},
{
// Zero value is dust with any relay fee"
"zero value with very small tx fee",
wire.TxOut{Value: 0, PkScript: pkScript},
wire.TxOut{Value: 0, ScriptPubKey: scriptPubKey},
1,
true,
},
{
"38 byte public key script with value 584",
wire.TxOut{Value: 584, PkScript: pkScript},
wire.TxOut{Value: 584, ScriptPubKey: scriptPubKey},
1000,
true,
},
{
"38 byte public key script with value 585",
wire.TxOut{Value: 585, PkScript: pkScript},
wire.TxOut{Value: 585, ScriptPubKey: scriptPubKey},
1000,
false,
},
{
// Maximum allowed value is never dust.
"max satoshi amount is never dust",
wire.TxOut{Value: util.MaxSatoshi, PkScript: pkScript},
wire.TxOut{Value: util.MaxSatoshi, ScriptPubKey: scriptPubKey},
util.MaxSatoshi,
false,
},
{
// Maximum int64 value causes overflow.
"maximum int64 value",
wire.TxOut{Value: 1<<63 - 1, PkScript: pkScript},
wire.TxOut{Value: 1<<63 - 1, ScriptPubKey: scriptPubKey},
1<<63 - 1,
true,
},
{
// Unspendable pkScript due to an invalid public key
// Unspendable scriptPubKey due to an invalid public key
// script.
"unspendable pkScript",
wire.TxOut{Value: 5000, PkScript: []byte{0x01}},
"unspendable scriptPubKey",
wire.TxOut{Value: 5000, ScriptPubKey: []byte{0x01}},
0, // no relay fee
true,
},
@ -184,13 +184,13 @@ func TestCheckTransactionStandard(t *testing.T) {
if err != nil {
t.Fatalf("NewAddressPubKeyHash: unexpected error: %v", err)
}
dummyPkScript, err := txscript.PayToAddrScript(addr)
dummyScriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("PayToAddrScript: unexpected error: %v", err)
}
dummyTxOut := wire.TxOut{
Value: 100000000, // 1 BTC
PkScript: dummyPkScript,
Value: 100000000, // 1 BTC
ScriptPubKey: dummyScriptPubKey,
}
tests := []struct {
@ -228,7 +228,7 @@ func TestCheckTransactionStandard(t *testing.T) {
name: "Transaction size is too large",
tx: wire.NewNativeMsgTx(1, []*wire.TxIn{&dummyTxIn}, []*wire.TxOut{{
Value: 0,
PkScript: bytes.Repeat([]byte{0x00},
ScriptPubKey: bytes.Repeat([]byte{0x00},
MaxStandardTxSize+1),
}}),
height: 300000,
@ -262,8 +262,8 @@ func TestCheckTransactionStandard(t *testing.T) {
{
name: "Valid but non standard public key script",
tx: wire.NewNativeMsgTx(1, []*wire.TxIn{&dummyTxIn}, []*wire.TxOut{{
Value: 100000000,
PkScript: []byte{txscript.OpTrue},
Value: 100000000,
ScriptPubKey: []byte{txscript.OpTrue},
}}),
height: 300000,
isStandard: false,
@ -272,8 +272,8 @@ func TestCheckTransactionStandard(t *testing.T) {
{
name: "Dust output",
tx: wire.NewNativeMsgTx(1, []*wire.TxIn{&dummyTxIn}, []*wire.TxOut{{
Value: 0,
PkScript: dummyPkScript,
Value: 0,
ScriptPubKey: dummyScriptPubKey,
}}),
height: 300000,
isStandard: false,
@ -282,8 +282,8 @@ func TestCheckTransactionStandard(t *testing.T) {
{
name: "Nulldata transaction",
tx: wire.NewNativeMsgTx(1, []*wire.TxIn{&dummyTxIn}, []*wire.TxOut{{
Value: 0,
PkScript: []byte{txscript.OpReturn},
Value: 0,
ScriptPubKey: []byte{txscript.OpReturn},
}}),
height: 300000,
isStandard: false,

View File

@ -346,7 +346,7 @@ func (g *BlkTmplGenerator) UpdateBlockTime(msgBlock *wire.MsgBlock) error {
// height. It also recalculates and updates the new merkle root that results
// from changing the coinbase script.
func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, extraNonce uint64) error {
coinbasePayloadPkScript, _, err := blockdag.DeserializeCoinbasePayload(msgBlock.Transactions[util.CoinbaseTransactionIndex])
coinbasePayloadScriptPubKey, _, err := blockdag.DeserializeCoinbasePayload(msgBlock.Transactions[util.CoinbaseTransactionIndex])
if err != nil {
return err
}
@ -355,7 +355,7 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, extraNonce
if err != nil {
return err
}
coinbasePayload, err := blockdag.SerializeCoinbasePayload(coinbasePayloadPkScript, coinbasePayloadExtraData)
coinbasePayload, err := blockdag.SerializeCoinbasePayload(coinbasePayloadScriptPubKey, coinbasePayloadExtraData)
if err != nil {
return err
}

View File

@ -32,9 +32,9 @@ func TestNewBlockTemplate(t *testing.T) {
}
defer teardownFunc()
pkScript, err := txscript.NewScriptBuilder().AddOp(txscript.OpTrue).Script()
scriptPubKey, err := txscript.NewScriptBuilder().AddOp(txscript.OpTrue).Script()
if err != nil {
t.Fatalf("Failed to create pkScript: %v", err)
t.Fatalf("Failed to create scriptPubKey: %v", err)
}
policy := Policy{
@ -108,8 +108,8 @@ func TestNewBlockTemplate(t *testing.T) {
SignatureScript: signatureScript,
}
txOut := &wire.TxOut{
PkScript: pkScript,
Value: 1,
ScriptPubKey: scriptPubKey,
Value: 1,
}
tx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
@ -123,8 +123,8 @@ func TestNewBlockTemplate(t *testing.T) {
SignatureScript: signatureScript,
}
txOut = &wire.TxOut{
PkScript: pkScript,
Value: 1,
ScriptPubKey: scriptPubKey,
Value: 1,
}
nonFinalizedTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
nonFinalizedTx.LockTime = dag.ChainHeight() + 2
@ -142,8 +142,8 @@ func TestNewBlockTemplate(t *testing.T) {
SignatureScript: signatureScript,
}
txOut = &wire.TxOut{
PkScript: pkScript,
Value: 1,
ScriptPubKey: scriptPubKey,
Value: 1,
}
nonExistingSubnetworkTx := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut},
nonExistingSubnetwork, 1, []byte{})
@ -158,8 +158,8 @@ func TestNewBlockTemplate(t *testing.T) {
SignatureScript: signatureScript,
}
txOut = &wire.TxOut{
PkScript: pkScript,
Value: 1,
ScriptPubKey: scriptPubKey,
Value: 1,
}
subnetworkTx1 := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut}, existingSubnetwork, 1, []byte{})
@ -172,8 +172,8 @@ func TestNewBlockTemplate(t *testing.T) {
SignatureScript: signatureScript,
}
txOut = &wire.TxOut{
PkScript: pkScript,
Value: 1,
ScriptPubKey: scriptPubKey,
Value: 1,
}
subnetworkTx2 := wire.NewSubnetworkMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut}, existingSubnetwork,
100, // Subnetwork gas limit is 90

View File

@ -104,7 +104,7 @@ func (g *BlkTmplGenerator) newTxsForBlockTemplate(payToAddress util.Address, sou
txFees: make([]uint64, 0),
}
coinbasePayloadPkScript, err := txscript.PayToAddrScript(payToAddress)
coinbasePayloadScriptPubKey, err := txscript.PayToAddrScript(payToAddress)
if err != nil {
return nil, err
}
@ -116,7 +116,7 @@ func (g *BlkTmplGenerator) newTxsForBlockTemplate(payToAddress util.Address, sou
if err != nil {
return nil, err
}
coinbaseTx, err := g.dag.NextBlockCoinbaseTransactionNoLock(coinbasePayloadPkScript, coinbasePayloadExtraData)
coinbaseTx, err := g.dag.NextBlockCoinbaseTransactionNoLock(coinbasePayloadScriptPubKey, coinbasePayloadExtraData)
if err != nil {
return nil, err
}

View File

@ -72,9 +72,9 @@ func TestSelectTxs(t *testing.T) {
if err != nil {
t.Fatalf("Error creating signature script: %s", err)
}
pkScript, err := txscript.NewScriptBuilder().AddOp(txscript.OpTrue).Script()
scriptPubKey, err := txscript.NewScriptBuilder().AddOp(txscript.OpTrue).Script()
if err != nil {
t.Fatalf("Failed to create pkScript: %v", err)
t.Fatalf("Failed to create scriptPubKey: %v", err)
}
tests := []struct {
@ -487,8 +487,8 @@ func TestSelectTxs(t *testing.T) {
SignatureScript: signatureScript,
}
txOut := &wire.TxOut{
PkScript: pkScript,
Value: 1,
ScriptPubKey: scriptPubKey,
Value: 1,
}
msgTx := wire.NewSubnetworkMsgTx(
wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut},

View File

@ -545,7 +545,7 @@ func handleCreateRawTransaction(s *Server, cmd interface{}, closeChan <-chan str
}
// Create a new script which pays to the provided address.
pkScript, err := txscript.PayToAddrScript(addr)
scriptPubKey, err := txscript.PayToAddrScript(addr)
if err != nil {
context := "Failed to generate pay-to-address script"
return nil, internalRPCError(err.Error(), context)
@ -558,7 +558,7 @@ func handleCreateRawTransaction(s *Server, cmd interface{}, closeChan <-chan str
return nil, internalRPCError(err.Error(), context)
}
txOut := wire.NewTxOut(uint64(satoshi), pkScript)
txOut := wire.NewTxOut(uint64(satoshi), scriptPubKey)
mtx.AddTxOut(txOut)
}
@ -637,13 +637,13 @@ func createVoutList(mtx *wire.MsgTx, chainParams *dagconfig.Params, filterAddrMa
for i, v := range mtx.TxOut {
// The disassembled string will contain [error] inline if the
// script doesn't fully parse, so ignore the error here.
disbuf, _ := txscript.DisasmString(v.PkScript)
disbuf, _ := txscript.DisasmString(v.ScriptPubKey)
// Ignore the error here since an error means the script
// couldn't parse and there is no additional information about
// it anyways.
scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(
v.PkScript, chainParams)
scriptClass, addrs, reqSigs, _ := txscript.ExtractScriptPubKeyAddrs(
v.ScriptPubKey, chainParams)
// Encode the addresses while checking if the address passes the
// filter when needed.
@ -672,7 +672,7 @@ func createVoutList(mtx *wire.MsgTx, chainParams *dagconfig.Params, filterAddrMa
vout.Value = util.Amount(v.Value).ToBTC()
vout.ScriptPubKey.Addresses = encodedAddrs
vout.ScriptPubKey.Asm = disbuf
vout.ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
vout.ScriptPubKey.Hex = hex.EncodeToString(v.ScriptPubKey)
vout.ScriptPubKey.Type = scriptClass.String()
vout.ScriptPubKey.ReqSigs = int32(reqSigs)
@ -783,7 +783,7 @@ func handleDecodeScript(s *Server, cmd interface{}, closeChan <-chan struct{}) (
// Get information about the script.
// Ignore the error here since an error means the script couldn't parse
// and there is no additinal information about it anyways.
scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script,
scriptClass, addrs, reqSigs, _ := txscript.ExtractScriptPubKeyAddrs(script,
s.cfg.DAGParams)
addresses := make([]string, len(addrs))
for i, addr := range addrs {
@ -1611,12 +1611,12 @@ func (state *gbtWorkState) updateBlockTemplate(s *Server, useCoinbaseValue bool)
// Update the block coinbase output of the template to
// pay to the randomly selected payment address.
pkScript, err := txscript.PayToAddrScript(payToAddr)
scriptPubKey, err := txscript.PayToAddrScript(payToAddr)
if err != nil {
context := "Failed to create pay-to-addr script"
return internalRPCError(err.Error(), context)
}
template.Block.Transactions[util.CoinbaseTransactionIndex].TxOut[0].PkScript = pkScript
template.Block.Transactions[util.CoinbaseTransactionIndex].TxOut[0].ScriptPubKey = scriptPubKey
template.ValidPayAddress = true
// Update the merkle root.
@ -2739,7 +2739,7 @@ func handleGetTxOut(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
var bestBlockHash string
var confirmations *uint64
var value uint64
var pkScript []byte
var scriptPubKey []byte
var isCoinbase bool
isInMempool := false
includeMempool := true
@ -2772,7 +2772,7 @@ func handleGetTxOut(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
bestBlockHash = s.cfg.DAG.SelectedTipHash().String()
value = txOut.Value
pkScript = txOut.PkScript
scriptPubKey = txOut.ScriptPubKey
isCoinbase = mtx.IsCoinBase()
isInMempool = true
} else {
@ -2802,19 +2802,19 @@ func handleGetTxOut(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
bestBlockHash = s.cfg.DAG.SelectedTipHash().String()
value = entry.Amount()
pkScript = entry.PkScript()
scriptPubKey = entry.ScriptPubKey()
isCoinbase = entry.IsCoinbase()
}
// Disassemble script into single line printable format.
// The disassembled string will contain [error] inline if the script
// doesn't fully parse, so ignore the error here.
disbuf, _ := txscript.DisasmString(pkScript)
disbuf, _ := txscript.DisasmString(scriptPubKey)
// Get further info about the script.
// Ignore the error here since an error means the script couldn't parse
// and there is no additional information about it anyways.
scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(pkScript,
scriptClass, addrs, reqSigs, _ := txscript.ExtractScriptPubKeyAddrs(scriptPubKey,
s.cfg.DAGParams)
addresses := make([]string, len(addrs))
for i, addr := range addrs {
@ -2828,7 +2828,7 @@ func handleGetTxOut(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
Value: util.Amount(value).ToBTC(),
ScriptPubKey: btcjson.ScriptPubKeyResult{
Asm: disbuf,
Hex: hex.EncodeToString(pkScript),
Hex: hex.EncodeToString(scriptPubKey),
ReqSigs: int32(reqSigs),
Type: scriptClass.String(),
Addresses: addresses,
@ -3052,8 +3052,8 @@ func createVinListPrevOut(s *Server, mtx *wire.MsgTx, chainParams *dagconfig.Par
// Ignore the error here since an error means the script
// couldn't parse and there is no additional information about
// it anyways.
_, addrs, _, _ := txscript.ExtractPkScriptAddrs(
originTxOut.PkScript, chainParams)
_, addrs, _, _ := txscript.ExtractScriptPubKeyAddrs(
originTxOut.ScriptPubKey, chainParams)
// Encode the addresses while checking if the address passes the
// filter when needed.

View File

@ -622,8 +622,8 @@ func (m *wsNotificationManager) subscribedClients(tx *util.Tx,
}
for i, output := range msgTx.TxOut {
_, addrs, _, err := txscript.ExtractPkScriptAddrs(
output.PkScript, m.server.cfg.DAGParams)
_, addrs, _, err := txscript.ExtractScriptPubKeyAddrs(
output.ScriptPubKey, m.server.cfg.DAGParams)
if err != nil {
// Clients are not able to subscribe to
// nonstandard or non-address outputs.
@ -1595,8 +1595,8 @@ func rescanBlockFilter(filter *wsClientFilter, block *util.Block, params *dagcon
// Scan outputs.
for i, output := range msgTx.TxOut {
_, addrs, _, err := txscript.ExtractPkScriptAddrs(
output.PkScript, params)
_, addrs, _, err := txscript.ExtractScriptPubKeyAddrs(
output.ScriptPubKey, params)
if err != nil {
continue
}

View File

@ -45,14 +45,14 @@ func TestBadPC(t *testing.T) {
},
}
txOuts := []*wire.TxOut{{
Value: 1000000000,
PkScript: nil,
Value: 1000000000,
ScriptPubKey: nil,
}}
tx := wire.NewNativeMsgTx(1, txIns, txOuts)
pkScript := mustParseShortForm("NOP")
scriptPubKey := mustParseShortForm("NOP")
for _, test := range tests {
vm, err := NewEngine(pkScript, tx, 0, 0, nil)
vm, err := NewEngine(scriptPubKey, tx, 0, 0, nil)
if err != nil {
t.Errorf("Failed to create script: %v", err)
}
@ -114,14 +114,14 @@ func TestCheckErrorCondition(t *testing.T) {
Sequence: 4294967295,
}}
txOuts := []*wire.TxOut{{
Value: 1000000000,
PkScript: nil,
Value: 1000000000,
ScriptPubKey: nil,
}}
tx := wire.NewNativeMsgTx(1, txIns, txOuts)
pkScript := mustParseShortForm(test.script)
scriptPubKey := mustParseShortForm(test.script)
vm, err := NewEngine(pkScript, tx, 0, 0, nil)
vm, err := NewEngine(scriptPubKey, tx, 0, 0, nil)
if err != nil {
t.Errorf("TestCheckErrorCondition: %d: failed to create script: %v", i, err)
}
@ -409,14 +409,14 @@ func TestDisasmPC(t *testing.T) {
Sequence: 4294967295,
}}
txOuts := []*wire.TxOut{{
Value: 1000000000,
PkScript: nil,
Value: 1000000000,
ScriptPubKey: nil,
}}
tx := wire.NewNativeMsgTx(1, txIns, txOuts)
pkScript := mustParseShortForm("OP_DROP NOP TRUE")
scriptPubKey := mustParseShortForm("OP_DROP NOP TRUE")
vm, err := NewEngine(pkScript, tx, 0, 0, nil)
vm, err := NewEngine(scriptPubKey, tx, 0, 0, nil)
if err != nil {
t.Fatalf("failed to create script: %v", err)
}
@ -469,13 +469,13 @@ func TestDisasmScript(t *testing.T) {
Sequence: 4294967295,
}}
txOuts := []*wire.TxOut{{
Value: 1000000000,
PkScript: nil,
Value: 1000000000,
ScriptPubKey: nil,
}}
tx := wire.NewNativeMsgTx(1, txIns, txOuts)
pkScript := mustParseShortForm("OP_DROP NOP TRUE")
scriptPubKey := mustParseShortForm("OP_DROP NOP TRUE")
vm, err := NewEngine(pkScript, tx, 0, 0, nil)
vm, err := NewEngine(scriptPubKey, tx, 0, 0, nil)
if err != nil {
t.Fatalf("failed to create script: %v", err)
}

View File

@ -50,7 +50,7 @@ func ExamplePayToAddrScript() {
// This example demonstrates extracting information from a standard public key
// script.
func ExampleExtractPkScriptAddrs() {
func ExampleExtractScriptPubKeyAddrs() {
// Start with a standard pay-to-pubkey-hash script.
scriptHex := "76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
script, err := hex.DecodeString(scriptHex)
@ -60,7 +60,7 @@ func ExampleExtractPkScriptAddrs() {
}
// Extract and print details from the script.
scriptClass, addresses, reqSigs, err := txscript.ExtractPkScriptAddrs(
scriptClass, addresses, reqSigs, err := txscript.ExtractScriptPubKeyAddrs(
script, &dagconfig.MainNetParams)
if err != nil {
fmt.Println(err)

View File

@ -214,11 +214,11 @@ func parseExpectedResult(expected string) ([]ErrorCode, error) {
// createSpendTx generates a basic spending transaction given the passed
// signature and public key scripts.
func createSpendingTx(sigScript, pkScript []byte) *wire.MsgTx {
func createSpendingTx(sigScript, scriptPubKey []byte) *wire.MsgTx {
outpoint := wire.NewOutpoint(&daghash.TxID{}, ^uint32(0))
txIn := wire.NewTxIn(outpoint, []byte{Op0, Op0})
txOut := wire.NewTxOut(0, pkScript)
txOut := wire.NewTxOut(0, scriptPubKey)
coinbaseTx := wire.NewNativeMsgTx(wire.TxVersion, []*wire.TxIn{txIn}, []*wire.TxOut{txOut})
outpoint = wire.NewOutpoint(coinbaseTx.TxID(), 0)

View File

@ -337,7 +337,7 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.Msg
// All but current output get zeroed out.
for i := 0; i < idx; i++ {
txCopy.TxOut[i].Value = 0
txCopy.TxOut[i].PkScript = nil
txCopy.TxOut[i].ScriptPubKey = nil
}
// Sequence on all other inputs is 0, too.
@ -472,8 +472,8 @@ func GetPreciseSigOpCount(scriptSig, scriptPubKey []byte, isP2SH bool) int {
// IsUnspendable returns whether the passed public key script is unspendable, or
// guaranteed to fail at execution. This allows inputs to be pruned instantly
// when entering the UTXO set.
func IsUnspendable(pkScript []byte) bool {
pops, err := parseScript(pkScript)
func IsUnspendable(scriptPubKey []byte) bool {
pops, err := parseScript(scriptPubKey)
if err != nil {
return true
}

View File

@ -3816,10 +3816,10 @@ func TestGetPreciseSigOps(t *testing.T) {
// The signature in the p2sh script is nonsensical for the tests since
// this script will never be executed. What matters is that it matches
// the right pattern.
pkScript := mustParseShortForm("HASH160 DATA_20 0x433ec2ac1ffa1b7b7d0" +
scriptPubKey := mustParseShortForm("HASH160 DATA_20 0x433ec2ac1ffa1b7b7d0" +
"27f564529c57197f9ae88 EQUAL")
for _, test := range tests {
count := GetPreciseSigOpCount(test.scriptSig, pkScript, true)
count := GetPreciseSigOpCount(test.scriptSig, scriptPubKey, true)
if count != test.nSigOps {
t.Errorf("%s: expected count of %d, got %d", test.name,
test.nSigOps, count)
@ -3943,18 +3943,18 @@ func TestIsUnspendable(t *testing.T) {
t.Parallel()
tests := []struct {
name string
pkScript []byte
expected bool
name string
scriptPubKey []byte
expected bool
}{
{
// Unspendable
pkScript: []byte{0x6a, 0x04, 0x74, 0x65, 0x73, 0x74},
expected: true,
scriptPubKey: []byte{0x6a, 0x04, 0x74, 0x65, 0x73, 0x74},
expected: true,
},
{
// Spendable
pkScript: []byte{0x76, 0xa9, 0x14, 0x29, 0x95, 0xa0,
scriptPubKey: []byte{0x76, 0xa9, 0x14, 0x29, 0x95, 0xa0,
0xfe, 0x68, 0x43, 0xfa, 0x9b, 0x95, 0x45,
0x97, 0xf0, 0xdc, 0xa7, 0xa4, 0x4d, 0xf6,
0xfa, 0x0b, 0x5c, 0x88, 0xac},
@ -3963,7 +3963,7 @@ func TestIsUnspendable(t *testing.T) {
}
for i, test := range tests {
res := IsUnspendable(test.pkScript)
res := IsUnspendable(test.scriptPubKey)
if res != test.expected {
t.Errorf("TestIsUnspendable #%d failed: got %v want %v",
i, res, test.expected)

View File

@ -35,7 +35,7 @@ func RawTxInSignature(tx *wire.MsgTx, idx int, script []byte,
// from a previous output to the owner of privKey. tx must include all
// transaction inputs and outputs, however txin scripts are allowed to be filled
// or empty. The returned script is calculated to be used as the idx'th txin
// sigscript for tx. script is the PkScript of the previous output being used
// sigscript for tx. script is the ScriptPubKey of the previous output being used
// as the idx'th input. privKey is serialized in either a compressed or
// uncompressed format based on compress. This format must match the same format
// used to generate the payment address, or the script validation will fail.
@ -60,7 +60,7 @@ func sign(chainParams *dagconfig.Params, tx *wire.MsgTx, idx int,
script []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB) ([]byte,
ScriptClass, []util.Address, int, error) {
class, addresses, nrequired, err := ExtractPkScriptAddrs(script,
class, addresses, nrequired, err := ExtractScriptPubKeyAddrs(script,
chainParams)
if err != nil {
return nil, NonStandardTy, nil, 0, err
@ -95,13 +95,13 @@ func sign(chainParams *dagconfig.Params, tx *wire.MsgTx, idx int,
}
// mergeScripts merges sigScript and prevScript assuming they are both
// partial solutions for pkScript spending output idx of tx. class, addresses
// and nrequired are the result of extracting the addresses from pkscript.
// partial solutions for scriptPubKey spending output idx of tx. class, addresses
// and nrequired are the result of extracting the addresses from scriptPubKey.
// The return value is the best effort merging of the two scripts. Calling this
// function with addresses, class and nrequired that do not match pkScript is
// function with addresses, class and nrequired that do not match scriptPubKey is
// an error and results in undefined behaviour.
func mergeScripts(chainParams *dagconfig.Params, tx *wire.MsgTx, idx int,
pkScript []byte, class ScriptClass, addresses []util.Address,
scriptPubKey []byte, class ScriptClass, addresses []util.Address,
nRequired int, sigScript, prevScript []byte) ([]byte, error) {
// TODO: the scripthash and multisig paths here are overly
@ -127,7 +127,7 @@ func mergeScripts(chainParams *dagconfig.Params, tx *wire.MsgTx, idx int,
// We already know this information somewhere up the stack.
class, addresses, nrequired, _ :=
ExtractPkScriptAddrs(script, chainParams)
ExtractScriptPubKeyAddrs(script, chainParams)
// regenerate scripts.
sigScript, _ := unparseScript(sigPops)
@ -190,18 +190,18 @@ func (sc ScriptClosure) GetScript(address util.Address) ([]byte, error) {
}
// SignTxOutput signs output idx of the given tx to resolve the script given in
// pkScript with a signature type of hashType. Any keys required will be
// scriptPubKey with a signature type of hashType. Any keys required will be
// looked up by calling getKey() with the string of the given address.
// Any pay-to-script-hash signatures will be similarly looked up by calling
// getScript. If previousScript is provided then the results in previousScript
// will be merged in a type-dependent manner with the newly generated.
// signature script.
func SignTxOutput(chainParams *dagconfig.Params, tx *wire.MsgTx, idx int,
pkScript []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB,
scriptPubKey []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB,
previousScript []byte) ([]byte, error) {
sigScript, class, addresses, nrequired, err := sign(chainParams, tx,
idx, pkScript, hashType, kdb, sdb)
idx, scriptPubKey, hashType, kdb, sdb)
if err != nil {
return nil, err
}
@ -224,6 +224,6 @@ func SignTxOutput(chainParams *dagconfig.Params, tx *wire.MsgTx, idx int,
}
// Merge scripts. with any previous data, if any.
return mergeScripts(chainParams, tx, idx, pkScript, class,
return mergeScripts(chainParams, tx, idx, scriptPubKey, class,
addresses, nrequired, sigScript, previousScript)
}

View File

@ -53,10 +53,10 @@ func mkGetScript(scripts map[string][]byte) ScriptDB {
})
}
func checkScripts(msg string, tx *wire.MsgTx, idx int, sigScript, pkScript []byte) error {
func checkScripts(msg string, tx *wire.MsgTx, idx int, sigScript, scriptPubKey []byte) error {
tx.TxIn[idx].SignatureScript = sigScript
var flags ScriptFlags
vm, err := NewEngine(pkScript, tx, idx,
vm, err := NewEngine(scriptPubKey, tx, idx,
flags, nil)
if err != nil {
return fmt.Errorf("failed to make script engine for %s: %v",
@ -72,17 +72,17 @@ func checkScripts(msg string, tx *wire.MsgTx, idx int, sigScript, pkScript []byt
return nil
}
func signAndCheck(msg string, tx *wire.MsgTx, idx int, pkScript []byte,
func signAndCheck(msg string, tx *wire.MsgTx, idx int, scriptPubKey []byte,
hashType SigHashType, kdb KeyDB, sdb ScriptDB,
previousScript []byte) error {
sigScript, err := SignTxOutput(&dagconfig.TestNet3Params, tx, idx,
pkScript, hashType, kdb, sdb, nil)
scriptPubKey, hashType, kdb, sdb, nil)
if err != nil {
return fmt.Errorf("failed to sign output %s: %v", msg, err)
}
return checkScripts(msg, tx, idx, sigScript, pkScript)
return checkScripts(msg, tx, idx, sigScript, scriptPubKey)
}
func TestSignTxOutput(t *testing.T) {
@ -156,13 +156,13 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
}
if err := signAndCheck(msg, tx, i, pkScript, hashType,
if err := signAndCheck(msg, tx, i, scriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, false},
}), mkGetScript(nil), nil); err != nil {
@ -193,14 +193,14 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
}
sigScript, err := SignTxOutput(&dagconfig.TestNet3Params,
tx, i, pkScript, hashType,
tx, i, scriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, false},
}), mkGetScript(nil), nil)
@ -213,7 +213,7 @@ func TestSignTxOutput(t *testing.T) {
// by the above loop, this should be valid, now sign
// again and merge.
sigScript, err = SignTxOutput(&dagconfig.TestNet3Params,
tx, i, pkScript, hashType,
tx, i, scriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, false},
}), mkGetScript(nil), sigScript)
@ -223,7 +223,7 @@ func TestSignTxOutput(t *testing.T) {
break
}
err = checkScripts(msg, tx, i, sigScript, pkScript)
err = checkScripts(msg, tx, i, sigScript, scriptPubKey)
if err != nil {
t.Errorf("twice signed script invalid for "+
"%s: %v", msg, err)
@ -254,13 +254,13 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
}
if err := signAndCheck(msg, tx, i, pkScript, hashType,
if err := signAndCheck(msg, tx, i, scriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, true},
}), mkGetScript(nil), nil); err != nil {
@ -292,14 +292,14 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
}
sigScript, err := SignTxOutput(&dagconfig.TestNet3Params,
tx, i, pkScript, hashType,
tx, i, scriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, true},
}), mkGetScript(nil), nil)
@ -312,7 +312,7 @@ func TestSignTxOutput(t *testing.T) {
// by the above loop, this should be valid, now sign
// again and merge.
sigScript, err = SignTxOutput(&dagconfig.TestNet3Params,
tx, i, pkScript, hashType,
tx, i, scriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, true},
}), mkGetScript(nil), sigScript)
@ -322,7 +322,7 @@ func TestSignTxOutput(t *testing.T) {
break
}
err = checkScripts(msg, tx, i, sigScript, pkScript)
err = checkScripts(msg, tx, i, sigScript, scriptPubKey)
if err != nil {
t.Errorf("twice signed script invalid for "+
"%s: %v", msg, err)
@ -353,34 +353,34 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
break
}
scriptAddr, err := util.NewAddressScriptHash(
pkScript, util.Bech32PrefixDAGTest)
scriptPubKey, util.Bech32PrefixDAGTest)
if err != nil {
t.Errorf("failed to make p2sh addr for %s: %v",
msg, err)
break
}
scriptPkScript, err := PayToAddrScript(
scriptScriptPubKey, err := PayToAddrScript(
scriptAddr)
if err != nil {
t.Errorf("failed to make script pkscript for "+
t.Errorf("failed to make script scriptPubKey for "+
"%s: %v", msg, err)
break
}
if err := signAndCheck(msg, tx, i, scriptPkScript, hashType,
if err := signAndCheck(msg, tx, i, scriptScriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, false},
}), mkGetScript(map[string][]byte{
scriptAddr.EncodeAddress(): pkScript,
scriptAddr.EncodeAddress(): scriptPubKey,
}), nil); err != nil {
t.Error(err)
break
@ -409,35 +409,35 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
break
}
scriptAddr, err := util.NewAddressScriptHash(
pkScript, util.Bech32PrefixDAGTest)
scriptPubKey, util.Bech32PrefixDAGTest)
if err != nil {
t.Errorf("failed to make p2sh addr for %s: %v",
msg, err)
break
}
scriptPkScript, err := PayToAddrScript(
scriptScriptPubKey, err := PayToAddrScript(
scriptAddr)
if err != nil {
t.Errorf("failed to make script pkscript for "+
t.Errorf("failed to make script scriptPubKey for "+
"%s: %v", msg, err)
break
}
sigScript, err := SignTxOutput(&dagconfig.TestNet3Params,
tx, i, scriptPkScript, hashType,
tx, i, scriptScriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, false},
}), mkGetScript(map[string][]byte{
scriptAddr.EncodeAddress(): pkScript,
scriptAddr.EncodeAddress(): scriptPubKey,
}), nil)
if err != nil {
t.Errorf("failed to sign output %s: %v", msg,
@ -448,11 +448,11 @@ func TestSignTxOutput(t *testing.T) {
// by the above loop, this should be valid, now sign
// again and merge.
sigScript, err = SignTxOutput(&dagconfig.TestNet3Params,
tx, i, scriptPkScript, hashType,
tx, i, scriptScriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, false},
}), mkGetScript(map[string][]byte{
scriptAddr.EncodeAddress(): pkScript,
scriptAddr.EncodeAddress(): scriptPubKey,
}), nil)
if err != nil {
t.Errorf("failed to sign output %s a "+
@ -460,7 +460,7 @@ func TestSignTxOutput(t *testing.T) {
break
}
err = checkScripts(msg, tx, i, sigScript, scriptPkScript)
err = checkScripts(msg, tx, i, sigScript, scriptScriptPubKey)
if err != nil {
t.Errorf("twice signed script invalid for "+
"%s: %v", msg, err)
@ -491,33 +491,33 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
}
scriptAddr, err := util.NewAddressScriptHash(
pkScript, util.Bech32PrefixDAGTest)
scriptPubKey, util.Bech32PrefixDAGTest)
if err != nil {
t.Errorf("failed to make p2sh addr for %s: %v",
msg, err)
break
}
scriptPkScript, err := PayToAddrScript(
scriptScriptPubKey, err := PayToAddrScript(
scriptAddr)
if err != nil {
t.Errorf("failed to make script pkscript for "+
t.Errorf("failed to make script scriptPubKey for "+
"%s: %v", msg, err)
break
}
if err := signAndCheck(msg, tx, i, scriptPkScript, hashType,
if err := signAndCheck(msg, tx, i, scriptScriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, true},
}), mkGetScript(map[string][]byte{
scriptAddr.EncodeAddress(): pkScript,
scriptAddr.EncodeAddress(): scriptPubKey,
}), nil); err != nil {
t.Error(err)
break
@ -547,34 +547,34 @@ func TestSignTxOutput(t *testing.T) {
break
}
pkScript, err := PayToAddrScript(address)
scriptPubKey, err := PayToAddrScript(address)
if err != nil {
t.Errorf("failed to make pkscript "+
t.Errorf("failed to make scriptPubKey "+
"for %s: %v", msg, err)
}
scriptAddr, err := util.NewAddressScriptHash(
pkScript, util.Bech32PrefixDAGTest)
scriptPubKey, util.Bech32PrefixDAGTest)
if err != nil {
t.Errorf("failed to make p2sh addr for %s: %v",
msg, err)
break
}
scriptPkScript, err := PayToAddrScript(
scriptScriptPubKey, err := PayToAddrScript(
scriptAddr)
if err != nil {
t.Errorf("failed to make script pkscript for "+
t.Errorf("failed to make script scriptPubKey for "+
"%s: %v", msg, err)
break
}
sigScript, err := SignTxOutput(&dagconfig.TestNet3Params,
tx, i, scriptPkScript, hashType,
tx, i, scriptScriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, true},
}), mkGetScript(map[string][]byte{
scriptAddr.EncodeAddress(): pkScript,
scriptAddr.EncodeAddress(): scriptPubKey,
}), nil)
if err != nil {
t.Errorf("failed to sign output %s: %v", msg,
@ -585,11 +585,11 @@ func TestSignTxOutput(t *testing.T) {
// by the above loop, this should be valid, now sign
// again and merge.
sigScript, err = SignTxOutput(&dagconfig.TestNet3Params,
tx, i, scriptPkScript, hashType,
tx, i, scriptScriptPubKey, hashType,
mkGetKey(map[string]addressToKey{
address.EncodeAddress(): {key, true},
}), mkGetScript(map[string][]byte{
scriptAddr.EncodeAddress(): pkScript,
scriptAddr.EncodeAddress(): scriptPubKey,
}), nil)
if err != nil {
t.Errorf("failed to sign output %s a "+
@ -597,7 +597,7 @@ func TestSignTxOutput(t *testing.T) {
break
}
err = checkScripts(msg, tx, i, sigScript, scriptPkScript)
err = checkScripts(msg, tx, i, sigScript, scriptScriptPubKey)
if err != nil {
t.Errorf("twice signed script invalid for "+
"%s: %v", msg, err)
@ -626,7 +626,7 @@ var coinbaseOutpoint = &wire.Outpoint{
Index: (1 << 32) - 1,
}
// Pregenerated private key, with associated public key and pkScripts
// Pregenerated private key, with associated public key and scriptPubKeys
// for the uncompressed and compressed hash160.
var (
privKeyD = []byte{0x6b, 0x0f, 0xd8, 0xda, 0x54, 0x22, 0xd0, 0xb7,
@ -641,13 +641,13 @@ var (
0x63, 0x32, 0x62, 0xaa, 0x60, 0xc6, 0x83, 0x30, 0xbd, 0x24,
0x7e, 0xef, 0xdb, 0x6f, 0x2e, 0x8d, 0x56, 0xf0, 0x3c, 0x9f,
0x6d, 0xb6, 0xf8}
uncompressedPkScript = []byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
uncompressedScriptPubKey = []byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
0xeb, 0xa4, 0x02, 0xcb, 0x68, 0xe0, 0x69, 0x56, 0xbf, 0x32,
0x53, 0x90, 0x0e, 0x0a, 0x86, 0xc9, 0xfa, 0x88, 0xac}
compressedPkScript = []byte{0x76, 0xa9, 0x14, 0x27, 0x4d, 0x9f, 0x7f,
compressedScriptPubKey = []byte{0x76, 0xa9, 0x14, 0x27, 0x4d, 0x9f, 0x7f,
0x61, 0x7e, 0x7c, 0x7a, 0x1c, 0x1f, 0xb2, 0x75, 0x79, 0x10,
0x43, 0x65, 0x68, 0x27, 0x9d, 0x86, 0x88, 0xac}
shortPkScript = []byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
shortScriptPubKey = []byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
0xeb, 0xa4, 0x02, 0xcb, 0x68, 0xe0, 0x69, 0x56, 0xbf, 0x32,
0x53, 0x90, 0x0e, 0x0a, 0x88, 0xac}
uncompressedAddrStr = "1L6fd93zGmtzkK6CsZFVVoCwzZV3MUtJ4F"
@ -663,7 +663,7 @@ var sigScriptTests = []tstSigScript{
name: "one input uncompressed",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -677,13 +677,13 @@ var sigScriptTests = []tstSigScript{
name: "two inputs uncompressed",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
},
{
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -697,7 +697,7 @@ var sigScriptTests = []tstSigScript{
name: "one input compressed",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, compressedPkScript),
txout: wire.NewTxOut(coinbaseVal, compressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -711,13 +711,13 @@ var sigScriptTests = []tstSigScript{
name: "two inputs compressed",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, compressedPkScript),
txout: wire.NewTxOut(coinbaseVal, compressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
},
{
txout: wire.NewTxOut(coinbaseVal+fee, compressedPkScript),
txout: wire.NewTxOut(coinbaseVal+fee, compressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -731,7 +731,7 @@ var sigScriptTests = []tstSigScript{
name: "hashType SigHashNone",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -745,7 +745,7 @@ var sigScriptTests = []tstSigScript{
name: "hashType SigHashSingle",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -759,7 +759,7 @@ var sigScriptTests = []tstSigScript{
name: "hashType SigHashAll | SigHashAnyoneCanPay",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -773,7 +773,7 @@ var sigScriptTests = []tstSigScript{
name: "hashType SigHashAnyoneCanPay",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: false,
indexOutOfRange: false,
@ -787,7 +787,7 @@ var sigScriptTests = []tstSigScript{
name: "hashType non-exist",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: false,
indexOutOfRange: false,
@ -801,7 +801,7 @@ var sigScriptTests = []tstSigScript{
name: "invalid compression",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: false,
indexOutOfRange: false,
@ -812,10 +812,10 @@ var sigScriptTests = []tstSigScript{
scriptAtWrongIndex: false,
},
{
name: "short PkScript",
name: "short ScriptPubKey",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, shortPkScript),
txout: wire.NewTxOut(coinbaseVal, shortScriptPubKey),
sigscriptGenerates: false,
indexOutOfRange: false,
},
@ -828,13 +828,13 @@ var sigScriptTests = []tstSigScript{
name: "valid script at wrong index",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
},
{
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -848,13 +848,13 @@ var sigScriptTests = []tstSigScript{
name: "index out of range",
inputs: []tstInput{
{
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
},
{
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedPkScript),
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedScriptPubKey),
sigscriptGenerates: true,
inputValidates: true,
indexOutOfRange: false,
@ -897,7 +897,7 @@ nexttest:
idx = j
}
script, err = SignatureScript(tx, idx,
sigScriptTests[i].inputs[j].txout.PkScript,
sigScriptTests[i].inputs[j].txout.ScriptPubKey,
sigScriptTests[i].hashType, privKey,
sigScriptTests[i].compress)
@ -931,7 +931,7 @@ nexttest:
var scriptFlags ScriptFlags
for j := range tx.TxIn {
vm, err := NewEngine(sigScriptTests[i].
inputs[j].txout.PkScript, tx, j, scriptFlags, nil)
inputs[j].txout.ScriptPubKey, tx, j, scriptFlags, nil)
if err != nil {
t.Errorf("cannot create script vm for test %v: %v",
sigScriptTests[i].name, err)

View File

@ -110,9 +110,9 @@ func expectedInputs(pops []parsedOpcode, class ScriptClass) int {
// ScriptInfo houses information about a script pair that is determined by
// CalcScriptInfo.
type ScriptInfo struct {
// PkScriptClass is the class of the public key script and is equivalent
// ScriptPubKeyClass is the class of the public key script and is equivalent
// to calling GetScriptClass on it.
PkScriptClass ScriptClass
ScriptPubKeyClass ScriptClass
// NumInputs is the number of inputs provided by the public key script.
NumInputs int
@ -128,22 +128,22 @@ type ScriptInfo struct {
// CalcScriptInfo returns a structure providing data about the provided script
// pair. It will error if the pair is in someway invalid such that they can not
// be analysed, i.e. if they do not parse or the pkScript is not a push-only
// be analysed, i.e. if they do not parse or the scriptPubKey is not a push-only
// script
func CalcScriptInfo(sigScript, pkScript []byte, isP2SH bool) (*ScriptInfo, error) {
func CalcScriptInfo(sigScript, scriptPubKey []byte, isP2SH bool) (*ScriptInfo, error) {
sigPops, err := parseScript(sigScript)
if err != nil {
return nil, err
}
pkPops, err := parseScript(pkScript)
scriptPubKeyPops, err := parseScript(scriptPubKey)
if err != nil {
return nil, err
}
// Push only sigScript makes little sense.
si := new(ScriptInfo)
si.PkScriptClass = typeOfScript(pkPops)
si.ScriptPubKeyClass = typeOfScript(scriptPubKeyPops)
// Can't have a signature script that doesn't just push data.
if !isPushOnly(sigPops) {
@ -151,12 +151,12 @@ func CalcScriptInfo(sigScript, pkScript []byte, isP2SH bool) (*ScriptInfo, error
"signature script is not push only")
}
si.ExpectedInputs = expectedInputs(pkPops, si.PkScriptClass)
si.ExpectedInputs = expectedInputs(scriptPubKeyPops, si.ScriptPubKeyClass)
// All entries pushed to stack (or are OP_RESERVED and exec will fail).
si.NumInputs = len(sigPops)
if si.PkScriptClass == ScriptHashTy && isP2SH {
if si.ScriptPubKeyClass == ScriptHashTy && isP2SH {
// The pay-to-hash-script is the final data push of the
// signature script.
script := sigPops[len(sigPops)-1].data
@ -173,7 +173,7 @@ func CalcScriptInfo(sigScript, pkScript []byte, isP2SH bool) (*ScriptInfo, error
}
si.SigOps = getSigOpCount(shPops, true)
} else {
si.SigOps = getSigOpCount(pkPops, true)
si.SigOps = getSigOpCount(scriptPubKeyPops, true)
}
return si, nil
@ -271,17 +271,17 @@ func PushedData(script []byte) ([][]byte, error) {
return data, nil
}
// ExtractPkScriptAddrs returns the type of script, addresses and required
// signatures associated with the passed PkScript. Note that it only works for
// ExtractScriptPubKeyAddrs returns the type of script, addresses and required
// signatures associated with the passed ScriptPubKey. Note that it only works for
// 'standard' transaction script types. Any data such as public keys which are
// invalid are omitted from the results.
func ExtractPkScriptAddrs(pkScript []byte, chainParams *dagconfig.Params) (ScriptClass, []util.Address, int, error) {
func ExtractScriptPubKeyAddrs(scriptPubKey []byte, chainParams *dagconfig.Params) (ScriptClass, []util.Address, int, error) {
var addrs []util.Address
var requiredSigs int
// No valid addresses or required signatures if the script doesn't
// parse.
pops, err := parseScript(pkScript)
pops, err := parseScript(scriptPubKey)
if err != nil {
return NonStandardTy, nil, 0, err
}
@ -340,8 +340,8 @@ type AtomicSwapDataPushes struct {
//
// This function is only defined in the txscript package due to API limitations
// which prevent callers using txscript to parse nonstandard scripts.
func ExtractAtomicSwapDataPushes(version uint16, pkScript []byte) (*AtomicSwapDataPushes, error) {
pops, err := parseScript(pkScript)
func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSwapDataPushes, error) {
pops, err := parseScript(scriptPubKey)
if err != nil {
return nil, err
}

View File

@ -54,9 +54,9 @@ func newAddressScriptHash(scriptHash []byte) util.Address {
return addr
}
// TestExtractPkScriptAddrs ensures that extracting the type, addresses, and
// number of required signatures from PkScripts works as intended.
func TestExtractPkScriptAddrs(t *testing.T) {
// TestExtractScriptPubKeyAddrs ensures that extracting the type, addresses, and
// number of required signatures from scriptPubKeys works as intended.
func TestExtractScriptPubKeyAddrs(t *testing.T) {
t.Parallel()
tests := []struct {
@ -115,7 +115,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
},
// Note the technically the pubkey is the second item on the
// stack, but since the address extraction intentionally only
// works with standard PkScripts, this should not return any
// works with standard scriptPubKeys, this should not return any
// addresses.
{
name: "valid sigscript to reedeem p2pk - no addresses",
@ -148,27 +148,27 @@ func TestExtractPkScriptAddrs(t *testing.T) {
t.Logf("Running %d tests.", len(tests))
for i, test := range tests {
class, addrs, reqSigs, err := ExtractPkScriptAddrs(
class, addrs, reqSigs, err := ExtractScriptPubKeyAddrs(
test.script, &dagconfig.MainNetParams)
if err != nil {
}
if !reflect.DeepEqual(addrs, test.addrs) {
t.Errorf("ExtractPkScriptAddrs #%d (%s) unexpected "+
t.Errorf("ExtractScriptPubKeyAddrs #%d (%s) unexpected "+
"addresses\ngot %v\nwant %v", i, test.name,
addrs, test.addrs)
continue
}
if reqSigs != test.reqSigs {
t.Errorf("ExtractPkScriptAddrs #%d (%s) unexpected "+
t.Errorf("ExtractScriptPubKeyAddrs #%d (%s) unexpected "+
"number of required signatures - got %d, "+
"want %d", i, test.name, reqSigs, test.reqSigs)
continue
}
if class != test.class {
t.Errorf("ExtractPkScriptAddrs #%d (%s) unexpected "+
t.Errorf("ExtractScriptPubKeyAddrs #%d (%s) unexpected "+
"script type - got %s, want %s", i, test.name,
class, test.class)
continue
@ -182,9 +182,9 @@ func TestCalcScriptInfo(t *testing.T) {
t.Parallel()
tests := []struct {
name string
sigScript string
pkScript string
name string
sigScript string
scriptPubKey string
isP2SH bool
@ -194,10 +194,10 @@ func TestCalcScriptInfo(t *testing.T) {
{
// Invented scripts, the hashes do not match
// Truncated version of test below:
name: "pkscript doesn't parse",
name: "scriptPubKey doesn't parse",
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS EQUAL",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c",
isP2SH: true,
scriptInfoErr: scriptError(ErrMalformedPush, ""),
@ -207,7 +207,7 @@ func TestCalcScriptInfo(t *testing.T) {
// Truncated version of p2sh script below.
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
isP2SH: true,
scriptInfoErr: scriptError(ErrMalformedPush, ""),
@ -218,14 +218,14 @@ func TestCalcScriptInfo(t *testing.T) {
sigScript: "1 81 DATA_25 DUP HASH160 DATA_20 0x010203" +
"0405060708090a0b0c0d0e0f1011121314 EQUALVERIFY " +
"CHECKSIG",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
isP2SH: true,
scriptInfo: ScriptInfo{
PkScriptClass: ScriptHashTy,
NumInputs: 3,
ExpectedInputs: 3, // nonstandard p2sh.
SigOps: 1,
ScriptPubKeyClass: ScriptHashTy,
NumInputs: 3,
ExpectedInputs: 3, // nonstandard p2sh.
SigOps: 1,
},
},
{
@ -234,23 +234,23 @@ func TestCalcScriptInfo(t *testing.T) {
name: "p2sh nonstandard script",
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS EQUAL",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
isP2SH: true,
scriptInfo: ScriptInfo{
PkScriptClass: ScriptHashTy,
NumInputs: 3,
ExpectedInputs: -1, // nonstandard p2sh.
SigOps: 0,
ScriptPubKeyClass: ScriptHashTy,
NumInputs: 3,
ExpectedInputs: -1, // nonstandard p2sh.
SigOps: 0,
},
},
}
for _, test := range tests {
sigScript := mustParseShortForm(test.sigScript)
pkScript := mustParseShortForm(test.pkScript)
scriptPubKey := mustParseShortForm(test.scriptPubKey)
si, err := CalcScriptInfo(sigScript, pkScript, test.isP2SH)
si, err := CalcScriptInfo(sigScript, scriptPubKey, test.isP2SH)
if e := checkScriptError(err, test.scriptInfoErr); e != nil {
t.Errorf("scriptinfo test %q: %v", test.name, e)
continue
@ -349,7 +349,7 @@ func TestPayToAddrScript(t *testing.T) {
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
pkScript, err := PayToAddrScript(test.in)
scriptPubKey, err := PayToAddrScript(test.in)
if e := checkScriptError(err, test.err); e != nil {
t.Errorf("PayToAddrScript #%d unexpected error - "+
"got %v, want %v", i, err, test.err)
@ -357,9 +357,9 @@ func TestPayToAddrScript(t *testing.T) {
}
expected := mustParseShortForm(test.expected)
if !bytes.Equal(pkScript, expected) {
if !bytes.Equal(scriptPubKey, expected) {
t.Errorf("PayToAddrScript #%d got: %x\nwant: %x",
i, pkScript, expected)
i, scriptPubKey, expected)
continue
}
}

View File

@ -359,7 +359,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x12a05f200, // 5000000000
PkScript: []byte{
ScriptPubKey: []byte{
0x41, // OP_DATA_65
0x04, 0x1b, 0x0e, 0x8c, 0x25, 0x67, 0xc1, 0x25,
0x36, 0xaa, 0x13, 0x35, 0x7b, 0x79, 0xa0, 0x73,
@ -419,7 +419,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0x2123e300, // 556000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -432,7 +432,7 @@ var Block100000 = wire.MsgBlock{
},
{
Value: 0x108e20f00, // 4444000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -488,7 +488,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -501,7 +501,7 @@ var Block100000 = wire.MsgBlock{
},
{
Value: 0x11d260c0, // 299000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20
@ -558,7 +558,7 @@ var Block100000 = wire.MsgBlock{
TxOut: []*wire.TxOut{
{
Value: 0xf4240, // 1000000
PkScript: []byte{
ScriptPubKey: []byte{
0x76, // OP_DUP
0xa9, // OP_HASH160
0x14, // OP_DATA_20

View File

@ -250,7 +250,7 @@ func (bf *Filter) AddOutpoint(outpoint *wire.Outpoint) {
// script.
//
// This function MUST be called with the filter lock held.
func (bf *Filter) maybeAddOutpoint(pkScript []byte, outTxID *daghash.TxID, outIdx uint32) {
func (bf *Filter) maybeAddOutpoint(scriptPubKey []byte, outTxID *daghash.TxID, outIdx uint32) {
if bf.msgFilterLoad.Flags == wire.BloomUpdateAll {
outpoint := wire.NewOutpoint(outTxID, outIdx)
bf.addOutpoint(outpoint)
@ -277,7 +277,7 @@ func (bf *Filter) matchTxAndUpdate(tx *util.Tx) bool {
// from the client and avoids some potential races that could otherwise
// occur.
for i, txOut := range tx.MsgTx().TxOut {
pushedData, err := txscript.PushedData(txOut.PkScript)
pushedData, err := txscript.PushedData(txOut.ScriptPubKey)
if err != nil {
continue
}
@ -288,7 +288,7 @@ func (bf *Filter) matchTxAndUpdate(tx *util.Tx) bool {
}
matched = true
bf.maybeAddOutpoint(txOut.PkScript, tx.ID(), uint32(i))
bf.maybeAddOutpoint(txOut.ScriptPubKey, tx.ID(), uint32(i))
break
}
}

View File

@ -20,7 +20,7 @@ type Coin interface {
ID() *daghash.TxID
Index() uint32
Value() util.Amount
PkScript() []byte
ScriptPubKey() []byte
NumConfs() int64
ValueAge() int64
}
@ -380,13 +380,13 @@ func (c *SimpleCoin) Value() util.Amount {
return util.Amount(c.txOut().Value)
}
// PkScript returns the outpoint script of the Coin.
// ScriptPubKey returns the outpoint script of the Coin.
//
// This can be used to determine what type of script the Coin uses
// and extract standard addresses if possible using
// txscript.ExtractPkScriptAddrs for example.
func (c *SimpleCoin) PkScript() []byte {
return c.txOut().PkScript
// txscript.ExtractScriptPubKeyAddrs for example.
func (c *SimpleCoin) ScriptPubKey() []byte {
return c.txOut().ScriptPubKey
}
// NumConfs returns the number of confirmations that the transaction the Coin references

View File

@ -25,13 +25,13 @@ type TestCoin struct {
TxNumConfs int64
}
func (c *TestCoin) Hash() *daghash.Hash { return c.TxHash }
func (c *TestCoin) ID() *daghash.TxID { return c.TxID }
func (c *TestCoin) Index() uint32 { return c.TxIndex }
func (c *TestCoin) Value() util.Amount { return c.TxValue }
func (c *TestCoin) PkScript() []byte { return nil }
func (c *TestCoin) NumConfs() int64 { return c.TxNumConfs }
func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumConfs }
func (c *TestCoin) Hash() *daghash.Hash { return c.TxHash }
func (c *TestCoin) ID() *daghash.TxID { return c.TxID }
func (c *TestCoin) Index() uint32 { return c.TxIndex }
func (c *TestCoin) Value() util.Amount { return c.TxValue }
func (c *TestCoin) ScriptPubKey() []byte { return nil }
func (c *TestCoin) NumConfs() int64 { return c.TxNumConfs }
func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumConfs }
func NewCoin(index int64, value util.Amount, numConfs int64) coinset.Coin {
h := sha256.New()
@ -240,13 +240,13 @@ var (
"6D3E3C6628B98D88ACE86EF102000000001976A914AC3F99" +
"5655E81B875B38B64351D6F896DDBFC68588AC0000000000" +
"000000000000000000000000000000000000000000000000"
testSimpleCoinTxValue0 = util.Amount(3500000)
testSimpleCoinTxValueAge0 = int64(testSimpleCoinTxValue0) * testSimpleCoinNumConfs
testSimpleCoinTxPkScript0Hex = "76a914686dd149a79b4a559d561fbc396d3e3c6628b98d88ac"
testSimpleCoinTxPkScript0Bytes, _ = hex.DecodeString(testSimpleCoinTxPkScript0Hex)
testSimpleCoinTxBytes, _ = hex.DecodeString(testSimpleCoinTxHex)
testSimpleCoinTx, _ = util.NewTxFromBytes(testSimpleCoinTxBytes)
testSimpleCoin = &coinset.SimpleCoin{
testSimpleCoinTxValue0 = util.Amount(3500000)
testSimpleCoinTxValueAge0 = int64(testSimpleCoinTxValue0) * testSimpleCoinNumConfs
testSimpleCoinTxScriptPubKey0Hex = "76a914686dd149a79b4a559d561fbc396d3e3c6628b98d88ac"
testSimpleCoinTxScriptPubKey0Bytes, _ = hex.DecodeString(testSimpleCoinTxScriptPubKey0Hex)
testSimpleCoinTxBytes, _ = hex.DecodeString(testSimpleCoinTxHex)
testSimpleCoinTx, _ = util.NewTxFromBytes(testSimpleCoinTxBytes)
testSimpleCoin = &coinset.SimpleCoin{
Tx: testSimpleCoinTx,
TxIndex: 0,
TxNumConfs: testSimpleCoinNumConfs,
@ -263,8 +263,8 @@ func TestSimpleCoin(t *testing.T) {
if testSimpleCoin.Value() != testSimpleCoinTxValue0 {
t.Error("Different value of coin value than expected")
}
if !bytes.Equal(testSimpleCoin.PkScript(), testSimpleCoinTxPkScript0Bytes) {
t.Error("Different value of coin pkScript than expected")
if !bytes.Equal(testSimpleCoin.ScriptPubKey(), testSimpleCoinTxScriptPubKey0Bytes) {
t.Error("Different value of coin scriptPubKey than expected")
}
if testSimpleCoin.NumConfs() != 1 {
t.Error("Differet value of num confs than expected")

View File

@ -322,7 +322,7 @@ func BuildBasicFilter(block *wire.MsgBlock) (*gcs.Filter, error) {
// In order to build a basic filter, we'll range over the entire block,
// adding the outpoint data as well as the data pushes within the
// pkScript.
// scriptPubKey.
for i, tx := range block.Transactions {
// First we'll compute the bash of the transaction and add that
// directly to the filter.
@ -340,7 +340,7 @@ func BuildBasicFilter(block *wire.MsgBlock) (*gcs.Filter, error) {
// For each output in a transaction, we'll add each of the
// individual data pushes within the script.
for _, txOut := range tx.TxOut {
b.AddEntry(txOut.PkScript)
b.AddEntry(txOut.ScriptPubKey)
}
}

View File

@ -68,13 +68,13 @@ func RegisterSubnetworkForTest(dag *blockdag.BlockDAG, params *dagconfig.Params,
SignatureScript: signatureScript,
}
pkScript, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
scriptPubKey, err := txscript.PayToScriptHashScript(blockdag.OpTrueScript)
if err != nil {
return nil, err
}
txOut := &wire.TxOut{
PkScript: pkScript,
Value: fundsBlockCbTx.TxOut[0].Value,
ScriptPubKey: scriptPubKey,
Value: fundsBlockCbTx.TxOut[0].Value,
}
registryTx := wire.NewRegistryMsgTx(1, []*wire.TxIn{txIn}, []*wire.TxOut{txOut}, gasLimit)

View File

@ -86,10 +86,10 @@ func (s sortableInputSlice) Less(i, j int) bool {
}
// Output comparison function.
// First sort based on amount (smallest first), then PkScript.
// First sort based on amount (smallest first), then ScriptPubKey.
func (s sortableOutputSlice) Less(i, j int) bool {
if s[i].Value == s[j].Value {
return bytes.Compare(s[i].PkScript, s[j].PkScript) < 0
return bytes.Compare(s[i].ScriptPubKey, s[j].ScriptPubKey) < 0
}
return s[i].Value < s[j].Value
}

View File

@ -43,7 +43,7 @@ var genesisCoinbaseTxIns = []*TxIn{
var genesisCoinbaseTxOuts = []*TxOut{
{
Value: 0x12a05f200,
PkScript: []byte{
ScriptPubKey: []byte{
0x41, 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, /* |A.g....U| */
0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, /* |H'.g..q0| */
0xb7, 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, /* |..\..(.9| */
@ -207,7 +207,7 @@ func BenchmarkWriteOutpoint(b *testing.B) {
func BenchmarkReadTxOut(b *testing.B) {
buf := []byte{
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
0x43, // Varint for length of pk script
0x43, // Varint for length of scriptPubKey
0x41, // OP_DATA_65
0x04, 0x96, 0xb5, 0x38, 0xe8, 0x53, 0x51, 0x9c,
0x72, 0x6a, 0x2c, 0x91, 0xe6, 0x1e, 0xc1, 0x16,
@ -225,7 +225,7 @@ func BenchmarkReadTxOut(b *testing.B) {
for i := 0; i < b.N; i++ {
r.Seek(0, 0)
readTxOut(r, 0, 0, &txOut)
scriptPool.Return(txOut.PkScript)
scriptPool.Return(txOut.ScriptPubKey)
}
}
@ -285,7 +285,7 @@ func BenchmarkDeserializeTxSmall(b *testing.B) {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
0x01, // Varint for number of output transactions
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
0x43, // Varint for length of pk script
0x43, // Varint for length of scriptPubKey
0x41, // OP_DATA_65
0x04, 0x96, 0xb5, 0x38, 0xe8, 0x53, 0x51, 0x9c,
0x72, 0x6a, 0x2c, 0x91, 0xe6, 0x1e, 0xc1, 0x16,

View File

@ -528,7 +528,7 @@ var blockOne = MsgBlock{
[]*TxOut{
{
Value: 0x12a05f200,
PkScript: []byte{
ScriptPubKey: []byte{
0x41, // OP_DATA_65
0x04, 0x96, 0xb5, 0x38, 0xe8, 0x53, 0x51, 0x9c,
0x72, 0x6a, 0x2c, 0x91, 0xe6, 0x1e, 0xc1, 0x16,
@ -586,7 +586,7 @@ var blockOneBytes = []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
0x01, // Varint for number of transaction outputs
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
0x43, // Varint for length of pk script
0x43, // Varint for length of scriptPubKey
0x41, // OP_DATA_65
0x04, 0x96, 0xb5, 0x38, 0xe8, 0x53, 0x51, 0x9c,
0x72, 0x6a, 0x2c, 0x91, 0xe6, 0x1e, 0xc1, 0x16,

View File

@ -67,7 +67,7 @@ const (
maxTxInPerMessage = (MaxMessagePayload / minTxInPayload) + 1
// MinTxOutPayload is the minimum payload size for a transaction output.
// Value 8 bytes + Varint for PkScript length 1 byte.
// Value 8 bytes + Varint for ScriptPubKey length 1 byte.
MinTxOutPayload = 9
// maxTxOutPerMessage is the maximum number of transactions outputs that
@ -240,24 +240,24 @@ func NewTxIn(prevOut *Outpoint, signatureScript []byte) *TxIn {
// TxOut defines a bitcoin transaction output.
type TxOut struct {
Value uint64
PkScript []byte
Value uint64
ScriptPubKey []byte
}
// SerializeSize returns the number of bytes it would take to serialize the
// the transaction output.
func (t *TxOut) SerializeSize() int {
// Value 8 bytes + serialized varint size for the length of PkScript +
// PkScript bytes.
return 8 + VarIntSerializeSize(uint64(len(t.PkScript))) + len(t.PkScript)
// Value 8 bytes + serialized varint size for the length of ScriptPubKey +
// ScriptPubKey bytes.
return 8 + VarIntSerializeSize(uint64(len(t.ScriptPubKey))) + len(t.ScriptPubKey)
}
// NewTxOut returns a new bitcoin transaction output with the provided
// transaction value and public key script.
func NewTxOut(value uint64, pkScript []byte) *TxOut {
func NewTxOut(value uint64, scriptPubKey []byte) *TxOut {
return &TxOut{
Value: value,
PkScript: pkScript,
Value: value,
ScriptPubKey: scriptPubKey,
}
}
@ -290,7 +290,7 @@ func (msg *MsgTx) AddTxOut(to *TxOut) {
// IsCoinBase determines whether or not a transaction is a coinbase transaction. A coinbase
// transaction is a special transaction created by miners that distributes fees and block subsidy
// to the previous blocks' miners, and to specify the pkScript that will be used to pay the current
// to the previous blocks' miners, and to specify the scriptPubKey that will be used to pay the current
// miner in future blocks. Each input of the coinbase transaction should set index to maximum
// value and reference the relevant block id, instead of previous transaction id.
func (msg *MsgTx) IsCoinBase() bool {
@ -377,9 +377,9 @@ func (msg *MsgTx) Copy() *MsgTx {
// Deep copy the old TxOut data.
for _, oldTxOut := range msg.TxOut {
// Deep copy the old PkScript
// Deep copy the old ScriptPubKey
var newScript []byte
oldScript := oldTxOut.PkScript
oldScript := oldTxOut.ScriptPubKey
oldScriptLen := len(oldScript)
if oldScriptLen > 0 {
newScript = make([]byte, oldScriptLen)
@ -389,8 +389,8 @@ func (msg *MsgTx) Copy() *MsgTx {
// Create new txOut with the deep copied data and append it to
// new Tx.
newTxOut := TxOut{
Value: oldTxOut.Value,
PkScript: newScript,
Value: oldTxOut.Value,
ScriptPubKey: newScript,
}
newTx.TxOut = append(newTx.TxOut, &newTxOut)
}
@ -437,10 +437,10 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
scriptPool.Return(txIn.SignatureScript)
}
for _, txOut := range msg.TxOut {
if txOut == nil || txOut.PkScript == nil {
if txOut == nil || txOut.ScriptPubKey == nil {
continue
}
scriptPool.Return(txOut.PkScript)
scriptPool.Return(txOut.ScriptPubKey)
}
}
@ -491,7 +491,7 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
returnScriptBuffers()
return err
}
totalScriptSize += uint64(len(to.PkScript))
totalScriptSize += uint64(len(to.ScriptPubKey))
}
lockTime, err := binaryserializer.Uint64(r, littleEndian)
@ -567,18 +567,18 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
for i := 0; i < len(msg.TxOut); i++ {
// Copy the public key script into the contiguous buffer at the
// appropriate offset.
pkScript := msg.TxOut[i].PkScript
copy(scripts[offset:], pkScript)
scriptPubKey := msg.TxOut[i].ScriptPubKey
copy(scripts[offset:], scriptPubKey)
// Reset the public key script of the transaction output to the
// slice of the contiguous buffer where the script lives.
scriptSize := uint64(len(pkScript))
scriptSize := uint64(len(scriptPubKey))
end := offset + scriptSize
msg.TxOut[i].PkScript = scripts[offset:end:end]
msg.TxOut[i].ScriptPubKey = scripts[offset:end:end]
offset += scriptSize
// Return the temporary script buffer to the pool.
scriptPool.Return(pkScript)
scriptPool.Return(scriptPubKey)
}
return nil
@ -768,11 +768,11 @@ func (msg *MsgTx) MaxPayloadLength(pver uint32) uint32 {
return MaxMessagePayload
}
// PkScriptLocs returns a slice containing the start of each public key script
// ScriptPubKeyLocs returns a slice containing the start of each public key script
// within the raw serialized transaction. The caller can easily obtain the
// length of each script by using len on the script available via the
// appropriate transaction output entry.
func (msg *MsgTx) PkScriptLocs() []int {
func (msg *MsgTx) ScriptPubKeyLocs() []int {
numTxOut := len(msg.TxOut)
if numTxOut == 0 {
return nil
@ -792,18 +792,18 @@ func (msg *MsgTx) PkScriptLocs() []int {
}
// Calculate and set the appropriate offset for each public key script.
pkScriptLocs := make([]int, numTxOut)
scriptPubKeyLocs := make([]int, numTxOut)
for i, txOut := range msg.TxOut {
// The offset of the script in the transaction output is:
//
// Value 8 bytes + serialized varint size for the length of
// PkScript.
n += 8 + VarIntSerializeSize(uint64(len(txOut.PkScript)))
pkScriptLocs[i] = n
n += len(txOut.PkScript)
// ScriptPubKey.
n += 8 + VarIntSerializeSize(uint64(len(txOut.ScriptPubKey)))
scriptPubKeyLocs[i] = n
n += len(txOut.ScriptPubKey)
}
return pkScriptLocs
return scriptPubKeyLocs
}
// IsSubnetworkCompatible return true iff subnetworkID is one or more of the following:
@ -978,7 +978,7 @@ func readTxOut(r io.Reader, pver uint32, version int32, to *TxOut) error {
return err
}
to.PkScript, err = readScript(r, pver, MaxMessagePayload,
to.ScriptPubKey, err = readScript(r, pver, MaxMessagePayload,
"transaction output public key script")
return err
}
@ -991,5 +991,5 @@ func WriteTxOut(w io.Writer, pver uint32, version int32, to *TxOut) error {
return err
}
return WriteVarBytes(w, pver, to.PkScript)
return WriteVarBytes(w, pver, to.ScriptPubKey)
}

View File

@ -80,7 +80,7 @@ func TestTx(t *testing.T) {
// Ensure we get the same transaction output back out.
txValue := uint64(5000000000)
pkScript := []byte{
scriptPubKey := []byte{
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42,
@ -93,16 +93,16 @@ func TestTx(t *testing.T) {
0xa6, // 65-byte signature
0xac, // OP_CHECKSIG
}
txOut := NewTxOut(txValue, pkScript)
txOut := NewTxOut(txValue, scriptPubKey)
if txOut.Value != txValue {
t.Errorf("NewTxOut: wrong pk script - got %v, want %v",
t.Errorf("NewTxOut: wrong scriptPubKey - got %v, want %v",
txOut.Value, txValue)
}
if !bytes.Equal(txOut.PkScript, pkScript) {
t.Errorf("NewTxOut: wrong pk script - got %v, want %v",
spew.Sdump(txOut.PkScript),
spew.Sdump(pkScript))
if !bytes.Equal(txOut.ScriptPubKey, scriptPubKey) {
t.Errorf("NewTxOut: wrong scriptPubKey - got %v, want %v",
spew.Sdump(txOut.ScriptPubKey),
spew.Sdump(scriptPubKey))
}
// Ensure transaction inputs are added properly.
@ -147,7 +147,7 @@ func TestTxHashAndID(t *testing.T) {
}
txOut := &TxOut{
Value: 5000000000,
PkScript: []byte{
ScriptPubKey: []byte{
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42,
@ -212,14 +212,14 @@ func TestTxHashAndID(t *testing.T) {
txOuts := []*TxOut{
{
Value: 244623243,
PkScript: []byte{
ScriptPubKey: []byte{
0x76, 0xA9, 0x14, 0xBA, 0xDE, 0xEC, 0xFD, 0xEF, 0x05, 0x07, 0x24, 0x7F, 0xC8, 0xF7, 0x42, 0x41,
0xD7, 0x3B, 0xC0, 0x39, 0x97, 0x2D, 0x7B, 0x88, 0xAC,
},
},
{
Value: 44602432,
PkScript: []byte{
ScriptPubKey: []byte{
0x76, 0xA9, 0x14, 0xC1, 0x09, 0x32, 0x48, 0x3F, 0xEC, 0x93, 0xED, 0x51, 0xF5, 0xFE, 0x95, 0xE7,
0x25, 0x59, 0xF2, 0xCC, 0x70, 0x43, 0xF9, 0x88, 0xAC,
},
@ -352,9 +352,9 @@ func TestTxWireErrors(t *testing.T) {
{multiTx, multiTxEncoded, pver, 57, io.ErrShortWrite, io.EOF},
// Force error in transaction output value.
{multiTx, multiTxEncoded, pver, 58, io.ErrShortWrite, io.EOF},
// Force error in transaction output pk script length.
// Force error in transaction output scriptPubKey length.
{multiTx, multiTxEncoded, pver, 66, io.ErrShortWrite, io.EOF},
// Force error in transaction output pk script.
// Force error in transaction output scriptPubKey.
{multiTx, multiTxEncoded, pver, 67, io.ErrShortWrite, io.EOF},
// Force error in transaction output lock time.
{multiTx, multiTxEncoded, pver, 210, io.ErrShortWrite, io.EOF},
@ -434,11 +434,11 @@ func TestTxSerialize(t *testing.T) {
}
tests := []struct {
name string
in *MsgTx // Message to encode
out *MsgTx // Expected decoded message
buf []byte // Serialized data
pkScriptLocs []int // Expected output script locations
name string
in *MsgTx // Message to encode
out *MsgTx // Expected decoded message
buf []byte // Serialized data
scriptPubKeyLocs []int // Expected output script locations
}{
// No transactions.
{
@ -473,7 +473,7 @@ func TestTxSerialize(t *testing.T) {
multiTx,
multiTx,
multiTxEncoded,
multiTxPkScriptLocs,
multiTxScriptPubKeyLocs,
},
}
@ -507,21 +507,21 @@ func TestTxSerialize(t *testing.T) {
}
// Ensure the public key script locations are accurate.
pkScriptLocs := test.in.PkScriptLocs()
if !reflect.DeepEqual(pkScriptLocs, test.pkScriptLocs) {
t.Errorf("PkScriptLocs #%d\n got: %s want: %s", i,
spew.Sdump(pkScriptLocs),
spew.Sdump(test.pkScriptLocs))
scriptPubKeyLocs := test.in.ScriptPubKeyLocs()
if !reflect.DeepEqual(scriptPubKeyLocs, test.scriptPubKeyLocs) {
t.Errorf("ScriptPubKeyLocs #%d\n got: %s want: %s", i,
spew.Sdump(scriptPubKeyLocs),
spew.Sdump(test.scriptPubKeyLocs))
continue
}
for j, loc := range pkScriptLocs {
wantPkScript := test.in.TxOut[j].PkScript
gotPkScript := test.buf[loc : loc+len(wantPkScript)]
if !bytes.Equal(gotPkScript, wantPkScript) {
t.Errorf("PkScriptLocs #%d:%d\n unexpected "+
for j, loc := range scriptPubKeyLocs {
wantScriptPubKey := test.in.TxOut[j].ScriptPubKey
gotScriptPubKey := test.buf[loc : loc+len(wantScriptPubKey)]
if !bytes.Equal(gotScriptPubKey, wantScriptPubKey) {
t.Errorf("ScriptPubKeyLocs #%d:%d\n unexpected "+
"script got: %s want: %s", i, j,
spew.Sdump(gotPkScript),
spew.Sdump(wantPkScript))
spew.Sdump(gotScriptPubKey),
spew.Sdump(wantScriptPubKey))
}
}
}
@ -555,9 +555,9 @@ func TestTxSerializeErrors(t *testing.T) {
{multiTx, multiTxEncoded, 57, io.ErrShortWrite, io.EOF},
// Force error in transaction output value.
{multiTx, multiTxEncoded, 58, io.ErrShortWrite, io.EOF},
// Force error in transaction output pk script length.
// Force error in transaction output scriptPubKey length.
{multiTx, multiTxEncoded, 66, io.ErrShortWrite, io.EOF},
// Force error in transaction output pk script.
// Force error in transaction output scriptPubKey.
{multiTx, multiTxEncoded, 67, io.ErrShortWrite, io.EOF},
// Force error in transaction output lock time.
{multiTx, multiTxEncoded, 210, io.ErrShortWrite, io.EOF},
@ -857,7 +857,7 @@ var multiTxIns = []*TxIn{
var multiTxOuts = []*TxOut{
{
Value: 0x12a05f200,
PkScript: []byte{
ScriptPubKey: []byte{
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42,
@ -873,7 +873,7 @@ var multiTxOuts = []*TxOut{
},
{
Value: 0x5f5e100,
PkScript: []byte{
ScriptPubKey: []byte{
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42,
@ -905,7 +905,7 @@ var multiTxEncoded = []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Sequence
0x02, // Varint for number of output transactions
0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, 0x00, 0x00, // Transaction amount
0x43, // Varint for length of pk script
0x43, // Varint for length of scriptPubKey
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42,
@ -918,7 +918,7 @@ var multiTxEncoded = []byte{
0xa6, // 65-byte signature
0xac, // OP_CHECKSIG
0x00, 0xe1, 0xf5, 0x05, 0x00, 0x00, 0x00, 0x00, // Transaction amount
0x43, // Varint for length of pk script
0x43, // Varint for length of scriptPubKey
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42,
@ -936,6 +936,6 @@ var multiTxEncoded = []byte{
0x00, 0x00, 0x00, 0x00, // Sub Network ID
}
// multiTxPkScriptLocs is the location information for the public key scripts
// multiTxScriptPubKeyLocs is the location information for the public key scripts
// located in multiTx.
var multiTxPkScriptLocs = []int{67, 143}
var multiTxScriptPubKeyLocs = []int{67, 143}