mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-09 06:33:16 +00:00
Migrates the `rpc` package to use new JSON encoder in #4955. Branched off of that PR. Tests pass, but I haven't done any manual testing beyond that. This should be handled as part of broader 0.34 testing.
47 lines
822 B
Go
47 lines
822 B
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"reflect"
|
|
|
|
tmjson "github.com/tendermint/tendermint/libs/json"
|
|
)
|
|
|
|
func argsToURLValues(args map[string]interface{}) (url.Values, error) {
|
|
values := make(url.Values)
|
|
if len(args) == 0 {
|
|
return values, nil
|
|
}
|
|
|
|
err := argsToJSON(args)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for key, val := range args {
|
|
values.Set(key, val.(string))
|
|
}
|
|
|
|
return values, nil
|
|
}
|
|
|
|
func argsToJSON(args map[string]interface{}) error {
|
|
for k, v := range args {
|
|
rt := reflect.TypeOf(v)
|
|
isByteSlice := rt.Kind() == reflect.Slice && rt.Elem().Kind() == reflect.Uint8
|
|
if isByteSlice {
|
|
bytes := reflect.ValueOf(v).Bytes()
|
|
args[k] = fmt.Sprintf("0x%X", bytes)
|
|
continue
|
|
}
|
|
|
|
data, err := tmjson.Marshal(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
args[k] = string(data)
|
|
}
|
|
return nil
|
|
}
|