8 "github.com/vapor/consensus/segwit"
9 "github.com/vapor/protocol/vm"
12 // DecodeProgResp is response for decode program
13 type DecodeProgResp struct {
14 Instructions string `json:"instructions"`
17 func (a *API) decodeProgram(ctx context.Context, ins struct {
18 Program string `json:"program"`
20 prog, err := hex.DecodeString(ins.Program)
22 return NewErrorResponse(err)
25 // if program is P2PKH or P2SH script, convert it into actual executed program
26 if segwit.IsP2WPKHScript(prog) {
27 if witnessProg, err := segwit.ConvertP2PKHSigProgram(prog); err == nil {
30 } else if segwit.IsP2WSHScript(prog) {
31 if witnessProg, err := segwit.ConvertP2SHProgram(prog); err == nil {
36 insts, err := vm.ParseProgram(prog)
38 return NewErrorResponse(err)
42 for _, inst := range insts {
43 result += fmt.Sprintf("%s %s\n", inst.Op, hex.EncodeToString(inst.Data))
45 return NewSuccessResponse(DecodeProgResp{Instructions: result})