mirror of
https://github.com/btcsuite/btcd.git
synced 2026-08-16 13:00:29 +02:00
txscript: Expose AddOps on ScriptBuilder. (#734)
This exposes a new function on the ScriptBuilder type named AddOps that allows multiple opcodes to be added via a single call and adds tests to exercise the new function. Finally, it updates a couple of places in the signing code that were abusing the interface by setting its private script directly to use the new public function instead.
This commit is contained in:
parent
fb9b640ef2
commit
cee207c64c
3 changed files with 44 additions and 4 deletions
|
|
@ -73,6 +73,27 @@ func (b *ScriptBuilder) AddOp(opcode byte) *ScriptBuilder {
|
|||
return b
|
||||
}
|
||||
|
||||
// AddOps pushes the passed opcodes to the end of the script. The script will
|
||||
// not be modified if pushing the opcodes would cause the script to exceed the
|
||||
// maximum allowed script engine size.
|
||||
func (b *ScriptBuilder) AddOps(opcodes []byte) *ScriptBuilder {
|
||||
if b.err != nil {
|
||||
return b
|
||||
}
|
||||
|
||||
// Pushes that would cause the script to exceed the largest allowed
|
||||
// script size would result in a non-canonical script.
|
||||
if len(b.script)+len(opcodes) > maxScriptSize {
|
||||
str := fmt.Sprintf("adding opcodes would exceed the maximum "+
|
||||
"allowed canonical script length of %d", maxScriptSize)
|
||||
b.err = ErrScriptNotCanonical(str)
|
||||
return b
|
||||
}
|
||||
|
||||
b.script = append(b.script, opcodes...)
|
||||
return b
|
||||
}
|
||||
|
||||
// canonicalDataSize returns the number of bytes the canonical encoding of the
|
||||
// data will take.
|
||||
func canonicalDataSize(data []byte) int {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue