From 81722c373b3d4fcfc40f64fb0afe81ebaf0d1dbd Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 2 Sep 2021 09:57:19 +0300 Subject: [PATCH] [#746] morph/client: Don't cache GAS contract address on NeoFS-side Caching is performed inside `GetNativeContractHash` method of neo-go client, so the additional cache level is redundant. Signed-off-by: Leonard Lyubich --- CHANGELOG.md | 3 ++- pkg/morph/client/client.go | 16 ++++++++++++---- pkg/morph/client/multi.go | 7 ------- pkg/morph/client/notary.go | 7 ++++++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc45adb..16722348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -587,7 +587,8 @@ NeoFS-API v2.0 support and updated brand-new storage node application. First public review release. -[Unreleased]: https://github.com/nspcc-dev/neofs-node/compare/v0.23.1...master +[Unreleased]: https://github.com/nspcc-dev/neofs-node/compare/v0.24.0...master +[0.24.0]: https://github.com/nspcc-dev/neofs-node/compare/v0.23.1...v0.24.0 [0.23.1]: https://github.com/nspcc-dev/neofs-node/compare/v0.23.0...v0.23.1 [0.23.0]: https://github.com/nspcc-dev/neofs-node/compare/v0.22.3...v0.23.0 [0.22.3]: https://github.com/nspcc-dev/neofs-node/compare/v0.22.2...v0.22.3 diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 44b75828..47c9f805 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -47,8 +47,6 @@ type singleClient struct { acc *wallet.Account // neo account - gas util.Uint160 // native gas script-hash - waitInterval time.Duration signer *transaction.Signer @@ -215,7 +213,12 @@ func (c *Client) TransferGas(receiver util.Uint160, amount fixedn.Fixed8) error }) } - txHash, err := c.client.TransferNEP17(c.acc, receiver, c.gas, int64(amount), 0, nil, nil) + gas, err := c.client.GetNativeContractHash(nativenames.Gas) + if err != nil { + return err + } + + txHash, err := c.client.TransferNEP17(c.acc, receiver, gas, int64(amount), 0, nil, nil) if err != nil { return err } @@ -281,7 +284,12 @@ func (c *Client) GasBalance() (res int64, err error) { }) } - return c.client.NEP17BalanceOf(c.gas, c.acc.PrivateKey().GetScriptHash()) + gas, err := c.client.GetNativeContractHash(nativenames.Gas) + if err != nil { + return 0, err + } + + return c.client.NEP17BalanceOf(gas, c.acc.PrivateKey().GetScriptHash()) } // Committee returns keys of chain committee from neo native contract. diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index e7caca66..7b3055ff 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -3,7 +3,6 @@ package client import ( "sync" - "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/wallet" "go.uber.org/zap" @@ -37,17 +36,11 @@ func (x *multiClient) createForAddress(addr string) (*Client, error) { return nil, err } - gas, err := cli.GetNativeContractHash(nativenames.Gas) - if err != nil { - return nil, err - } - c := &Client{ singleClient: &singleClient{ logger: x.cfg.logger, client: cli, acc: x.account, - gas: gas, waitInterval: x.cfg.waitInterval, signer: x.cfg.signer, notary: x.sharedNotary, diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index f3ff02e3..dc051e70 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -151,10 +151,15 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uin return util.Uint256{}, fmt.Errorf("can't get blockchain height: %w", err) } + gas, err := c.client.GetNativeContractHash(nativenames.Gas) + if err != nil { + return util.Uint256{}, err + } + txHash, err := c.client.TransferNEP17( c.acc, c.notary.notary, - c.gas, + gas, int64(amount), 0, []interface{}{c.acc.PrivateKey().GetScriptHash(), int64(bc + delta)},