Compare commits
No commits in common. "99c704f6ff3ccdf7a83f97ba7bf01be446266c26" and "8a47d1d674efa0e79fd3a637759ce9236650c2b2" have entirely different histories.
99c704f6ff
...
8a47d1d674
24
dev/api.go
24
dev/api.go
@ -23,17 +23,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("sarafu-api.devapi")
|
||||
aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$")
|
||||
searchDomain = ".sarafu.local"
|
||||
logg = logging.NewVanilla().WithDomain("sarafu-api.devapi")
|
||||
aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$")
|
||||
searchDomain = ".sarafu.local"
|
||||
)
|
||||
|
||||
const (
|
||||
pubKeyLen int = 20
|
||||
hashLen int = 32
|
||||
defaultDecimals = 6
|
||||
zeroAddress string = "0x0000000000000000000000000000000000000000"
|
||||
defaultVoucherBalance float64 = 500.00
|
||||
pubKeyLen int = 20
|
||||
hashLen int = 32
|
||||
defaultDecimals = 6
|
||||
zeroAddress string = "0x0000000000000000000000000000000000000000"
|
||||
)
|
||||
|
||||
type Tx struct {
|
||||
@ -106,6 +105,7 @@ type DevAccountService struct {
|
||||
defaultAccount string
|
||||
emitterFunc event.EmitterFunc
|
||||
pfx []byte
|
||||
// accountsSession map[string]string
|
||||
}
|
||||
|
||||
func NewDevAccountService(ctx context.Context, ss storage.StorageService) *DevAccountService {
|
||||
@ -342,17 +342,13 @@ func (das *DevAccountService) saveAlias(ctx context.Context, alias map[string]st
|
||||
if das.db == nil {
|
||||
return fmt.Errorf("Db cannot be nil")
|
||||
}
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unresolved session id")
|
||||
}
|
||||
for k, v := range alias {
|
||||
k_ := das.prefixKeyFor("alias", k)
|
||||
v_, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
das.db.SetSession(sessionId)
|
||||
das.db.SetSession("")
|
||||
das.db.SetPrefix(db.DATATYPE_USERDATA)
|
||||
return das.db.Put(ctx, []byte(k_), v_)
|
||||
}
|
||||
@ -435,7 +431,7 @@ func (das *DevAccountService) FetchVouchers(ctx context.Context, publicKey strin
|
||||
ContractAddress: voucher.Address,
|
||||
TokenSymbol: voucher.Symbol,
|
||||
TokenDecimals: strconv.Itoa(voucher.Decimals),
|
||||
Balance: strconv.Itoa(int(defaultVoucherBalance)),
|
||||
Balance: strconv.Itoa(500),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -12,15 +13,14 @@ import (
|
||||
"regexp"
|
||||
|
||||
"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/visedriver/testutil/mocks"
|
||||
"github.com/grassrootseconomics/eth-custodial/pkg/api"
|
||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||
)
|
||||
|
||||
var (
|
||||
aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$")
|
||||
aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$")
|
||||
searchDomain = ".sarafu.eth"
|
||||
)
|
||||
|
||||
type HTTPAccountService struct {
|
||||
@ -228,9 +228,15 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin
|
||||
|
||||
// TODO: Use actual custodial api to request available alias
|
||||
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||
storageService := mocks.NewMemStorageService(ctx)
|
||||
svc := dev.NewDevAccountService(ctx, storageService)
|
||||
return svc.RequestAlias(ctx, publicKey, hint)
|
||||
var alias string
|
||||
if !aliasRegex.MatchString(hint) {
|
||||
return nil, fmt.Errorf("alias hint does not match: %s", publicKey)
|
||||
}
|
||||
alias = hint
|
||||
alias = alias + searchDomain
|
||||
return &models.RequestAliasResult{
|
||||
Alias: alias,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TODO: remove eth-custodial api dependency
|
||||
|
Loading…
Reference in New Issue
Block a user