Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/refactor zboxcore #638

Merged
merged 18 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/system_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: 0chain/actions/.github/workflows/manual_system_tests.yml@master
with:
zbox_cli_branch: ${{ github.ref_name }}
repo_snapshots_branch: ${{ github.event.inputs.repo_snapshots_branch }}
repo_snapshots_branch: fix/refactor-zboxcore
test_file_filter: ${{ github.event.inputs.test_file_filter }}
skip_tests: ${{ github.event.inputs.skip_tests }}
run_smoke_tests: ${{ github.event.inputs.run_smoke_tests }}
Expand Down
157 changes: 0 additions & 157 deletions cmd/readpool.go

This file was deleted.

63 changes: 7 additions & 56 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package cmd

import (
_ "embed"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/logger"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/0chain/gosdk/zboxcore/blockchain"
"github.com/0chain/gosdk/core/client"
"github.com/0chain/zboxcli/util"

"github.com/0chain/gosdk/core/zcncrypto"
Expand All @@ -37,9 +35,6 @@

var walletJSON string

//go:embed config.yaml
var configStr string

var rootCmd = &cobra.Command{
Use: "zbox",
Short: "zbox is a decentralized storage application written on the 0Chain platform",
Expand Down Expand Up @@ -83,48 +78,21 @@
cfg, err := conf.LoadConfigFile(filepath.Join(configDir, cfgFile))
if err != nil {
fmt.Println("Can't read config:", err)
fmt.Println("using default config")
fmt.Printf("config: %v", configStr)
v := viper.New()
v.SetConfigType("yaml")
err := v.ReadConfig(strings.NewReader(configStr))
if err != nil {
fmt.Println("error reading default config:", err)
os.Exit(1)
}
cfg, err = conf.LoadConfig(v)
if err != nil {
fmt.Println("error loading default config:", err)
os.Exit(1)
}
os.Exit(1)
}

if networkFile == "" {
networkFile = "network.yaml"
}
network, _ := conf.LoadNetworkFile(filepath.Join(configDir, networkFile))

// syncing loggers
logger.SyncLoggers([]*logger.Logger{zcncore.GetLogger(), sdk.GetLogger()})

// set the log file
zcncore.SetLogFile("cmdlog.log", !bSilent)
sdk.SetLogFile("cmdlog.log", !bSilent)
sdk.SetMinSubmit(cfg.MinSubmit)

if network.IsValid() {
zcncore.SetNetwork(network.Miners, network.Sharders)
conf.InitChainNetwork(&conf.Network{
Miners: network.Miners,
Sharders: network.Sharders,
})
}

err = zcncore.InitZCNSDK(cfg.BlockWorker, cfg.SignatureScheme,
zcncore.WithChainID(cfg.ChainID),
zcncore.WithMinSubmit(cfg.MinSubmit),
zcncore.WithMinConfirmation(cfg.MinConfirmation),
zcncore.WithConfirmationChainLength(cfg.ConfirmationChainLength))
err = client.Init(context.Background(), cfg)
if err != nil {
fmt.Println("Error initializing core SDK.", err)
os.Exit(1)
Expand Down Expand Up @@ -198,35 +166,18 @@
}

//init the storage sdk with the known miners, sharders and client wallet info
if err = sdk.InitStorageSDK(
if err = client.InitSDK(

Check failure on line 169 in cmd/root.go

View workflow job for this annotation

GitHub Actions / unit-test

undefined: client.InitSDK
walletJSON,
cfg.BlockWorker,
cfg.ChainID,
cfg.SignatureScheme,
cfg.PreferredBlobbers,
nonce,
zcncore.ConvertToValue(txFee),
false, true,
int(zcncore.ConvertToValue(txFee)),
); err != nil {
fmt.Println("Error in sdk init", err)
os.Exit(1)
}

// set wallet info along whether split key is used
err = zcncore.SetWalletInfo(walletJSON, false)
if err != nil {
fmt.Println("Error in wallet info initialization", err)
os.Exit(1)
}

// additional settings depending network latency
blockchain.SetMaxTxnQuery(cfg.MaxTxnQuery)
blockchain.SetQuerySleepTime(cfg.QuerySleepTime)

conf.InitClientConfig(&cfg)

if network.IsValid() {
sdk.SetNetwork(network.Miners, network.Sharders)
}

sdk.SetNumBlockDownloads(10)
}
5 changes: 3 additions & 2 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/0chain/gosdk/core/transaction"
"log"
"time"

Expand All @@ -23,7 +24,7 @@ var scConfig = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
doJSON, _ := cmd.Flags().GetBool("json")

var conf, err = sdk.GetStorageSCConfig()
var conf, err = transaction.GetConfig("storage_sc_config")
if err != nil {
log.Fatalf("Failed to get storage SC configurations: %v", err)
}
Expand Down Expand Up @@ -77,7 +78,7 @@ var lsBlobers = &cobra.Command{
}
list, err := sdk.GetBlobbers(isActive, isStakable)
if err != nil {
log.Fatalf("Failed to get storage SC configurations: %v", err)
log.Fatalf("Failed to get blobbers: %v", err)
}

if doJSON {
Expand Down
10 changes: 5 additions & 5 deletions cmd/walletinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"fmt"
"os"

"github.com/0chain/gosdk/core/client"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/zboxcore/client"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/zboxcli/util"

Expand Down Expand Up @@ -48,11 +48,11 @@
fmt.Println("Error getting the public key for encryption. ", err.Error())
return
}
data[0] = []string{client.GetClientPublicKey(), client.GetClientID(), encPubKey}
data[0] = []string{client.PublicKey(), client.Id(), encPubKey}

Check failure on line 51 in cmd/walletinfo.go

View workflow job for this annotation

GitHub Actions / unit-test

undefined: client.Id
if doJSON {
j := make(map[string]string)
j["client_public_key"] = client.GetClientPublicKey()
j["client_id"] = client.GetClientID()
j["client_public_key"] = client.PublicKey()
j["client_id"] = client.Id()

Check failure on line 55 in cmd/walletinfo.go

View workflow job for this annotation

GitHub Actions / unit-test

undefined: client.Id
j["encryption_public_key"] = encPubKey
util.PrintJSON(j)
return
Expand All @@ -70,7 +70,7 @@
Run: func(cmd *cobra.Command, args []string) {
data, _ := cmd.Flags().GetString("data")
if data == "" {
data = client.GetClientID()
data = client.Id()

Check failure on line 73 in cmd/walletinfo.go

View workflow job for this annotation

GitHub Actions / unit-test

undefined: client.Id
} else {
data = encryption.Hash(data)
}
Expand Down
Loading
Loading