-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: auth-register command to use new method ZCNSCAddAuthorizer.
go mod tidy.
- Loading branch information
1 parent
905407c
commit fb0cc02
Showing
3 changed files
with
107 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
Check failure on line 4 in cmd/auth-register.go GitHub Actions / unit-test
|
||
"github.com/0chain/gosdk/zcnbridge" | ||
Check failure on line 5 in cmd/auth-register.go GitHub Actions / unit-test
|
||
"github.com/0chain/gosdk/zcncore" | ||
Check failure on line 6 in cmd/auth-register.go GitHub Actions / unit-test
|
||
"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)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters