contracts, swarm: implement EIP-1577 (#19285)
* contracts/ens: update public resolver solidity code
* contracts/ens: update public resolver, update go bindings
* update build
* fix ens.sol
* contracts/ens: change contract interface
* contracts/ens: implement public resolver changes
* contracts/ens: added ENSRegistry contract
* contracts/ens: reinstate old contract code
* contracts/ens: update README.md
* contracts/ens: added test coverage for fallback contract
* contracts/ens: added support for fallback contract
* contracts/ens: removed unused contract code
* contracts/ens: add todo and decode multicodec stub
* add encode
* vendor: add ipfs cid libraries
* contracts/ens: cid sanity tests
* contracts/ens: more cid sanity checks
* contracts/ens: wip integration
* wip
* Revert "vendor: add ipfs cid libraries"
This reverts commit 29d9b6b294
.
* contracts/ens: removed multiformats dependencies
* contracts/ens: added decode tests
* contracts/ens: added eip spec test, minor changes to exiting tests
* contracts/ens: moved cid decoding to own file
* contracts/ens: added unit test to encode hash to content hash
* contracts/ens: removed unused code
* contracts/ens: fix ens tests to use cid decode and encode
* contracts/ens: adjust swarm multicodecs after pr merge
* contracts/ens: fix linter error
* constracts/ens: address PR comments
* cmd, contracts: make peoples lives easier
* contracts/ens: fix linter error
* contracts/ens: address PR comments
This commit is contained in:
@ -16,25 +16,35 @@
|
||||
|
||||
package ens
|
||||
|
||||
//go:generate abigen --sol contract/ENS.sol --exc contract/AbstractENS.sol:AbstractENS --pkg contract --out contract/ens.go
|
||||
//go:generate abigen --sol contract/FIFSRegistrar.sol --exc contract/AbstractENS.sol:AbstractENS --pkg contract --out contract/fifsregistrar.go
|
||||
//go:generate abigen --sol contract/PublicResolver.sol --exc contract/AbstractENS.sol:AbstractENS --pkg contract --out contract/publicresolver.go
|
||||
//go:generate abigen --sol contract/ENS.sol --pkg contract --out contract/ens.go
|
||||
//go:generate abigen --sol contract/ENSRegistry.sol --exc contract/ENS.sol:ENS --pkg contract --out contract/ensregistry.go
|
||||
//go:generate abigen --sol contract/FIFSRegistrar.sol --exc contract/ENS.sol:ENS --pkg contract --out contract/fifsregistrar.go
|
||||
//go:generate abigen --sol contract/PublicResolver.sol --exc contract/ENS.sol:ENS --pkg contract --out contract/publicresolver.go
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/ens/contract"
|
||||
"github.com/ethereum/go-ethereum/contracts/ens/fallback_contract"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
var (
|
||||
MainNetAddress = common.HexToAddress("0x314159265dD8dbb310642f98f50C066173C1259b")
|
||||
TestNetAddress = common.HexToAddress("0x112234455c3a32fd11230c42e7bccd4a84e02010")
|
||||
MainNetAddress = common.HexToAddress("0x314159265dD8dbb310642f98f50C066173C1259b")
|
||||
TestNetAddress = common.HexToAddress("0x112234455c3a32fd11230c42e7bccd4a84e02010")
|
||||
contentHash_Interface_Id [4]byte
|
||||
)
|
||||
|
||||
const contentHash_Interface_Id_Spec = 0xbc1c58d1
|
||||
|
||||
func init() {
|
||||
binary.BigEndian.PutUint32(contentHash_Interface_Id[:], contentHash_Interface_Id_Spec)
|
||||
}
|
||||
|
||||
// ENS is the swarm domain name registry and resolver
|
||||
type ENS struct {
|
||||
*contract.ENSSession
|
||||
@ -60,7 +70,7 @@ func NewENS(transactOpts *bind.TransactOpts, contractAddr common.Address, contra
|
||||
// DeployENS deploys an instance of the ENS nameservice, with a 'first-in, first-served' root registrar.
|
||||
func DeployENS(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *ENS, error) {
|
||||
// Deploy the ENS registry
|
||||
ensAddr, _, _, err := contract.DeployENS(transactOpts, contractBackend)
|
||||
ensAddr, _, _, err := contract.DeployENSRegistry(transactOpts, contractBackend)
|
||||
if err != nil {
|
||||
return ensAddr, nil, err
|
||||
}
|
||||
@ -110,6 +120,21 @@ func (ens *ENS) getResolver(node [32]byte) (*contract.PublicResolverSession, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ens *ENS) getFallbackResolver(node [32]byte) (*fallback_contract.PublicResolverSession, error) {
|
||||
resolverAddr, err := ens.Resolver(node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := fallback_contract.NewPublicResolver(resolverAddr, ens.contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fallback_contract.PublicResolverSession{
|
||||
Contract: resolver,
|
||||
TransactOpts: ens.TransactOpts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ens *ENS) getRegistrar(node [32]byte) (*contract.FIFSRegistrarSession, error) {
|
||||
registrarAddr, err := ens.Owner(node)
|
||||
if err != nil {
|
||||
@ -133,11 +158,33 @@ func (ens *ENS) Resolve(name string) (common.Hash, error) {
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
ret, err := resolver.Content(node)
|
||||
|
||||
// IMPORTANT: The old contract is deprecated. This code should be removed latest on June 1st 2019
|
||||
supported, err := resolver.SupportsInterface(contentHash_Interface_Id)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
return common.BytesToHash(ret[:]), nil
|
||||
|
||||
if !supported {
|
||||
resolver, err := ens.getFallbackResolver(node)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
ret, err := resolver.Content(node)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
return common.BytesToHash(ret[:]), nil
|
||||
}
|
||||
|
||||
// END DEPRECATED CODE
|
||||
|
||||
contentHash, err := resolver.Contenthash(node)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
return extractContentHash(contentHash)
|
||||
}
|
||||
|
||||
// Addr is a non-transactional call that returns the address associated with a name.
|
||||
@ -181,15 +228,36 @@ func (ens *ENS) Register(name string) (*types.Transaction, error) {
|
||||
}
|
||||
|
||||
// SetContentHash sets the content hash associated with a name. Only works if the caller
|
||||
// owns the name, and the associated resolver implements a `setContent` function.
|
||||
func (ens *ENS) SetContentHash(name string, hash common.Hash) (*types.Transaction, error) {
|
||||
// owns the name, and the associated resolver implements a `setContenthash` function.
|
||||
func (ens *ENS) SetContentHash(name string, hash []byte) (*types.Transaction, error) {
|
||||
node := EnsNode(name)
|
||||
|
||||
resolver, err := ens.getResolver(node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts := ens.TransactOpts
|
||||
opts.GasLimit = 200000
|
||||
return resolver.Contract.SetContent(&opts, node, hash)
|
||||
|
||||
// IMPORTANT: The old contract is deprecated. This code should be removed latest on June 1st 2019
|
||||
supported, err := resolver.SupportsInterface(contentHash_Interface_Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !supported {
|
||||
resolver, err := ens.getFallbackResolver(node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := ens.TransactOpts
|
||||
opts.GasLimit = 200000
|
||||
var b [32]byte
|
||||
copy(b[:], hash)
|
||||
return resolver.Contract.SetContent(&opts, node, b)
|
||||
}
|
||||
|
||||
// END DEPRECATED CODE
|
||||
return resolver.Contract.SetContenthash(&opts, node, hash)
|
||||
}
|
||||
|
Reference in New Issue
Block a user