From 905407c9a27894a336e85f9e0dad33a9d3adf7a0 Mon Sep 17 00:00:00 2001 From: yash10019coder Date: Wed, 18 Sep 2024 02:29:08 +0530 Subject: [PATCH 1/4] go mod tidy. --- go.mod | 4 ++-- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2632d87..a09d5cd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0chain/zwalletcli go 1.21 require ( - github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c + github.com/0chain/gosdk v1.17.7-0.20240915215339-03ae61489c3a github.com/ethereum/go-ethereum v1.13.2 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 @@ -112,4 +112,4 @@ require ( ) // temporary, for development -//replace github.com/0chain/gosdk => ../gosdk +replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index edd0165..d3d2e6b 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= 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.17.7-0.20240913214358-e71c555b3b9c h1:o8SPHAi3/bUMFqMPVNhMs77Ce5qxLzs5Q9YYyuT/llQ= -github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= +github.com/0chain/gosdk v1.17.7-0.20240915215339-03ae61489c3a h1:S50oSGLap4c953VHWbQ6/pPWVHWHs7GMW21ZXfMBGq8= +github.com/0chain/gosdk v1.17.7-0.20240915215339-03ae61489c3a/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= 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= From fb0cc02dbb716e1f7fdd0d9a14d8f49165e90721 Mon Sep 17 00:00:00 2001 From: yash10019coder Date: Thu, 19 Sep 2024 00:43:01 +0530 Subject: [PATCH 2/4] refactor: auth-register command to use new method ZCNSCAddAuthorizer. go mod tidy. --- cmd/auth-register.go | 215 +++++++++++++++++++++---------------------- go.mod | 2 +- go.sum | 2 - 3 files changed, 107 insertions(+), 112 deletions(-) diff --git a/cmd/auth-register.go b/cmd/auth-register.go index 4d89b85..64ae42d 100644 --- a/cmd/auth-register.go +++ b/cmd/auth-register.go @@ -1,111 +1,108 @@ package cmd -// -//import ( -// "context" -// "log" -// "strings" -// -// "github.com/0chain/gosdk/zcnbridge" -// "github.com/0chain/gosdk/zcnbridge/transaction" -// "github.com/0chain/gosdk/zcncore" -// "github.com/pkg/errors" -//) -// -////goland:noinspection ALL -//func init() { -// rootCmd.AddCommand( -// createCommandWithBridge( -// "auth-register", -// "Register an authorizer manually", -// "Register an authorizer manually", -// registerAuthorizerInChain, -// true, -// &Option{ -// name: "url", -// typename: "string", -// value: "", -// usage: "authorizer endpoint url", -// required: true, -// }, -// &Option{ -// name: "client_id", -// typename: "string", -// value: "", -// usage: "the client_id of the wallet", -// required: true, -// }, -// &Option{ -// name: "client_key", -// typename: "string", -// value: "", -// usage: "the client_key which is the public key of the wallet", -// required: true, -// }, -// &Option{ -// name: "min_stake", -// typename: "int64", -// value: int64(1), -// usage: "the minimum stake value for the stake pool", -// required: false, -// }, -// &Option{ -// name: "max_stake", -// typename: "int64", -// value: int64(10), -// usage: "the maximum stake value for the stake pool", -// required: false, -// }, -// &Option{ -// name: "num_delegates", -// typename: "int", -// value: 5, -// usage: "the number of delegates in the authorizer stake pool", -// required: false, -// }, -// &Option{ -// name: "service_charge", -// typename: "float64", -// value: 0.0, -// usage: "the service charge for the authorizer stake pool", -// required: false, -// }, -// )) -//} -// -//// registerAuthorizerInChain registers a new authorizer -//// addAuthorizerPayload *addAuthorizerPayload -//func registerAuthorizerInChain(bc *zcnbridge.BridgeClient, args ...*Arg) { -// clientID := GetClientID(args) -// clientKey := GetClientKey(args) -// url := GetURL(args) -// numDelegates := GetNumDelegates(args) -// serviceCharge := GetServiceCharge(args) -// -// input := &zcncore.AddAuthorizerPayload{ -// PublicKey: clientKey, -// URL: url, -// StakePoolSettings: zcncore.AuthorizerStakePoolSettings{ -// DelegateWallet: clientID, -// NumDelegates: numDelegates, -// ServiceCharge: serviceCharge, -// }, -// } -// -// trx, err := transaction.AddAuthorizer(context.Background(), input) -// if err != nil { -// log.Fatal(err, "failed to add authorizer with transaction: '%s'", trx.GetHash()) -// } -// -// log.Printf("Authorizer submitted OK... " + trx.GetHash()) -// log.Printf("Starting verification: " + trx.GetHash()) -// -// err = trx.Verify(context.Background()) -// if err != nil { -// if strings.Contains(err.Error(), "already exists") { -// ExitWithError("Authorizer has already been added to 0Chain... Continue") -// } else { -// ExitWithError(errors.Wrapf(err, "failed to verify transaction: '%s'", trx.GetHash())) -// } -// } -//} +import ( + "github.com/0chain/gosdk/core/transaction" + "github.com/0chain/gosdk/zcnbridge" + "github.com/0chain/gosdk/zcncore" + "github.com/pkg/errors" + "log" + "strings" +) + +//goland:noinspection ALL +func init() { + rootCmd.AddCommand( + createCommandWithBridge( + "auth-register", + "Register an authorizer manually", + "Register an authorizer manually", + registerAuthorizerInChain, + true, + &Option{ + name: "url", + typename: "string", + value: "", + usage: "authorizer endpoint url", + required: true, + }, + &Option{ + name: "client_id", + typename: "string", + value: "", + usage: "the client_id of the wallet", + required: true, + }, + &Option{ + name: "client_key", + typename: "string", + value: "", + usage: "the client_key which is the public key of the wallet", + required: true, + }, + &Option{ + name: "min_stake", + typename: "int64", + value: int64(1), + usage: "the minimum stake value for the stake pool", + required: false, + }, + &Option{ + name: "max_stake", + typename: "int64", + value: int64(10), + usage: "the maximum stake value for the stake pool", + required: false, + }, + &Option{ + name: "num_delegates", + typename: "int", + value: 5, + usage: "the number of delegates in the authorizer stake pool", + required: false, + }, + &Option{ + name: "service_charge", + typename: "float64", + value: 0.0, + usage: "the service charge for the authorizer stake pool", + required: false, + }, + )) +} + +// registerAuthorizerInChain registers a new authorizer +// addAuthorizerPayload *addAuthorizerPayload +func registerAuthorizerInChain(bc *zcnbridge.BridgeClient, args ...*Arg) { + clientID := GetClientID(args) + clientKey := GetClientKey(args) + url := GetURL(args) + numDelegates := GetNumDelegates(args) + serviceCharge := GetServiceCharge(args) + + input := &zcncore.AddAuthorizerPayload{ + PublicKey: clientKey, + URL: url, + StakePoolSettings: zcncore.AuthorizerStakePoolSettings{ + DelegateWallet: clientID, + NumDelegates: numDelegates, + ServiceCharge: serviceCharge, + }, + } + + hash, _, _, txn, err := zcncore.ZCNSCAddAuthorizer(input) + if err != nil { + log.Fatal(err, "failed to add authorizer with transaction: '%s'", hash) + } + + log.Printf("Authorizer submitted OK... " + hash) + log.Printf("Starting verification: " + hash) + + txn, err = transaction.VerifyTransaction(hash) + if err != nil { + if strings.Contains(err.Error(), "already exists") { + ExitWithError("Authorizer has already been added to 0Chain... Continue") + } else { + ExitWithError(errors.Wrapf(err, "failed to verify transaction: '%s'", txn.Hash)) + } + } +} diff --git a/go.mod b/go.mod index a09d5cd..4b5b439 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/ethereum/go-ethereum v1.13.2 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 + github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.16.0 @@ -68,7 +69,6 @@ require ( github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/philhofer/fwd v1.1.2-0.20210722190033-5c56ac6d0bb9 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/common v0.39.0 // indirect github.com/prometheus/procfs v0.11.0 // indirect diff --git a/go.sum b/go.sum index d3d2e6b..0b8aa37 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= 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.17.7-0.20240915215339-03ae61489c3a h1:S50oSGLap4c953VHWbQ6/pPWVHWHs7GMW21ZXfMBGq8= -github.com/0chain/gosdk v1.17.7-0.20240915215339-03ae61489c3a/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= 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= From acdca50bf181ea2960c4ba1e9c24ff4a8adbb5eb Mon Sep 17 00:00:00 2001 From: yash10019coder Date: Thu, 19 Sep 2024 00:48:25 +0530 Subject: [PATCH 3/4] refactor: go mod to use latest gosdk from fix/refactor-zboxcore PR. go mod tidy. --- go.mod | 2 +- go.sum | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4b5b439..efc4500 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0chain/zwalletcli go 1.21 require ( - github.com/0chain/gosdk v1.17.7-0.20240915215339-03ae61489c3a + github.com/0chain/gosdk v1.17.7-0.20240917221834-5e19f7a24a72 github.com/ethereum/go-ethereum v1.13.2 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 diff --git a/go.sum b/go.sum index 0b8aa37..d98e1ad 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,9 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= 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.17.7-0.20240915215339-03ae61489c3a/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= +github.com/0chain/gosdk v1.17.7-0.20240917221834-5e19f7a24a72 h1:XTA+MdqqC0zxDYQ7YjKaEFesm17CltsNoZn5tdif3Fc= +github.com/0chain/gosdk v1.17.7-0.20240917221834-5e19f7a24a72/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= 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= From ec78e61f50461d347fa358e39f6a9d5b05a929dd Mon Sep 17 00:00:00 2001 From: yash10019coder Date: Thu, 19 Sep 2024 00:51:22 +0530 Subject: [PATCH 4/4] refactor: go mod to use latest gosdk from fix/refactor-zboxcore PR. go mod tidy. --- go.mod | 2 +- go.sum | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index efc4500..670869c 100644 --- a/go.mod +++ b/go.mod @@ -112,4 +112,4 @@ require ( ) // temporary, for development -replace github.com/0chain/gosdk => ../gosdk +//replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index d98e1ad..17ea23c 100644 --- a/go.sum +++ b/go.sum @@ -40,7 +40,6 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= 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.17.7-0.20240915215339-03ae61489c3a/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= github.com/0chain/gosdk v1.17.7-0.20240917221834-5e19f7a24a72 h1:XTA+MdqqC0zxDYQ7YjKaEFesm17CltsNoZn5tdif3Fc= github.com/0chain/gosdk v1.17.7-0.20240917221834-5e19f7a24a72/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=