From 5bdcd4c241ed7e09811ce98e22e950d398220175 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 21 Jul 2021 12:19:55 +0300 Subject: [PATCH 1/2] client: add GetCandidateRegisterPrice method It's important for clients. --- pkg/rpc/client/native.go | 11 ++++++++++- pkg/rpc/client/rpc_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/client/native.go b/pkg/rpc/client/native.go index 6081d1175..bfbed495e 100644 --- a/pkg/rpc/client/native.go +++ b/pkg/rpc/client/native.go @@ -30,11 +30,20 @@ func (c *Client) GetNNSPrice(nnsHash util.Uint160) (int64, error) { // GetGasPerBlock invokes `getGasPerBlock` method on a native NEO contract. func (c *Client) GetGasPerBlock() (int64, error) { + return c.getFromNEO("getGasPerBlock") +} + +// GetCandidateRegisterPrice invokes `getRegisterPrice` method on native NEO contract. +func (c *Client) GetCandidateRegisterPrice() (int64, error) { + return c.getFromNEO("getRegisterPrice") +} + +func (c *Client) getFromNEO(meth string) (int64, error) { neoHash, err := c.GetNativeContractHash(nativenames.Neo) if err != nil { return 0, fmt.Errorf("failed to get native NEO hash: %w", err) } - return c.invokeNativeGetMethod(neoHash, "getGasPerBlock") + return c.invokeNativeGetMethod(neoHash, meth) } // GetDesignatedByRole invokes `getDesignatedByRole` method on a native RoleManagement contract. diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index c33f37497..55fff2543 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -478,6 +478,18 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, + "getCandidateRegisterPrice": { + { + name: "positive", + invoke: func(c *Client) (interface{}, error) { + return c.GetCandidateRegisterPrice() + }, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"100000000000"}],"tx":null}}`, + result: func(c *Client) interface{} { + return int64(100000000000) + }, + }, + }, "getDesignatedByRole": { { name: "positive", From 5fbb60a9ed012b55c11c5d1d440aa246efc7fd4b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 21 Jul 2021 12:25:42 +0300 Subject: [PATCH 2/2] cli/wallet: request candidate registration price Hardcoding 1000 is wrong. Inspired by neo-project/neo-node#788. --- cli/wallet/validator.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index cee1ffaf4..0289ae47c 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -90,7 +90,7 @@ func newValidatorCommands() []cli.Command { } func handleRegister(ctx *cli.Context) error { - return handleCandidate(ctx, "registerCandidate", 1001*100000000) // registering costs 1000 GAS + return handleCandidate(ctx, "registerCandidate", 100000000) // 1 additional GAS. } func handleUnregister(ctx *cli.Context) error { @@ -122,6 +122,14 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { return cli.NewExitError(err, 1) } + if sysGas >= 0 { + regPrice, err := c.GetCandidateRegisterPrice() + if err != nil { + return cli.NewExitError(err, 1) + } + sysGas += regPrice + } + gas := flags.Fixed8FromContext(ctx, "gas") neoContractHash, err := c.GetNativeContractHash(nativenames.Neo) if err != nil {