forked from TrueCloudLab/frostfs-node
[#2091] morph/client: Do not use deprecated methods
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
51e886dd67
commit
6af52c46d8
5 changed files with 33 additions and 65 deletions
|
@ -8,12 +8,10 @@ import (
|
|||
"time"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
|
@ -119,6 +117,7 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
|
|||
cli.endpoints.init(cfg.endpoints)
|
||||
|
||||
var err error
|
||||
var act *actor.Actor
|
||||
if cfg.singleCli != nil {
|
||||
// return client in single RPC node mode that uses
|
||||
// predefined WS client
|
||||
|
@ -129,51 +128,42 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
|
|||
// inactive mode will be enabled
|
||||
cli.client = cfg.singleCli
|
||||
|
||||
cli.rpcActor, err = newActor(cfg.singleCli, acc, *cfg)
|
||||
act, err = newActor(cfg.singleCli, acc, *cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create RPC actor: %w", err)
|
||||
}
|
||||
|
||||
cli.gasToken, err = newGasToken(cli.client, cli.rpcActor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create gas token actor: %w", err)
|
||||
}
|
||||
} else {
|
||||
cli.client, cli.rpcActor, cli.gasToken, err = cli.newCli(cli.endpoints.list[0].Address)
|
||||
cli.client, act, err = cli.newCli(cli.endpoints.list[0].Address)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create RPC client: %w", err)
|
||||
}
|
||||
}
|
||||
cli.setActor(act)
|
||||
|
||||
go cli.notificationLoop()
|
||||
|
||||
return cli, nil
|
||||
}
|
||||
|
||||
func (c *Client) newCli(endpoint string) (*rpcclient.WSClient, *actor.Actor, *nep17.Token, error) {
|
||||
func (c *Client) newCli(endpoint string) (*rpcclient.WSClient, *actor.Actor, error) {
|
||||
cli, err := rpcclient.NewWS(c.cfg.ctx, endpoint, rpcclient.Options{
|
||||
DialTimeout: c.cfg.dialTimeout,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("WS client creation: %w", err)
|
||||
return nil, nil, fmt.Errorf("WS client creation: %w", err)
|
||||
}
|
||||
|
||||
err = cli.Init()
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("WS client initialization: %w", err)
|
||||
return nil, nil, fmt.Errorf("WS client initialization: %w", err)
|
||||
}
|
||||
|
||||
act, err := newActor(cli, c.acc, c.cfg)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("RPC actor creation: %w", err)
|
||||
return nil, nil, fmt.Errorf("RPC actor creation: %w", err)
|
||||
}
|
||||
|
||||
gas, err := newGasToken(cli, act)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("gas token actor: %w", err)
|
||||
}
|
||||
|
||||
return cli, act, gas, nil
|
||||
return cli, act, nil
|
||||
}
|
||||
|
||||
func newActor(ws *rpcclient.WSClient, acc *wallet.Account, cfg cfg) (*actor.Actor, error) {
|
||||
|
@ -188,15 +178,6 @@ func newActor(ws *rpcclient.WSClient, acc *wallet.Account, cfg cfg) (*actor.Acto
|
|||
}})
|
||||
}
|
||||
|
||||
func newGasToken(cli *rpcclient.WSClient, a *actor.Actor) (*nep17.Token, error) {
|
||||
gasHash, err := cli.GetNativeContractHash(nativenames.Gas)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gas contract hash: %w", err)
|
||||
}
|
||||
|
||||
return nep17.New(a, gasHash), nil
|
||||
}
|
||||
|
||||
func newClientCache() cache {
|
||||
c, _ := lru.New(100) // returns error only if size is negative
|
||||
return cache{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue