* Instantiate a pushdata opcode from a * buffer (this differs from fromData in * that it will _always_ be a pushdata op). * @param {Buffer} data * @returns {Opcode}
(data)
| 453 | */ |
| 454 | |
| 455 | static fromPush(data) { |
| 456 | assert(Buffer.isBuffer(data)); |
| 457 | |
| 458 | if (data.length === 0) |
| 459 | return this.fromOp(opcodes.OP_0); |
| 460 | |
| 461 | if (data.length <= 0x4b) |
| 462 | return new this(data.length, data); |
| 463 | |
| 464 | if (data.length <= 0xff) |
| 465 | return new this(opcodes.OP_PUSHDATA1, data); |
| 466 | |
| 467 | if (data.length <= 0xffff) |
| 468 | return new this(opcodes.OP_PUSHDATA2, data); |
| 469 | |
| 470 | if (data.length <= 0xffffffff) |
| 471 | return new this(opcodes.OP_PUSHDATA4, data); |
| 472 | |
| 473 | throw new Error('Pushdata size too large.'); |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Instantiate a pushdata opcode from a string. |
no test coverage detected