Skip to content

Commit

Permalink
fix(cmd/rpc): parsing JSON for all parameters, and adding handler to …
Browse files Browse the repository at this point in the history
…GetSharesByNamespace (#2113)
  • Loading branch information
distractedm1nd committed May 2, 2023
1 parent 5c0b128 commit 7e65a72
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func parseParams(method string, params []string) []interface{} {
switch method {
case "GetSharesByNamespace":
// 1. Share Root
parsedParams[0] = params[0]
root, err := parseJSON(params[0])
if err != nil {
panic(fmt.Errorf("couldn't parse share root as json: %v", err))
}
parsedParams[0] = root
// 2. NamespaceID
if strings.HasPrefix(params[1], "0x") {
decoded, err := hex.DecodeString(params[1][2:])
Expand Down Expand Up @@ -219,11 +223,11 @@ func parseParams(method string, params []string) []interface{} {

for i, param := range params {
if param[0] == '{' || param[0] == '[' {
var raw json.RawMessage
if err := json.Unmarshal([]byte(param), &raw); err == nil {
parsedParams[i] = raw
} else {
rawJSON, err := parseJSON(param)
if err != nil {
parsedParams[i] = param
} else {
parsedParams[i] = rawJSON
}
} else {
// try to parse arguments as numbers before adding them as strings
Expand Down Expand Up @@ -317,3 +321,9 @@ func parseSignatureForHelpstring(methodSig reflect.StructField) string {
simplifiedSignature += ")"
return simplifiedSignature
}

func parseJSON(param string) (json.RawMessage, error) {
var raw json.RawMessage
err := json.Unmarshal([]byte(param), &raw)
return raw, err
}

0 comments on commit 7e65a72

Please sign in to comment.