ens-names #8
@ -16,12 +16,14 @@ const (
|
|||||||
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
|
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
|
||||||
voucherDataPathPrefix = "/api/v1/token"
|
voucherDataPathPrefix = "/api/v1/token"
|
||||||
AliasPrefix = "api/v1/alias"
|
AliasPrefix = "api/v1/alias"
|
||||||
|
AliasEnsPrefix = "/api/v1/bypass"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
custodialURLBase string
|
custodialURLBase string
|
||||||
dataURLBase string
|
dataURLBase string
|
||||||
BearerToken string
|
BearerToken string
|
||||||
|
aliasEnsURLBase string
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -34,6 +36,7 @@ var (
|
|||||||
VoucherTransfersURL string
|
VoucherTransfersURL string
|
||||||
VoucherDataURL string
|
VoucherDataURL string
|
||||||
CheckAliasURL string
|
CheckAliasURL string
|
||||||
|
AliasEnsURL string
|
||||||
)
|
)
|
||||||
|
|
||||||
func setBase() error {
|
func setBase() error {
|
||||||
@ -41,6 +44,7 @@ func setBase() error {
|
|||||||
|
|
||||||
custodialURLBase = env.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003")
|
custodialURLBase = env.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003")
|
||||||
dataURLBase = env.GetEnv("DATA_URL_BASE", "http://localhost:5006")
|
dataURLBase = env.GetEnv("DATA_URL_BASE", "http://localhost:5006")
|
||||||
|
aliasEnsURLBase = env.GetEnv("ALIAS_ENS_BASE", "http://localhost:5015")
|
||||||
BearerToken = env.GetEnv("BEARER_TOKEN", "")
|
BearerToken = env.GetEnv("BEARER_TOKEN", "")
|
||||||
|
|
||||||
_, err = url.Parse(custodialURLBase)
|
_, err = url.Parse(custodialURLBase)
|
||||||
@ -69,5 +73,6 @@ func LoadConfig() error {
|
|||||||
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
|
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
|
||||||
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
|
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
|
||||||
CheckAliasURL, _ = url.JoinPath(dataURLBase, AliasPrefix)
|
CheckAliasURL, _ = url.JoinPath(dataURLBase, AliasPrefix)
|
||||||
|
AliasEnsURL, _ = url.JoinPath(aliasEnsURLBase, AliasEnsPrefix)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,3 +7,13 @@ type RequestAliasResult struct {
|
|||||||
type AliasAddress struct {
|
type AliasAddress struct {
|
||||||
Address string
|
Address string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AliasEnsResult struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
AutoChoose bool `json:"autoChoose"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AliasEnsAddressResult struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
}
|
||||||
|
@ -225,28 +225,77 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
func resolveAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
var r models.AliasAddress
|
var (
|
||||||
|
aliasEnsResult models.AliasEnsAddressResult
|
||||||
|
)
|
||||||
|
|
||||||
ep, err := url.JoinPath(config.CheckAliasURL, alias)
|
ep, err := url.JoinPath(config.AliasEnsURL, "/resolve")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest("GET", ep, nil)
|
|
||||||
|
u, err := url.Parse(ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, err = doRequest(ctx, req, &r)
|
|
||||||
return &r, err
|
query := u.Query()
|
||||||
|
query.Set("name", alias)
|
||||||
|
u.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", u.String(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = doRequest(ctx, req, &aliasEnsResult)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &models.AliasAddress{Address: aliasEnsResult.Address}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use actual custodial api to request available alias
|
|
||||||
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
if as.SS == nil {
|
if as.SS == nil {
|
||||||
return nil, fmt.Errorf("The storage service cannot be nil")
|
return nil, fmt.Errorf("The storage service cannot be nil")
|
||||||
}
|
}
|
||||||
|
if as.UseApi {
|
||||||
|
enr, err := requestEnsAlias(ctx, publicKey, hint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &models.RequestAliasResult{Alias: enr.Name}, nil
|
||||||
|
} else {
|
||||||
svc := dev.NewDevAccountService(ctx, as.SS)
|
svc := dev.NewDevAccountService(ctx, as.SS)
|
||||||
return svc.RequestAlias(ctx, publicKey, hint)
|
return svc.RequestAlias(ctx, publicKey, hint)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*models.AliasEnsResult, error) {
|
||||||
|
var r models.AliasEnsResult
|
||||||
|
|
||||||
|
ep, err := url.JoinPath(config.AliasEnsURL, "/register")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
//Payload with the address and hint to derive an ENS name
|
||||||
|
payload := map[string]string{
|
||||||
|
"address": publicKey,
|
||||||
|
"hint": hint,
|
||||||
|
}
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = doRequest(ctx, req, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &r, nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: remove eth-custodial api dependency
|
// TODO: remove eth-custodial api dependency
|
||||||
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user