Pretty-print all disassembled EVM instructions to stdout.
(code string)
| 101 | |
| 102 | // Pretty-print all disassembled EVM instructions to stdout. |
| 103 | func PrintDisassembled(code string) error { |
| 104 | script, err := hex.DecodeString(code) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | |
| 109 | it := NewInstructionIterator(script) |
| 110 | for it.Next() { |
| 111 | if it.Arg() != nil && 0 < len(it.Arg()) { |
| 112 | fmt.Printf("%06v: %v 0x%x\n", it.PC(), it.Op(), it.Arg()) |
| 113 | } else { |
| 114 | fmt.Printf("%06v: %v\n", it.PC(), it.Op()) |
| 115 | } |
| 116 | } |
| 117 | return it.Error() |
| 118 | } |
| 119 | |
| 120 | // Return all disassembled EVM instructions in human-readable format. |
| 121 | func Disassemble(script []byte) ([]string, error) { |