disasmOpcode writes a human-readable disassembly of the provided opcode and data into the provided buffer. The compact flag indicates the disassembly should print a more compact representation of data-carrying and small integer opcodes. For example, OP_0 through OP_16 are replaced with the numeric
(buf *strings.Builder, op *opcode, data []byte, compact bool)
| 713 | // opposed to including the opcode that specifies the amount of data to push as |
| 714 | // well. |
| 715 | func disasmOpcode(buf *strings.Builder, op *opcode, data []byte, compact bool) { |
| 716 | // Replace opcode which represent values (e.g. OP_0 through OP_16 and |
| 717 | // OP_1NEGATE) with the raw value when performing a compact disassembly. |
| 718 | opcodeName := op.name |
| 719 | if compact { |
| 720 | if replName, ok := opcodeOnelineRepls[opcodeName]; ok { |
| 721 | opcodeName = replName |
| 722 | } |
| 723 | |
| 724 | // Either write the human-readable opcode or the parsed data in hex for |
| 725 | // data-carrying opcodes. |
| 726 | switch { |
| 727 | case op.length == 1: |
| 728 | buf.WriteString(opcodeName) |
| 729 | |
| 730 | default: |
| 731 | buf.WriteString(hex.EncodeToString(data)) |
| 732 | } |
| 733 | |
| 734 | return |
| 735 | } |
| 736 | |
| 737 | buf.WriteString(opcodeName) |
| 738 | |
| 739 | switch op.length { |
| 740 | // Only write the opcode name for non-data push opcodes. |
| 741 | case 1: |
| 742 | return |
| 743 | |
| 744 | // Add length for the OP_PUSHDATA# opcodes. |
| 745 | case -1: |
| 746 | buf.WriteString(fmt.Sprintf(" 0x%02x", len(data))) |
| 747 | case -2: |
| 748 | buf.WriteString(fmt.Sprintf(" 0x%04x", len(data))) |
| 749 | case -4: |
| 750 | buf.WriteString(fmt.Sprintf(" 0x%08x", len(data))) |
| 751 | } |
| 752 | |
| 753 | buf.WriteString(fmt.Sprintf(" 0x%02x", data)) |
| 754 | } |
| 755 | |
| 756 | // ******************************************* |
| 757 | // Opcode implementation functions start here. |
no outgoing calls
searching dependent graphs…