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)
| 255 | // not be modified if pushing the data would cause the script to exceed the |
| 256 | // maximum allowed script engine size. |
| 257 | func (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. |
| 286 | func (b *ScriptBuilder) Reset() *ScriptBuilder { |