[NOD-1532] OpTrueScript should also return the redeem script

This commit is contained in:
Mike Zak 2020-11-16 10:44:04 +02:00 committed by Svarog
parent 34be898491
commit dc80a39c54
3 changed files with 12 additions and 8 deletions

View File

@ -38,9 +38,11 @@ func (tc *testConsensus) AddBlock(parentHashes []*externalapi.DomainHash, coinba
tc.lock.Lock()
defer tc.lock.Unlock()
scriptPublicKey, _ := testutils.OpTrueScript()
if coinbaseData == nil {
coinbaseData = &externalapi.DomainCoinbaseData{
ScriptPublicKey: testutils.OpTrueScript(),
ScriptPublicKey: scriptPublicKey,
ExtraData: []byte{},
}
}

View File

@ -11,10 +11,9 @@ import (
// Assumes that the output being spent has opTrueScript as it's scriptPublicKey
// Creates the value of the spent output minus 1 sompi
func CreateTransaction(txToSpend *externalapi.DomainTransaction) (*externalapi.DomainTransaction, error) {
opTrueScript := OpTrueScript()
scriptPublicKey, redeemScript := OpTrueScript()
scriptPublicKey := opTrueScript
signatureScript, err := txscript.PayToScriptHashSignatureScript(opTrueScript, nil)
signatureScript, err := txscript.PayToScriptHashSignatureScript(redeemScript, nil)
if err != nil {
return nil, err
}

View File

@ -5,11 +5,14 @@ import (
"github.com/pkg/errors"
)
// OpTrueScript returns a P2SH script paying to an anyone-can-spend address
func OpTrueScript() []byte {
opTrueScript, err := txscript.PayToScriptHashScript([]byte{txscript.OpTrue})
// OpTrueScript returns a P2SH script paying to an anyone-can-spend address,
// The second return value is a redeemScript to be used with txscript.PayToScriptHashSignatureScript
func OpTrueScript() (scriptPublicKey, redeemScript []byte) {
var err error
redeemScript = []byte{txscript.OpTrue}
scriptPublicKey, err = txscript.PayToScriptHashScript(redeemScript)
if err != nil {
panic(errors.Wrapf(err, "Couldn't parse opTrueScript. This should never happen"))
}
return opTrueScript
return scriptPublicKey, redeemScript
}