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

fix(cmd): fix namespace representation in cmd output #3537

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 40 additions & 31 deletions nodebuilder/blob/cmd/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"reflect"
"strconv"
"strings"

"github.com/spf13/cobra"

Expand All @@ -32,14 +33,14 @@ func init() {
&base64Flag,
"base64",
false,
"printed blob's data a base64 string",
"printed blob's data and namespace as base64 strings",
)

getAllCmd.PersistentFlags().BoolVar(
&base64Flag,
"base64",
false,
"printed blob's data as a base64 string",
"printed blob's data and namespace as base64 strings",
)

submitCmd.PersistentFlags().Float64Var(
Expand Down Expand Up @@ -76,6 +77,9 @@ var getCmd = &cobra.Command{
return fmt.Errorf("error parsing a height: %w", err)
}

if !strings.HasPrefix(args[1], "0x") {
return fmt.Errorf("only hex namespace is supported")
}
namespace, err := cmdnode.ParseV0Namespace(args[1])
if err != nil {
return fmt.Errorf("error parsing a namespace: %w", err)
Expand All @@ -88,7 +92,7 @@ var getCmd = &cobra.Command{

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

formatter := formatData
formatter := formatData(args[1])
if base64Flag || err != nil {
formatter = nil
}
Expand All @@ -113,12 +117,15 @@ var getAllCmd = &cobra.Command{
}

namespace, err := cmdnode.ParseV0Namespace(args[1])
if !strings.HasPrefix(args[1], "0x") {
return fmt.Errorf("only hex namespace is supported")
}
if err != nil {
return fmt.Errorf("error parsing a namespace: %w", err)
}

blobs, err := client.Blob.GetAll(cmd.Context(), height, []share.Namespace{namespace})
formatter := formatData
formatter := formatData(args[1])
if base64Flag || err != nil {
formatter = nil
}
Expand Down Expand Up @@ -266,36 +273,38 @@ var getProofCmd = &cobra.Command{
},
}

func formatData(data interface{}) interface{} {
type tempBlob struct {
Namespace []byte `json:"namespace"`
Data string `json:"data"`
ShareVersion uint32 `json:"share_version"`
Commitment []byte `json:"commitment"`
Index int `json:"index"`
}
func formatData(ns string) func(interface{}) interface{} {
return func(data interface{}) interface{} {
type tempBlob struct {
Namespace string `json:"namespace"`
Data string `json:"data"`
ShareVersion uint32 `json:"share_version"`
Commitment []byte `json:"commitment"`
Index int `json:"index"`
}

if reflect.TypeOf(data).Kind() == reflect.Slice {
blobs := data.([]*blob.Blob)
result := make([]tempBlob, len(blobs))
for i, b := range blobs {
result[i] = tempBlob{
Namespace: b.Namespace(),
Data: string(b.Data),
ShareVersion: b.ShareVersion,
Commitment: b.Commitment,
Index: b.Index(),
if reflect.TypeOf(data).Kind() == reflect.Slice {
blobs := data.([]*blob.Blob)
result := make([]tempBlob, len(blobs))
for i, b := range blobs {
result[i] = tempBlob{
Namespace: ns,
Data: string(b.Data),
ShareVersion: b.ShareVersion,
Commitment: b.Commitment,
Index: b.Index(),
}
}
return result
}
return result
}

b := data.(*blob.Blob)
return tempBlob{
Namespace: b.Namespace(),
Data: string(b.Data),
ShareVersion: b.ShareVersion,
Commitment: b.Commitment,
Index: b.Index(),
b := data.(*blob.Blob)
return tempBlob{
Namespace: ns,
Data: string(b.Data),
ShareVersion: b.ShareVersion,
Commitment: b.Commitment,
Index: b.Index(),
}
}
}