resolve alias address based on UseApi field
This commit is contained in:
parent
bc7afa50a4
commit
3f9dc89a40
@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -24,7 +25,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HTTPAccountService struct {
|
type HTTPAccountService struct {
|
||||||
ss storage.StorageService
|
SS storage.StorageService
|
||||||
|
UseApi bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameters:
|
// Parameters:
|
||||||
@ -211,25 +213,38 @@ func (as *HTTPAccountService) TokenTransfer(ctx context.Context, amount, from, t
|
|||||||
// Parameters:
|
// Parameters:
|
||||||
// - alias: The alias of the user.
|
// - alias: The alias of the user.
|
||||||
func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
|
if as.SS == nil {
|
||||||
|
return nil, fmt.Errorf("The storage service cannot be nil")
|
||||||
|
}
|
||||||
|
svc := dev.NewDevAccountService(ctx, as.SS)
|
||||||
|
if as.UseApi {
|
||||||
|
return resolveAliasAddress(ctx, alias)
|
||||||
|
} else {
|
||||||
|
return svc.CheckAliasAddress(ctx, alias)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
var r models.AliasAddress
|
var r models.AliasAddress
|
||||||
|
|
||||||
ep, err := url.JoinPath(config.CheckAliasURL, alias)
|
ep, err := url.JoinPath(config.CheckAliasURL, alias)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", ep, nil)
|
req, err := http.NewRequest("GET", ep, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = doRequest(ctx, req, &r)
|
_, err = doRequest(ctx, req, &r)
|
||||||
return &r, err
|
return &r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use actual custodial api to request available alias
|
// 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) {
|
||||||
svc := dev.NewDevAccountService(ctx, as.ss)
|
if as.SS == nil {
|
||||||
|
return nil, fmt.Errorf("The storage service cannot be nil")
|
||||||
|
}
|
||||||
|
svc := dev.NewDevAccountService(ctx, as.SS)
|
||||||
return svc.RequestAlias(ctx, publicKey, hint)
|
return svc.RequestAlias(ctx, publicKey, hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user