MCPcopy
hub / github.com/bcoin-org/bcoin / fromInt

Method fromInt

lib/script/opcode.js:517–530  ·  view source on GitHub ↗

* Instantiate an opcode from a Number. * @param {Number} num * @returns {Opcode}

(num)

Source from the content-addressed store, hash-verified

515 */
516
517 static fromInt(num) {
518 assert(Number.isSafeInteger(num));
519
520 if (num === 0)
521 return this.fromOp(opcodes.OP_0);
522
523 if (num === -1)
524 return this.fromOp(opcodes.OP_1NEGATE);
525
526 if (num >= 1 && num <= 16)
527 return this.fromOp(num + 0x50);
528
529 return this.fromNum(ScriptNum.fromNumber(num));
530 }
531
532 /**
533 * Instantiate an opcode from a Number.

Callers 1

toNumMethod · 0.45

Calls 2

fromOpMethod · 0.95
fromNumMethod · 0.95

Tested by

no test coverage detected