diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 9d8d26ebf3..b60ffe79ef 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -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 diff --git a/pkg/morph/client/nns.go b/pkg/morph/client/nns.go index f20b621974..4ae3d303ab 100644 --- a/pkg/morph/client/nns.go +++ b/pkg/morph/client/nns.go @@ -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) }