@@ -7,13 +7,13 @@ import (
77 "strings"
88
99 "github.com/cosmos/cosmos-sdk/client/context"
10- sdk "github.com/cosmos/cosmos-sdk/types"
1110 "github.com/cosmos/cosmos-sdk/types/rest"
1211 "github.com/cosmos/cosmos-sdk/x/auth/client/utils"
1312 "github.com/dfinance/dvm-proto/go/vm_grpc"
1413 "github.com/gorilla/mux"
1514 "github.com/spf13/viper"
1615
16+ addrHelper "github.com/dfinance/dnode/helpers/types"
1717 "github.com/dfinance/dnode/x/common_vm"
1818 vmClient "github.com/dfinance/dnode/x/vm/client"
1919 "github.com/dfinance/dnode/x/vm/internal/types"
@@ -36,6 +36,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
3636 r .HandleFunc (fmt .Sprintf ("/%s/data/{%s}/{%s}" , types .ModuleName , accountAddrName , vmPathName ), getData (cliCtx )).Methods ("GET" )
3737 r .HandleFunc (fmt .Sprintf ("/%s/tx/{%s}" , types .ModuleName , txHash ), getTxVMStatus (cliCtx )).Methods ("GET" )
3838}
39+
3940// Compile godoc
4041// @Tags vm
4142// @Summary Get compiled byteCode
@@ -57,9 +58,20 @@ func compile(cliCtx context.CLIContext) http.HandlerFunc {
5758 }
5859
5960 compilerAddr := viper .GetString (vmClient .FlagCompilerAddr )
61+
62+ address , err := addrHelper .GetAccAddressFromHexOrBech32 (req .Account )
63+ if err != nil {
64+ rest .WriteErrorResponse (
65+ w ,
66+ http .StatusUnprocessableEntity ,
67+ fmt .Sprintf ("error parsing address: %v" , err ),
68+ )
69+ return
70+ }
71+
6072 sourceFile := & vm_grpc.SourceFile {
6173 Text : req .Code ,
62- Address : [] byte ( req . Account ),
74+ Address : common_vm . Bech32ToLibra ( address ),
6375 }
6476
6577 byteCode , err := vmClient .Compile (compilerAddr , sourceFile )
@@ -82,7 +94,7 @@ func compile(cliCtx context.CLIContext) http.HandlerFunc {
8294// @ID vmGetData
8395// @Accept json
8496// @Produce json
85- // @Param accountAddr path string true "account address (Libra HEX Bech32)"
97+ // @Param accountAddr path string true "account address (Libra HEX / Bech32)"
8698// @Param vmPath path string true "VM path (HEX string)"
8799// @Success 200 {object} VmData
88100// @Failure 422 {object} rest.ErrorResponse "Returned if the request doesn't have valid path params"
@@ -94,18 +106,14 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc {
94106 rawAddress := vars [accountAddrName ]
95107 rawPath := vars [vmPathName ]
96108
97- var address sdk.AccAddress
98- address , err := hex .DecodeString (rawAddress )
109+ address , err := addrHelper .GetAccAddressFromHexOrBech32 (rawAddress )
99110 if err != nil {
100- address , err = sdk .AccAddressFromBech32 (rawAddress )
101- if err != nil {
102- rest .WriteErrorResponse (
103- w ,
104- http .StatusUnprocessableEntity ,
105- fmt .Sprintf ("can't parse address %q (should be libra hex or bech32): %v" , rawAddress , err ),
106- )
107- return
108- }
111+ rest .WriteErrorResponse (
112+ w ,
113+ http .StatusUnprocessableEntity ,
114+ fmt .Sprintf ("address parsing error: %v" , err ),
115+ )
116+ return
109117 }
110118
111119 path , err := hex .DecodeString (rawPath )
0 commit comments