You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ncdns/namecoin/namecoin.go

56 lines
1.5 KiB
Go

package namecoin
import (
"fmt"
"github.com/namecoin/btcd/btcjson"
"github.com/namecoin/btcd/rpcclient"
"gopkg.in/hlandau/madns.v2/merr"
"github.com/namecoin/ncrpcclient"
)
// Client represents an ncrpcclient.Client with an additional DNS-friendly
// convenience wrapper around NameShow.
type Client struct {
*ncrpcclient.Client
}
func New(config *rpcclient.ConnConfig, ntfnHandlers *rpcclient.NotificationHandlers) (*Client, error) {
ncClient, err := ncrpcclient.New(config, ntfnHandlers)
if err != nil {
return nil, err
}
return &Client{ncClient}, nil
}
// NameQuery returns the value of a name. If the name doesn't exist, the error
// returned will be merr.ErrNoSuchDomain.
func (c *Client) NameQuery(name string, streamIsolationID string) (string, error) {
// TODO: Pass stream isolation ID to namecoind, and remove this error
if streamIsolationID != "" {
return "", fmt.Errorf("Stream isolation ID '%s' is not yet passed to namecoind", streamIsolationID)
}
nameData, err := c.NameShow(name)
if err != nil {
if jerr, ok := err.(*btcjson.RPCError); ok {
if jerr.Code == btcjson.ErrRPCWallet {
// ErrRPCWallet from name_show indicates that
// the name does not exist.
return "", merr.ErrNoSuchDomain
}
}
// Some error besides NXDOMAIN happened; pass that error
// through unaltered.
return "", err
}
// TODO: check the "value_error" field for errors and report those to the caller.
// We got the name data. Return the value.
return nameData.Value, nil
}