mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
Merge pull request #2468 from nspcc-dev/rpc/improve-init
rpc: improve RPC Client initialization
This commit is contained in:
commit
7a2c7fa0bf
2 changed files with 9 additions and 15 deletions
|
@ -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
Loading…
Reference in a new issue