MCPcopy Index your code
hub / github.com/btcsuite/btcd / AddInt64

Method AddInt64

txscript/scriptbuilder.go:257–283  ·  view source on GitHub ↗

AddInt64 pushes the passed integer to the end of the script. The script will not be modified if pushing the data would cause the script to exceed the maximum allowed script engine size.

(val int64)

Source from the content-addressed store, hash-verified

255// not be modified if pushing the data would cause the script to exceed the
256// maximum allowed script engine size.
257func (b *ScriptBuilder) AddInt64(val int64) *ScriptBuilder {
258 if b.err != nil {
259 return b
260 }
261
262 // Pushes that would cause the script to exceed the largest allowed
263 // script size would result in a non-canonical script.
264 if len(b.script)+1 > MaxScriptSize {
265 str := fmt.Sprintf("adding an integer would exceed the "+
266 "maximum allow canonical script length of %d",
267 MaxScriptSize)
268 b.err = ErrScriptNotCanonical(str)
269 return b
270 }
271
272 // Fast path for small integers and OP_1NEGATE.
273 if val == 0 {
274 b.script = append(b.script, OP_0)
275 return b
276 }
277 if val == -1 || (val >= 1 && val <= 16) {
278 b.script = append(b.script, byte((OP_1-1)+val))
279 return b
280 }
281
282 return b.AddData(scriptNum(val).Bytes())
283}
284
285// Reset resets the script so it has no content.
286func (b *ScriptBuilder) Reset() *ScriptBuilder {

Callers 15

compareScriptFunction · 0.95
TestExceedMaxScriptSizeFunction · 0.95
TestErroredScriptFunction · 0.95
parseShortFormFunction · 0.95
processScriptFunction · 0.95
CreateCoinbaseTxMethod · 0.80
createCSVOutputFunction · 0.80
standardCoinbaseScriptFunction · 0.80
standardCoinbaseScriptFunction · 0.80
StandardCoinbaseScriptFunction · 0.80
createTestCoinbaseFunction · 0.80

Calls 4

AddDataMethod · 0.95
ErrScriptNotCanonicalTypeAlias · 0.85
scriptNumTypeAlias · 0.85
BytesMethod · 0.45

Tested by 9

TestExceedMaxScriptSizeFunction · 0.76
TestErroredScriptFunction · 0.76
parseShortFormFunction · 0.76
CreateCoinbaseTxMethod · 0.64
createCSVOutputFunction · 0.64
createTestCoinbaseFunction · 0.64
TestHasCanonicalPushFunction · 0.64