Skip to content

Commit

Permalink
fix: remove debug log and fix resume upload progress
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Oct 12, 2023
1 parent 0aafdae commit 3967104
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
5 changes: 2 additions & 3 deletions cmd/cmd_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func importKey(ctx *cli.Context) error {
if err != nil {
return toCmdErr(err)
}
fmt.Println("- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!")

// encrypt the private key
encryptContent, err = EncryptKey(key, password, EncryptScryptN, EncryptScryptP)
Expand All @@ -274,7 +273,7 @@ func importKey(ctx *cli.Context) error {
// if it is the first keystore, set it as the default key
checkAndWriteDefaultKey(homeDir, convertAddressToLower(key.Address.String()))

fmt.Printf("key address: %s, encrypted key file: %s \n", key.Address, keyFilePath)
fmt.Printf("imported account: %s, keystore: %s \n", key.Address, keyFilePath)
return nil
}

Expand Down Expand Up @@ -428,7 +427,7 @@ func createAccount(ctx *cli.Context) error {
// if it is the first keystore, set it as the default key
checkAndWriteDefaultKey(homeDir, convertAddressToLower(key.Address.String()))

fmt.Printf("created new account: {%s} \n", account.GetAddress())
fmt.Printf("created new account: {%s}, keystore: %s \n", account.GetAddress(), keyFilePath)
return nil
}

Expand Down
31 changes: 16 additions & 15 deletions cmd/cmd_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (

"cosmossdk.io/math"
"github.com/bnb-chain/greenfield-go-sdk/client"
"github.com/bnb-chain/greenfield/sdk/types"

sdktypes "github.com/bnb-chain/greenfield-go-sdk/types"
"github.com/bnb-chain/greenfield/sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -486,26 +485,28 @@ func uploadFile(bucketName, objectName, filePath, urlInfo string, ctx *cli.Conte
opt.DisableResumable = false
}

if opt.DisableResumable {
progressReader := &ProgressReader{
Reader: reader,
Total: objectSize,
StartTime: time.Now(),
LastPrinted: time.Now(),
}
progressReader := &ProgressReader{
Reader: reader,
Total: objectSize,
StartTime: time.Now(),
LastPrinted: time.Now(),
}

// if print big file progress, the printing progress should be delayed to obtain a more accurate display.
if objectSize > progressDelayPrintSize {
progressReader.LastPrinted = time.Now().Add(2 * time.Second)
}
// if print big file progress, the printing progress should be delayed to obtain a more accurate display.
if objectSize > progressDelayPrintSize {
progressReader.LastPrinted = time.Now().Add(3 * time.Second)
}

if opt.DisableResumable {
fmt.Println("uploading is beginning...")
if err = gnfdClient.PutObject(c, bucketName, objectName,
objectSize, progressReader, opt); err != nil {
return toCmdErr(err)
}
} else {
fmt.Println("resumable uploading is beginning...")
if err = gnfdClient.PutObject(c, bucketName, objectName,
objectSize, reader, opt); err != nil {
objectSize, progressReader, opt); err != nil {
return toCmdErr(err)
}
}
Expand All @@ -524,7 +525,7 @@ func uploadFile(bucketName, objectName, filePath, urlInfo string, ctx *cli.Conte
for {
select {
case <-timeout:
return toCmdErr(errors.New("object not sealed after 1 hour"))
return toCmdErr(errors.New("object not sealed after one hour"))
case <-ticker.C:
count++
headObjOutput, queryErr := gnfdClient.HeadObject(c, bucketName, objectName)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ the resource url can be the follow types:
3) grn:g:owneraddress:groupname, it indicates the group policy
Examples:
$ gnfd-cmd policy rm --groupId 111 grn:o::gnfd-bucket/gnfd-object`,
$ gnfd-cmd policy ls --groupId 111 grn:o::gnfd-bucket/gnfd-object`,
Flags: []cli.Flag{
&cli.Uint64Flag{
Name: groupIDFlag,
Expand Down
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import (
"os"
"path/filepath"

"github.com/rs/zerolog"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)

var globalContext, _ = context.WithCancel(context.Background())

func init() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}

func main() {
homeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/bnb-chain/greenfield-go-sdk v1.0.0
github.com/cosmos/cosmos-sdk v0.47.3
github.com/ethereum/go-ethereum v1.10.26
github.com/rs/zerolog v1.29.1
github.com/urfave/cli/v2 v2.10.2
golang.org/x/term v0.9.0
)
Expand All @@ -25,7 +26,7 @@ require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f // indirect
github.com/bnb-chain/greenfield-common/go v0.0.0-20230906132736-eb2f0efea228 // indirect
github.com/btcsuite/btcd v0.23.3 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.2 // indirect
Expand Down Expand Up @@ -107,7 +108,6 @@ require (
github.com/prysmaticlabs/prysm v0.0.0-20220124113610-e26cde5e091b // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr
github.com/bnb-chain/greenfield-cometbft v1.0.0/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-common v0.0.8 h1:OGRXHurdjPhdgAmLzMzNccFvsS0aIb4a/03IuqHYeME=
github.com/bnb-chain/greenfield-common v0.0.8/go.mod h1:XW4HfxK9D61fLflqfp4OUqtVJuRaf6j8LSygmIs2EAk=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0 h1:hWRvYunA4Um19gwL1SVfMwN9l431ROC7XZ+A5+xM/Bk=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230906132736-eb2f0efea228 h1:WywBaew30hZuqDTOQbkRV3uBg6XHjNIE1s3AXVXbG+8=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230906132736-eb2f0efea228/go.mod h1:K9jK80fbahciC+FAvrch8Qsbw9ZkvVgjfKsqrzPTAVA=
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=
Expand Down

0 comments on commit 3967104

Please sign in to comment.