Skip to content

Commit

Permalink
add file parse for blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
bao1029p committed Nov 19, 2023
1 parent d66bff5 commit a6c4c5e
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
38 changes: 36 additions & 2 deletions x/blob/client/cli/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions x/blob/client/cli/test_blob.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Blobs": [
{
"namespaceID": "0x00010203040506070809",
"blob": "0x48656c6c6f2c20576f726c6421"
},
{
"namespaceID": "0x00010203040506070809",
"blob": "0x48656c6c6f2c20576f726c6421"
}
]
}
51 changes: 51 additions & 0 deletions x/blob/client/cli/util.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a6c4c5e

Please sign in to comment.