Skip to content

Commit

Permalink
Merge pull request #1514 from 0chain/feature/kms-wallet-setup
Browse files Browse the repository at this point in the history
Feature: add automatic kms wallet detection
  • Loading branch information
dabasov authored Dec 13, 2024
2 parents f865e7f + be6991f commit fb6ebf7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
17 changes: 14 additions & 3 deletions code/go/0chain.net/blobber/zcn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"time"

"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/handler"
Expand All @@ -11,8 +13,8 @@ import (
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
"github.com/0chain/blobber/code/go/0chain.net/core/node"
"github.com/0chain/gosdk/core/client"
"github.com/0chain/gosdk/zcncore"
"go.uber.org/zap"
"time"
)

func registerOnChain() error {
Expand Down Expand Up @@ -81,11 +83,20 @@ func setupServerChain() error {
serverChain := chain.NewChainFromConfig()
chain.SetServerChain(serverChain)

if err := client.InitSDK(node.Self.GetWalletString(), serverChain.BlockWorker, config.Configuration.ChainID, config.Configuration.SignatureScheme,
0, false, true); err != nil {
err := client.InitSDK("{}", serverChain.BlockWorker, config.Configuration.ChainID, config.Configuration.SignatureScheme, 0, false)
if err != nil {
return err
}

err = zcncore.SetGeneralWalletInfo(node.Self.GetWalletString(), config.Configuration.SignatureScheme)
if err != nil {
return err
}

if client.GetClient().IsSplit {
zcncore.RegisterZauthServer(serverChain.ZauthServer)
}

fmt.Print(" [OK]\n")
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ func setup(t *testing.T) {
},
),
)

//if err := client.InitSDK(server.URL, "ed25519"); err != nil {
// t.Fatal(err)
//}
}
func setupMockForFileManagerInit(mock sqlmock.Sqlmock) {
mock.ExpectBegin()
Expand Down
4 changes: 3 additions & 1 deletion code/go/0chain.net/core/chain/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Chain struct {
OwnerID string
ParentChainID string
BlockWorker string
ZauthServer string

GenesisBlockHash string
}
Expand All @@ -44,12 +45,13 @@ func (c *Chain) Validate(ctx context.Context) error {
return nil
}

//NewChainFromConfig - create a new chain from config
// NewChainFromConfig - create a new chain from config
func NewChainFromConfig() *Chain {
chain := Provider()
chain.ID = common.ToKey(config.Configuration.ChainID)
chain.OwnerID = viper.GetString("server_chain.owner")
chain.BlockWorker = viper.GetString("block_worker")
chain.ZauthServer = viper.GetString("zauth_server")
return chain
}

Expand Down
21 changes: 17 additions & 4 deletions code/go/0chain.net/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"flag"
"fmt"
"github.com/0chain/gosdk/core/client"
coreTxn "github.com/0chain/gosdk/core/transaction"
"log"
"net/http"
"os"
Expand All @@ -14,6 +12,9 @@ import (
"strings"
"time"

"github.com/0chain/gosdk/core/client"
coreTxn "github.com/0chain/gosdk/core/transaction"

"github.com/0chain/blobber/code/go/0chain.net/core/build"
"github.com/0chain/blobber/code/go/0chain.net/core/chain"
"github.com/0chain/blobber/code/go/0chain.net/core/common/handler"
Expand Down Expand Up @@ -231,11 +232,23 @@ func SetupValidatorOnBC(logDir string) error {
var logName = logDir + "/validator.log"
zcncore.SetLogFile(logName, false)
zcncore.SetLogLevel(3)
if err := client.InitSDK(node.Self.GetWalletString(), serverChain.BlockWorker,
config.Configuration.ChainID, config.Configuration.SignatureScheme, int64(0), false, true); err != nil {

err := client.InitSDK("{}", serverChain.BlockWorker, config.Configuration.ChainID, config.Configuration.SignatureScheme, int64(0), false)
if err != nil {
return err
}

err = zcncore.SetGeneralWalletInfo(node.Self.GetWalletString(), config.Configuration.SignatureScheme)
if err != nil {
return err
}

if client.GetClient().IsSplit {
zcncore.RegisterZauthServer(serverChain.ZauthServer)
}

go RegisterValidator()

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.5

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.18.0
github.com/0chain/gosdk v1.18.14-0.20241213132439-44330cc9ecb8
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/didip/tollbooth/v6 v6.1.2
github.com/go-openapi/runtime v0.26.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.18.0 h1:6mSiUFb4liT50wdsx59tEWMHKWkKQUlZT91ouQAeKcc=
github.com/0chain/gosdk v1.18.0/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
github.com/0chain/gosdk v1.18.14-0.20241213132439-44330cc9ecb8 h1:JvP2ZRYlUT/PQ7dkB4anvgPZXwGBW2sO2SypmKQ9Zu4=
github.com/0chain/gosdk v1.18.14-0.20241213132439-44330cc9ecb8/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
Expand Down

0 comments on commit fb6ebf7

Please sign in to comment.