From d332413affd0488c16be6567c7bc983d3d001b8e Mon Sep 17 00:00:00 2001 From: bao1029p Date: Thu, 2 Nov 2023 01:18:17 +0700 Subject: [PATCH 01/23] allow submit multiple blobs in CLI --- cmd/celestia-appd/cmd/download-genesis.go | 23 +++++------ x/blob/client/cli/payforblob.go | 48 +++++++++++++---------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/cmd/celestia-appd/cmd/download-genesis.go b/cmd/celestia-appd/cmd/download-genesis.go index ced81d352f..cc90da8824 100644 --- a/cmd/celestia-appd/cmd/download-genesis.go +++ b/cmd/celestia-appd/cmd/download-genesis.go @@ -28,9 +28,9 @@ func downloadGenesisCommand() *cobra.Command { Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { chainID := getChainIDOrDefault(args) - if !isKnownChainID(chainID) { - return fmt.Errorf("unknown chain-id: %s. Must be: celestia, mocha-4, or arabica-10", chainID) - } + // if !isKnownChainID(chainID) { + // return fmt.Errorf("unknown chain-id: %s. Must be: celestia, mocha-4, or arabica-10", chainID) + // } outputFile := server.GetServerContextFromCmd(cmd).Config.GenesisFile() fmt.Printf("Downloading genesis file for %s to %s\n", chainID, outputFile) @@ -41,20 +41,20 @@ func downloadGenesisCommand() *cobra.Command { fmt.Printf("Downloaded genesis file for %s to %s\n", chainID, outputFile) // Compute SHA-256 hash of the downloaded file - hash, err := computeSha256(outputFile) + _, err := computeSha256(outputFile) if err != nil { return fmt.Errorf("error computing sha256 hash: %s", err) } // Compare computed hash against known hash - knownHash, ok := chainIDToSha256[chainID] - if !ok { - return fmt.Errorf("unknown chain-id: %s", chainID) - } + // knownHash, ok := chainIDToSha256[chainID] + // if !ok { + // return fmt.Errorf("unknown chain-id: %s", chainID) + // } - if hash != knownHash { - return fmt.Errorf("sha256 hash mismatch: got %s, expected %s", hash, knownHash) - } + // if hash != knownHash { + // return fmt.Errorf("sha256 hash mismatch: got %s, expected %s", hash, knownHash) + // } fmt.Printf("SHA-256 hash verified for %s\n", chainID) return nil @@ -96,6 +96,7 @@ func contains(slice []string, s string) bool { // downloadFile will download a URL to a local file. func downloadFile(filepath string, url string) error { resp, err := http.Get(url) + fmt.Println(resp.StatusCode) if err != nil { return err } diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 52ebff4cf6..70d3087672 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 blob", + Use: "PayForBlobs namespaceID 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" + @@ -40,16 +40,14 @@ func CmdPayForBlob() *cobra.Command { "\t--keyring-backend test \\\n" + "\t--fees 21000utia \\\n" + "\t--yes", - Short: "Pay for a data blob to be published to Celestia.", - Long: "Pay for a data blob to be published to Celestia.\n" + + Short: "Pay for a data blobs to be published to Celestia.", + Long: "Pay for a data blobs to be published to Celestia.\n" + "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" + - // TODO: allow for more than one blob to be sumbmitted via the CLI - "This command currently only supports a single blob per invocation.\n", + "blob must be a hex encoded string of any length.\n", Aliases: []string{"PayForBlob"}, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 2 { - return fmt.Errorf("PayForBlobs requires two arguments: namespaceID and blob") + return fmt.Errorf("PayForBlobs requires two arguments or more: namespaceID and blobs") } return nil }, @@ -68,19 +66,27 @@ func CmdPayForBlob() *cobra.Command { return err } - arg1 := strings.TrimPrefix(args[1], "0x") - rawblob, err := hex.DecodeString(arg1) - if err != nil { - return fmt.Errorf("failure to decode hex blob: %w", err) - } - - shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion) - blob, err := types.NewBlob(namespace, rawblob, shareVersion) - if err != nil { - return err + var blobs []*blob.Blob + // Skip the first argument as it's the namespaceID + blobArgs := args[1:] + for i := range blobArgs { + arg := strings.TrimPrefix(blobArgs[i], "0x") + rawblob, err := hex.DecodeString(arg) + if err != nil { + fmt.Printf("failure to decode hex blob, argument value %s: %s", blobArgs[i], err.Error()) + continue + } + + shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion) + blob, err := types.NewBlob(namespace, rawblob, shareVersion) + if err != nil { + fmt.Printf("failure to create blob from raw blob, argument value %s: %s", blobArgs[i], err.Error()) + continue + } + blobs = append(blobs, blob) } - return broadcastPFB(cmd, blob) + return broadcastPFB(cmd, blobs...) }, } @@ -108,7 +114,7 @@ func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, // broadcastPFB creates the new PFB message type that will later be broadcast to tendermint nodes // this private func is used in CmdPayForBlob -func broadcastPFB(cmd *cobra.Command, b *blob.Blob) error { +func broadcastPFB(cmd *cobra.Command, b ...*blob.Blob) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -116,7 +122,7 @@ func broadcastPFB(cmd *cobra.Command, b *blob.Blob) error { // TODO: allow the user to override the share version via a new flag // See https://github.com/celestiaorg/celestia-app/issues/1041 - pfbMsg, err := types.NewMsgPayForBlobs(clientCtx.FromAddress.String(), b) + pfbMsg, err := types.NewMsgPayForBlobs(clientCtx.FromAddress.String(), b...) if err != nil { return err } @@ -131,7 +137,7 @@ func broadcastPFB(cmd *cobra.Command, b *blob.Blob) error { return err } - blobTx, err := blob.MarshalBlobTx(txBytes, b) + blobTx, err := blob.MarshalBlobTx(txBytes, b...) if err != nil { return err } From d66bff5e548df36a442d7fb2fe7002706de79aa5 Mon Sep 17 00:00:00 2001 From: bao1029p Date: Wed, 8 Nov 2023 03:30:29 +0700 Subject: [PATCH 02/23] add print log when fail --- x/blob/client/cli/payforblob.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 70d3087672..0cb82e69a5 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -73,14 +73,14 @@ func CmdPayForBlob() *cobra.Command { arg := strings.TrimPrefix(blobArgs[i], "0x") rawblob, err := hex.DecodeString(arg) if err != nil { - fmt.Printf("failure to decode hex blob, argument value %s: %s", blobArgs[i], err.Error()) + fmt.Printf("failure to decode hex blob value %s: %s", blobArgs[i], err.Error()) continue } shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion) blob, err := types.NewBlob(namespace, rawblob, shareVersion) if err != nil { - fmt.Printf("failure to create blob from raw blob, argument value %s: %s", blobArgs[i], err.Error()) + fmt.Printf("failure to create blob with hex blob value %s: %s", blobArgs[i], err.Error()) continue } blobs = append(blobs, blob) From a6c4c5e7d13a891e9c859270d2f508e2aa3230ab Mon Sep 17 00:00:00 2001 From: bao1029p Date: Mon, 20 Nov 2023 06:14:45 +0700 Subject: [PATCH 03/23] add file parse for blobs --- x/blob/client/cli/payforblob.go | 38 ++++++++++++++++++++++-- x/blob/client/cli/test_blob.json | 12 ++++++++ x/blob/client/cli/util.go | 51 ++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 x/blob/client/cli/test_blob.json create mode 100644 x/blob/client/cli/util.go 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 +} From 488c541cf96aaac8bdef3009a84329533e7b317a Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Wed, 29 Nov 2023 15:36:59 +0700 Subject: [PATCH 04/23] debugging --- .DS_Store | Bin 0 -> 8196 bytes x/.DS_Store | Bin 0 -> 6148 bytes x/blob/.DS_Store | Bin 0 -> 6148 bytes x/blob/client/.DS_Store | Bin 0 -> 6148 bytes x/blob/client/cli/util.go | 17 +++++++---------- 5 files changed, 7 insertions(+), 10 deletions(-) create mode 100644 .DS_Store create mode 100644 x/.DS_Store create mode 100644 x/blob/.DS_Store create mode 100644 x/blob/client/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2e4588bca17ea0eacb4b83de5c1a8dc2dc8fa476 GIT binary patch literal 8196 zcmeI1%We}f6o!wR+k^_p0;IA)8i{RHTFR|rlcw#W5(TNLU;!v(k`RVW#!+TMimIaQ z;Td=Z*1QPs!V3OlPs`Y8H(j7g*pYo^?Ef6w-?(u-AtKS3bk~TMh{!``TU$hNM&fqP zb7>)~VP^qh1>`1`>} zW?RqfOk4HUfkGVtV2h|$3D@eMe^{R@VC$KkX^R>pp?T+?(rk`o6 z-ASmP5hv?eWG57n9X*7vm0h(Dyr)Qj7ezNF%Zh~Bl7Uo2$-y$|P9zbsXmx_X?{qp=xrp>Jug z(Dq*~=E$SynLflkzU6onv-pXnV-9&;nfi#mf)UHPF*Ad+vK|KP;j;&M_KIbSD5v>PxYL1wgKwekkS>Y4e5fz2JQqZ9pi&upa3yNTx zjI#G|KY~#dCh6+xPq9!amdX{c;w^e_n(yVbnYPnO(rAxg@!f%xQE+nI4qk-4X{&Z) zOU7wCjC*6{5O#ZzynY$RT{&&YN!(48Z&NpTRj=Br-8wp2TYvm$*PFMB)Y5A2K>F{H797i(dKUXnRjVB&%|5rF% z;RsxqKtX#hEyC`c|Nj5N@tvb1;0RoP0;0Ix+-_i;C%dsdWIk*A$ZwH3v2LcVazUYv jfgc5S>j8aT+1z01_OKEOCt>B|xdTm{1N}F@gi2U}ICPI^M{3$RUd4JN+*` z_mA|yaDq3xo2qsJaYBghNV{)8=EL)(-SrTWm@MKQq5%=PXpGJ_x}ON|bGslNv%;H# zeZ0uz$0(B#=IqdlWxz7nNdnPRZTr{ zyQSBsIlL9@kv_p9LxhBimKA^fdGCE_NjijP{u`@rEvqgq5bZ!kiz#Ww=y0~@V_<6K zGBIF|hTFePN!wg41D1h5Vu0@l4~@|`SZh>Q2Rc;(039qV!C3wJ13g{<`UY!_Sb+#_ z3e={;lo-NP4nmt_-#7ZTMr}?)MTQ>}S(pk%n8HJNN}YtS(e{=B%RrNXEj=CZ`~Upc z^?%dI&MX6#f&YpD;p_+d6QpF`)(gq;TkD~HKx1LOTB9;SXP#p<;HUT|niA}JJOKIz TYmHce*dGB!gY7H>f0cnB&dZp( literal 0 HcmV?d00001 diff --git a/x/blob/.DS_Store b/x/blob/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..19ab4ffe3a52ef2cfe39c295c8aa8444bd1ac844 GIT binary patch literal 6148 zcmeHKO>fgM7=GPlUAlqj0VFseMdDhOjxu24Qc8E=z-2*j092YK+M;D~)udFYs+2qY z2L1wP{s{kt6Fjf&Nl8}N4I%I=*^fWo$Iko2v11|Y(|i)A(M%EIFoMgQS8*E3#Zb=EFjHJ#cepLLHE!QpE_eHn9(KI`{@$wNE%)#B zI^O;MgVn0#-neu3@!|M1IZNe76(R|2WXi4@JcmyxR0MeM&(cJu$7p9xlR}aZs7uEr ztKx{;=r0So4IdUUq6~6oYdPO*oNG1Cm|qyU`C2wdQ=Rcdz2p!tFrwKyPJ<&UbDDGt z--xEns76G*G(MM>MvKl6eMoaP{u&L47f6+HNCy~aM9+a;@WbjHO0_a$6S00!Pm|R= zIoh%(s@5)7z$|rl=W*d&nw6ofe*J+SHvk6) z3yo-j2~7oRsxVg!VQvmW)6qXL{)I+OC!uD>IA&&HZYaWBJcOs*NendF+$vxds4B3b zt8G624}N|Buaa!dDqt1(rxXy*$R7<6k~v#11jlEshx87Kjr|IZih|4>$Ev_b@l7OU a=<~P$92hJ#q6KDu1e6RmvkLrC1%3j++s^+0 literal 0 HcmV?d00001 diff --git a/x/blob/client/.DS_Store b/x/blob/client/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..08da558a8a8ba0b6e40630d8ac0d2d5278884fdc GIT binary patch literal 6148 zcmeHK!A=`75FIBeI6{?jC{nqt#5ID@w6uuJ65zm>AM?H&Gw zGe5%bz#H43rnE``gvu0h)8ut{SBf95osu6rHzlpLfp`?rIhwL2?zA>Jz<=NEpLZ{mwI$%|I&R#mFCHw%k; zQ7`G!=%*P+MXwm;o!;;(w~mZS?F&|~Qk7Kn18Ko_cfilKb& zpjrN_kD5WqU49qf6b{Se3zKY*Nt-u~|1sHlP9l`>Uhk&I) K3Sr Date: Wed, 29 Nov 2023 16:12:03 +0700 Subject: [PATCH 05/23] add new proto for blobJSON --- pkg/blob/blob.pb.go | 262 +++++++++++++++++++++++-- proto/celestia/core/v1/blob/blob.proto | 10 +- x/blob/client/cli/payforblob.go | 92 ++++----- x/blob/client/cli/test_blob.json | 4 +- x/blob/client/cli/util.go | 27 +-- 5 files changed, 301 insertions(+), 94 deletions(-) diff --git a/pkg/blob/blob.pb.go b/pkg/blob/blob.pb.go index 3bd6447adb..002af03d4a 100644 --- a/pkg/blob/blob.pb.go +++ b/pkg/blob/blob.pb.go @@ -157,34 +157,88 @@ func (m *BlobTx) GetTypeId() string { return "" } +type BlobJson struct { + NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` + Blob string `protobuf:"bytes,2,opt,name=blob,proto3" json:"blob,omitempty"` +} + +func (m *BlobJson) Reset() { *m = BlobJson{} } +func (m *BlobJson) String() string { return proto.CompactTextString(m) } +func (*BlobJson) ProtoMessage() {} +func (*BlobJson) Descriptor() ([]byte, []int) { + return fileDescriptor_c6da8a12c2dbf976, []int{2} +} +func (m *BlobJson) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlobJson) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlobJson.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BlobJson) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlobJson.Merge(m, src) +} +func (m *BlobJson) XXX_Size() int { + return m.Size() +} +func (m *BlobJson) XXX_DiscardUnknown() { + xxx_messageInfo_BlobJson.DiscardUnknown(m) +} + +var xxx_messageInfo_BlobJson proto.InternalMessageInfo + +func (m *BlobJson) GetNamespaceId() string { + if m != nil { + return m.NamespaceId + } + return "" +} + +func (m *BlobJson) GetBlob() string { + if m != nil { + return m.Blob + } + return "" +} + func init() { proto.RegisterType((*Blob)(nil), "celestia.core.v1.blob.Blob") proto.RegisterType((*BlobTx)(nil), "celestia.core.v1.blob.BlobTx") + proto.RegisterType((*BlobJson)(nil), "celestia.core.v1.blob.BlobJson") } func init() { proto.RegisterFile("celestia/core/v1/blob/blob.proto", fileDescriptor_c6da8a12c2dbf976) } var fileDescriptor_c6da8a12c2dbf976 = []byte{ - // 289 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, - 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0xca, 0xc9, - 0x4f, 0x02, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xa2, 0x30, 0x15, 0x7a, 0x20, 0x15, - 0x7a, 0x65, 0x86, 0x7a, 0x20, 0x49, 0xa5, 0x7e, 0x46, 0x2e, 0x16, 0xa7, 0x9c, 0xfc, 0x24, 0x21, - 0x45, 0x2e, 0x9e, 0xbc, 0xc4, 0xdc, 0xd4, 0xe2, 0x82, 0xc4, 0xe4, 0xd4, 0xf8, 0xcc, 0x14, 0x09, - 0x46, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x6e, 0xb8, 0x98, 0x67, 0x8a, 0x90, 0x10, 0x17, 0x4b, 0x4a, - 0x62, 0x49, 0xa2, 0x04, 0x13, 0x58, 0x0a, 0xcc, 0x16, 0x52, 0xe6, 0xe2, 0x2d, 0xce, 0x48, 0x2c, - 0x4a, 0x8d, 0x2f, 0x4b, 0x2d, 0x2a, 0xce, 0xcc, 0xcf, 0x93, 0x60, 0x56, 0x60, 0xd4, 0xe0, 0x0d, - 0xe2, 0x01, 0x0b, 0x86, 0x41, 0xc4, 0x84, 0xb4, 0xb9, 0x04, 0x11, 0x66, 0xc3, 0x14, 0xb2, 0x80, - 0x15, 0x0a, 0xc0, 0x25, 0xa0, 0x8a, 0x95, 0x52, 0xb8, 0xd8, 0x40, 0x0e, 0x0a, 0xa9, 0x10, 0xe2, - 0xe3, 0x62, 0x2a, 0xa9, 0x80, 0x3a, 0x84, 0xa9, 0xa4, 0x42, 0xc8, 0x90, 0x8b, 0x15, 0xe4, 0xe6, - 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x69, 0x3d, 0xac, 0x5e, 0xd2, 0x03, 0xe9, 0x0e, - 0x82, 0xa8, 0x14, 0x12, 0xe7, 0x62, 0x2f, 0xa9, 0x2c, 0x00, 0x7b, 0x08, 0xe4, 0x30, 0xce, 0x20, - 0x36, 0x10, 0xd7, 0x33, 0xc5, 0xc9, 0xed, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, - 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, - 0xa2, 0x74, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x61, 0x16, 0xe4, - 0x17, 0xa5, 0xc3, 0xd9, 0xba, 0x89, 0x05, 0x05, 0xfa, 0x05, 0xd9, 0xe9, 0xe0, 0xc0, 0x4d, 0x62, - 0x03, 0x87, 0xae, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x06, 0x11, 0x3d, 0x47, 0x81, 0x01, 0x00, - 0x00, + // 312 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x4b, 0xfb, 0x30, + 0x18, 0xc6, 0x97, 0x6e, 0xff, 0xfd, 0x5d, 0xb6, 0x89, 0x06, 0xc4, 0x82, 0x10, 0xea, 0xbc, 0x14, + 0xd4, 0x94, 0xea, 0x27, 0x70, 0x07, 0x61, 0x1e, 0x8b, 0x78, 0xf0, 0x32, 0xd2, 0x36, 0x74, 0xc5, + 0xae, 0x09, 0x4d, 0x2c, 0xf5, 0x53, 0xe8, 0xc7, 0xf2, 0xb8, 0xa3, 0x47, 0x69, 0xbf, 0x88, 0x24, + 0x5b, 0xeb, 0xc1, 0x5d, 0xca, 0xdb, 0xe7, 0xf9, 0xe5, 0xe5, 0x79, 0x78, 0xa1, 0x13, 0xb1, 0x8c, + 0x49, 0x95, 0x52, 0x2f, 0xe2, 0x05, 0xf3, 0x4a, 0xdf, 0x0b, 0x33, 0x1e, 0x9a, 0x0f, 0x11, 0x05, + 0x57, 0x1c, 0x9d, 0xb4, 0x04, 0xd1, 0x04, 0x29, 0x7d, 0xa2, 0xcd, 0xd9, 0x3b, 0x80, 0x83, 0x79, + 0xc6, 0x43, 0x74, 0x0e, 0x27, 0x39, 0x5d, 0x33, 0x29, 0x68, 0xc4, 0x96, 0x69, 0x6c, 0x03, 0x07, + 0xb8, 0x93, 0x60, 0xdc, 0x69, 0x8b, 0x18, 0x21, 0x38, 0x88, 0xa9, 0xa2, 0xb6, 0x65, 0x2c, 0x33, + 0xa3, 0x0b, 0x38, 0x95, 0x2b, 0x5a, 0xb0, 0x65, 0xc9, 0x0a, 0x99, 0xf2, 0xdc, 0xee, 0x3b, 0xc0, + 0x9d, 0x06, 0x13, 0x23, 0x3e, 0x6d, 0x35, 0x74, 0x09, 0x8f, 0x7f, 0x77, 0xb7, 0xe0, 0xc0, 0x80, + 0x47, 0x9d, 0xb1, 0x83, 0x67, 0x31, 0x1c, 0xea, 0x40, 0x8f, 0x15, 0x3a, 0x84, 0x96, 0xaa, 0x76, + 0x41, 0x2c, 0x55, 0x21, 0x1f, 0xfe, 0xd3, 0x99, 0xa5, 0x6d, 0x39, 0x7d, 0x77, 0x7c, 0x73, 0x46, + 0xf6, 0x56, 0x22, 0xfa, 0x75, 0xb0, 0x25, 0xd1, 0x29, 0xfc, 0xaf, 0xde, 0x84, 0x29, 0xa4, 0x83, + 0x8d, 0x82, 0xa1, 0xfe, 0x5d, 0xc4, 0xb3, 0x3b, 0x78, 0xa0, 0xb9, 0x07, 0xc9, 0xf3, 0xbd, 0xd5, + 0x47, 0x7f, 0xaa, 0xeb, 0x85, 0xa6, 0xfa, 0x28, 0x30, 0xf3, 0xfc, 0xfe, 0xb3, 0xc6, 0x60, 0x53, + 0x63, 0xf0, 0x5d, 0x63, 0xf0, 0xd1, 0xe0, 0xde, 0xa6, 0xc1, 0xbd, 0xaf, 0x06, 0xf7, 0x9e, 0xaf, + 0x92, 0x54, 0xad, 0x5e, 0x43, 0x12, 0xf1, 0xb5, 0xd7, 0x66, 0xe4, 0x45, 0xd2, 0xcd, 0xd7, 0x54, + 0x08, 0x4f, 0xbc, 0x24, 0xe6, 0x3e, 0xe1, 0xd0, 0x1c, 0xe8, 0xf6, 0x27, 0x00, 0x00, 0xff, 0xff, + 0x88, 0x3e, 0xa3, 0xdb, 0xc4, 0x01, 0x00, 0x00, } func (m *Blob) Marshal() (dAtA []byte, err error) { @@ -285,6 +339,43 @@ func (m *BlobTx) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *BlobJson) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *BlobJson) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlobJson) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Blob) > 0 { + i -= len(m.Blob) + copy(dAtA[i:], m.Blob) + i = encodeVarintBlob(dAtA, i, uint64(len(m.Blob))) + i-- + dAtA[i] = 0x12 + } + if len(m.NamespaceId) > 0 { + i -= len(m.NamespaceId) + copy(dAtA[i:], m.NamespaceId) + i = encodeVarintBlob(dAtA, i, uint64(len(m.NamespaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintBlob(dAtA []byte, offset int, v uint64) int { offset -= sovBlob(v) base := offset @@ -342,6 +433,23 @@ func (m *BlobTx) Size() (n int) { return n } +func (m *BlobJson) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.NamespaceId) + if l > 0 { + n += 1 + l + sovBlob(uint64(l)) + } + l = len(m.Blob) + if l > 0 { + n += 1 + l + sovBlob(uint64(l)) + } + return n +} + func sovBlob(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -654,6 +762,120 @@ func (m *BlobTx) Unmarshal(dAtA []byte) error { } return nil } +func (m *BlobJson) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlob + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: BlobJson: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlobJson: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NamespaceId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlob + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthBlob + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBlob + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NamespaceId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Blob", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlob + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthBlob + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBlob + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Blob = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBlob(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBlob + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipBlob(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/proto/celestia/core/v1/blob/blob.proto b/proto/celestia/core/v1/blob/blob.proto index 41e0620ab7..f3dd6a4322 100644 --- a/proto/celestia/core/v1/blob/blob.proto +++ b/proto/celestia/core/v1/blob/blob.proto @@ -21,4 +21,12 @@ message BlobTx { bytes tx = 1; repeated Blob blobs = 2; string type_id = 3; -} \ No newline at end of file +} + + +// BlobJson define a simple file in JSON format for user to pass in as argument +// in payForBlob CLI. +message BlobJson { + string namespace_id = 1; + string blob = 2; +} diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index dedf56b591..56aed1d06e 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -32,9 +32,9 @@ const ( func CmdPayForBlob() *cobra.Command { cmd := &cobra.Command{ - Use: "PayForBlobs namespaceID path blobs", + Use: "PayForBlobs [path/to/blob.json]", // This example command can be run in a new terminal after running single-node.sh - Example: "celestia-appd tx blob PayForBlobs 0x00010203040506070809 0x48656c6c6f2c20576f726c6421 \\\n" + + Example: "celestia-appd tx blob PayForBlobs path/to/blob.json \\\n" + "\t--chain-id private \\\n" + "\t--from validator \\\n" + "\t--keyring-backend test \\\n" + @@ -42,79 +42,63 @@ func CmdPayForBlob() *cobra.Command { "\t--yes", Short: "Pay for a data blobs to be published to Celestia.", Long: "Pay for a data blobs to be published to Celestia.\n" + - "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", + `Where blob.json contains: + + { + "Blobs": [ + { + "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 + + `, Aliases: []string{"PayForBlob"}, Args: func(cmd *cobra.Command, args []string) error { - if len(args) < 2 { - return fmt.Errorf("PayForBlobs requires two arguments or more: namespaceID and blobs") + if len(args) < 1 { + return fmt.Errorf("PayForBlobs requires one arguments: path to blob.json") } 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 { - return fmt.Errorf("failed to decode hex namespace ID: %w", err) - } namespaceVersion, err := cmd.Flags().GetUint8(FlagNamespaceVersion) - if err != nil { - return err - } - namespace, err := getNamespace(namespaceID, namespaceVersion) - if err != nil { - return err - } + path := args[0] - path := args[1] - - _, err = parseSubmitBlobs(clientCtx.Codec, path) + paresdBlobs, 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[2:] - for i := range blobArgs { - arg := strings.TrimPrefix(blobArgs[i], "0x") - rawblob, err := hex.DecodeString(arg) + for i := range paresdBlobs { + namespaceID, err := hex.DecodeString(strings.TrimPrefix(paresdBlobs[i].NamespaceId, "0x")) + 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", blobArgs[i], err.Error()) + 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", blobArgs[i], err.Error()) + fmt.Printf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) continue } blobs = append(blobs, blob) diff --git a/x/blob/client/cli/test_blob.json b/x/blob/client/cli/test_blob.json index 0223a05d81..e5b400cf01 100644 --- a/x/blob/client/cli/test_blob.json +++ b/x/blob/client/cli/test_blob.json @@ -1,11 +1,11 @@ { "Blobs": [ { - "namespaceID": "0x00010203040506070809", + "namespaceId": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" }, { - "namespaceID": "0x00010203040506070809", + "namespaceId": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" } ] diff --git a/x/blob/client/cli/util.go b/x/blob/client/cli/util.go index 4d89f8b2fa..fa4d0f2df5 100644 --- a/x/blob/client/cli/util.go +++ b/x/blob/client/cli/util.go @@ -2,47 +2,40 @@ package cli import ( "encoding/json" - "fmt" "os" + "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/cosmos/cosmos-sdk/codec" ) +// Define the raw content from the file input. type blobs struct { Blobs []json.RawMessage } -type blobJSON struct { - NamespaceID string - Blob string -} - -func parseSubmitBlobs(cdc codec.Codec, path string) ([]blobJSON, error) { +func parseSubmitBlobs(cdc codec.Codec, path string) ([]blob.BlobJson, error) { var rawBlobs blobs content, err := os.ReadFile(path) if err != nil { - return []blobJSON{}, err + return []blob.BlobJson{}, err } err = json.Unmarshal(content, &rawBlobs) if err != nil { - return []blobJSON{}, err + return []blob.BlobJson{}, err } - blobs := make([]blobJSON, len(rawBlobs.Blobs)) + blobs := make([]blob.BlobJson, len(rawBlobs.Blobs)) for i, anyJSON := range rawBlobs.Blobs { - var blob blobJSON - fmt.Println(anyJSON) - err := cdc.UnmarshalJSON(anyJSON, blob) + var blob blob.BlobJson + err = cdc.UnmarshalJSON(anyJSON, &blob) if err != nil { - return []blobJSON{}, err + break } blobs[i] = blob } - fmt.Println(blobs) - - return blobs, nil + return blobs, err } From 5ff6bce73d5da18d4d630327d82bb3059db62c04 Mon Sep 17 00:00:00 2001 From: bao1029p Date: Wed, 29 Nov 2023 16:41:40 +0700 Subject: [PATCH 06/23] minor clean up --- .DS_Store | Bin 8196 -> 0 bytes cmd/celestia-appd/cmd/download_genesis.go | 23 +++++++++++----------- x/blob/client/cli/test_blob.json | 12 ----------- 3 files changed, 11 insertions(+), 24 deletions(-) delete mode 100644 .DS_Store delete mode 100644 x/blob/client/cli/test_blob.json diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 2e4588bca17ea0eacb4b83de5c1a8dc2dc8fa476..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeI1%We}f6o!wR+k^_p0;IA)8i{RHTFR|rlcw#W5(TNLU;!v(k`RVW#!+TMimIaQ z;Td=Z*1QPs!V3OlPs`Y8H(j7g*pYo^?Ef6w-?(u-AtKS3bk~TMh{!``TU$hNM&fqP zb7>)~VP^qh1>`1`>} zW?RqfOk4HUfkGVtV2h|$3D@eMe^{R@VC$KkX^R>pp?T+?(rk`o6 z-ASmP5hv?eWG57n9X*7vm0h(Dyr)Qj7ezNF%Zh~Bl7Uo2$-y$|P9zbsXmx_X?{qp=xrp>Jug z(Dq*~=E$SynLflkzU6onv-pXnV-9&;nfi#mf)UHPF*Ad+vK|KP;j;&M_KIbSD5v>PxYL1wgKwekkS>Y4e5fz2JQqZ9pi&upa3yNTx zjI#G|KY~#dCh6+xPq9!amdX{c;w^e_n(yVbnYPnO(rAxg@!f%xQE+nI4qk-4X{&Z) zOU7wCjC*6{5O#ZzynY$RT{&&YN!(48Z&NpTRj=Br-8wp2TYvm$*PFMB)Y5A2K>F{H797i(dKUXnRjVB&%|5rF% z;RsxqKtX#hEyC`c|Nj5N@tvb1;0RoP0;0Ix+-_i;C%dsdWIk*A$ZwH3v2LcVazUYv j Date: Wed, 29 Nov 2023 16:45:21 +0700 Subject: [PATCH 07/23] minor --- x/.DS_Store | Bin 6148 -> 0 bytes x/blob/.DS_Store | Bin 6148 -> 0 bytes x/blob/client/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 x/.DS_Store delete mode 100644 x/blob/.DS_Store delete mode 100644 x/blob/client/.DS_Store diff --git a/x/.DS_Store b/x/.DS_Store deleted file mode 100644 index c1160af496325d4b484d6078a381c742e3f18706..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKO>fgc5S>j8aT+1z01_OKEOCt>B|xdTm{1N}F@gi2U}ICPI^M{3$RUd4JN+*` z_mA|yaDq3xo2qsJaYBghNV{)8=EL)(-SrTWm@MKQq5%=PXpGJ_x}ON|bGslNv%;H# zeZ0uz$0(B#=IqdlWxz7nNdnPRZTr{ zyQSBsIlL9@kv_p9LxhBimKA^fdGCE_NjijP{u`@rEvqgq5bZ!kiz#Ww=y0~@V_<6K zGBIF|hTFePN!wg41D1h5Vu0@l4~@|`SZh>Q2Rc;(039qV!C3wJ13g{<`UY!_Sb+#_ z3e={;lo-NP4nmt_-#7ZTMr}?)MTQ>}S(pk%n8HJNN}YtS(e{=B%RrNXEj=CZ`~Upc z^?%dI&MX6#f&YpD;p_+d6QpF`)(gq;TkD~HKx1LOTB9;SXP#p<;HUT|niA}JJOKIz TYmHce*dGB!gY7H>f0cnB&dZp( diff --git a/x/blob/.DS_Store b/x/blob/.DS_Store deleted file mode 100644 index 19ab4ffe3a52ef2cfe39c295c8aa8444bd1ac844..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKO>fgM7=GPlUAlqj0VFseMdDhOjxu24Qc8E=z-2*j092YK+M;D~)udFYs+2qY z2L1wP{s{kt6Fjf&Nl8}N4I%I=*^fWo$Iko2v11|Y(|i)A(M%EIFoMgQS8*E3#Zb=EFjHJ#cepLLHE!QpE_eHn9(KI`{@$wNE%)#B zI^O;MgVn0#-neu3@!|M1IZNe76(R|2WXi4@JcmyxR0MeM&(cJu$7p9xlR}aZs7uEr ztKx{;=r0So4IdUUq6~6oYdPO*oNG1Cm|qyU`C2wdQ=Rcdz2p!tFrwKyPJ<&UbDDGt z--xEns76G*G(MM>MvKl6eMoaP{u&L47f6+HNCy~aM9+a;@WbjHO0_a$6S00!Pm|R= zIoh%(s@5)7z$|rl=W*d&nw6ofe*J+SHvk6) z3yo-j2~7oRsxVg!VQvmW)6qXL{)I+OC!uD>IA&&HZYaWBJcOs*NendF+$vxds4B3b zt8G624}N|Buaa!dDqt1(rxXy*$R7<6k~v#11jlEshx87Kjr|IZih|4>$Ev_b@l7OU a=<~P$92hJ#q6KDu1e6RmvkLrC1%3j++s^+0 diff --git a/x/blob/client/.DS_Store b/x/blob/client/.DS_Store deleted file mode 100644 index 08da558a8a8ba0b6e40630d8ac0d2d5278884fdc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!A=`75FIBeI6{?jC{nqt#5ID@w6uuJ65zm>AM?H&Gw zGe5%bz#H43rnE``gvu0h)8ut{SBf95osu6rHzlpLfp`?rIhwL2?zA>Jz<=NEpLZ{mwI$%|I&R#mFCHw%k; zQ7`G!=%*P+MXwm;o!;;(w~mZS?F&|~Qk7Kn18Ko_cfilKb& zpjrN_kD5WqU49qf6b{Se3zKY*Nt-u~|1sHlP9l`>Uhk&I) K3Sr Date: Wed, 29 Nov 2023 18:47:21 +0700 Subject: [PATCH 08/23] fix testcase --- x/blob/client/testutil/integration_test.go | 45 +++++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 0674189940..aff242e1c6 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/testutil" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" @@ -63,11 +64,39 @@ func (s *IntegrationTestSuite) TearDownSuite() { func (s *IntegrationTestSuite) TestSubmitPayForBlob() { require := s.Require() val := s.network.Validators[0] - hexNamespace := hex.EncodeToString(appns.RandomBlobNamespaceID()) - invalidNamespaceID := hex.EncodeToString(bytes.Repeat([]byte{0}, 8)) // invalid because ID is expected to be 10 bytes hexBlob := "0204033704032c0b162109000908094d425837422c2116" + validBlob := fmt.Sprintf(` + { + "Blobs": [ + { + "namespaceId": "%s", + "blob": "%s" + }, + { + "namespaceId": "%s", + "blob": "%s" + } + ] + } + `, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob) + validPropFile := testutil.WriteToNewTempFile(s.T(), validBlob) + + invalidBlob := fmt.Sprintf(` + "Blobs": [ + { + "namespaceId": "%s", + "blob": "%s" + }, + { + "namespaceId": "%s", + "blob": "%s" + } + ] + `, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob) + invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidBlob) + testCases := []struct { name string args []string @@ -78,8 +107,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { name: "valid transaction", args: []string{ - hexNamespace, - hexBlob, + validPropFile.Name(), fmt.Sprintf("--from=%s", username), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), @@ -92,8 +120,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { name: "unsupported share version", args: []string{ - hexNamespace, - hexBlob, + validPropFile.Name(), fmt.Sprintf("--from=%s", username), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), @@ -107,8 +134,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { name: "invalid namespace ID", args: []string{ - invalidNamespaceID, - hexBlob, + invalidPropFile.Name(), fmt.Sprintf("--from=%s", username), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), @@ -121,8 +147,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { name: "invalid namespace version", args: []string{ - hexNamespace, - hexBlob, + validPropFile.Name(), fmt.Sprintf("--from=%s", username), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), From c978ada3f7aa3ad368341ece42339f749f92464e Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Wed, 29 Nov 2023 19:00:31 +0700 Subject: [PATCH 09/23] minor --- x/blob/client/testutil/integration_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 90b3555b5f..50e575602a 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -79,16 +79,18 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { validPropFile := testutil.WriteToNewTempFile(s.T(), validBlob) invalidBlob := fmt.Sprintf(` - "Blobs": [ - { - "namespaceId": "%s", - "blob": "%s" - }, - { - "namespaceId": "%s", - "blob": "%s" - } - ] + { + "Blobs": [ + { + "namespaceId": "%s", + "blob": "%s" + }, + { + "namespaceId": "%s", + "blob": "%s" + } + ] + } `, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob) invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidBlob) From db3647e30ea3c2a86e9813906e149a43b5769eec Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 1 Dec 2023 00:29:58 +0700 Subject: [PATCH 10/23] resolve requested changes --- pkg/blob/blob.pb.go | 262 ++----------------------- proto/celestia/core/v1/blob/blob.proto | 7 - x/blob/client/cli/payforblob.go | 12 +- x/blob/client/cli/util.go | 27 +-- 4 files changed, 38 insertions(+), 270 deletions(-) diff --git a/pkg/blob/blob.pb.go b/pkg/blob/blob.pb.go index 002af03d4a..3bd6447adb 100644 --- a/pkg/blob/blob.pb.go +++ b/pkg/blob/blob.pb.go @@ -157,88 +157,34 @@ func (m *BlobTx) GetTypeId() string { return "" } -type BlobJson struct { - NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"` - Blob string `protobuf:"bytes,2,opt,name=blob,proto3" json:"blob,omitempty"` -} - -func (m *BlobJson) Reset() { *m = BlobJson{} } -func (m *BlobJson) String() string { return proto.CompactTextString(m) } -func (*BlobJson) ProtoMessage() {} -func (*BlobJson) Descriptor() ([]byte, []int) { - return fileDescriptor_c6da8a12c2dbf976, []int{2} -} -func (m *BlobJson) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BlobJson) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BlobJson.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *BlobJson) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlobJson.Merge(m, src) -} -func (m *BlobJson) XXX_Size() int { - return m.Size() -} -func (m *BlobJson) XXX_DiscardUnknown() { - xxx_messageInfo_BlobJson.DiscardUnknown(m) -} - -var xxx_messageInfo_BlobJson proto.InternalMessageInfo - -func (m *BlobJson) GetNamespaceId() string { - if m != nil { - return m.NamespaceId - } - return "" -} - -func (m *BlobJson) GetBlob() string { - if m != nil { - return m.Blob - } - return "" -} - func init() { proto.RegisterType((*Blob)(nil), "celestia.core.v1.blob.Blob") proto.RegisterType((*BlobTx)(nil), "celestia.core.v1.blob.BlobTx") - proto.RegisterType((*BlobJson)(nil), "celestia.core.v1.blob.BlobJson") } func init() { proto.RegisterFile("celestia/core/v1/blob/blob.proto", fileDescriptor_c6da8a12c2dbf976) } var fileDescriptor_c6da8a12c2dbf976 = []byte{ - // 312 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x4b, 0xfb, 0x30, - 0x18, 0xc6, 0x97, 0x6e, 0xff, 0xfd, 0x5d, 0xb6, 0x89, 0x06, 0xc4, 0x82, 0x10, 0xea, 0xbc, 0x14, - 0xd4, 0x94, 0xea, 0x27, 0x70, 0x07, 0x61, 0x1e, 0x8b, 0x78, 0xf0, 0x32, 0xd2, 0x36, 0x74, 0xc5, - 0xae, 0x09, 0x4d, 0x2c, 0xf5, 0x53, 0xe8, 0xc7, 0xf2, 0xb8, 0xa3, 0x47, 0x69, 0xbf, 0x88, 0x24, - 0x5b, 0xeb, 0xc1, 0x5d, 0xca, 0xdb, 0xe7, 0xf9, 0xe5, 0xe5, 0x79, 0x78, 0xa1, 0x13, 0xb1, 0x8c, - 0x49, 0x95, 0x52, 0x2f, 0xe2, 0x05, 0xf3, 0x4a, 0xdf, 0x0b, 0x33, 0x1e, 0x9a, 0x0f, 0x11, 0x05, - 0x57, 0x1c, 0x9d, 0xb4, 0x04, 0xd1, 0x04, 0x29, 0x7d, 0xa2, 0xcd, 0xd9, 0x3b, 0x80, 0x83, 0x79, - 0xc6, 0x43, 0x74, 0x0e, 0x27, 0x39, 0x5d, 0x33, 0x29, 0x68, 0xc4, 0x96, 0x69, 0x6c, 0x03, 0x07, - 0xb8, 0x93, 0x60, 0xdc, 0x69, 0x8b, 0x18, 0x21, 0x38, 0x88, 0xa9, 0xa2, 0xb6, 0x65, 0x2c, 0x33, - 0xa3, 0x0b, 0x38, 0x95, 0x2b, 0x5a, 0xb0, 0x65, 0xc9, 0x0a, 0x99, 0xf2, 0xdc, 0xee, 0x3b, 0xc0, - 0x9d, 0x06, 0x13, 0x23, 0x3e, 0x6d, 0x35, 0x74, 0x09, 0x8f, 0x7f, 0x77, 0xb7, 0xe0, 0xc0, 0x80, - 0x47, 0x9d, 0xb1, 0x83, 0x67, 0x31, 0x1c, 0xea, 0x40, 0x8f, 0x15, 0x3a, 0x84, 0x96, 0xaa, 0x76, - 0x41, 0x2c, 0x55, 0x21, 0x1f, 0xfe, 0xd3, 0x99, 0xa5, 0x6d, 0x39, 0x7d, 0x77, 0x7c, 0x73, 0x46, - 0xf6, 0x56, 0x22, 0xfa, 0x75, 0xb0, 0x25, 0xd1, 0x29, 0xfc, 0xaf, 0xde, 0x84, 0x29, 0xa4, 0x83, - 0x8d, 0x82, 0xa1, 0xfe, 0x5d, 0xc4, 0xb3, 0x3b, 0x78, 0xa0, 0xb9, 0x07, 0xc9, 0xf3, 0xbd, 0xd5, - 0x47, 0x7f, 0xaa, 0xeb, 0x85, 0xa6, 0xfa, 0x28, 0x30, 0xf3, 0xfc, 0xfe, 0xb3, 0xc6, 0x60, 0x53, - 0x63, 0xf0, 0x5d, 0x63, 0xf0, 0xd1, 0xe0, 0xde, 0xa6, 0xc1, 0xbd, 0xaf, 0x06, 0xf7, 0x9e, 0xaf, - 0x92, 0x54, 0xad, 0x5e, 0x43, 0x12, 0xf1, 0xb5, 0xd7, 0x66, 0xe4, 0x45, 0xd2, 0xcd, 0xd7, 0x54, - 0x08, 0x4f, 0xbc, 0x24, 0xe6, 0x3e, 0xe1, 0xd0, 0x1c, 0xe8, 0xf6, 0x27, 0x00, 0x00, 0xff, 0xff, - 0x88, 0x3e, 0xa3, 0xdb, 0xc4, 0x01, 0x00, 0x00, + // 289 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, + 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0xca, 0xc9, + 0x4f, 0x02, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xa2, 0x30, 0x15, 0x7a, 0x20, 0x15, + 0x7a, 0x65, 0x86, 0x7a, 0x20, 0x49, 0xa5, 0x7e, 0x46, 0x2e, 0x16, 0xa7, 0x9c, 0xfc, 0x24, 0x21, + 0x45, 0x2e, 0x9e, 0xbc, 0xc4, 0xdc, 0xd4, 0xe2, 0x82, 0xc4, 0xe4, 0xd4, 0xf8, 0xcc, 0x14, 0x09, + 0x46, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x6e, 0xb8, 0x98, 0x67, 0x8a, 0x90, 0x10, 0x17, 0x4b, 0x4a, + 0x62, 0x49, 0xa2, 0x04, 0x13, 0x58, 0x0a, 0xcc, 0x16, 0x52, 0xe6, 0xe2, 0x2d, 0xce, 0x48, 0x2c, + 0x4a, 0x8d, 0x2f, 0x4b, 0x2d, 0x2a, 0xce, 0xcc, 0xcf, 0x93, 0x60, 0x56, 0x60, 0xd4, 0xe0, 0x0d, + 0xe2, 0x01, 0x0b, 0x86, 0x41, 0xc4, 0x84, 0xb4, 0xb9, 0x04, 0x11, 0x66, 0xc3, 0x14, 0xb2, 0x80, + 0x15, 0x0a, 0xc0, 0x25, 0xa0, 0x8a, 0x95, 0x52, 0xb8, 0xd8, 0x40, 0x0e, 0x0a, 0xa9, 0x10, 0xe2, + 0xe3, 0x62, 0x2a, 0xa9, 0x80, 0x3a, 0x84, 0xa9, 0xa4, 0x42, 0xc8, 0x90, 0x8b, 0x15, 0xe4, 0xe6, + 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x69, 0x3d, 0xac, 0x5e, 0xd2, 0x03, 0xe9, 0x0e, + 0x82, 0xa8, 0x14, 0x12, 0xe7, 0x62, 0x2f, 0xa9, 0x2c, 0x00, 0x7b, 0x08, 0xe4, 0x30, 0xce, 0x20, + 0x36, 0x10, 0xd7, 0x33, 0xc5, 0xc9, 0xed, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, + 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, + 0xa2, 0x74, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x61, 0x16, 0xe4, + 0x17, 0xa5, 0xc3, 0xd9, 0xba, 0x89, 0x05, 0x05, 0xfa, 0x05, 0xd9, 0xe9, 0xe0, 0xc0, 0x4d, 0x62, + 0x03, 0x87, 0xae, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x06, 0x11, 0x3d, 0x47, 0x81, 0x01, 0x00, + 0x00, } func (m *Blob) Marshal() (dAtA []byte, err error) { @@ -339,43 +285,6 @@ func (m *BlobTx) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *BlobJson) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *BlobJson) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BlobJson) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Blob) > 0 { - i -= len(m.Blob) - copy(dAtA[i:], m.Blob) - i = encodeVarintBlob(dAtA, i, uint64(len(m.Blob))) - i-- - dAtA[i] = 0x12 - } - if len(m.NamespaceId) > 0 { - i -= len(m.NamespaceId) - copy(dAtA[i:], m.NamespaceId) - i = encodeVarintBlob(dAtA, i, uint64(len(m.NamespaceId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintBlob(dAtA []byte, offset int, v uint64) int { offset -= sovBlob(v) base := offset @@ -433,23 +342,6 @@ func (m *BlobTx) Size() (n int) { return n } -func (m *BlobJson) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.NamespaceId) - if l > 0 { - n += 1 + l + sovBlob(uint64(l)) - } - l = len(m.Blob) - if l > 0 { - n += 1 + l + sovBlob(uint64(l)) - } - return n -} - func sovBlob(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -762,120 +654,6 @@ func (m *BlobTx) Unmarshal(dAtA []byte) error { } return nil } -func (m *BlobJson) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlob - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: BlobJson: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BlobJson: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NamespaceId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlob - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthBlob - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthBlob - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NamespaceId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Blob", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBlob - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthBlob - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthBlob - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Blob = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipBlob(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthBlob - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipBlob(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/proto/celestia/core/v1/blob/blob.proto b/proto/celestia/core/v1/blob/blob.proto index f3dd6a4322..cf193b9691 100644 --- a/proto/celestia/core/v1/blob/blob.proto +++ b/proto/celestia/core/v1/blob/blob.proto @@ -23,10 +23,3 @@ message BlobTx { string type_id = 3; } - -// BlobJson define a simple file in JSON format for user to pass in as argument -// in payForBlob CLI. -message BlobJson { - string namespace_id = 1; - string blob = 2; -} diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 56aed1d06e..ff3c963bfa 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "strings" "github.com/spf13/cobra" @@ -66,6 +67,10 @@ func CmdPayForBlob() *cobra.Command { if len(args) < 1 { return fmt.Errorf("PayForBlobs requires one arguments: path to blob.json") } + path := args[0] + if filepath.Ext(path) != ".json" { + return fmt.Errorf("invalid file extension, require json got %s", filepath.Ext(path)) + } return nil }, RunE: func(cmd *cobra.Command, args []string) error { @@ -91,15 +96,14 @@ func CmdPayForBlob() *cobra.Command { 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 + return fmt.Errorf("failure to decode hex blob value %s: %s", hexStr, err.Error()) } 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 + return fmt.Errorf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) + } blobs = append(blobs, blob) } diff --git a/x/blob/client/cli/util.go b/x/blob/client/cli/util.go index fa4d0f2df5..d38dd8f770 100644 --- a/x/blob/client/cli/util.go +++ b/x/blob/client/cli/util.go @@ -4,38 +4,31 @@ import ( "encoding/json" "os" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/cosmos/cosmos-sdk/codec" ) // Define the raw content from the file input. type blobs struct { - Blobs []json.RawMessage + Blobs []blobJson } -func parseSubmitBlobs(cdc codec.Codec, path string) ([]blob.BlobJson, error) { +type blobJson struct { + NamespaceId string + Blob string +} + +func parseSubmitBlobs(cdc codec.Codec, path string) ([]blobJson, error) { var rawBlobs blobs content, err := os.ReadFile(path) if err != nil { - return []blob.BlobJson{}, err + return []blobJson{}, err } err = json.Unmarshal(content, &rawBlobs) if err != nil { - return []blob.BlobJson{}, err - } - - blobs := make([]blob.BlobJson, len(rawBlobs.Blobs)) - for i, anyJSON := range rawBlobs.Blobs { - var blob blob.BlobJson - err = cdc.UnmarshalJSON(anyJSON, &blob) - if err != nil { - break - } - - blobs[i] = blob + return []blobJson{}, err } - return blobs, err + return rawBlobs.Blobs, err } From 844bd0aaf33a0870ddb971b1c3cdddbb9632d833 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 1 Dec 2023 00:37:10 +0700 Subject: [PATCH 11/23] fix lint --- x/blob/client/cli/payforblob.go | 9 +++++---- x/blob/client/cli/util.go | 14 ++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index ff3c963bfa..5e9a64b0e8 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -74,18 +74,20 @@ func CmdPayForBlob() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) namespaceVersion, err := cmd.Flags().GetUint8(FlagNamespaceVersion) + if err != nil { + return err + } path := args[0] - paresdBlobs, err := parseSubmitBlobs(clientCtx.Codec, path) + paresdBlobs, err := parseSubmitBlobs(path) if err != nil { return err } var blobs []*blob.Blob for i := range paresdBlobs { - namespaceID, err := hex.DecodeString(strings.TrimPrefix(paresdBlobs[i].NamespaceId, "0x")) + namespaceID, err := hex.DecodeString(strings.TrimPrefix(paresdBlobs[i].NamespaceID, "0x")) if err != nil { return fmt.Errorf("failed to decode hex namespace ID: %w", err) } @@ -103,7 +105,6 @@ func CmdPayForBlob() *cobra.Command { blob, err := types.NewBlob(namespace, rawblob, shareVersion) if err != nil { return fmt.Errorf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) - } blobs = append(blobs, blob) } diff --git a/x/blob/client/cli/util.go b/x/blob/client/cli/util.go index d38dd8f770..6c53d0eab7 100644 --- a/x/blob/client/cli/util.go +++ b/x/blob/client/cli/util.go @@ -3,31 +3,29 @@ package cli import ( "encoding/json" "os" - - "github.com/cosmos/cosmos-sdk/codec" ) // Define the raw content from the file input. type blobs struct { - Blobs []blobJson + Blobs []blobJSON } -type blobJson struct { - NamespaceId string +type blobJSON struct { + NamespaceID string Blob string } -func parseSubmitBlobs(cdc codec.Codec, path string) ([]blobJson, error) { +func parseSubmitBlobs(path string) ([]blobJSON, error) { var rawBlobs blobs content, err := os.ReadFile(path) if err != nil { - return []blobJson{}, err + return []blobJSON{}, err } err = json.Unmarshal(content, &rawBlobs) if err != nil { - return []blobJson{}, err + return []blobJSON{}, err } return rawBlobs.Blobs, err From 1ae5e5372b5750c770e7d9361d71613eba699dd9 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 1 Dec 2023 01:24:27 +0700 Subject: [PATCH 12/23] add creae json file for testing --- x/blob/client/testutil/integration_test.go | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 50e575602a..386131b0bf 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -4,13 +4,14 @@ import ( "bytes" "encoding/hex" "fmt" + "os" "strconv" "testing" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/testutil" "github.com/gogo/protobuf/proto" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -37,6 +38,23 @@ type IntegrationTestSuite struct { kr keyring.Keyring } +// Create a .json file for testing +func createTestFile(t testing.TB, s string) *os.File { + t.Helper() + + tempdir, err := os.MkdirTemp("", "") + require.NoError(t, err) + t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) + + fp, err := os.CreateTemp(tempdir, "*.json") + require.NoError(t, err) + _, err = fp.WriteString(s) + + require.Nil(t, err) + + return fp +} + func NewIntegrationTestSuite(cfg cosmosnet.Config) *IntegrationTestSuite { return &IntegrationTestSuite{cfg: cfg} } @@ -76,7 +94,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { ] } `, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob) - validPropFile := testutil.WriteToNewTempFile(s.T(), validBlob) + validPropFile := createTestFile(s.T(), validBlob) invalidBlob := fmt.Sprintf(` { @@ -92,7 +110,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { ] } `, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob) - invalidPropFile := testutil.WriteToNewTempFile(s.T(), invalidBlob) + invalidPropFile := createTestFile(s.T(), invalidBlob) testCases := []struct { name string From 762d4f3826b34ea819ece2dbf3db7f94ce416e14 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 1 Dec 2023 01:40:20 +0700 Subject: [PATCH 13/23] minor --- proto/celestia/core/v1/blob/blob.proto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proto/celestia/core/v1/blob/blob.proto b/proto/celestia/core/v1/blob/blob.proto index cf193b9691..41e0620ab7 100644 --- a/proto/celestia/core/v1/blob/blob.proto +++ b/proto/celestia/core/v1/blob/blob.proto @@ -21,5 +21,4 @@ message BlobTx { bytes tx = 1; repeated Blob blobs = 2; string type_id = 3; -} - +} \ No newline at end of file From f0e2e9c73e0b23fe038968f18d5ccc015ee045e5 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Sat, 2 Dec 2023 15:40:00 +0700 Subject: [PATCH 14/23] remove unnecessary testcase --- x/blob/client/testutil/integration_test.go | 58 ---------------------- 1 file changed, 58 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 386131b0bf..16c0fa0490 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -1,7 +1,6 @@ package testutil import ( - "bytes" "encoding/hex" "fmt" "os" @@ -96,22 +95,6 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { `, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob) validPropFile := createTestFile(s.T(), validBlob) - invalidBlob := fmt.Sprintf(` - { - "Blobs": [ - { - "namespaceId": "%s", - "blob": "%s" - }, - { - "namespaceId": "%s", - "blob": "%s" - } - ] - } - `, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob, hex.EncodeToString(bytes.Repeat([]byte{0}, 8)), hexBlob) - invalidPropFile := createTestFile(s.T(), invalidBlob) - testCases := []struct { name string args []string @@ -132,47 +115,6 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { expectedCode: 0, respType: &sdk.TxResponse{}, }, - { - name: "unsupported share version", - args: []string{ - validPropFile.Name(), - fmt.Sprintf("--from=%s", username), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=1", paycli.FlagShareVersion), - }, - expectErr: true, - expectedCode: 0, - respType: &sdk.TxResponse{}, - }, - { - name: "invalid namespace ID", - args: []string{ - invalidPropFile.Name(), - fmt.Sprintf("--from=%s", username), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - }, - expectErr: true, - expectedCode: 0, - respType: &sdk.TxResponse{}, - }, - { - name: "invalid namespace version", - args: []string{ - validPropFile.Name(), - fmt.Sprintf("--from=%s", username), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=1", paycli.FlagNamespaceVersion), - }, - expectErr: true, - expectedCode: 0, - respType: &sdk.TxResponse{}, - }, } for _, tc := range testCases { From 8b5e6c338b1c1c47cec0d5eb97d3e1112c4501d5 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 00:10:59 +0700 Subject: [PATCH 15/23] resolve state breaking issue by execpt both usage of input --- x/blob/client/cli/payforblob.go | 80 +++++++++++++++------- x/blob/client/testutil/integration_test.go | 16 ++++- 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 5e9a64b0e8..1968698d4b 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -29,11 +29,15 @@ const ( // FlagNamespaceVersion allows the user to override the namespace version when // submitting a PayForBlob. FlagNamespaceVersion = "namespace-version" + + // FlagNamespaceVersion allows the user to override the namespace version when + // submitting a PayForBlob. + FlagBlobsFilePath = "blobs-file-path" ) func CmdPayForBlob() *cobra.Command { cmd := &cobra.Command{ - Use: "PayForBlobs [path/to/blob.json]", + Use: "PayForBlobs [namespaceID, blob] [path/to/blob.json]", // This example command can be run in a new terminal after running single-node.sh Example: "celestia-appd tx blob PayForBlobs path/to/blob.json \\\n" + "\t--chain-id private \\\n" + @@ -43,6 +47,7 @@ func CmdPayForBlob() *cobra.Command { "\t--yes", Short: "Pay for a data blobs to be published to Celestia.", Long: "Pay for a data blobs to be published to Celestia.\n" + + "User can use namespaceID and blob or path to a json file as argument" + `Where blob.json contains: { @@ -60,17 +65,21 @@ func CmdPayForBlob() *cobra.Command { 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 - `, Aliases: []string{"PayForBlob"}, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { - return fmt.Errorf("PayForBlobs requires one arguments: path to blob.json") + return fmt.Errorf("PayForBlobs requires atleast one argument") } - path := args[0] - if filepath.Ext(path) != ".json" { - return fmt.Errorf("invalid file extension, require json got %s", filepath.Ext(path)) + + // If there is only one argument we assume it to be a file path so we check the file extension + if len(args) == 1 { + path := args[0] + if filepath.Ext(path) != ".json" { + return fmt.Errorf("invalid file extension, require json got %s", filepath.Ext(path)) + } } + return nil }, RunE: func(cmd *cobra.Command, args []string) error { @@ -78,33 +87,35 @@ func CmdPayForBlob() *cobra.Command { if err != nil { return err } - path := args[0] - paresdBlobs, err := parseSubmitBlobs(path) + shareVersion, err := cmd.Flags().GetUint8(FlagShareVersion) if err != nil { return err } - var blobs []*blob.Blob - for i := range paresdBlobs { - namespaceID, err := hex.DecodeString(strings.TrimPrefix(paresdBlobs[i].NamespaceID, "0x")) - if err != nil { - return fmt.Errorf("failed to decode hex namespace ID: %w", err) - } - namespace, err := getNamespace(namespaceID, namespaceVersion) + // In case of arguments contain namespaceID and blob + if len(args) >= 2 { + blob, err := getBlobFromArguments(args[0], args[1], namespaceVersion, shareVersion) if err != nil { return err } - hexStr := strings.TrimPrefix(paresdBlobs[i].Blob, "0x") - rawblob, err := hex.DecodeString(hexStr) - if err != nil { - return fmt.Errorf("failure to decode hex blob value %s: %s", hexStr, err.Error()) - } - shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion) - blob, err := types.NewBlob(namespace, rawblob, shareVersion) + return broadcastPFB(cmd, blob) + } + + // In case of argument contains file path to submit multiple blobs + path := args[0] + + paresdBlobs, err := parseSubmitBlobs(path) + if err != nil { + return err + } + + var blobs []*blob.Blob + for _, paresdBlob := range paresdBlobs { + blob, err := getBlobFromArguments(paresdBlob.NamespaceID, paresdBlob.Blob, namespaceVersion, shareVersion) if err != nil { - return fmt.Errorf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) + return err } blobs = append(blobs, blob) } @@ -120,6 +131,29 @@ func CmdPayForBlob() *cobra.Command { return cmd } +func getBlobFromArguments(namespaceIdArg, blobArg string, namespaceVersion, shareVersion uint8) (*blob.Blob, error) { + namespaceID, err := hex.DecodeString(strings.TrimPrefix(namespaceIdArg, "0x")) + if err != nil { + return nil, fmt.Errorf("failed to decode hex namespace ID: %w", err) + } + namespace, err := getNamespace(namespaceID, namespaceVersion) + if err != nil { + return nil, err + } + hexStr := strings.TrimPrefix(blobArg, "0x") + rawblob, err := hex.DecodeString(hexStr) + if err != nil { + return nil, fmt.Errorf("failure to decode hex blob value %s: %s", hexStr, err.Error()) + } + + blob, err := types.NewBlob(namespace, rawblob, shareVersion) + if err != nil { + return nil, fmt.Errorf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) + } + + return blob, nil +} + func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, error) { switch namespaceVersion { case appns.NamespaceVersionZero: diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 16c0fa0490..fa7dbfff88 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -103,7 +103,21 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { respType proto.Message }{ { - name: "valid transaction", + name: "single blob valid transaction", + args: []string{ + hex.EncodeToString(appns.RandomBlobNamespaceID()), + hexBlob, + fmt.Sprintf("--from=%s", username), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + }, + expectErr: false, + expectedCode: 0, + respType: &sdk.TxResponse{}, + }, + { + name: "multiple blobs valid transaction", args: []string{ validPropFile.Name(), fmt.Sprintf("--from=%s", username), From 607e3d7f52d6a3d558ee7b9337b17d7cfd2a3636 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 00:23:40 +0700 Subject: [PATCH 16/23] minor --- x/blob/client/cli/payforblob.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 1968698d4b..0c6333d72f 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -131,8 +131,8 @@ func CmdPayForBlob() *cobra.Command { return cmd } -func getBlobFromArguments(namespaceIdArg, blobArg string, namespaceVersion, shareVersion uint8) (*blob.Blob, error) { - namespaceID, err := hex.DecodeString(strings.TrimPrefix(namespaceIdArg, "0x")) +func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shareVersion uint8) (*blob.Blob, error) { + namespaceID, err := hex.DecodeString(strings.TrimPrefix(namespaceIDArg, "0x")) if err != nil { return nil, fmt.Errorf("failed to decode hex namespace ID: %w", err) } From d8fccc969ecd7de14bdeae507879a5abd452eacc Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 01:38:52 +0700 Subject: [PATCH 17/23] remove unused flag --- x/blob/client/cli/payforblob.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 0c6333d72f..4dbea199cc 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -29,10 +29,6 @@ const ( // FlagNamespaceVersion allows the user to override the namespace version when // submitting a PayForBlob. FlagNamespaceVersion = "namespace-version" - - // FlagNamespaceVersion allows the user to override the namespace version when - // submitting a PayForBlob. - FlagBlobsFilePath = "blobs-file-path" ) func CmdPayForBlob() *cobra.Command { From 05b3683dcc7bd576cccef116ab3723d23d44fdda Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 02:51:58 +0700 Subject: [PATCH 18/23] switch to use flag for input file --- x/blob/client/cli/payforblob.go | 56 +++++++++++++++------- x/blob/client/testutil/integration_test.go | 28 +++++++++-- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 4dbea199cc..5a84f006b8 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -29,22 +29,35 @@ const ( // FlagNamespaceVersion allows the user to override the namespace version when // submitting a PayForBlob. FlagNamespaceVersion = "namespace-version" + + // FlagNamespaceVersion allows the user to override the namespace version when + // submitting a PayForBlob. + FlagFileInput = "input-file" ) func CmdPayForBlob() *cobra.Command { cmd := &cobra.Command{ - Use: "PayForBlobs [namespaceID, blob] [path/to/blob.json]", + Use: "PayForBlobs [namespaceID blob]", // This example command can be run in a new terminal after running single-node.sh - Example: "celestia-appd tx blob PayForBlobs path/to/blob.json \\\n" + + Example: "celestia-appd tx blob PayForBlobs 0x00010203040506070809 0x48656c6c6f2c20576f726c6421 \\\n" + "\t--chain-id private \\\n" + "\t--from validator \\\n" + "\t--keyring-backend test \\\n" + "\t--fees 21000utia \\\n" + - "\t--yes", - Short: "Pay for a data blobs to be published to Celestia.", - Long: "Pay for a data blobs to be published to Celestia.\n" + - "User can use namespaceID and blob or path to a json file as argument" + - `Where blob.json contains: + "\t--yes \\\n" + + "\n" + + "celestia-appd tx blob PayForBlobs --input-file path/to/blobs.json \\\n" + + "\t--chain-id private \\\n" + + "\t--from validator \\\n" + + "\t--keyring-backend test \\\n" + + "\t--fees 21000utia \\\n" + + "\t--yes \\\n" + + "\\\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: { "Blobs": [ @@ -64,16 +77,22 @@ func CmdPayForBlob() *cobra.Command { `, Aliases: []string{"PayForBlob"}, Args: func(cmd *cobra.Command, args []string) error { - if len(args) < 1 { - return fmt.Errorf("PayForBlobs requires atleast one argument") + path, err := cmd.Flags().GetString(FlagFileInput) + if err != nil { + return err } - // If there is only one argument we assume it to be a file path so we check the file extension - if len(args) == 1 { - path := args[0] + // 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)) } + + return nil + } + + if len(args) < 2 { + return fmt.Errorf("PayForBlobs requires two argument: namespaceID and blob") } return nil @@ -89,8 +108,13 @@ func CmdPayForBlob() *cobra.Command { return err } - // In case of arguments contain namespaceID and blob - if len(args) >= 2 { + path, err := cmd.Flags().GetString(FlagFileInput) + if err != nil { + return err + } + + // In case of no file input, get the namespaceID and blob from the arguments + if path == "" { blob, err := getBlobFromArguments(args[0], args[1], namespaceVersion, shareVersion) if err != nil { return err @@ -99,9 +123,6 @@ func CmdPayForBlob() *cobra.Command { return broadcastPFB(cmd, blob) } - // In case of argument contains file path to submit multiple blobs - path := args[0] - paresdBlobs, err := parseSubmitBlobs(path) if err != nil { return err @@ -123,6 +144,7 @@ func CmdPayForBlob() *cobra.Command { flags.AddTxFlagsToCmd(cmd) cmd.PersistentFlags().Uint8(FlagNamespaceVersion, 0, "Specify the namespace version (default 0)") cmd.PersistentFlags().Uint8(FlagShareVersion, 0, "Specify the share version (default 0)") + cmd.PersistentFlags().String(FlagFileInput, "", "Specify the file input") _ = cmd.MarkFlagRequired(flags.FlagFrom) return cmd } diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index fa7dbfff88..7fa36c173d 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -38,14 +38,20 @@ type IntegrationTestSuite struct { } // Create a .json file for testing -func createTestFile(t testing.TB, s string) *os.File { +func createTestFile(t testing.TB, s string, isValid bool) *os.File { t.Helper() tempdir, err := os.MkdirTemp("", "") require.NoError(t, err) t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) - fp, err := os.CreateTemp(tempdir, "*.json") + var fp *os.File + + if isValid { + fp, err = os.CreateTemp(tempdir, "*.json") + } else { + fp, err = os.CreateTemp(tempdir, "") + } require.NoError(t, err) _, err = fp.WriteString(s) @@ -93,7 +99,8 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { ] } `, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob) - validPropFile := createTestFile(s.T(), validBlob) + validPropFile := createTestFile(s.T(), validBlob, true) + invalidPropFile := createTestFile(s.T(), validBlob, false) testCases := []struct { name string @@ -119,16 +126,29 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { name: "multiple blobs valid transaction", args: []string{ - validPropFile.Name(), fmt.Sprintf("--from=%s", username), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", paycli.FlagFileInput, validPropFile.Name()), }, expectErr: false, expectedCode: 0, respType: &sdk.TxResponse{}, }, + { + name: "multiple blobs with invalid file path extension", + args: []string{ + fmt.Sprintf("--from=%s", username), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", paycli.FlagFileInput, invalidPropFile.Name()), + }, + expectErr: true, + expectedCode: 0, + respType: &sdk.TxResponse{}, + }, } for _, tc := range testCases { From 70f1dd4bcdec880e70ebaf0a0e88b42e6a717bd8 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 03:26:10 +0700 Subject: [PATCH 19/23] minor update --- x/blob/client/cli/payforblob.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 5a84f006b8..501c59ad2a 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -30,8 +30,8 @@ const ( // submitting a PayForBlob. FlagNamespaceVersion = "namespace-version" - // FlagNamespaceVersion allows the user to override the namespace version when - // submitting a PayForBlob. + // FlagFileInput allows the user to provide file path to the json file + // for submitting multiple blobs. FlagFileInput = "input-file" ) From 809e2899c3a39198a981fee64e4a7a6245c63698 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 04:39:33 +0700 Subject: [PATCH 20/23] minor lint fix --- x/blob/client/cli/payforblob.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 501c59ad2a..dadb72a6de 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/hex" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -92,7 +93,7 @@ func CmdPayForBlob() *cobra.Command { } if len(args) < 2 { - return fmt.Errorf("PayForBlobs requires two argument: namespaceID and blob") + return errors.New("PayForBlobs requires two arguments: namespaceID and blob") } return nil From 332cc50095c5faf3708f84a16b54f0e97cbd30b5 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 04:53:36 +0700 Subject: [PATCH 21/23] minor command description update --- x/blob/client/cli/payforblob.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index dadb72a6de..85339e435f 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -63,11 +63,11 @@ func CmdPayForBlob() *cobra.Command { { "Blobs": [ { - "namespaceId": "0x00010203040506070809", + "namespaceID": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" }, { - "namespaceId": "0x00010203040506070809", + "namespaceID": "0x00010203040506070809", "blob": "0x48656c6c6f2c20576f726c6421" } ] From eb75bef500a0897a112251bcb504ba34ab4f7c43 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Tue, 5 Dec 2023 04:59:38 +0700 Subject: [PATCH 22/23] minor update for consistency --- x/blob/client/testutil/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 7fa36c173d..e22865907d 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -89,11 +89,11 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { "Blobs": [ { - "namespaceId": "%s", + "namespaceID": "%s", "blob": "%s" }, { - "namespaceId": "%s", + "namespaceID": "%s", "blob": "%s" } ] From 5421c88c269c38afb7eda35a581e7c4c324c7a35 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Tue, 5 Dec 2023 11:25:45 -0500 Subject: [PATCH 23/23] Update x/blob/client/cli/payforblob.go --- x/blob/client/cli/payforblob.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 85339e435f..1dbabb541b 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -45,15 +45,13 @@ func CmdPayForBlob() *cobra.Command { "\t--from validator \\\n" + "\t--keyring-backend test \\\n" + "\t--fees 21000utia \\\n" + - "\t--yes \\\n" + - "\n" + + "\t--yes \n\n" + "celestia-appd tx blob PayForBlobs --input-file path/to/blobs.json \\\n" + "\t--chain-id private \\\n" + "\t--from validator \\\n" + "\t--keyring-backend test \\\n" + "\t--fees 21000utia \\\n" + - "\t--yes \\\n" + - "\\\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" +