Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/rpc): add commands for the p2p module #2599

43 changes: 14 additions & 29 deletions cmd/celestia/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package main

import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"reflect"
"strconv"

Expand Down Expand Up @@ -66,7 +64,12 @@ var getCmd = &cobra.Command{

blob, err := client.Blob.Get(cmd.Context(), height, namespace, commitment)

printOutput(blob, err)
formatter := formatData
if base64Flag || err != nil {
formatter = nil
}

printOutput(blob, err, formatter)
return nil
},
}
Expand All @@ -93,7 +96,12 @@ var getAllCmd = &cobra.Command{

blobs, err := client.Blob.GetAll(cmd.Context(), height, []share.Namespace{namespace})

printOutput(blobs, err)
formatter := formatData
if base64Flag || err != nil {
formatter = nil
}

printOutput(blobs, err, formatter)
return nil
},
}
Expand Down Expand Up @@ -128,7 +136,7 @@ var submitCmd = &cobra.Command{
Commitment: parsedBlob.Commitment,
}

printOutput(response, err)
printOutput(response, err, nil)
return nil
},
}
Expand Down Expand Up @@ -160,34 +168,11 @@ var getProofCmd = &cobra.Command{

proof, err := client.Blob.GetProof(cmd.Context(), height, namespace, commitment)

printOutput(proof, err)
printOutput(proof, err, nil)
return nil
},
}

func printOutput(data interface{}, err error) {
if err != nil {
data = err
}

if !base64Flag && err == nil {
data = formatData(data)
}

resp := struct {
Result interface{} `json:"result"`
}{
Result: data,
}

bytes, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Fprintln(os.Stdout, string(bytes))
}

func formatData(data interface{}) interface{} {
type tempBlob struct {
Namespace []byte `json:"namespace"`
Expand Down
Loading
Loading