diff --git a/remote/http/service.go b/remote/http/service.go index 15eaa24..aca8ae0 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "log" "net/http" @@ -24,7 +25,8 @@ var ( ) type HTTPAccountService struct { - ss storage.StorageService + SS storage.StorageService + UseApi bool } // Parameters: @@ -211,25 +213,38 @@ func (as *HTTPAccountService) TokenTransfer(ctx context.Context, amount, from, t // Parameters: // - alias: The alias of the user. 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 ep, err := url.JoinPath(config.CheckAliasURL, alias) if err != nil { return nil, err } - req, err := http.NewRequest("GET", ep, nil) if err != nil { return nil, err } - _, err = doRequest(ctx, req, &r) return &r, err } // TODO: Use actual custodial api to request available alias 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) }