From cbfa7f0e8f5a9c48b2f6410c4c0acc83ae5e3040 Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Fri, 22 Sep 2023 11:14:32 +0800 Subject: [PATCH 1/5] fix: fix err value --- cmd/cmd_object.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/cmd_object.go b/cmd/cmd_object.go index 69ed671..0cff7a1 100644 --- a/cmd/cmd_object.go +++ b/cmd/cmd_object.go @@ -636,9 +636,9 @@ func getObject(ctx *cli.Context) error { LastPrinted: time.Now(), } - body, info, getErr := gnfdClient.GetObject(c, bucketName, objectName, opt) - if getErr != nil { - return toCmdErr(err) + body, info, downloadErr := gnfdClient.GetObject(c, bucketName, objectName, opt) + if downloadErr != nil { + return toCmdErr(downloadErr) } _, err = io.Copy(pw, body) From c86a1225aee8b9c7a1bc57dc1cd0083e990709ca Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Fri, 22 Sep 2023 11:14:54 +0800 Subject: [PATCH 2/5] fix: improve quota command --- cmd/cmd_payment.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/cmd_payment.go b/cmd/cmd_payment.go index 64be96d..7bdd81d 100644 --- a/cmd/cmd_payment.go +++ b/cmd/cmd_payment.go @@ -110,8 +110,14 @@ func getQuotaInfo(ctx *cli.Context) error { return toCmdErr(err) } - fmt.Printf(" quota info:\n charged quota:%d \n free quota remained :%d \n charged quota consumed:%d \n free quota consumed: %d \n", - quotaInfo.ReadQuotaSize, quotaInfo.SPFreeReadQuotaSize, quotaInfo.ReadConsumedSize, quotaInfo.FreeConsumedSize) + nameMaxLen := len("consumed charged quota:") + format := fmt.Sprintf("%%-%ds %%-%dd \n", nameMaxLen, 50) + firstLineFormat := fmt.Sprintf("%%-%ds %%-%ds \n", nameMaxLen, 50) + fmt.Printf(firstLineFormat, "quota name", "quota value") + fmt.Printf(format, "charged quota:", quotaInfo.ReadQuotaSize) + fmt.Printf(format, "remained free quota:", quotaInfo.SPFreeReadQuotaSize) + fmt.Printf(format, "consumed charged quota:", quotaInfo.ReadConsumedSize) + fmt.Printf(format, "consumed free quota:", quotaInfo.FreeConsumedSize) return nil } From 00ecb36df1f74349b281cd1159cab62cc60037c8 Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Fri, 22 Sep 2023 11:46:10 +0800 Subject: [PATCH 3/5] fix: update readme and version command --- README.md | 2 +- cmd/utils.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1f51d4..4875710 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ To obtain the latest release, please visit the following URL: https://github.com git clone https://github.com/bnb-chain/greenfield-cmd.git cd greenfield-cmd # Find the latest release here: https://github.com/bnb-chain/greenfield-cmd/releases -git checkout -b branch-name v0.1.0 +git checkout -b branch-name v0.1.1 make build cd build ./gnfd-cmd -h diff --git a/cmd/utils.go b/cmd/utils.go index 96da141..1224d63 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -28,7 +28,7 @@ import ( ) const ( - Version = "v0.1.0" + Version = "v0.1.1" maxFileSize = 64 * 1024 * 1024 * 1024 maxPutWithoutResumeSize = 2 * 1024 * 1024 * 1024 publicReadType = "public-read" From aaf4b665a4ada087ecbd82c1b66ca5e82e608bdb Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Fri, 22 Sep 2023 14:08:36 +0800 Subject: [PATCH 4/5] chore: update dependency to v0.2.6 --- cmd/client_gnfd.go | 6 +++--- cmd/cmd_delete.go | 6 +++--- cmd/cmd_object.go | 6 +++--- cmd/cmd_policy.go | 14 +++++++------- cmd/cmd_sp.go | 2 +- go.mod | 6 +++--- go.sum | 14 ++++++++------ 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/cmd/client_gnfd.go b/cmd/client_gnfd.go index 565cb9c..096d498 100644 --- a/cmd/client_gnfd.go +++ b/cmd/client_gnfd.go @@ -33,7 +33,7 @@ func showVersion(ctx *cli.Context) error { } // NewClient returns a new greenfield client -func NewClient(ctx *cli.Context, isQueryCmd bool) (client.Client, error) { +func NewClient(ctx *cli.Context, isQueryCmd bool) (client.IClient, error) { var ( account *types.Account err error @@ -57,7 +57,7 @@ func NewClient(ctx *cli.Context, isQueryCmd bool) (client.Client, error) { return nil, err } - var cli client.Client + var cli client.IClient if host != "" { cli, err = client.New(chainId, rpcAddr, client.Option{DefaultAccount: account, Host: host}) } else { @@ -112,7 +112,7 @@ func ParseBucket(urlPath string) (bucketName string) { return splits[0] } -func waitTxnStatus(cli client.Client, ctx context.Context, txnHash string, txnInfo string) error { +func waitTxnStatus(cli client.IClient, ctx context.Context, txnHash string, txnInfo string) error { ctxTimeout, cancel := context.WithTimeout(ctx, ContextTimeout) defer cancel() diff --git a/cmd/cmd_delete.go b/cmd/cmd_delete.go index d5c7fe4..1a870ad 100644 --- a/cmd/cmd_delete.go +++ b/cmd/cmd_delete.go @@ -98,7 +98,7 @@ func deleteBucket(ctx *cli.Context) error { if err != nil { return toCmdErr(err) } - + fmt.Printf("delete_bucket: %s \ntransaction hash: %s\n", bucketName, txnHash) return nil } @@ -164,7 +164,7 @@ func deleteObject(ctx *cli.Context) error { return nil } -func deleteObjectByPage(cli client.Client, c context.Context, bucketName, prefixName string) error { +func deleteObjectByPage(cli client.IClient, c context.Context, bucketName, prefixName string) error { var ( listResult sdktypes.ListObjectsResult continuationToken string @@ -195,7 +195,7 @@ func deleteObjectByPage(cli client.Client, c context.Context, bucketName, prefix return nil } -func deleteObjectAndWaitTxn(cli client.Client, c context.Context, bucketName, objectName string) { +func deleteObjectAndWaitTxn(cli client.IClient, c context.Context, bucketName, objectName string) { txnHash, err := cli.DeleteObject(c, bucketName, objectName, sdktypes.DeleteObjectOption{TxOpts: &TxnOptionWithSyncMode}) if err != nil { fmt.Printf("failed to delele object %s err:%v\n", objectName, err) diff --git a/cmd/cmd_object.go b/cmd/cmd_object.go index 0cff7a1..9abca99 100644 --- a/cmd/cmd_object.go +++ b/cmd/cmd_object.go @@ -357,7 +357,7 @@ func putObject(ctx *cli.Context) error { // uploadFolder upload folder and the files inside to bucket in a recursive way func uploadFolder(urlInfo string, ctx *cli.Context, - gnfdClient client.Client) error { + gnfdClient client.IClient) error { // upload folder with recursive flag bucketName := ParseBucket(urlInfo) if bucketName == "" { @@ -398,7 +398,7 @@ func uploadFolder(urlInfo string, ctx *cli.Context, } func uploadFile(bucketName, objectName, filePath, urlInfo string, ctx *cli.Context, - gnfdClient client.Client, uploadSigleFolder, printTxnHash bool, objectSize int64) error { + gnfdClient client.IClient, uploadSigleFolder, printTxnHash bool, objectSize int64) error { var file *os.File contentType := ctx.String(contentTypeFlag) secondarySPAccs := ctx.String(secondarySPFlag) @@ -722,7 +722,7 @@ func listObjects(ctx *cli.Context) error { return nil } -func listObjectByPage(cli client.Client, c context.Context, bucketName, prefixName string, isRecursive bool) error { +func listObjectByPage(cli client.IClient, c context.Context, bucketName, prefixName string, isRecursive bool) error { var ( listResult sdktypes.ListObjectsResult continuationToken string diff --git a/cmd/cmd_policy.go b/cmd/cmd_policy.go index 2cdbf04..7a8dbc3 100644 --- a/cmd/cmd_policy.go +++ b/cmd/cmd_policy.go @@ -359,7 +359,7 @@ func handleListPolicy(ctx *cli.Context, resource string, policyType ResourceType return nil } -func handleObjectPolicy(ctx *cli.Context, client client.Client, bucketName, objectName string, principal sdktypes.Principal, +func handleObjectPolicy(ctx *cli.Context, client client.IClient, bucketName, objectName string, principal sdktypes.Principal, statements []*permTypes.Statement, delete bool) error { c, cancelObjectPolicy := context.WithCancel(globalContext) defer cancelObjectPolicy() @@ -393,7 +393,7 @@ func handleObjectPolicy(ctx *cli.Context, client client.Client, bucketName, obje return nil } -func handleBucketPolicy(ctx *cli.Context, client client.Client, bucketName string, principal sdktypes.Principal, +func handleBucketPolicy(ctx *cli.Context, client client.IClient, bucketName string, principal sdktypes.Principal, statements []*permTypes.Statement, delete bool) error { c, cancelBucketPolicy := context.WithCancel(globalContext) defer cancelBucketPolicy() @@ -427,7 +427,7 @@ func handleBucketPolicy(ctx *cli.Context, client client.Client, bucketName strin return nil } -func handleGroupPolicy(ctx *cli.Context, client client.Client, groupName string, +func handleGroupPolicy(ctx *cli.Context, client client.IClient, groupName string, statements []*permTypes.Statement, delete bool) error { c, cancelPolicy := context.WithCancel(globalContext) defer cancelPolicy() @@ -509,7 +509,7 @@ func parseGroupResource(resourceName string) (string, string, error) { return objectPath[:index], objectPath[index+1:], nil } -func printObjectPolicy(ctx *cli.Context, cli client.Client, bucketName, objectName string) { +func printObjectPolicy(ctx *cli.Context, cli client.IClient, bucketName, objectName string) { // get the latest policy from chain groupId := ctx.Uint64(groupIDFlag) grantee := ctx.String(granteeFlag) @@ -528,7 +528,7 @@ func printObjectPolicy(ctx *cli.Context, cli client.Client, bucketName, objectNa } } -func listObjectPolicy(ctx *cli.Context, cli client.Client, bucketName, objectName, resourceName string) error { +func listObjectPolicy(ctx *cli.Context, cli client.IClient, bucketName, objectName, resourceName string) error { // get the latest policy from chain groupId := ctx.Uint64(groupIDFlag) grantee := ctx.String(granteeFlag) @@ -553,7 +553,7 @@ func listObjectPolicy(ctx *cli.Context, cli client.Client, bucketName, objectNam return nil } -func printBucketPolicy(ctx *cli.Context, cli client.Client, bucketName string) { +func printBucketPolicy(ctx *cli.Context, cli client.IClient, bucketName string) { c, cancelPolicy := context.WithCancel(globalContext) defer cancelPolicy() // get the latest policy from chain @@ -572,7 +572,7 @@ func printBucketPolicy(ctx *cli.Context, cli client.Client, bucketName string) { } } -func listBucketPolicy(ctx *cli.Context, cli client.Client, bucketName, resourceName string) error { +func listBucketPolicy(ctx *cli.Context, cli client.IClient, bucketName, resourceName string) error { c, cancelPolicy := context.WithCancel(globalContext) defer cancelPolicy() diff --git a/cmd/cmd_sp.go b/cmd/cmd_sp.go index bc1dd76..4dca3f3 100644 --- a/cmd/cmd_sp.go +++ b/cmd/cmd_sp.go @@ -170,7 +170,7 @@ func getQuotaPrice(ctx *cli.Context) error { return nil } -func getSPAddr(spAddressInfo string, cli client.Client, c context.Context) (sdk.AccAddress, error) { +func getSPAddr(spAddressInfo string, cli client.IClient, c context.Context) (sdk.AccAddress, error) { var addr sdk.AccAddress var err error var spList []sptypes.StorageProvider diff --git a/go.mod b/go.mod index ea4608e..d11cdb3 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.20 require ( cosmossdk.io/math v1.0.1 github.com/BurntSushi/toml v1.3.2 - github.com/bnb-chain/greenfield v0.2.5 - github.com/bnb-chain/greenfield-go-sdk v0.2.5 + github.com/bnb-chain/greenfield v0.2.6 + github.com/bnb-chain/greenfield-go-sdk v0.2.6 github.com/cosmos/cosmos-sdk v0.47.3 github.com/ethereum/go-ethereum v1.10.26 github.com/urfave/cli/v2 v2.10.2 @@ -153,7 +153,7 @@ replace ( github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.3 github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.5 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.6 github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ) diff --git a/go.sum b/go.sum index d10a5fc..f31173e 100644 --- a/go.sum +++ b/go.sum @@ -154,22 +154,24 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/greenfield v0.2.5 h1:AmHvGfJmHm7FXB4II4mAB6i68bw98p86ZlIs9r6YeRM= -github.com/bnb-chain/greenfield v0.2.5/go.mod h1:nNsy8QGR8+R0j6Qz/duNE94NDDNuomC6wWDCzfl7jKc= +github.com/bnb-chain/greenfield v0.2.6 h1:U40wmSBQR4Wd0HiVCu/J6zqoLS4YUrvNgyuX71kgK3U= +github.com/bnb-chain/greenfield v0.2.6/go.mod h1:8kGVzKu3BEbpotk2Lmp/OzPh+nhbMsuUJueZtn0he4s= github.com/bnb-chain/greenfield-cometbft v0.0.3 h1:tv8NMy3bzX/1urqXGQIIAZSLy83loiI+dG0VKeyh1CY= github.com/bnb-chain/greenfield-cometbft v0.0.3/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU= github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI= github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f h1:zJvB2wCd80DQ9Nh/ZNQiP8MrHygSpDoav7OzHyIi/pM= github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f/go.mod h1:it3JJVHeG9Wp4QED2GkY/7V9Qo3BuPdoC5/4/U6ecJM= -github.com/bnb-chain/greenfield-cosmos-sdk v0.2.5 h1:8zIn/ExfMHZVBbVwhILG9KYO1m3pZO8I8stpqbFgzkk= -github.com/bnb-chain/greenfield-cosmos-sdk v0.2.5/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY= +github.com/bnb-chain/greenfield-cosmos-sdk v0.2.6 h1:aPrd2nG2nYZr8nSmGgN8efus6sni4OIZ1Bdx6s+mS3A= +github.com/bnb-chain/greenfield-cosmos-sdk v0.2.6/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY= github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8= github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM= github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s= github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210/go.mod h1:An0MllWJY6PxibUpnwGk8jOm+a/qIxlKmL5Zyp9NnaM= -github.com/bnb-chain/greenfield-go-sdk v0.2.5 h1:ErI7nUtNCRDvpXSVaG/XKXEBhTcmiofg/2ciKU1uBag= -github.com/bnb-chain/greenfield-go-sdk v0.2.5/go.mod h1:rWI9Xgcto7ujajNfG6x7+lW1SzbJWBkIgnOcoNjWS7U= +github.com/bnb-chain/greenfield-go-sdk v0.2.6-0.20230922033934-cdcf8250f37d h1:BxrPzgrB8Ara+wnMfEv/X/4fEw6YGecPhIy96NgmKkE= +github.com/bnb-chain/greenfield-go-sdk v0.2.6-0.20230922033934-cdcf8250f37d/go.mod h1:MrxZcdoK/YC8o0wECOv8fskozBokekxApLbi1P6qeTI= +github.com/bnb-chain/greenfield-go-sdk v0.2.6 h1:CGmMK+Ie3ZXae86rGYJnaF7FmO+y92S4a/Qp7DzxhLU= +github.com/bnb-chain/greenfield-go-sdk v0.2.6/go.mod h1:MrxZcdoK/YC8o0wECOv8fskozBokekxApLbi1P6qeTI= github.com/bnb-chain/greenfield-iavl v0.20.1 h1:y3L64GU99otNp27/xLVBTDbv4eroR6CzoYz0rbaVotM= github.com/bnb-chain/greenfield-iavl v0.20.1/go.mod h1:oLksTs8dfh7DYIKBro7hbRQ+ewls7ghJ27pIXlbEXyI= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= From cf29d545fa5778dd757e4364c46298803eeeb97b Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Fri, 22 Sep 2023 14:21:43 +0800 Subject: [PATCH 5/5] chore: update change log --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ea148..c642196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v0.1.1 +FEATURES +* [#89](https://github.com/bnb-chain/greenfield-cmd/pull/89) support resumable download by adding a flag to "object get cmd" +* [#90](https://github.com/bnb-chain/greenfield-cmd/pull/90) improve cmd of downloading and uploading with printing progress details and speed +* [#90](https://github.com/bnb-chain/greenfield-cmd/pull/92) update dependency of go-sdk and greenfield to v0.2.6 + +BUGFIX +* [#90](https://github.com/bnb-chain/greenfield-cmd/pull/90) solve the problem of parsing object name err when recursive upload folder + ## v0.1.0 FEATURES