mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Merge branch 'dev-20-primitive-blockdag' into dev-34-update-blockdag
This commit is contained in:
commit
a4eed8bf99
@ -175,11 +175,11 @@ const (
|
||||
// standard pay-to-pubkey-hash script along with the pubkey hash it is paying to
|
||||
// if it is.
|
||||
func isPubKeyHash(script []byte) (bool, []byte) {
|
||||
if len(script) == 25 && script[0] == txscript.OP_DUP &&
|
||||
script[1] == txscript.OP_HASH160 &&
|
||||
script[2] == txscript.OP_DATA_20 &&
|
||||
script[23] == txscript.OP_EQUALVERIFY &&
|
||||
script[24] == txscript.OP_CHECKSIG {
|
||||
if len(script) == 25 && script[0] == txscript.OpDup &&
|
||||
script[1] == txscript.OpHash160 &&
|
||||
script[2] == txscript.OpData20 &&
|
||||
script[23] == txscript.OpEqualVerify &&
|
||||
script[24] == txscript.OpCheckSig {
|
||||
|
||||
return true, script[3:23]
|
||||
}
|
||||
@ -191,9 +191,9 @@ func isPubKeyHash(script []byte) (bool, []byte) {
|
||||
// standard pay-to-script-hash script along with the script hash it is paying to
|
||||
// if it is.
|
||||
func isScriptHash(script []byte) (bool, []byte) {
|
||||
if len(script) == 23 && script[0] == txscript.OP_HASH160 &&
|
||||
script[1] == txscript.OP_DATA_20 &&
|
||||
script[22] == txscript.OP_EQUAL {
|
||||
if len(script) == 23 && script[0] == txscript.OpHash160 &&
|
||||
script[1] == txscript.OpData20 &&
|
||||
script[22] == txscript.OpEqual {
|
||||
|
||||
return true, script[2:22]
|
||||
}
|
||||
@ -212,8 +212,8 @@ func isScriptHash(script []byte) (bool, []byte) {
|
||||
// to a valid compressed or uncompressed pubkey.
|
||||
func isPubKey(script []byte) (bool, []byte) {
|
||||
// Pay-to-compressed-pubkey script.
|
||||
if len(script) == 35 && script[0] == txscript.OP_DATA_33 &&
|
||||
script[34] == txscript.OP_CHECKSIG && (script[1] == 0x02 ||
|
||||
if len(script) == 35 && script[0] == txscript.OpData33 &&
|
||||
script[34] == txscript.OpCheckSig && (script[1] == 0x02 ||
|
||||
script[1] == 0x03) {
|
||||
|
||||
// Ensure the public key is valid.
|
||||
@ -225,8 +225,8 @@ func isPubKey(script []byte) (bool, []byte) {
|
||||
}
|
||||
|
||||
// Pay-to-uncompressed-pubkey script.
|
||||
if len(script) == 67 && script[0] == txscript.OP_DATA_65 &&
|
||||
script[66] == txscript.OP_CHECKSIG && script[1] == 0x04 {
|
||||
if len(script) == 67 && script[0] == txscript.OpData65 &&
|
||||
script[66] == txscript.OpCheckSig && script[1] == 0x04 {
|
||||
|
||||
// Ensure the public key is valid.
|
||||
serializedPubKey := script[1:66]
|
||||
@ -361,32 +361,32 @@ func decompressScript(compressedPkScript []byte) []byte {
|
||||
// <OP_DUP><OP_HASH160><20 byte hash><OP_EQUALVERIFY><OP_CHECKSIG>
|
||||
case cstPayToPubKeyHash:
|
||||
pkScript := make([]byte, 25)
|
||||
pkScript[0] = txscript.OP_DUP
|
||||
pkScript[1] = txscript.OP_HASH160
|
||||
pkScript[2] = txscript.OP_DATA_20
|
||||
pkScript[0] = txscript.OpDup
|
||||
pkScript[1] = txscript.OpHash160
|
||||
pkScript[2] = txscript.OpData20
|
||||
copy(pkScript[3:], compressedPkScript[bytesRead:bytesRead+20])
|
||||
pkScript[23] = txscript.OP_EQUALVERIFY
|
||||
pkScript[24] = txscript.OP_CHECKSIG
|
||||
pkScript[23] = txscript.OpEqualVerify
|
||||
pkScript[24] = txscript.OpCheckSig
|
||||
return pkScript
|
||||
|
||||
// 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.OP_HASH160
|
||||
pkScript[1] = txscript.OP_DATA_20
|
||||
pkScript[0] = txscript.OpHash160
|
||||
pkScript[1] = txscript.OpData20
|
||||
copy(pkScript[2:], compressedPkScript[bytesRead:bytesRead+20])
|
||||
pkScript[22] = txscript.OP_EQUAL
|
||||
pkScript[22] = txscript.OpEqual
|
||||
return pkScript
|
||||
|
||||
// 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.OP_DATA_33
|
||||
pkScript[0] = txscript.OpData33
|
||||
pkScript[1] = byte(encodedScriptSize)
|
||||
copy(pkScript[2:], compressedPkScript[bytesRead:bytesRead+32])
|
||||
pkScript[34] = txscript.OP_CHECKSIG
|
||||
pkScript[34] = txscript.OpCheckSig
|
||||
return pkScript
|
||||
|
||||
// Pay-to-uncompressed-pubkey script. The resulting script is:
|
||||
@ -405,9 +405,9 @@ func decompressScript(compressedPkScript []byte) []byte {
|
||||
}
|
||||
|
||||
pkScript := make([]byte, 67)
|
||||
pkScript[0] = txscript.OP_DATA_65
|
||||
pkScript[0] = txscript.OpData65
|
||||
copy(pkScript[1:], key.SerializeUncompressed())
|
||||
pkScript[66] = txscript.OP_CHECKSIG
|
||||
pkScript[66] = txscript.OpCheckSig
|
||||
return pkScript
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ const (
|
||||
var (
|
||||
// opTrueScript is simply a public key script that contains the OP_TRUE
|
||||
// opcode. It is defined here to reduce garbage creation.
|
||||
opTrueScript = []byte{txscript.OP_TRUE}
|
||||
opTrueScript = []byte{txscript.OpTrue}
|
||||
|
||||
// lowFee is a single satoshi and exists to make the test code more
|
||||
// readable.
|
||||
@ -218,8 +218,8 @@ func makeTestGenerator(params *dagconfig.Params) (testGenerator, error) {
|
||||
func payToScriptHashScript(redeemScript []byte) []byte {
|
||||
redeemScriptHash := btcutil.Hash160(redeemScript)
|
||||
script, err := txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_HASH160).AddData(redeemScriptHash).
|
||||
AddOp(txscript.OP_EQUAL).Script()
|
||||
AddOp(txscript.OpHash160).AddData(redeemScriptHash).
|
||||
AddOp(txscript.OpEqual).Script()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -252,7 +252,7 @@ func standardCoinbaseScript(blockHeight int32, extraNonce uint64) ([]byte, error
|
||||
// provided data.
|
||||
func opReturnScript(data []byte) []byte {
|
||||
builder := txscript.NewScriptBuilder()
|
||||
script, err := builder.AddOp(txscript.OP_RETURN).AddData(data).Script()
|
||||
script, err := builder.AddOp(txscript.OpReturn).AddData(data).Script()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -775,7 +775,7 @@ func (g *testGenerator) assertTipBlockTxOutOpReturn(txIndex, txOutIndex uint32)
|
||||
}
|
||||
|
||||
txOut := tx.TxOut[txOutIndex]
|
||||
if txOut.PkScript[0] != txscript.OP_RETURN {
|
||||
if txOut.PkScript[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))
|
||||
@ -1052,7 +1052,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b5(2) -> b12(3) -> b13(4) -> b15(5)
|
||||
// \-> b3(1) -> b4(2)
|
||||
g.setTip("b13")
|
||||
manySigOps := repeatOpcode(txscript.OP_CHECKSIG, maxBlockSigOps)
|
||||
manySigOps := repeatOpcode(txscript.OpCheckSig, maxBlockSigOps)
|
||||
g.nextBlock("b15", outs[5], replaceSpendScript(manySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps)
|
||||
accepted()
|
||||
@ -1063,7 +1063,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b5(2) -> b12(3) -> b13(4) -> b15(5)
|
||||
// \ \-> b16(7)
|
||||
// \-> b3(1) -> b4(2)
|
||||
tooManySigOps := repeatOpcode(txscript.OP_CHECKSIG, maxBlockSigOps+1)
|
||||
tooManySigOps := repeatOpcode(txscript.OpCheckSig, maxBlockSigOps+1)
|
||||
g.nextBlock("b16", outs[6], replaceSpendScript(tooManySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
|
||||
rejected(blockdag.ErrTooManySigOps)
|
||||
@ -1204,7 +1204,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b30(7) -> b31(8)
|
||||
//
|
||||
// OP_CHECKMULTISIG counts for 20 sigops.
|
||||
manySigOps = repeatOpcode(txscript.OP_CHECKMULTISIG, maxBlockSigOps/20)
|
||||
manySigOps = repeatOpcode(txscript.OpCheckMultiSig, maxBlockSigOps/20)
|
||||
g.nextBlock("b31", outs[8], replaceSpendScript(manySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps)
|
||||
accepted()
|
||||
@ -1216,8 +1216,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// \-> b32(9)
|
||||
//
|
||||
// OP_CHECKMULTISIG counts for 20 sigops.
|
||||
tooManySigOps = repeatOpcode(txscript.OP_CHECKMULTISIG, maxBlockSigOps/20)
|
||||
tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG)
|
||||
tooManySigOps = repeatOpcode(txscript.OpCheckMultiSig, maxBlockSigOps/20)
|
||||
tooManySigOps = append(manySigOps, txscript.OpCheckSig)
|
||||
g.nextBlock("b32", outs[9], replaceSpendScript(tooManySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
|
||||
rejected(blockdag.ErrTooManySigOps)
|
||||
@ -1226,7 +1226,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
//
|
||||
// ... -> b31(8) -> b33(9)
|
||||
g.setTip("b31")
|
||||
manySigOps = repeatOpcode(txscript.OP_CHECKMULTISIGVERIFY, maxBlockSigOps/20)
|
||||
manySigOps = repeatOpcode(txscript.OpCheckMultiSigVerify, maxBlockSigOps/20)
|
||||
g.nextBlock("b33", outs[9], replaceSpendScript(manySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps)
|
||||
accepted()
|
||||
@ -1237,8 +1237,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b33(9)
|
||||
// \-> b34(10)
|
||||
//
|
||||
tooManySigOps = repeatOpcode(txscript.OP_CHECKMULTISIGVERIFY, maxBlockSigOps/20)
|
||||
tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG)
|
||||
tooManySigOps = repeatOpcode(txscript.OpCheckMultiSigVerify, maxBlockSigOps/20)
|
||||
tooManySigOps = append(manySigOps, txscript.OpCheckSig)
|
||||
g.nextBlock("b34", outs[10], replaceSpendScript(tooManySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
|
||||
rejected(blockdag.ErrTooManySigOps)
|
||||
@ -1248,7 +1248,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b33(9) -> b35(10)
|
||||
//
|
||||
g.setTip("b33")
|
||||
manySigOps = repeatOpcode(txscript.OP_CHECKSIGVERIFY, maxBlockSigOps)
|
||||
manySigOps = repeatOpcode(txscript.OpCheckSigVerify, maxBlockSigOps)
|
||||
g.nextBlock("b35", outs[10], replaceSpendScript(manySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps)
|
||||
accepted()
|
||||
@ -1259,7 +1259,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b35(10)
|
||||
// \-> b36(11)
|
||||
//
|
||||
tooManySigOps = repeatOpcode(txscript.OP_CHECKSIGVERIFY, maxBlockSigOps+1)
|
||||
tooManySigOps = repeatOpcode(txscript.OpCheckSigVerify, maxBlockSigOps+1)
|
||||
g.nextBlock("b36", outs[11], replaceSpendScript(tooManySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
|
||||
rejected(blockdag.ErrTooManySigOps)
|
||||
@ -1293,9 +1293,9 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// signature operations to be used in the next three blocks.
|
||||
const redeemScriptSigOps = 9
|
||||
redeemScript := pushDataScript(g.privKey.PubKey().SerializeCompressed())
|
||||
redeemScript = append(redeemScript, bytes.Repeat([]byte{txscript.OP_2DUP,
|
||||
txscript.OP_CHECKSIGVERIFY}, redeemScriptSigOps-1)...)
|
||||
redeemScript = append(redeemScript, txscript.OP_CHECKSIG)
|
||||
redeemScript = append(redeemScript, bytes.Repeat([]byte{txscript.Op2Dup,
|
||||
txscript.OpCheckSigVerify}, redeemScriptSigOps-1)...)
|
||||
redeemScript = append(redeemScript, txscript.OpCheckSig)
|
||||
assertScriptSigOpsCount(redeemScript, redeemScriptSigOps)
|
||||
|
||||
// Create a block that has enough pay-to-script-hash outputs such that
|
||||
@ -1352,7 +1352,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.OP_CHECKSIG, fill)
|
||||
tx.TxOut[0].PkScript = repeatOpcode(txscript.OpCheckSig, fill)
|
||||
b.AddTransaction(tx)
|
||||
})
|
||||
rejected(blockdag.ErrTooManySigOps)
|
||||
@ -1386,7 +1386,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.OP_CHECKSIG, fill)
|
||||
tx.TxOut[0].PkScript = repeatOpcode(txscript.OpCheckSig, fill)
|
||||
b.AddTransaction(tx)
|
||||
})
|
||||
accepted()
|
||||
@ -1887,8 +1887,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b69(20)
|
||||
// \-> b70(21)
|
||||
scriptSize := maxBlockSigOps + 5 + (maxScriptElementSize + 1) + 1
|
||||
tooManySigOps = repeatOpcode(txscript.OP_CHECKSIG, scriptSize)
|
||||
tooManySigOps[maxBlockSigOps] = txscript.OP_PUSHDATA4
|
||||
tooManySigOps = repeatOpcode(txscript.OpCheckSig, scriptSize)
|
||||
tooManySigOps[maxBlockSigOps] = txscript.OpPushData4
|
||||
binary.LittleEndian.PutUint32(tooManySigOps[maxBlockSigOps+1:],
|
||||
maxScriptElementSize+1)
|
||||
g.nextBlock("b70", outs[21], replaceSpendScript(tooManySigOps))
|
||||
@ -1904,8 +1904,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// \-> b71(21)
|
||||
g.setTip("b69")
|
||||
scriptSize = maxBlockSigOps + 5 + maxScriptElementSize + 1
|
||||
tooManySigOps = repeatOpcode(txscript.OP_CHECKSIG, scriptSize)
|
||||
tooManySigOps[maxBlockSigOps+1] = txscript.OP_PUSHDATA4
|
||||
tooManySigOps = repeatOpcode(txscript.OpCheckSig, scriptSize)
|
||||
tooManySigOps[maxBlockSigOps+1] = txscript.OpPushData4
|
||||
binary.LittleEndian.PutUint32(tooManySigOps[maxBlockSigOps+2:], 0xffffffff)
|
||||
g.nextBlock("b71", outs[21], replaceSpendScript(tooManySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps + 1)
|
||||
@ -1920,8 +1920,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// ... -> b69(20) -> b72(21)
|
||||
g.setTip("b69")
|
||||
scriptSize = maxBlockSigOps + 5 + maxScriptElementSize
|
||||
manySigOps = repeatOpcode(txscript.OP_CHECKSIG, scriptSize)
|
||||
manySigOps[maxBlockSigOps] = txscript.OP_PUSHDATA4
|
||||
manySigOps = repeatOpcode(txscript.OpCheckSig, scriptSize)
|
||||
manySigOps[maxBlockSigOps] = txscript.OpPushData4
|
||||
binary.LittleEndian.PutUint32(manySigOps[maxBlockSigOps+1:], 0xffffffff)
|
||||
g.nextBlock("b72", outs[21], replaceSpendScript(manySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps)
|
||||
@ -1934,8 +1934,8 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
//
|
||||
// ... -> b72(21) -> b73(22)
|
||||
scriptSize = maxBlockSigOps + 5 + (maxScriptElementSize + 1)
|
||||
manySigOps = repeatOpcode(txscript.OP_CHECKSIG, scriptSize)
|
||||
manySigOps[maxBlockSigOps] = txscript.OP_PUSHDATA4
|
||||
manySigOps = repeatOpcode(txscript.OpCheckSig, scriptSize)
|
||||
manySigOps[maxBlockSigOps] = txscript.OpPushData4
|
||||
g.nextBlock("b73", outs[22], replaceSpendScript(manySigOps))
|
||||
g.assertTipBlockSigOpsCount(maxBlockSigOps)
|
||||
accepted()
|
||||
@ -1947,12 +1947,12 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
|
||||
// Create block with an invalid opcode in a dead execution path.
|
||||
//
|
||||
// ... -> b73(22) -> b74(23)
|
||||
script := []byte{txscript.OP_IF, txscript.OP_INVALIDOPCODE,
|
||||
txscript.OP_ELSE, txscript.OP_TRUE, txscript.OP_ENDIF}
|
||||
script := []byte{txscript.OpIf, txscript.OpInvalidOpCode,
|
||||
txscript.OpElse, txscript.OpTrue, txscript.OpEndIf}
|
||||
g.nextBlock("b74", outs[23], replaceSpendScript(script), func(b *wire.MsgBlock) {
|
||||
tx2 := b.Transactions[1]
|
||||
tx3 := createSpendTxForTx(tx2, lowFee)
|
||||
tx3.TxIn[0].SignatureScript = []byte{txscript.OP_FALSE}
|
||||
tx3.TxIn[0].SignatureScript = []byte{txscript.OpFalse}
|
||||
b.AddTransaction(tx3)
|
||||
})
|
||||
accepted()
|
||||
|
@ -599,11 +599,11 @@ func ExtractCoinbaseHeight(coinbaseTx *btcutil.Tx) (int32, error) {
|
||||
// Detect the case when the block height is a small integer encoded with
|
||||
// as single byte.
|
||||
opcode := int(sigScript[0])
|
||||
if opcode == txscript.OP_0 {
|
||||
if opcode == txscript.Op0 {
|
||||
return 0, nil
|
||||
}
|
||||
if opcode >= txscript.OP_1 && opcode <= txscript.OP_16 {
|
||||
return int32(opcode - (txscript.OP_1 - 1)), nil
|
||||
if opcode >= txscript.Op1 && opcode <= txscript.Op16 {
|
||||
return int32(opcode - (txscript.Op1 - 1)), nil
|
||||
}
|
||||
|
||||
// Otherwise, the opcode is the length of the following bytes which
|
||||
|
@ -114,72 +114,72 @@ func TestCheckPkScriptStandard(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"key1 and key2",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_2).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op2).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_2).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op2).AddOp(txscript.OpCheckMultiSig),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"key1 or key2",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op1).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_2).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op2).AddOp(txscript.OpCheckMultiSig),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"escrow",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_2).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op2).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddData(pubKeys[2]).
|
||||
AddOp(txscript.OP_3).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op3).AddOp(txscript.OpCheckMultiSig),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"one of four",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op1).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddData(pubKeys[2]).AddData(pubKeys[3]).
|
||||
AddOp(txscript.OP_4).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op4).AddOp(txscript.OpCheckMultiSig),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"malformed1",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_3).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op3).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_2).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op2).AddOp(txscript.OpCheckMultiSig),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"malformed2",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_2).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op2).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_3).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op3).AddOp(txscript.OpCheckMultiSig),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"malformed3",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_0).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op0).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_2).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op2).AddOp(txscript.OpCheckMultiSig),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"malformed4",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op1).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_0).AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.Op0).AddOp(txscript.OpCheckMultiSig),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"malformed5",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op1).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]).
|
||||
AddOp(txscript.OP_CHECKMULTISIG),
|
||||
AddOp(txscript.OpCheckMultiSig),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"malformed6",
|
||||
txscript.NewScriptBuilder().AddOp(txscript.OP_1).
|
||||
txscript.NewScriptBuilder().AddOp(txscript.Op1).
|
||||
AddData(pubKeys[0]).AddData(pubKeys[1]),
|
||||
false,
|
||||
},
|
||||
@ -392,7 +392,7 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{{
|
||||
PreviousOutPoint: dummyPrevOut,
|
||||
SignatureScript: []byte{
|
||||
txscript.OP_CHECKSIGVERIFY},
|
||||
txscript.OpCheckSigVerify},
|
||||
Sequence: wire.MaxTxInSequenceNum,
|
||||
}},
|
||||
TxOut: []*wire.TxOut{&dummyTxOut},
|
||||
@ -409,7 +409,7 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{&dummyTxIn},
|
||||
TxOut: []*wire.TxOut{{
|
||||
Value: 100000000,
|
||||
PkScript: []byte{txscript.OP_TRUE},
|
||||
PkScript: []byte{txscript.OpTrue},
|
||||
}},
|
||||
LockTime: 0,
|
||||
},
|
||||
@ -424,10 +424,10 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{&dummyTxIn},
|
||||
TxOut: []*wire.TxOut{{
|
||||
Value: 0,
|
||||
PkScript: []byte{txscript.OP_RETURN},
|
||||
PkScript: []byte{txscript.OpReturn},
|
||||
}, {
|
||||
Value: 0,
|
||||
PkScript: []byte{txscript.OP_RETURN},
|
||||
PkScript: []byte{txscript.OpReturn},
|
||||
}},
|
||||
LockTime: 0,
|
||||
},
|
||||
@ -457,7 +457,7 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
TxIn: []*wire.TxIn{&dummyTxIn},
|
||||
TxOut: []*wire.TxOut{{
|
||||
Value: 0,
|
||||
PkScript: []byte{txscript.OP_RETURN},
|
||||
PkScript: []byte{txscript.OpReturn},
|
||||
}},
|
||||
LockTime: 0,
|
||||
},
|
||||
|
@ -257,7 +257,7 @@ func createCoinbaseTx(params *dagconfig.Params, coinbaseScript []byte, nextBlock
|
||||
} else {
|
||||
var err error
|
||||
scriptBuilder := txscript.NewScriptBuilder()
|
||||
pkScript, err = scriptBuilder.AddOp(txscript.OP_TRUE).Script()
|
||||
pkScript, err = scriptBuilder.AddOp(txscript.OpTrue).Script()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error {
|
||||
}
|
||||
|
||||
// Note that this includes OP_RESERVED which counts as a push operation.
|
||||
if pop.opcode.value > OP_16 {
|
||||
if pop.opcode.value > Op16 {
|
||||
vm.numOps++
|
||||
if vm.numOps > MaxOpsPerScript {
|
||||
str := fmt.Sprintf("exceeded max operation limit of %d",
|
||||
@ -163,7 +163,7 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error {
|
||||
// Ensure all executed data push opcodes use the minimal encoding when
|
||||
// the minimal data verification flag is set.
|
||||
if vm.dstack.verifyMinimalData && vm.isBranchExecuting() &&
|
||||
pop.opcode.value >= 0 && pop.opcode.value <= OP_PUSHDATA4 {
|
||||
pop.opcode.value >= 0 && pop.opcode.value <= OpPushData4 {
|
||||
|
||||
if err := pop.checkMinimalDataPush(); err != nil {
|
||||
return err
|
||||
|
@ -172,7 +172,7 @@ func TestInvalidFlagCombinations(t *testing.T) {
|
||||
}),
|
||||
Index: 0,
|
||||
},
|
||||
SignatureScript: []uint8{OP_NOP},
|
||||
SignatureScript: []uint8{OpNop},
|
||||
Sequence: 4294967295,
|
||||
},
|
||||
},
|
||||
@ -184,7 +184,7 @@ func TestInvalidFlagCombinations(t *testing.T) {
|
||||
},
|
||||
LockTime: 0,
|
||||
}
|
||||
pkScript := []byte{OP_NOP}
|
||||
pkScript := []byte{OpNop}
|
||||
|
||||
for i, test := range tests {
|
||||
_, err := NewEngine(pkScript, tx, 0, test, nil)
|
||||
|
@ -103,7 +103,7 @@ func ExampleSignTxOutput() {
|
||||
// contains a single output that pays to address in the amount of 1 BTC.
|
||||
originTx := wire.NewMsgTx(wire.TxVersion)
|
||||
prevOut := wire.NewOutPoint(&daghash.Hash{}, ^uint32(0))
|
||||
txIn := wire.NewTxIn(prevOut, []byte{txscript.OP_0, txscript.OP_0})
|
||||
txIn := wire.NewTxIn(prevOut, []byte{txscript.Op0, txscript.Op0})
|
||||
originTx.AddTxIn(txIn)
|
||||
pkScript, err := txscript.PayToAddrScript(addr)
|
||||
if err != nil {
|
||||
|
1100
txscript/opcode.go
1100
txscript/opcode.go
File diff suppressed because it is too large
Load Diff
@ -18,9 +18,9 @@ import (
|
||||
func TestOpcodeDisabled(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []byte{OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT,
|
||||
OP_AND, OP_OR, OP_2MUL, OP_2DIV, OP_MUL, OP_DIV, OP_MOD,
|
||||
OP_LSHIFT, OP_RSHIFT,
|
||||
tests := []byte{OpCat, OpSubStr, OpLeft, OpRight, OpInvert,
|
||||
OpAnd, OpOr, Op2Mul, Op2Div, OpMul, OpDiv, OpMod,
|
||||
OpLShift, OpRShift,
|
||||
}
|
||||
for _, opcodeVal := range tests {
|
||||
pop := parsedOpcode{opcode: &opcodeArray[opcodeVal], data: nil}
|
||||
|
@ -82,8 +82,8 @@ func parseShortForm(script string) ([]byte, error) {
|
||||
// have the same value, so detect those by name and
|
||||
// allow them.
|
||||
if (opcodeName == "OP_FALSE" || opcodeName == "OP_TRUE") ||
|
||||
(opcodeValue != OP_0 && (opcodeValue < OP_1 ||
|
||||
opcodeValue > OP_16)) {
|
||||
(opcodeValue != Op0 && (opcodeValue < Op1 ||
|
||||
opcodeValue > Op16)) {
|
||||
|
||||
ops[strings.TrimPrefix(opcodeName, "OP_")] = opcodeValue
|
||||
}
|
||||
@ -242,7 +242,7 @@ func createSpendingTx(sigScript, pkScript []byte) *wire.MsgTx {
|
||||
coinbaseTx := wire.NewMsgTx(wire.TxVersion)
|
||||
|
||||
outPoint := wire.NewOutPoint(&daghash.Hash{}, ^uint32(0))
|
||||
txIn := wire.NewTxIn(outPoint, []byte{OP_0, OP_0})
|
||||
txIn := wire.NewTxIn(outPoint, []byte{Op0, Op0})
|
||||
txOut := wire.NewTxOut(0, pkScript)
|
||||
coinbaseTx.AddTxIn(txIn)
|
||||
coinbaseTx.AddTxOut(txOut)
|
||||
|
@ -45,7 +45,7 @@ const (
|
||||
// isSmallInt returns whether or not the opcode is considered a small integer,
|
||||
// which is an OP_0, or OP_1 through OP_16.
|
||||
func isSmallInt(op *opcode) bool {
|
||||
if op.value == OP_0 || (op.value >= OP_1 && op.value <= OP_16) {
|
||||
if op.value == Op0 || (op.value >= Op1 && op.value <= Op16) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@ -55,9 +55,9 @@ func isSmallInt(op *opcode) bool {
|
||||
// transaction, false otherwise.
|
||||
func isScriptHash(pops []parsedOpcode) bool {
|
||||
return len(pops) == 3 &&
|
||||
pops[0].opcode.value == OP_HASH160 &&
|
||||
pops[1].opcode.value == OP_DATA_20 &&
|
||||
pops[2].opcode.value == OP_EQUAL
|
||||
pops[0].opcode.value == OpHash160 &&
|
||||
pops[1].opcode.value == OpData20 &&
|
||||
pops[2].opcode.value == OpEqual
|
||||
}
|
||||
|
||||
// IsPayToScriptHash returns true if the script is in the standard
|
||||
@ -81,7 +81,7 @@ func isPushOnly(pops []parsedOpcode) bool {
|
||||
// NOTE: This does consider OP_RESERVED to be a data push
|
||||
// instruction, but execution of OP_RESERVED will fail anyways
|
||||
// and matches the behavior required by consensus.
|
||||
if pop.opcode.value > OP_16 {
|
||||
if pop.opcode.value > Op16 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -246,20 +246,20 @@ func canonicalPush(pop parsedOpcode) bool {
|
||||
opcode := pop.opcode.value
|
||||
data := pop.data
|
||||
dataLen := len(pop.data)
|
||||
if opcode > OP_16 {
|
||||
if opcode > Op16 {
|
||||
return true
|
||||
}
|
||||
|
||||
if opcode < OP_PUSHDATA1 && opcode > OP_0 && (dataLen == 1 && data[0] <= 16) {
|
||||
if opcode < OpPushData1 && opcode > Op0 && (dataLen == 1 && data[0] <= 16) {
|
||||
return false
|
||||
}
|
||||
if opcode == OP_PUSHDATA1 && dataLen < OP_PUSHDATA1 {
|
||||
if opcode == OpPushData1 && dataLen < OpPushData1 {
|
||||
return false
|
||||
}
|
||||
if opcode == OP_PUSHDATA2 && dataLen <= 0xff {
|
||||
if opcode == OpPushData2 && dataLen <= 0xff {
|
||||
return false
|
||||
}
|
||||
if opcode == OP_PUSHDATA4 && dataLen <= 0xffff {
|
||||
if opcode == OpPushData4 && dataLen <= 0xffff {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -348,7 +348,7 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.Msg
|
||||
}
|
||||
|
||||
// Remove all instances of OP_CODESEPARATOR from the script.
|
||||
script = removeOpcode(script, OP_CODESEPARATOR)
|
||||
script = removeOpcode(script, OpCodeSeparator)
|
||||
|
||||
// Make a shallow copy of the transaction, zeroing out the script for
|
||||
// all inputs that are not currently being processed.
|
||||
@ -415,11 +415,11 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.Msg
|
||||
// asSmallInt returns the passed opcode, which must be true according to
|
||||
// isSmallInt(), as an integer.
|
||||
func asSmallInt(op *opcode) int {
|
||||
if op.value == OP_0 {
|
||||
if op.value == Op0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(op.value - (OP_1 - 1))
|
||||
return int(op.value - (Op1 - 1))
|
||||
}
|
||||
|
||||
// getSigOpCount is the implementation function for counting the number of
|
||||
@ -430,20 +430,20 @@ func getSigOpCount(pops []parsedOpcode, precise bool) int {
|
||||
nSigs := 0
|
||||
for i, pop := range pops {
|
||||
switch pop.opcode.value {
|
||||
case OP_CHECKSIG:
|
||||
case OpCheckSig:
|
||||
fallthrough
|
||||
case OP_CHECKSIGVERIFY:
|
||||
case OpCheckSigVerify:
|
||||
nSigs++
|
||||
case OP_CHECKMULTISIG:
|
||||
case OpCheckMultiSig:
|
||||
fallthrough
|
||||
case OP_CHECKMULTISIGVERIFY:
|
||||
case OpCheckMultiSigVerify:
|
||||
// If we are being precise then look for familiar
|
||||
// patterns for multisig, for now all we recognize is
|
||||
// OP_1 - OP_16 to signify the number of pubkeys.
|
||||
// Otherwise, we use the max of 20.
|
||||
if precise && i > 0 &&
|
||||
pops[i-1].opcode.value >= OP_1 &&
|
||||
pops[i-1].opcode.value <= OP_16 {
|
||||
pops[i-1].opcode.value >= Op1 &&
|
||||
pops[i-1].opcode.value <= Op16 {
|
||||
nSigs += asSmallInt(pops[i-1].opcode)
|
||||
} else {
|
||||
nSigs += MaxPubKeysPerMultiSig
|
||||
@ -521,5 +521,5 @@ func IsUnspendable(pkScript []byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
return len(pops) > 0 && pops[0].opcode.value == OP_RETURN
|
||||
return len(pops) > 0 && pops[0].opcode.value == OpReturn
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -110,7 +110,7 @@ func canonicalDataSize(data []byte) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
if dataLen < OP_PUSHDATA1 {
|
||||
if dataLen < OpPushData1 {
|
||||
return 1 + dataLen
|
||||
} else if dataLen <= 0xff {
|
||||
return 2 + dataLen
|
||||
@ -132,13 +132,13 @@ func (b *ScriptBuilder) addData(data []byte) *ScriptBuilder {
|
||||
// by one of the "small integer" opcodes, use that opcode instead of
|
||||
// a data push opcode followed by the number.
|
||||
if dataLen == 0 || dataLen == 1 && data[0] == 0 {
|
||||
b.script = append(b.script, OP_0)
|
||||
b.script = append(b.script, Op0)
|
||||
return b
|
||||
} else if dataLen == 1 && data[0] <= 16 {
|
||||
b.script = append(b.script, (OP_1-1)+data[0])
|
||||
b.script = append(b.script, (Op1-1)+data[0])
|
||||
return b
|
||||
} else if dataLen == 1 && data[0] == 0x81 {
|
||||
b.script = append(b.script, byte(OP_1NEGATE))
|
||||
b.script = append(b.script, byte(Op1Negate))
|
||||
return b
|
||||
}
|
||||
|
||||
@ -146,19 +146,19 @@ func (b *ScriptBuilder) addData(data []byte) *ScriptBuilder {
|
||||
// enough so the data push instruction is only a single byte.
|
||||
// Otherwise, choose the smallest possible OP_PUSHDATA# opcode that
|
||||
// can represent the length of the data.
|
||||
if dataLen < OP_PUSHDATA1 {
|
||||
b.script = append(b.script, byte((OP_DATA_1-1)+dataLen))
|
||||
if dataLen < OpPushData1 {
|
||||
b.script = append(b.script, byte((OpData1-1)+dataLen))
|
||||
} else if dataLen <= 0xff {
|
||||
b.script = append(b.script, OP_PUSHDATA1, byte(dataLen))
|
||||
b.script = append(b.script, OpPushData1, byte(dataLen))
|
||||
} else if dataLen <= 0xffff {
|
||||
buf := make([]byte, 2)
|
||||
binary.LittleEndian.PutUint16(buf, uint16(dataLen))
|
||||
b.script = append(b.script, OP_PUSHDATA2)
|
||||
b.script = append(b.script, OpPushData2)
|
||||
b.script = append(b.script, buf...)
|
||||
} else {
|
||||
buf := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(buf, uint32(dataLen))
|
||||
b.script = append(b.script, OP_PUSHDATA4)
|
||||
b.script = append(b.script, OpPushData4)
|
||||
b.script = append(b.script, buf...)
|
||||
}
|
||||
|
||||
@ -240,11 +240,11 @@ func (b *ScriptBuilder) AddInt64(val int64) *ScriptBuilder {
|
||||
|
||||
// Fast path for small integers and OP_1NEGATE.
|
||||
if val == 0 {
|
||||
b.script = append(b.script, OP_0)
|
||||
b.script = append(b.script, Op0)
|
||||
return b
|
||||
}
|
||||
if val == -1 || (val >= 1 && val <= 16) {
|
||||
b.script = append(b.script, byte((OP_1-1)+val))
|
||||
b.script = append(b.script, byte((Op1-1)+val))
|
||||
return b
|
||||
}
|
||||
|
||||
|
@ -21,18 +21,18 @@ func TestScriptBuilderAddOp(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "push OP_0",
|
||||
opcodes: []byte{OP_0},
|
||||
expected: []byte{OP_0},
|
||||
opcodes: []byte{Op0},
|
||||
expected: []byte{Op0},
|
||||
},
|
||||
{
|
||||
name: "push OP_1 OP_2",
|
||||
opcodes: []byte{OP_1, OP_2},
|
||||
expected: []byte{OP_1, OP_2},
|
||||
opcodes: []byte{Op1, Op2},
|
||||
expected: []byte{Op1, Op2},
|
||||
},
|
||||
{
|
||||
name: "push OP_HASH160 OP_EQUAL",
|
||||
opcodes: []byte{OP_HASH160, OP_EQUAL},
|
||||
expected: []byte{OP_HASH160, OP_EQUAL},
|
||||
opcodes: []byte{OpHash160, OpEqual},
|
||||
expected: []byte{OpHash160, OpEqual},
|
||||
},
|
||||
}
|
||||
|
||||
@ -88,44 +88,44 @@ func TestScriptBuilderAddInt64(t *testing.T) {
|
||||
val int64
|
||||
expected []byte
|
||||
}{
|
||||
{name: "push -1", val: -1, expected: []byte{OP_1NEGATE}},
|
||||
{name: "push small int 0", val: 0, expected: []byte{OP_0}},
|
||||
{name: "push small int 1", val: 1, expected: []byte{OP_1}},
|
||||
{name: "push small int 2", val: 2, expected: []byte{OP_2}},
|
||||
{name: "push small int 3", val: 3, expected: []byte{OP_3}},
|
||||
{name: "push small int 4", val: 4, expected: []byte{OP_4}},
|
||||
{name: "push small int 5", val: 5, expected: []byte{OP_5}},
|
||||
{name: "push small int 6", val: 6, expected: []byte{OP_6}},
|
||||
{name: "push small int 7", val: 7, expected: []byte{OP_7}},
|
||||
{name: "push small int 8", val: 8, expected: []byte{OP_8}},
|
||||
{name: "push small int 9", val: 9, expected: []byte{OP_9}},
|
||||
{name: "push small int 10", val: 10, expected: []byte{OP_10}},
|
||||
{name: "push small int 11", val: 11, expected: []byte{OP_11}},
|
||||
{name: "push small int 12", val: 12, expected: []byte{OP_12}},
|
||||
{name: "push small int 13", val: 13, expected: []byte{OP_13}},
|
||||
{name: "push small int 14", val: 14, expected: []byte{OP_14}},
|
||||
{name: "push small int 15", val: 15, expected: []byte{OP_15}},
|
||||
{name: "push small int 16", val: 16, expected: []byte{OP_16}},
|
||||
{name: "push 17", val: 17, expected: []byte{OP_DATA_1, 0x11}},
|
||||
{name: "push 65", val: 65, expected: []byte{OP_DATA_1, 0x41}},
|
||||
{name: "push 127", val: 127, expected: []byte{OP_DATA_1, 0x7f}},
|
||||
{name: "push 128", val: 128, expected: []byte{OP_DATA_2, 0x80, 0}},
|
||||
{name: "push 255", val: 255, expected: []byte{OP_DATA_2, 0xff, 0}},
|
||||
{name: "push 256", val: 256, expected: []byte{OP_DATA_2, 0, 0x01}},
|
||||
{name: "push 32767", val: 32767, expected: []byte{OP_DATA_2, 0xff, 0x7f}},
|
||||
{name: "push 32768", val: 32768, expected: []byte{OP_DATA_3, 0, 0x80, 0}},
|
||||
{name: "push -2", val: -2, expected: []byte{OP_DATA_1, 0x82}},
|
||||
{name: "push -3", val: -3, expected: []byte{OP_DATA_1, 0x83}},
|
||||
{name: "push -4", val: -4, expected: []byte{OP_DATA_1, 0x84}},
|
||||
{name: "push -5", val: -5, expected: []byte{OP_DATA_1, 0x85}},
|
||||
{name: "push -17", val: -17, expected: []byte{OP_DATA_1, 0x91}},
|
||||
{name: "push -65", val: -65, expected: []byte{OP_DATA_1, 0xc1}},
|
||||
{name: "push -127", val: -127, expected: []byte{OP_DATA_1, 0xff}},
|
||||
{name: "push -128", val: -128, expected: []byte{OP_DATA_2, 0x80, 0x80}},
|
||||
{name: "push -255", val: -255, expected: []byte{OP_DATA_2, 0xff, 0x80}},
|
||||
{name: "push -256", val: -256, expected: []byte{OP_DATA_2, 0x00, 0x81}},
|
||||
{name: "push -32767", val: -32767, expected: []byte{OP_DATA_2, 0xff, 0xff}},
|
||||
{name: "push -32768", val: -32768, expected: []byte{OP_DATA_3, 0x00, 0x80, 0x80}},
|
||||
{name: "push -1", val: -1, expected: []byte{Op1Negate}},
|
||||
{name: "push small int 0", val: 0, expected: []byte{Op0}},
|
||||
{name: "push small int 1", val: 1, expected: []byte{Op1}},
|
||||
{name: "push small int 2", val: 2, expected: []byte{Op2}},
|
||||
{name: "push small int 3", val: 3, expected: []byte{Op3}},
|
||||
{name: "push small int 4", val: 4, expected: []byte{Op4}},
|
||||
{name: "push small int 5", val: 5, expected: []byte{Op5}},
|
||||
{name: "push small int 6", val: 6, expected: []byte{Op6}},
|
||||
{name: "push small int 7", val: 7, expected: []byte{Op7}},
|
||||
{name: "push small int 8", val: 8, expected: []byte{Op8}},
|
||||
{name: "push small int 9", val: 9, expected: []byte{Op9}},
|
||||
{name: "push small int 10", val: 10, expected: []byte{Op10}},
|
||||
{name: "push small int 11", val: 11, expected: []byte{Op11}},
|
||||
{name: "push small int 12", val: 12, expected: []byte{Op12}},
|
||||
{name: "push small int 13", val: 13, expected: []byte{Op13}},
|
||||
{name: "push small int 14", val: 14, expected: []byte{Op14}},
|
||||
{name: "push small int 15", val: 15, expected: []byte{Op15}},
|
||||
{name: "push small int 16", val: 16, expected: []byte{Op16}},
|
||||
{name: "push 17", val: 17, expected: []byte{OpData1, 0x11}},
|
||||
{name: "push 65", val: 65, expected: []byte{OpData1, 0x41}},
|
||||
{name: "push 127", val: 127, expected: []byte{OpData1, 0x7f}},
|
||||
{name: "push 128", val: 128, expected: []byte{OpData2, 0x80, 0}},
|
||||
{name: "push 255", val: 255, expected: []byte{OpData2, 0xff, 0}},
|
||||
{name: "push 256", val: 256, expected: []byte{OpData2, 0, 0x01}},
|
||||
{name: "push 32767", val: 32767, expected: []byte{OpData2, 0xff, 0x7f}},
|
||||
{name: "push 32768", val: 32768, expected: []byte{OpData3, 0, 0x80, 0}},
|
||||
{name: "push -2", val: -2, expected: []byte{OpData1, 0x82}},
|
||||
{name: "push -3", val: -3, expected: []byte{OpData1, 0x83}},
|
||||
{name: "push -4", val: -4, expected: []byte{OpData1, 0x84}},
|
||||
{name: "push -5", val: -5, expected: []byte{OpData1, 0x85}},
|
||||
{name: "push -17", val: -17, expected: []byte{OpData1, 0x91}},
|
||||
{name: "push -65", val: -65, expected: []byte{OpData1, 0xc1}},
|
||||
{name: "push -127", val: -127, expected: []byte{OpData1, 0xff}},
|
||||
{name: "push -128", val: -128, expected: []byte{OpData2, 0x80, 0x80}},
|
||||
{name: "push -255", val: -255, expected: []byte{OpData2, 0xff, 0x80}},
|
||||
{name: "push -256", val: -256, expected: []byte{OpData2, 0x00, 0x81}},
|
||||
{name: "push -32767", val: -32767, expected: []byte{OpData2, 0xff, 0xff}},
|
||||
{name: "push -32768", val: -32768, expected: []byte{OpData3, 0x00, 0x80, 0x80}},
|
||||
}
|
||||
|
||||
builder := NewScriptBuilder()
|
||||
@ -159,70 +159,70 @@ func TestScriptBuilderAddData(t *testing.T) {
|
||||
useFull bool // use AddFullData instead of AddData.
|
||||
}{
|
||||
// BIP0062: Pushing an empty byte sequence must use OP_0.
|
||||
{name: "push empty byte sequence", data: nil, expected: []byte{OP_0}},
|
||||
{name: "push 1 byte 0x00", data: []byte{0x00}, expected: []byte{OP_0}},
|
||||
{name: "push empty byte sequence", data: nil, expected: []byte{Op0}},
|
||||
{name: "push 1 byte 0x00", data: []byte{0x00}, expected: []byte{Op0}},
|
||||
|
||||
// BIP0062: Pushing a 1-byte sequence of byte 0x01 through 0x10 must use OP_n.
|
||||
{name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{OP_1}},
|
||||
{name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{OP_2}},
|
||||
{name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{OP_3}},
|
||||
{name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{OP_4}},
|
||||
{name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{OP_5}},
|
||||
{name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{OP_6}},
|
||||
{name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{OP_7}},
|
||||
{name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{OP_8}},
|
||||
{name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{OP_9}},
|
||||
{name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{OP_10}},
|
||||
{name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{OP_11}},
|
||||
{name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{OP_12}},
|
||||
{name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{OP_13}},
|
||||
{name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{OP_14}},
|
||||
{name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{OP_15}},
|
||||
{name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{OP_16}},
|
||||
{name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{Op1}},
|
||||
{name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{Op2}},
|
||||
{name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{Op3}},
|
||||
{name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{Op4}},
|
||||
{name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{Op5}},
|
||||
{name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{Op6}},
|
||||
{name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{Op7}},
|
||||
{name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{Op8}},
|
||||
{name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{Op9}},
|
||||
{name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{Op10}},
|
||||
{name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{Op11}},
|
||||
{name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{Op12}},
|
||||
{name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{Op13}},
|
||||
{name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{Op14}},
|
||||
{name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{Op15}},
|
||||
{name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{Op16}},
|
||||
|
||||
// BIP0062: Pushing the byte 0x81 must use OP_1NEGATE.
|
||||
{name: "push 1 byte 0x81", data: []byte{0x81}, expected: []byte{OP_1NEGATE}},
|
||||
{name: "push 1 byte 0x81", data: []byte{0x81}, expected: []byte{Op1Negate}},
|
||||
|
||||
// BIP0062: Pushing any other byte sequence up to 75 bytes must
|
||||
// use the normal data push (opcode byte n, with n the number of
|
||||
// bytes, followed n bytes of data being pushed).
|
||||
{name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{OP_DATA_1, 0x11}},
|
||||
{name: "push 1 byte 0x80", data: []byte{0x80}, expected: []byte{OP_DATA_1, 0x80}},
|
||||
{name: "push 1 byte 0x82", data: []byte{0x82}, expected: []byte{OP_DATA_1, 0x82}},
|
||||
{name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{OP_DATA_1, 0xff}},
|
||||
{name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{OpData1, 0x11}},
|
||||
{name: "push 1 byte 0x80", data: []byte{0x80}, expected: []byte{OpData1, 0x80}},
|
||||
{name: "push 1 byte 0x82", data: []byte{0x82}, expected: []byte{OpData1, 0x82}},
|
||||
{name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{OpData1, 0xff}},
|
||||
{
|
||||
name: "push data len 17",
|
||||
data: bytes.Repeat([]byte{0x49}, 17),
|
||||
expected: append([]byte{OP_DATA_17}, bytes.Repeat([]byte{0x49}, 17)...),
|
||||
expected: append([]byte{OpData17}, bytes.Repeat([]byte{0x49}, 17)...),
|
||||
},
|
||||
{
|
||||
name: "push data len 75",
|
||||
data: bytes.Repeat([]byte{0x49}, 75),
|
||||
expected: append([]byte{OP_DATA_75}, bytes.Repeat([]byte{0x49}, 75)...),
|
||||
expected: append([]byte{OpData75}, bytes.Repeat([]byte{0x49}, 75)...),
|
||||
},
|
||||
|
||||
// BIP0062: Pushing 76 to 255 bytes must use OP_PUSHDATA1.
|
||||
{
|
||||
name: "push data len 76",
|
||||
data: bytes.Repeat([]byte{0x49}, 76),
|
||||
expected: append([]byte{OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0x49}, 76)...),
|
||||
expected: append([]byte{OpPushData1, 76}, bytes.Repeat([]byte{0x49}, 76)...),
|
||||
},
|
||||
{
|
||||
name: "push data len 255",
|
||||
data: bytes.Repeat([]byte{0x49}, 255),
|
||||
expected: append([]byte{OP_PUSHDATA1, 255}, bytes.Repeat([]byte{0x49}, 255)...),
|
||||
expected: append([]byte{OpPushData1, 255}, bytes.Repeat([]byte{0x49}, 255)...),
|
||||
},
|
||||
|
||||
// BIP0062: Pushing 256 to 520 bytes must use OP_PUSHDATA2.
|
||||
{
|
||||
name: "push data len 256",
|
||||
data: bytes.Repeat([]byte{0x49}, 256),
|
||||
expected: append([]byte{OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0x49}, 256)...),
|
||||
expected: append([]byte{OpPushData2, 0, 1}, bytes.Repeat([]byte{0x49}, 256)...),
|
||||
},
|
||||
{
|
||||
name: "push data len 520",
|
||||
data: bytes.Repeat([]byte{0x49}, 520),
|
||||
expected: append([]byte{OP_PUSHDATA2, 0x08, 0x02}, bytes.Repeat([]byte{0x49}, 520)...),
|
||||
expected: append([]byte{OpPushData2, 0x08, 0x02}, bytes.Repeat([]byte{0x49}, 520)...),
|
||||
},
|
||||
|
||||
// BIP0062: OP_PUSHDATA4 can never be used, as pushes over 520
|
||||
@ -252,7 +252,7 @@ func TestScriptBuilderAddData(t *testing.T) {
|
||||
{
|
||||
name: "push data len 32767 (non-canonical)",
|
||||
data: bytes.Repeat([]byte{0x49}, 32767),
|
||||
expected: append([]byte{OP_PUSHDATA2, 255, 127}, bytes.Repeat([]byte{0x49}, 32767)...),
|
||||
expected: append([]byte{OpPushData2, 255, 127}, bytes.Repeat([]byte{0x49}, 32767)...),
|
||||
useFull: true,
|
||||
},
|
||||
|
||||
@ -260,7 +260,7 @@ func TestScriptBuilderAddData(t *testing.T) {
|
||||
{
|
||||
name: "push data len 65536 (non-canonical)",
|
||||
data: bytes.Repeat([]byte{0x49}, 65536),
|
||||
expected: append([]byte{OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0x49}, 65536)...),
|
||||
expected: append([]byte{OpPushData4, 0, 0, 1, 0}, bytes.Repeat([]byte{0x49}, 65536)...),
|
||||
useFull: true,
|
||||
},
|
||||
}
|
||||
@ -312,7 +312,7 @@ func TestExceedMaxScriptSize(t *testing.T) {
|
||||
// Ensure adding an opcode that would exceed the maximum size of the
|
||||
// script does not add the data.
|
||||
builder.Reset().AddFullData(make([]byte, MaxScriptSize-3))
|
||||
script, err = builder.AddOp(OP_0).Script()
|
||||
script, err = builder.AddOp(Op0).Script()
|
||||
if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil {
|
||||
t.Fatalf("ScriptBuilder.AddOp unexpected modified script - "+
|
||||
"got len %d, want len %d", len(script), len(origScript))
|
||||
@ -384,7 +384,7 @@ func TestErroredScript(t *testing.T) {
|
||||
}
|
||||
|
||||
// Ensure adding an opcode to a script that has errored doesn't succeed.
|
||||
script, err = builder.AddOp(OP_0).Script()
|
||||
script, err = builder.AddOp(Op0).Script()
|
||||
if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil {
|
||||
t.Fatal("ScriptBuilder.AddOp succeeded on errored script")
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func signMultiSig(tx *wire.MsgTx, idx int, subScript []byte, hashType SigHashTyp
|
||||
// We start with a single OP_FALSE to work around the (now standard)
|
||||
// but in the reference implementation that causes a spurious pop at
|
||||
// the end of OP_CHECKMULTISIG.
|
||||
builder := NewScriptBuilder().AddOp(OP_FALSE)
|
||||
builder := NewScriptBuilder().AddOp(OpFalse)
|
||||
signed := 0
|
||||
for _, addr := range addresses {
|
||||
key, _, err := kdb.GetKey(addr)
|
||||
@ -315,7 +315,7 @@ sigLoop:
|
||||
|
||||
// Extra opcode to handle the extra arg consumed (due to previous bugs
|
||||
// in the reference implementation).
|
||||
builder := NewScriptBuilder().AddOp(OP_FALSE)
|
||||
builder := NewScriptBuilder().AddOp(OpFalse)
|
||||
doneSigs := 0
|
||||
// This assumes that addresses are in the same order as in the script.
|
||||
for _, addr := range addresses {
|
||||
@ -332,7 +332,7 @@ sigLoop:
|
||||
|
||||
// padding for missing ones.
|
||||
for i := doneSigs; i < nRequired; i++ {
|
||||
builder.AddOp(OP_0)
|
||||
builder.AddOp(Op0)
|
||||
}
|
||||
|
||||
script, _ := builder.Script()
|
||||
|
@ -1608,7 +1608,7 @@ nexttest:
|
||||
for i := range sigScriptTests {
|
||||
tx := wire.NewMsgTx(wire.TxVersion)
|
||||
|
||||
output := wire.NewTxOut(500, []byte{OP_RETURN})
|
||||
output := wire.NewTxOut(500, []byte{OpReturn})
|
||||
tx.AddTxOut(output)
|
||||
|
||||
for range sigScriptTests[i].inputs {
|
||||
|
@ -80,18 +80,18 @@ func isPubkey(pops []parsedOpcode) bool {
|
||||
// Valid pubkeys are either 33 or 65 bytes.
|
||||
return len(pops) == 2 &&
|
||||
(len(pops[0].data) == 33 || len(pops[0].data) == 65) &&
|
||||
pops[1].opcode.value == OP_CHECKSIG
|
||||
pops[1].opcode.value == OpCheckSig
|
||||
}
|
||||
|
||||
// isPubkeyHash returns true if the script passed is a pay-to-pubkey-hash
|
||||
// transaction, false otherwise.
|
||||
func isPubkeyHash(pops []parsedOpcode) bool {
|
||||
return len(pops) == 5 &&
|
||||
pops[0].opcode.value == OP_DUP &&
|
||||
pops[1].opcode.value == OP_HASH160 &&
|
||||
pops[2].opcode.value == OP_DATA_20 &&
|
||||
pops[3].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[4].opcode.value == OP_CHECKSIG
|
||||
pops[0].opcode.value == OpDup &&
|
||||
pops[1].opcode.value == OpHash160 &&
|
||||
pops[2].opcode.value == OpData20 &&
|
||||
pops[3].opcode.value == OpEqualVerify &&
|
||||
pops[4].opcode.value == OpCheckSig
|
||||
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ func isMultiSig(pops []parsedOpcode) bool {
|
||||
if !isSmallInt(pops[l-2].opcode) {
|
||||
return false
|
||||
}
|
||||
if pops[l-1].opcode.value != OP_CHECKMULTISIG {
|
||||
if pops[l-1].opcode.value != OpCheckMultiSig {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -136,14 +136,14 @@ func isNullData(pops []parsedOpcode) bool {
|
||||
// OP_RETURN SMALLDATA (where SMALLDATA is a data push up to
|
||||
// MaxDataCarrierSize bytes).
|
||||
l := len(pops)
|
||||
if l == 1 && pops[0].opcode.value == OP_RETURN {
|
||||
if l == 1 && pops[0].opcode.value == OpReturn {
|
||||
return true
|
||||
}
|
||||
|
||||
return l == 2 &&
|
||||
pops[0].opcode.value == OP_RETURN &&
|
||||
pops[0].opcode.value == OpReturn &&
|
||||
(isSmallInt(pops[1].opcode) || pops[1].opcode.value <=
|
||||
OP_PUSHDATA4) &&
|
||||
OpPushData4) &&
|
||||
len(pops[1].data) <= MaxDataCarrierSize
|
||||
}
|
||||
|
||||
@ -311,23 +311,23 @@ func CalcMultiSigStats(script []byte) (int, int, error) {
|
||||
// output to a 20-byte pubkey hash. It is expected that the input is a valid
|
||||
// hash.
|
||||
func payToPubKeyHashScript(pubKeyHash []byte) ([]byte, error) {
|
||||
return NewScriptBuilder().AddOp(OP_DUP).AddOp(OP_HASH160).
|
||||
AddData(pubKeyHash).AddOp(OP_EQUALVERIFY).AddOp(OP_CHECKSIG).
|
||||
return NewScriptBuilder().AddOp(OpDup).AddOp(OpHash160).
|
||||
AddData(pubKeyHash).AddOp(OpEqualVerify).AddOp(OpCheckSig).
|
||||
Script()
|
||||
}
|
||||
|
||||
// payToScriptHashScript creates a new script to pay a transaction output to a
|
||||
// script hash. It is expected that the input is a valid hash.
|
||||
func payToScriptHashScript(scriptHash []byte) ([]byte, error) {
|
||||
return NewScriptBuilder().AddOp(OP_HASH160).AddData(scriptHash).
|
||||
AddOp(OP_EQUAL).Script()
|
||||
return NewScriptBuilder().AddOp(OpHash160).AddData(scriptHash).
|
||||
AddOp(OpEqual).Script()
|
||||
}
|
||||
|
||||
// payToPubkeyScript creates a new script to pay a transaction output to a
|
||||
// public key. It is expected that the input is a valid pubkey.
|
||||
func payToPubKeyScript(serializedPubKey []byte) ([]byte, error) {
|
||||
return NewScriptBuilder().AddData(serializedPubKey).
|
||||
AddOp(OP_CHECKSIG).Script()
|
||||
AddOp(OpCheckSig).Script()
|
||||
}
|
||||
|
||||
// PayToAddrScript creates a new script to pay a transaction output to a the
|
||||
@ -373,7 +373,7 @@ func NullDataScript(data []byte) ([]byte, error) {
|
||||
return nil, scriptError(ErrTooMuchNullData, str)
|
||||
}
|
||||
|
||||
return NewScriptBuilder().AddOp(OP_RETURN).AddData(data).Script()
|
||||
return NewScriptBuilder().AddOp(OpReturn).AddData(data).Script()
|
||||
}
|
||||
|
||||
// MultiSigScript returns a valid script for a multisignature redemption where
|
||||
@ -393,7 +393,7 @@ func MultiSigScript(pubkeys []*btcutil.AddressPubKey, nrequired int) ([]byte, er
|
||||
builder.AddData(key.ScriptAddress())
|
||||
}
|
||||
builder.AddInt64(int64(len(pubkeys)))
|
||||
builder.AddOp(OP_CHECKMULTISIG)
|
||||
builder.AddOp(OpCheckMultiSig)
|
||||
|
||||
return builder.Script()
|
||||
}
|
||||
@ -410,7 +410,7 @@ func PushedData(script []byte) ([][]byte, error) {
|
||||
for _, pop := range pops {
|
||||
if pop.data != nil {
|
||||
data = append(data, pop.data)
|
||||
} else if pop.opcode.value == OP_0 {
|
||||
} else if pop.opcode.value == Op0 {
|
||||
data = append(data, nil)
|
||||
}
|
||||
}
|
||||
@ -528,26 +528,26 @@ func ExtractAtomicSwapDataPushes(version uint16, pkScript []byte) (*AtomicSwapDa
|
||||
if len(pops) != 20 {
|
||||
return nil, nil
|
||||
}
|
||||
isAtomicSwap := pops[0].opcode.value == OP_IF &&
|
||||
pops[1].opcode.value == OP_SIZE &&
|
||||
isAtomicSwap := pops[0].opcode.value == OpIf &&
|
||||
pops[1].opcode.value == OpSize &&
|
||||
canonicalPush(pops[2]) &&
|
||||
pops[3].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[4].opcode.value == OP_SHA256 &&
|
||||
pops[5].opcode.value == OP_DATA_32 &&
|
||||
pops[6].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[7].opcode.value == OP_DUP &&
|
||||
pops[8].opcode.value == OP_HASH160 &&
|
||||
pops[9].opcode.value == OP_DATA_20 &&
|
||||
pops[10].opcode.value == OP_ELSE &&
|
||||
pops[3].opcode.value == OpEqualVerify &&
|
||||
pops[4].opcode.value == OpSHA256 &&
|
||||
pops[5].opcode.value == OpData32 &&
|
||||
pops[6].opcode.value == OpEqualVerify &&
|
||||
pops[7].opcode.value == OpDup &&
|
||||
pops[8].opcode.value == OpHash160 &&
|
||||
pops[9].opcode.value == OpData20 &&
|
||||
pops[10].opcode.value == OpElse &&
|
||||
canonicalPush(pops[11]) &&
|
||||
pops[12].opcode.value == OP_CHECKLOCKTIMEVERIFY &&
|
||||
pops[13].opcode.value == OP_DROP &&
|
||||
pops[14].opcode.value == OP_DUP &&
|
||||
pops[15].opcode.value == OP_HASH160 &&
|
||||
pops[16].opcode.value == OP_DATA_20 &&
|
||||
pops[17].opcode.value == OP_ENDIF &&
|
||||
pops[18].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[19].opcode.value == OP_CHECKSIG
|
||||
pops[12].opcode.value == OpCheckLockTimeVerify &&
|
||||
pops[13].opcode.value == OpDrop &&
|
||||
pops[14].opcode.value == OpDup &&
|
||||
pops[15].opcode.value == OpHash160 &&
|
||||
pops[16].opcode.value == OpData20 &&
|
||||
pops[17].opcode.value == OpEndIf &&
|
||||
pops[18].opcode.value == OpEqualVerify &&
|
||||
pops[19].opcode.value == OpCheckSig
|
||||
if !isAtomicSwap {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "script that does not parse",
|
||||
script: []byte{OP_DATA_45},
|
||||
script: []byte{OpData45},
|
||||
addrs: nil,
|
||||
reqSigs: 0,
|
||||
class: NonStandardTy,
|
||||
@ -529,22 +529,22 @@ func TestPayToAddrScript(t *testing.T) {
|
||||
}
|
||||
|
||||
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg
|
||||
p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d"+
|
||||
p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d" +
|
||||
"74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed): %v",
|
||||
err)
|
||||
}
|
||||
p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b"+
|
||||
p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b" +
|
||||
"d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed 2): %v",
|
||||
err)
|
||||
}
|
||||
|
||||
p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411"+
|
||||
"db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5"+
|
||||
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4"+
|
||||
p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411" +
|
||||
"db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5" +
|
||||
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4" +
|
||||
"12a3"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (uncompressed): %v",
|
||||
@ -631,22 +631,22 @@ func TestMultiSigScript(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg
|
||||
p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d"+
|
||||
p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d" +
|
||||
"74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed): %v",
|
||||
err)
|
||||
}
|
||||
p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b"+
|
||||
p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b" +
|
||||
"d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (compressed 2): %v",
|
||||
err)
|
||||
}
|
||||
|
||||
p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411"+
|
||||
"db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5"+
|
||||
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4"+
|
||||
p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411" +
|
||||
"db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5" +
|
||||
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4" +
|
||||
"12a3"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create pubkey address (uncompressed): %v",
|
||||
|
168
upgrade.go
168
upgrade.go
@ -4,172 +4,8 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// dirEmpty returns whether or not the specified directory path is empty.
|
||||
func dirEmpty(dirPath string) (bool, error) {
|
||||
f, err := os.Open(dirPath)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Read the names of a max of one entry from the directory. When the
|
||||
// directory is empty, an io.EOF error will be returned, so allow it.
|
||||
names, err := f.Readdirnames(1)
|
||||
if err != nil && err != io.EOF {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return len(names) == 0, nil
|
||||
}
|
||||
|
||||
// oldBtcdHomeDir returns the OS specific home directory btcd used prior to
|
||||
// version 0.3.3. This has since been replaced with btcutil.AppDataDir, but
|
||||
// this function is still provided for the automatic upgrade path.
|
||||
func oldBtcdHomeDir() string {
|
||||
// Search for Windows APPDATA first. This won't exist on POSIX OSes.
|
||||
appData := os.Getenv("APPDATA")
|
||||
if appData != "" {
|
||||
return filepath.Join(appData, "btcd")
|
||||
}
|
||||
|
||||
// Fall back to standard HOME directory that works for most POSIX OSes.
|
||||
home := os.Getenv("HOME")
|
||||
if home != "" {
|
||||
return filepath.Join(home, ".btcd")
|
||||
}
|
||||
|
||||
// In the worst case, use the current directory.
|
||||
return "."
|
||||
}
|
||||
|
||||
// upgradeDBPathNet moves the database for a specific network from its
|
||||
// location prior to btcd version 0.2.0 and uses heuristics to ascertain the old
|
||||
// database type to rename to the new format.
|
||||
func upgradeDBPathNet(oldDbPath, netName string) error {
|
||||
// Prior to version 0.2.0, the database was named the same thing for
|
||||
// both sqlite and leveldb. Use heuristics to figure out the type
|
||||
// of the database and move it to the new path and name introduced with
|
||||
// version 0.2.0 accordingly.
|
||||
fi, err := os.Stat(oldDbPath)
|
||||
if err == nil {
|
||||
oldDbType := "sqlite"
|
||||
if fi.IsDir() {
|
||||
oldDbType = "leveldb"
|
||||
}
|
||||
|
||||
// The new database name is based on the database type and
|
||||
// resides in a directory named after the network type.
|
||||
newDbRoot := filepath.Join(filepath.Dir(cfg.DataDir), netName)
|
||||
newDbName := blockDbNamePrefix + "_" + oldDbType
|
||||
if oldDbType == "sqlite" {
|
||||
newDbName = newDbName + ".db"
|
||||
}
|
||||
newDbPath := filepath.Join(newDbRoot, newDbName)
|
||||
|
||||
// Create the new path if needed.
|
||||
err = os.MkdirAll(newDbRoot, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Move and rename the old database.
|
||||
err := os.Rename(oldDbPath, newDbPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// upgradeDBPaths moves the databases from their locations prior to btcd
|
||||
// version 0.2.0 to their new locations.
|
||||
func upgradeDBPaths() error {
|
||||
// Prior to version 0.2.0, the databases were in the "db" directory and
|
||||
// their names were suffixed by "testnet" and "regtest" for their
|
||||
// respective networks. Check for the old database and update it to the
|
||||
// new path introduced with version 0.2.0 accordingly.
|
||||
oldDbRoot := filepath.Join(oldBtcdHomeDir(), "db")
|
||||
upgradeDBPathNet(filepath.Join(oldDbRoot, "btcd.db"), "mainnet")
|
||||
upgradeDBPathNet(filepath.Join(oldDbRoot, "btcd_testnet.db"), "testnet")
|
||||
upgradeDBPathNet(filepath.Join(oldDbRoot, "btcd_regtest.db"), "regtest")
|
||||
|
||||
// Remove the old db directory.
|
||||
return os.RemoveAll(oldDbRoot)
|
||||
}
|
||||
|
||||
// upgradeDataPaths moves the application data from its location prior to btcd
|
||||
// version 0.3.3 to its new location.
|
||||
func upgradeDataPaths() error {
|
||||
// No need to migrate if the old and new home paths are the same.
|
||||
oldHomePath := oldBtcdHomeDir()
|
||||
newHomePath := defaultHomeDir
|
||||
if oldHomePath == newHomePath {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Only migrate if the old path exists and the new one doesn't.
|
||||
if fileExists(oldHomePath) && !fileExists(newHomePath) {
|
||||
// Create the new path.
|
||||
btcdLog.Infof("Migrating application home path from '%s' to '%s'",
|
||||
oldHomePath, newHomePath)
|
||||
err := os.MkdirAll(newHomePath, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Move old btcd.conf into new location if needed.
|
||||
oldConfPath := filepath.Join(oldHomePath, defaultConfigFilename)
|
||||
newConfPath := filepath.Join(newHomePath, defaultConfigFilename)
|
||||
if fileExists(oldConfPath) && !fileExists(newConfPath) {
|
||||
err := os.Rename(oldConfPath, newConfPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Move old data directory into new location if needed.
|
||||
oldDataPath := filepath.Join(oldHomePath, defaultDataDirname)
|
||||
newDataPath := filepath.Join(newHomePath, defaultDataDirname)
|
||||
if fileExists(oldDataPath) && !fileExists(newDataPath) {
|
||||
err := os.Rename(oldDataPath, newDataPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the old home if it is empty or show a warning if not.
|
||||
ohpEmpty, err := dirEmpty(oldHomePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ohpEmpty {
|
||||
err := os.Remove(oldHomePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
btcdLog.Warnf("Not removing '%s' since it contains files "+
|
||||
"not created by this application. You may "+
|
||||
"want to manually move them or delete them.",
|
||||
oldHomePath)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doUpgrades performs upgrades to btcd as new versions require it.
|
||||
// currently it's a placeholder we got from btcd upstream, that does nothing
|
||||
func doUpgrades() error {
|
||||
err := upgradeDBPaths()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return upgradeDataPaths()
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user