txscript: Remove unused GenerateSStxAddrPush.
This removes GenerateSStxAddrPush since it is no longer used by anything in the repository and is now available via the RewardCommitmentScript method of the relevant stdaddr address. It also removes the associated tests and nilAddrErrStr that is no longer used upon their removal.
This commit is contained in:
parent
19fa54d62c
commit
76d625dfd0
@ -12,7 +12,6 @@ import (
|
||||
"github.com/decred/dcrd/chaincfg/chainhash"
|
||||
"github.com/decred/dcrd/dcrec"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/decred/dcrd/dcrutil/v4"
|
||||
"github.com/decred/dcrd/txscript/v4/stdaddr"
|
||||
)
|
||||
|
||||
@ -20,11 +19,6 @@ const (
|
||||
// MaxDataCarrierSize is the maximum number of bytes allowed in pushed
|
||||
// data to be considered a nulldata transaction.
|
||||
MaxDataCarrierSize = 256
|
||||
|
||||
// nilAddrErrStr is the common error string to use for attempts to
|
||||
// generate payment scripts to nil addresses embedded within a
|
||||
// dcrutil.Address interface.
|
||||
nilAddrErrStr = "unable to generate payment script for nil address"
|
||||
)
|
||||
|
||||
// ScriptClass is an enumeration for the list of standard types of script.
|
||||
@ -744,51 +738,6 @@ func MultisigRedeemScriptFromScriptSig(script []byte) []byte {
|
||||
return finalOpcodeData(scriptVersion, script)
|
||||
}
|
||||
|
||||
// GenerateSStxAddrPush generates an OP_RETURN push for SSGen payment addresses in
|
||||
// an SStx.
|
||||
func GenerateSStxAddrPush(addr dcrutil.Address, amount dcrutil.Amount, limits uint16) ([]byte, error) {
|
||||
// Only pay to pubkey hash and pay to script hash are
|
||||
// supported.
|
||||
scriptType := PubKeyHashTy
|
||||
switch addr := addr.(type) {
|
||||
case *dcrutil.AddressPubKeyHash:
|
||||
if addr == nil {
|
||||
return nil, scriptError(ErrUnsupportedAddress,
|
||||
nilAddrErrStr)
|
||||
}
|
||||
if addr.DSA() != dcrec.STEcdsaSecp256k1 {
|
||||
str := "unable to generate payment script for " +
|
||||
"unsupported digital signature algorithm"
|
||||
return nil, scriptError(ErrUnsupportedAddress, str)
|
||||
}
|
||||
|
||||
case *dcrutil.AddressScriptHash:
|
||||
if addr == nil {
|
||||
return nil, scriptError(ErrUnsupportedAddress,
|
||||
nilAddrErrStr)
|
||||
}
|
||||
scriptType = ScriptHashTy
|
||||
|
||||
default:
|
||||
str := fmt.Sprintf("unable to generate payment script for "+
|
||||
"unsupported address type %T", addr)
|
||||
return nil, scriptError(ErrUnsupportedAddress, str)
|
||||
}
|
||||
|
||||
// Concatenate the prefix, pubkeyhash, and amount.
|
||||
adBytes := make([]byte, 20+8+2)
|
||||
copy(adBytes[0:20], addr.ScriptAddress())
|
||||
binary.LittleEndian.PutUint64(adBytes[20:28], uint64(amount))
|
||||
binary.LittleEndian.PutUint16(adBytes[28:30], limits)
|
||||
|
||||
// Set the bit flag indicating pay to script hash.
|
||||
if scriptType == ScriptHashTy {
|
||||
adBytes[27] |= 1 << 7
|
||||
}
|
||||
|
||||
return NewScriptBuilder().AddOp(OP_RETURN).AddData(adBytes).Script()
|
||||
}
|
||||
|
||||
// GenerateSSGenBlockRef generates an OP_RETURN push for the block header hash and
|
||||
// height which the block votes on.
|
||||
func GenerateSSGenBlockRef(blockHash chainhash.Hash, height uint32) ([]byte, error) {
|
||||
|
||||
@ -15,7 +15,6 @@ import (
|
||||
"github.com/decred/dcrd/chaincfg/chainhash"
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/decred/dcrd/dcrutil/v4"
|
||||
"github.com/decred/dcrd/txscript/v4/stdaddr"
|
||||
)
|
||||
|
||||
@ -915,51 +914,6 @@ func TestGenerateProvablyPruneableOut(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestGenerateSStxAddrPush ensures an expected OP_RETURN push is generated.
|
||||
func TestGenerateSStxAddrPush(t *testing.T) {
|
||||
testNetParams := chaincfg.TestNet3Params()
|
||||
var tests = []struct {
|
||||
addrStr string
|
||||
net stdaddr.AddressParams
|
||||
amount dcrutil.Amount
|
||||
limits uint16
|
||||
expected []byte
|
||||
}{
|
||||
{
|
||||
"Dcur2mcGjmENx4DhNqDctW5wJCVyT3Qeqkx",
|
||||
mainNetParams,
|
||||
1000,
|
||||
10,
|
||||
hexToBytes("6a1ef5916158e3e2c4551c1796708db8367207ed1" +
|
||||
"3bbe8030000000000800a00"),
|
||||
},
|
||||
{
|
||||
"TscB7V5RuR1oXpA364DFEsNDuAs8Rk6BHJE",
|
||||
testNetParams,
|
||||
543543,
|
||||
256,
|
||||
hexToBytes("6a1e7a5c4cca76f2e0b36db4763daacbd6cbb6ee6" +
|
||||
"e7b374b0800000000000001"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
addr, err := dcrutil.DecodeAddress(test.addrStr, test.net)
|
||||
if err != nil {
|
||||
t.Errorf("DecodeAddress failed: %v", err)
|
||||
continue
|
||||
}
|
||||
s, err := GenerateSStxAddrPush(addr, test.amount, test.limits)
|
||||
if err != nil {
|
||||
t.Errorf("GenerateSStxAddrPush failed: %v", err)
|
||||
continue
|
||||
}
|
||||
if !bytes.Equal(s, test.expected) {
|
||||
t.Errorf("GenerateSStxAddrPush: unexpected script:\n "+
|
||||
"got %x\nwant %x", s, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestGenerateSSGenBlockRef ensures an expected OP_RETURN push is generated.
|
||||
func TestGenerateSSGenBlockRef(t *testing.T) {
|
||||
var tests = []struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user