func (n *Name) CreateSubdomain(label string, controller common.Address, opts *bind.TransactOpts) (*types.Transaction, error) {
	fqdn := fmt.Sprintf("%s.%s", label, n.Name)
	subdomainController, err := n.registry.Owner(fqdn)
	if err != nil {
		return nil, err
	}
	if subdomainController != UnknownAddress {
		return nil, errors.New("that subdomain already exists")
	}
	return n.registry.SetSubdomainOwner(opts, n.Name, label, controller)
}
CreateSubdomain creates a subdomain on the name.
package ens
import (
	"crypto/rand"
	"errors"
	"fmt"
	"math/big"
	"time"
	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
)
type Name struct {
	backend bind.ContractBackend
	Name string
	Domain string
	Label string
	registry   *Registry
	registrar  *BaseRegistrar
	controller *ETHController
}
func NewName(backend bind.ContractBackend, name string) (*Name, error) {
	name, err := NormaliseDomain(name)
	if err != nil {
		return nil, err
	}
	domain := Domain(name)
	label, err := DomainPart(name, 1)
	if err != nil {
		return nil, err
	}
	registry, err := NewRegistry(backend)
	if err != nil {
		return nil, err
	}
	registrar, err := NewBaseRegistrar(backend, domain)
	if err != nil {
		return nil, err
	}
	controller, err := NewETHController(backend, domain)
	if err != nil {
		return nil, err
	}
	isValid, err := controller.IsValid(name)
	if err != nil {
		return nil, err
	}
	if !isValid {
		return nil, errors.New("name is not valid according to the rules of the registrar (too short, invalid characters, etc.)")
	}
	return &Name{
		backend:    backend,
		Name:       name,
		Domain:     domain,
		Label:      label,
		registry:   registry,
		registrar:  registrar,
		controller: controller,
	}, nil
}
func (n *Name) IsRegistered() (bool, error) {
	registrant, err := n.Registrant()
	if err != nil {
		return false, err
	}
	return registrant != UnknownAddress, nil
}
func (n *Name) ExtendRegistration(opts *bind.TransactOpts) (*types.Transaction, error) {
	isRegistered, err := n.IsRegistered()
	if err != nil {
		return nil, err
	}
	if !isRegistered {
		return nil, errors.New("name is not registered")
	}
	rentCost, err := n.RentCost()
	if err != nil {
		return nil, err
	}
	if opts.Value == nil || opts.Value.Cmp(rentCost) < 0 {
		return nil, errors.New("not enough funds to extend the registration")
	}
	return n.controller.Renew(opts, n.Name)
}
func (n *Name) RegistrationInterval() (time.Duration, error) {
	interval, err := n.controller.MinCommitmentInterval()
	if err != nil {
		return time.Duration(0), err
	}
	return time.Duration(interval.Int64()) * time.Second, nil
}
func (n *Name) RegisterStageOne(registrant common.Address, opts *bind.TransactOpts) (*types.Transaction, [32]byte, error) {
	var secret [32]byte
	_, err := rand.Read(secret[:])
	if err != nil {
		return nil, secret, err
	}
	isRegistered, err := n.IsRegistered()
	if err != nil {
		return nil, secret, err
	}
	if isRegistered {
		return nil, secret, errors.New("name is already registered")
	}
	signedTx, err := n.controller.Commit(opts, n.Label, registrant, secret)
	return signedTx, secret, err
}
func (n *Name) RegisterStageTwo(registrant common.Address, secret [32]byte, opts *bind.TransactOpts) (*types.Transaction, error) {
	commitTS, err := n.controller.CommitmentTime(n.Label, registrant, secret)
	if err != nil {
		return nil, err
	}
	if commitTS.Cmp(big.NewInt(0)) == 0 {
		return nil, errors.New("stage 2 attempted prior to successful stage 1 transaction")
	}
	commit := time.Unix(commitTS.Int64(), 0)
	minCommitIntervalTS, err := n.controller.MinCommitmentInterval()
	if err != nil {
		return nil, err
	}
	minCommitInterval := time.Duration(minCommitIntervalTS.Int64()) * time.Second
	minStageTwoTime := commit.Add(minCommitInterval)
	if time.Now().Before(minStageTwoTime) {
		return nil, errors.New("too early to send second transaction")
	}
	maxCommitIntervalTS, err := n.controller.MaxCommitmentInterval()
	if err != nil {
		return nil, err
	}
	maxCommitInterval := time.Duration(maxCommitIntervalTS.Int64()) * time.Second
	maxStageTwoTime := commit.Add(maxCommitInterval)
	if time.Now().After(maxStageTwoTime) {
		return nil, errors.New("too late to send second transaction")
	}
	return n.controller.Reveal(opts, n.Label, registrant, secret)
}
func (n *Name) Expires() (time.Time, error) {
	expiryTS, err := n.registrar.Expiry(n.Label)
	if err != nil {
		return time.Unix(0, 0), err
	}
	if expiryTS.Int64() == 0 {
		return time.Unix(0, 0), errors.New("not registered")
	}
	return time.Unix(expiryTS.Int64(), 0), nil
}
func (n *Name) Controller() (common.Address, error) {
	return n.registry.Owner(n.Name)
}
func (n *Name) SetController(controller common.Address, opts *bind.TransactOpts) (*types.Transaction, error) {
	curController, err := n.Controller()
	if err != nil {
		return nil, err
	}
	if curController == opts.From {
		return n.registry.SetOwner(opts, n.Name, controller)
	}
	registrant, err := n.Registrant()
	if err != nil {
		return nil, err
	}
	if registrant == opts.From && opts.From == controller {
		return n.Reclaim(opts)
	}
	return nil, errors.New("not authorised to change the controller")
}
func (n *Name) Reclaim(opts *bind.TransactOpts) (*types.Transaction, error) {
	registrant, err := n.Registrant()
	if err != nil {
		return nil, err
	}
	if registrant != opts.From {
		return nil, errors.New("not the registrant")
	}
	return n.registrar.Reclaim(opts, n.Name, registrant)
}
func (n *Name) Registrant() (common.Address, error) {
	return n.registrar.Owner(n.Label)
}
func (n *Name) Transfer(registrant common.Address, opts *bind.TransactOpts) (*types.Transaction, error) {
	currentRegistrant, err := n.Registrant()
	if err != nil {
		return nil, err
	}
	if currentRegistrant != opts.From {
		return nil, errors.New("not the current registrant")
	}
	return n.registrar.SetOwner(opts, n.Label, registrant)
}
func (n *Name) RentCost() (*big.Int, error) {
	return n.controller.RentCost(n.Label)
}