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 system tests #401

Merged
merged 4 commits into from
Sep 19, 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
215 changes: 106 additions & 109 deletions cmd/auth-register.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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.20240917221834-5e19f7a24a72
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
Expand Down Expand Up @@ -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
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 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.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=
Expand Down
Loading