From ebd733d1db2e75d849a637f68587534447ceccd0 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Mon, 8 Jan 2024 14:21:29 -0500 Subject: [PATCH] fix: CLI help for PayForBlob (#2991) Closes https://github.com/celestiaorg/celestia-app/issues/2990 ## Testing ```shell $ ./build/celestia-appd tx blob PayForBlob --help Pay for data blob(s) to be published to Celestia. To publish a single blob, specify the namespaceID and blob via CLI arguments. To publish multiple blobs, use the --input-file flag with the path to a JSON file. The JSON should look like: { "Blobs": [ { "namespaceID": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" }, { "namespaceID": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" } ] } The namespaceID is the user-specifiable portion of a version 0 namespace. The namespaceID must be a hex encoded string of 10 bytes. The blob must be a hex encoded string of non-zero length. Usage: celestia-appd tx blob PayForBlobs [namespaceID blob] [flags] ``` --- x/blob/client/cli/payforblob.go | 54 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 3b9c7a9bb6..c656151906 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -4,7 +4,6 @@ import ( "bufio" "encoding/hex" "encoding/json" - "errors" "fmt" "os" "path/filepath" @@ -31,15 +30,18 @@ const ( // submitting a PayForBlob. FlagNamespaceVersion = "namespace-version" - // FlagFileInput allows the user to provide file path to the json file - // for submitting multiple blobs. + // FlagFileInput allows the user to provide the path to a JSON file for + // submitting multiple blobs. FlagFileInput = "input-file" + + // FileInputExtension is the only file extension supported for + // FlagFileInput. + FileInputExtension = ".json" ) func CmdPayForBlob() *cobra.Command { cmd := &cobra.Command{ Use: "pay-for-blob [namespaceID blob]", - // This example command can be run in a new terminal after running single-node.sh Example: "celestia-appd tx blob pay-for-blob 0x00010203040506070809 0x48656c6c6f2c20576f726c6421 \\\n" + "\t--chain-id private \\\n" + "\t--from validator \\\n" + @@ -52,27 +54,28 @@ func CmdPayForBlob() *cobra.Command { "\t--keyring-backend test \\\n" + "\t--fees 21000utia \\\n" + "\t--yes \n", - Short: "Pay for a data blob(s) to be published to Celestia.", - Long: "Pay for a data blob(s) to be published to Celestia.\n" + - "User can use namespaceID and blob as argument for single blob submission \n" + - "or use --input-file flag with the path to a json file for multiple blobs submission, \n" + - `where the json file contains: - + Short: "Pay for data blob(s) to be published to Celestia.", + Long: `Pay for data blob(s) to be published to Celestia. +To publish a single blob, specify the namespaceID and blob via CLI arguments. +To publish multiple blobs, use the --input-file flag with the path to a JSON file. +The JSON should look like: + +{ + "Blobs": [ { - "Blobs": [ - { - "namespaceID": "0x00010203040506070809", - "blob": "0x48656c6c6f2c20576f726c6421" - }, - { - "namespaceID": "0x00010203040506070809", - "blob": "0x48656c6c6f2c20576f726c6421" - } - ] + "namespaceID": "0x00010203040506070809", + "blob": "0x48656c6c6f2c20576f726c6421" + }, + { + "namespaceID": "0x00010203040506070809", + "blob": "0x48656c6c6f2c20576f726c6421" } + ] +} - namespaceID is the user-specifiable portion of a version 0 namespace. It must be a hex encoded string of 10 bytes.\n - blob must be a hex encoded string of any length.\n +The namespaceID is the user-specifiable portion of a version 0 namespace. +The namespaceID must be a hex encoded string of 10 bytes. +The blob must be a hex encoded string of non-zero length. `, Aliases: []string{"pay-for-blobs", "PayForBlobs", "PayForBlob"}, Args: func(cmd *cobra.Command, args []string) error { @@ -81,17 +84,16 @@ func CmdPayForBlob() *cobra.Command { return err } - // If there is a file path input we'll check for the file extension if path != "" { - if filepath.Ext(path) != ".json" { - return fmt.Errorf("invalid file extension, require json got %s", filepath.Ext(path)) + if filepath.Ext(path) != FileInputExtension { + return fmt.Errorf("invalid file extension %v. The only supported extension is %s", filepath.Ext(path), FileInputExtension) } return nil } if len(args) < 2 { - return errors.New("pay-for-blob requires two arguments: namespaceID and blob") + return fmt.Errorf("pay-for-blob requires two arguments if %s isn't provided: namespaceID and blob", FlagFileInput) } return nil