mirror of
https://github.com/status-im/status-go.git
synced 2025-01-12 15:45:07 +00:00
feat: add reverse lookup for ens (#2912)
This commit is contained in:
parent
b2dce92f3f
commit
a69a59c601
@ -19,23 +19,26 @@ type ContractMaker struct {
|
|||||||
RPCClient *rpc.Client
|
RPCClient *rpc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ContractMaker) NewRegistry(chainID uint64) (*resolver.ENSRegistryWithFallback, error) {
|
func (c *ContractMaker) NewRegistryWithAddress(chainID uint64, address common.Address) (*resolver.ENSRegistryWithFallback, error) {
|
||||||
contractAddr, err := resolver.ContractAddress(chainID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
backend, err := c.RPCClient.EthClient(chainID)
|
backend, err := c.RPCClient.EthClient(chainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolver.NewENSRegistryWithFallback(
|
return resolver.NewENSRegistryWithFallback(
|
||||||
contractAddr,
|
address,
|
||||||
backend,
|
backend,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ContractMaker) NewRegistry(chainID uint64) (*resolver.ENSRegistryWithFallback, error) {
|
||||||
|
contractAddr, err := resolver.ContractAddress(chainID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.NewRegistryWithAddress(chainID, contractAddr)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ContractMaker) NewPublicResolver(chainID uint64, resolverAddress *common.Address) (*resolver.PublicResolver, error) {
|
func (c *ContractMaker) NewPublicResolver(chainID uint64, resolverAddress *common.Address) (*resolver.PublicResolver, error) {
|
||||||
backend, err := c.RPCClient.EthClient(chainID)
|
backend, err := c.RPCClient.EthClient(chainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/multiformats/go-multibase"
|
"github.com/multiformats/go-multibase"
|
||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/wealdtech/go-ens/v3"
|
||||||
"github.com/wealdtech/go-multicodec"
|
"github.com/wealdtech/go-multicodec"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
@ -98,6 +99,14 @@ func (api *API) Resolver(ctx context.Context, chainID uint64, username string) (
|
|||||||
return &resolver, nil
|
return &resolver, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) GetName(ctx context.Context, chainID uint64, address common.Address) (string, error) {
|
||||||
|
backend, err := api.contractMaker.RPCClient.EthClient(chainID)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return ens.ReverseResolve(backend, address)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) OwnerOf(ctx context.Context, chainID uint64, username string) (*common.Address, error) {
|
func (api *API) OwnerOf(ctx context.Context, chainID uint64, username string) (*common.Address, error) {
|
||||||
err := validateENSUsername(username)
|
err := validateENSUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/status-im/status-go/appdatabase"
|
"github.com/status-im/status-go/appdatabase"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
@ -67,6 +68,15 @@ func TestResolver(t *testing.T) {
|
|||||||
require.Equal(t, "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41", r.String())
|
require.Equal(t, "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41", r.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetName(t *testing.T) {
|
||||||
|
api, cancel := setupTestAPI(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
r, err := api.GetName(context.Background(), 1, common.HexToAddress("0x7d28Ab6948F3Db2F95A43742265D382a4888c120"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "rramos.eth", r)
|
||||||
|
}
|
||||||
|
|
||||||
func TestOwnerOf(t *testing.T) {
|
func TestOwnerOf(t *testing.T) {
|
||||||
api, cancel := setupTestAPI(t)
|
api, cancel := setupTestAPI(t)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user