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

Function disasmOpcode

txscript/opcode.go:715–754  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

713// opposed to including the opcode that specifies the amount of data to push as
714// well.
715func 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.

Callers 4

DisasmPCMethod · 0.85
DisasmScriptMethod · 0.85
TestOpcodeDisasmFunction · 0.85
DisasmStringFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestOpcodeDisasmFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…