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"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"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/request"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -146,6 +145,10 @@ func (c *Client) Init() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get network magic: %w", err)
|
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()
|
c.cacheLock.Lock()
|
||||||
defer c.cacheLock.Unlock()
|
defer c.cacheLock.Unlock()
|
||||||
|
@ -156,21 +159,10 @@ func (c *Client) Init() error {
|
||||||
c.cache.network = version.Magic
|
c.cache.network = version.Magic
|
||||||
c.cache.stateRootInHeader = version.StateRootInHeader
|
c.cache.stateRootInHeader = version.StateRootInHeader
|
||||||
}
|
}
|
||||||
neoContractHash, err := c.GetContractStateByAddressOrName(nativenames.Neo)
|
for _, ctr := range natives {
|
||||||
if err != nil {
|
c.cache.nativeHashes[ctr.Manifest.Name] = ctr.Hash
|
||||||
return fmt.Errorf("failed to get NEO contract scripthash: %w", err)
|
|
||||||
}
|
}
|
||||||
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
|
c.cache.initDone = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue