blockchain/standalone: Remove txscript dep.

The purpose of the standalone module is to avoid extra dependencies.
The treasury work unfortunately went against that goal and introduced a
dependency on txscript.  This remedies that by defining the necessary
opcodes directly which is perfectly acceptable because they are used in
consensus code and thus can't be changed without a vote.
This commit is contained in:
Dave Collins 2020-09-26 15:56:41 -05:00
parent acedac5085
commit 0ae1634cff
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2
3 changed files with 17 additions and 30 deletions

View File

@ -4,8 +4,5 @@ go 1.11
require (
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
github.com/decred/dcrd/txscript/v3 v3.0.0-20200611204838-4c5825cf9054
github.com/decred/dcrd/wire v1.4.0
)
replace github.com/decred/dcrd/txscript/v3 => ../../txscript

View File

@ -1,28 +1,8 @@
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4=
github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
github.com/decred/base58 v1.0.3 h1:KGZuh8d1WEMIrK0leQRM47W85KqCAdl2N+uagbctdDI=
github.com/decred/base58 v1.0.3/go.mod h1:pXP9cXCfM2sFLb2viz2FNIdeMWmZDBKG3ZBYbiSM78E=
github.com/decred/dcrd/chaincfg/chainhash v1.0.2 h1:rt5Vlq/jM3ZawwiacWjPa+smINyLRN07EO0cNBV6DGU=
github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60=
github.com/decred/dcrd/chaincfg/v3 v3.0.0 h1:+TFbu7ZmvBwM+SZz5mrj6cun9ts/6DAL5sqnsaFBHGQ=
github.com/decred/dcrd/chaincfg/v3 v3.0.0/go.mod h1:EspyubQ7D2w6tjP7rBGDIE7OTbuMgBjR2F2kZFnh31A=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/crypto/ripemd160 v1.0.1 h1:TjRL4LfftzTjXzaufov96iDAkbY2R3aTvH2YMYa1IOc=
github.com/decred/dcrd/crypto/ripemd160 v1.0.1/go.mod h1:F0H8cjIuWTRoixr/LM3REB8obcWkmYx0gbxpQWR8RPg=
github.com/decred/dcrd/dcrec v1.0.0 h1:W+z6Es+Rai3MXYVoPAxYr5U1DGis0Co33scJ6uH2J6o=
github.com/decred/dcrd/dcrec v1.0.0/go.mod h1:HIaqbEJQ+PDzQcORxnqen5/V1FR3B4VpIfmePklt8Q8=
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.1 h1:V6eqU1crZzuoFT4KG2LhaU5xDSdkHuvLQsj25wd7Wb4=
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.1/go.mod h1:d0H8xGMWbiIQP7gN3v2rByWUcuZPm9YsgmnfoxgbINc=
github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0 h1:sgNeV1VRMDzs6rzyPpxyM0jp317hnwiq58Filgag2xw=
github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0/go.mod h1:J70FGZSbzsjecRTiTzER+3f1KZLNaXkuv+yeFTKoxM8=
github.com/decred/dcrd/dcrutil/v3 v3.0.0 h1:n6uQaTQynIhCY89XsoDk2WQqcUcnbD+zUM9rnZcIOZo=
github.com/decred/dcrd/dcrutil/v3 v3.0.0/go.mod h1:iVsjcqVzLmYFGCZLet2H7Nq+7imV9tYcuY+0lC2mNsY=
github.com/decred/dcrd/wire v1.4.0 h1:KmSo6eTQIvhXS0fLBQ/l7hG7QLcSJQKSwSyzSqJYDk0=
github.com/decred/dcrd/wire v1.4.0/go.mod h1:WxC/0K+cCAnBh+SKsRjIX9YPgvrjhmE+6pZlel1G7Ro=
github.com/decred/slog v1.1.0 h1:uz5ZFfmaexj1rEDgZvzQ7wjGkoSPjw2LCh8K+K1VrW4=
github.com/decred/slog v1.1.0/go.mod h1:kVXlGnt6DHy2fV5OjSeuvCJ0OmlmTF6LFpEPMu/fOY0=

View File

@ -9,10 +9,20 @@ import (
"math"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/txscript/v3"
"github.com/decred/dcrd/wire"
)
const (
// These constants are opcodes are defined here to avoid a dependency on
// txscript. They are used in consensus code which can't be changed without
// a vote anyway, so not referring to them directly via txscript is safe.
opData12 = 0x0c
opReturn = 0x6a
opTAdd = 0xc1
opTSpend = 0xc2
opTGen = 0xc3
)
var (
// zeroHash is the zero value for a chainhash.Hash and is defined as a
// package level variable to avoid the need to create a new instance every
@ -70,9 +80,9 @@ func IsCoinBaseTx(tx *wire.MsgTx, isTreasuryEnabled bool) bool {
// TSpends have a TSpend opcode as the last byte of TxIn 0 and
// an OP_RETURN followed by at least one OP_TGEN in the zeroth
// TxOut script.
if tx.TxIn[0].SignatureScript[l-1] == txscript.OP_TSPEND &&
tx.TxOut[0].PkScript[0] == txscript.OP_RETURN &&
tx.TxOut[1].PkScript[0] == txscript.OP_TGEN {
if tx.TxIn[0].SignatureScript[l-1] == opTSpend &&
tx.TxOut[0].PkScript[0] == opReturn &&
tx.TxOut[1].PkScript[0] == opTGen {
return false
}
}
@ -96,13 +106,13 @@ func IsTreasuryBase(tx *wire.MsgTx) bool {
}
if len(tx.TxOut[0].PkScript) != 1 ||
tx.TxOut[0].PkScript[0] != txscript.OP_TADD {
tx.TxOut[0].PkScript[0] != opTAdd {
return false
}
if len(tx.TxOut[1].PkScript) != 14 ||
tx.TxOut[1].PkScript[0] != txscript.OP_RETURN ||
tx.TxOut[1].PkScript[1] != txscript.OP_DATA_12 {
tx.TxOut[1].PkScript[0] != opReturn ||
tx.TxOut[1].PkScript[1] != opData12 {
return false
}