github.com/noirx94/tendermintmp@v0.0.1/rpc/jsonrpc/client/encode.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "net/url" 6 "reflect" 7 8 tmjson "github.com/tendermint/tendermint/libs/json" 9 ) 10 11 func argsToURLValues(args map[string]interface{}) (url.Values, error) { 12 values := make(url.Values) 13 if len(args) == 0 { 14 return values, nil 15 } 16 17 err := argsToJSON(args) 18 if err != nil { 19 return nil, err 20 } 21 22 for key, val := range args { 23 values.Set(key, val.(string)) 24 } 25 26 return values, nil 27 } 28 29 func argsToJSON(args map[string]interface{}) error { 30 for k, v := range args { 31 rt := reflect.TypeOf(v) 32 isByteSlice := rt.Kind() == reflect.Slice && rt.Elem().Kind() == reflect.Uint8 33 if isByteSlice { 34 bytes := reflect.ValueOf(v).Bytes() 35 args[k] = fmt.Sprintf("0x%X", bytes) 36 continue 37 } 38 39 data, err := tmjson.Marshal(v) 40 if err != nil { 41 return err 42 } 43 args[k] = string(data) 44 } 45 return nil 46 }