dev-api-aliases #5

Merged
lash merged 6 commits from dev-api-aliases into master 2025-01-21 07:17:09 +01:00
Showing only changes of commit 99c704f6ff - Show all commits

View File

@ -5,7 +5,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"log" "log"
"net/http" "net/http"
@ -13,14 +12,15 @@ import (
"regexp" "regexp"
"git.grassecon.net/grassrootseconomics/sarafu-api/config" "git.grassecon.net/grassrootseconomics/sarafu-api/config"
"git.grassecon.net/grassrootseconomics/sarafu-api/dev"
"git.grassecon.net/grassrootseconomics/sarafu-api/models" "git.grassecon.net/grassrootseconomics/sarafu-api/models"
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
"github.com/grassrootseconomics/eth-custodial/pkg/api" "github.com/grassrootseconomics/eth-custodial/pkg/api"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
) )
var ( var (
aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$")
searchDomain = ".sarafu.eth"
) )
type HTTPAccountService struct { type HTTPAccountService struct {
@ -228,15 +228,9 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin
// 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) {
Review

Can't we just point this to devapi.RequestAlias?

Can't we just point this to devapi.RequestAlias?
Review

@lash Nice catch.Actually that brings up an idea,could we use the same implementation of the devapi to resolve the alias' address given that the api always returns the same address?

@lash Nice catch.Actually that brings up an idea,could we use the same implementation of the devapi to resolve the alias' address given that the api always returns the same address?
Review

yes for sure, while we wait or the api implementation.

yes for sure, while we wait or the api implementation.
var alias string storageService := mocks.NewMemStorageService(ctx)
if !aliasRegex.MatchString(hint) { svc := dev.NewDevAccountService(ctx, storageService)
return nil, fmt.Errorf("alias hint does not match: %s", publicKey) return svc.RequestAlias(ctx, publicKey, hint)
}
alias = hint
alias = alias + searchDomain
return &models.RequestAliasResult{
Alias: alias,
}, nil
} }
// TODO: remove eth-custodial api dependency // TODO: remove eth-custodial api dependency