rpc: improve RPC Client initialization

Thanks to #2463.
This commit is contained in:
Anna Shaleva 2022-05-06 13:56:09 +03:00
parent 75d06d18c9
commit 1782e16be4
2 changed files with 9 additions and 15 deletions

View file

@ -13,7 +13,6 @@ import (
"time"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -146,6 +145,10 @@ func (c *Client) Init() error {
if err != nil {
return fmt.Errorf("failed to get network magic: %w", err)
}
natives, err := c.GetNativeContracts()
if err != nil {
return fmt.Errorf("failed to get native contracts: %w", err)
}
c.cacheLock.Lock()
defer c.cacheLock.Unlock()
@ -156,21 +159,10 @@ func (c *Client) Init() error {
c.cache.network = version.Magic
c.cache.stateRootInHeader = version.StateRootInHeader
}
neoContractHash, err := c.GetContractStateByAddressOrName(nativenames.Neo)
if err != nil {
return fmt.Errorf("failed to get NEO contract scripthash: %w", err)
for _, ctr := range natives {
c.cache.nativeHashes[ctr.Manifest.Name] = ctr.Hash
}
c.cache.nativeHashes[nativenames.Neo] = neoContractHash.Hash
gasContractHash, err := c.GetContractStateByAddressOrName(nativenames.Gas)
if err != nil {
return fmt.Errorf("failed to get GAS contract scripthash: %w", err)
}
c.cache.nativeHashes[nativenames.Gas] = gasContractHash.Hash
policyContractHash, err := c.GetContractStateByAddressOrName(nativenames.Policy)
if err != nil {
return fmt.Errorf("failed to get Policy contract scripthash: %w", err)
}
c.cache.nativeHashes[nativenames.Policy] = policyContractHash.Hash
c.cache.initDone = true
return nil
}

File diff suppressed because one or more lines are too long