diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 0cb82e69a5..dedf56b591 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -32,7 +32,7 @@ const ( func CmdPayForBlob() *cobra.Command { cmd := &cobra.Command{ - Use: "PayForBlobs namespaceID blobs", + Use: "PayForBlobs namespaceID path blobs", // This example command can be run in a new terminal after running single-node.sh Example: "celestia-appd tx blob PayForBlobs 0x00010203040506070809 0x48656c6c6f2c20576f726c6421 \\\n" + "\t--chain-id private \\\n" + @@ -52,6 +52,7 @@ func CmdPayForBlob() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) arg0 := strings.TrimPrefix(args[0], "0x") namespaceID, err := hex.DecodeString(arg0) if err != nil { @@ -66,9 +67,42 @@ func CmdPayForBlob() *cobra.Command { return err } + path := args[1] + + _, err = parseSubmitBlobs(clientCtx.Codec, path) + if err != nil { + return err + } + + // var blobs []*blob.Blob + // for i := range paresdBlobs { + // namespaceID, err := hex.DecodeString(paresdBlobs[i].NamespaceID) + // if err != nil { + // return fmt.Errorf("failed to decode hex namespace ID: %w", err) + // } + // namespace, err := getNamespace(namespaceID, namespaceVersion) + // if err != nil { + // return err + // } + // hexStr := strings.TrimPrefix(paresdBlobs[i].Blob, "0x") + // rawblob, err := hex.DecodeString(hexStr) + // if err != nil { + // fmt.Printf("failure to decode hex blob value %s: %s", hexStr, err.Error()) + // continue + // } + + // shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion) + // blob, err := types.NewBlob(namespace, rawblob, shareVersion) + // if err != nil { + // fmt.Printf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) + // continue + // } + // blobs = append(blobs, blob) + // } + var blobs []*blob.Blob // Skip the first argument as it's the namespaceID - blobArgs := args[1:] + blobArgs := args[2:] for i := range blobArgs { arg := strings.TrimPrefix(blobArgs[i], "0x") rawblob, err := hex.DecodeString(arg) diff --git a/x/blob/client/cli/test_blob.json b/x/blob/client/cli/test_blob.json new file mode 100644 index 0000000000..0223a05d81 --- /dev/null +++ b/x/blob/client/cli/test_blob.json @@ -0,0 +1,12 @@ +{ + "Blobs": [ + { + "namespaceID": "0x00010203040506070809", + "blob": "0x48656c6c6f2c20576f726c6421" + }, + { + "namespaceID": "0x00010203040506070809", + "blob": "0x48656c6c6f2c20576f726c6421" + } + ] +} \ No newline at end of file diff --git a/x/blob/client/cli/util.go b/x/blob/client/cli/util.go new file mode 100644 index 0000000000..f9df3a867e --- /dev/null +++ b/x/blob/client/cli/util.go @@ -0,0 +1,51 @@ +package cli + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/cosmos/cosmos-sdk/codec" +) + +type blobs struct { + Blobs []json.RawMessage +} + +type blobJSON struct { + NamespaceID string + Blob string +} + +func parseSubmitBlobs(cdc codec.Codec, path string) ([]blobJSON, error) { + var content blobs + + rawBlobs, err := os.ReadFile(path) + if err != nil { + return []blobJSON{}, err + } + + fmt.Println(rawBlobs) + + err = json.Unmarshal(rawBlobs, &content) + if err != nil { + return []blobJSON{}, err + } + + fmt.Println(content) + + blobs := make([]blobJSON, len(content.Blobs)) + for i, anyJSON := range content.Blobs { + var blob blobJSON + err := cdc.UnmarshalInterfaceJSON(anyJSON, &blob) + if err != nil { + return []blobJSON{}, err + } + + blobs[i] = blob + } + + fmt.Println(blobs) + + return blobs, nil +}