[#749] morph/client: cache NNS contract hash
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
050a4bb2b0
commit
4838d3bb80
2 changed files with 13 additions and 5 deletions
|
@ -33,13 +33,18 @@ import (
|
|||
// expression (or just declaring a Client variable) is unsafe
|
||||
// and can lead to panic.
|
||||
type Client struct {
|
||||
// two mutual exclusive modes, exactly one must be non-nil
|
||||
cache
|
||||
|
||||
// two mutual exclusive modes, exactly one must be non-nil
|
||||
*singleClient // works with single neo-go client
|
||||
|
||||
*multiClient // creates and caches single clients
|
||||
}
|
||||
|
||||
type cache struct {
|
||||
nnsHash util.Uint160
|
||||
}
|
||||
|
||||
type singleClient struct {
|
||||
logger *logger.Logger // logging component
|
||||
|
||||
|
|
|
@ -58,12 +58,15 @@ func (c *Client) NNSContractAddress(name string) (sh util.Uint160, err error) {
|
|||
})
|
||||
}
|
||||
|
||||
cs, err := c.client.GetContractStateByID(nnsContractID) // cache it?
|
||||
if err != nil {
|
||||
return sh, fmt.Errorf("NNS contract state: %w", err)
|
||||
if c.nnsHash.Equals(util.Uint160{}) {
|
||||
cs, err := c.client.GetContractStateByID(nnsContractID)
|
||||
if err != nil {
|
||||
return sh, fmt.Errorf("NNS contract state: %w", err)
|
||||
}
|
||||
c.nnsHash = cs.Hash
|
||||
}
|
||||
|
||||
sh, err = nnsResolve(c.client, cs.Hash, name)
|
||||
sh, err = nnsResolve(c.client, c.nnsHash, name)
|
||||
if err != nil {
|
||||
return sh, fmt.Errorf("NNS.resolve: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue