Compare commits
12 Commits
lash/dev-a
...
master
Author | SHA1 | Date | |
---|---|---|---|
b22ff1e7f0 | |||
|
bca7c5de96 | ||
|
c128678f4a | ||
|
7001d1f828 | ||
|
9645a2af7b | ||
|
7a96b85b28 | ||
|
18a30a0065 | ||
|
a4976e6c52 | ||
|
7c697394b5 | ||
|
37bb460561 | ||
|
5511955438 | ||
|
25149ff265 |
182
dev/api.go
182
dev/api.go
@ -1,12 +1,13 @@
|
|||||||
package dev
|
package dev
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -14,13 +15,16 @@ import (
|
|||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
fsdb "git.defalsify.org/vise.git/db/fs"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||||
|
"git.grassecon.net/grassrootseconomics/common/phone"
|
||||||
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla().WithDomain("sarafu-api.devapi")
|
logg = logging.NewVanilla().WithDomain("sarafu-api.devapi")
|
||||||
|
aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -40,6 +44,25 @@ type Tx struct {
|
|||||||
When time.Time `json: "when"`
|
When time.Time `json: "when"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tx) ToTransferEvent() event.EventTokenTransfer {
|
||||||
|
return event.EventTokenTransfer{
|
||||||
|
To: t.To,
|
||||||
|
Value: t.Value,
|
||||||
|
VoucherAddress: t.Voucher,
|
||||||
|
TxHash: t.Hsh,
|
||||||
|
From: t.From,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tx) ToMintEvent() event.EventTokenMint {
|
||||||
|
return event.EventTokenMint{
|
||||||
|
To: t.To,
|
||||||
|
Value: t.Value,
|
||||||
|
VoucherAddress: t.Voucher,
|
||||||
|
TxHash: t.Hsh,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Track string `json: "track"`
|
Track string `json: "track"`
|
||||||
Address string `json: "address"`
|
Address string `json: "address"`
|
||||||
@ -50,6 +73,12 @@ type Account struct {
|
|||||||
Txs []string `json: "txs"`
|
Txs []string `json: "txs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Account) ToRegistrationEvent() event.EventCustodialRegistration {
|
||||||
|
return event.EventCustodialRegistration{
|
||||||
|
Account: a.Address,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Voucher struct {
|
type Voucher struct {
|
||||||
Name string `json: "name"`
|
Name string `json: "name"`
|
||||||
Address string `json: "address"`
|
Address string `json: "address"`
|
||||||
@ -61,7 +90,6 @@ type Voucher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DevAccountService struct {
|
type DevAccountService struct {
|
||||||
dir string
|
|
||||||
db db.Db
|
db db.Db
|
||||||
accounts map[string]Account
|
accounts map[string]Account
|
||||||
accountsTrack map[string]string
|
accountsTrack map[string]string
|
||||||
@ -74,13 +102,13 @@ type DevAccountService struct {
|
|||||||
autoVouchers []string
|
autoVouchers []string
|
||||||
autoVoucherValue map[string]int
|
autoVoucherValue map[string]int
|
||||||
defaultAccount string
|
defaultAccount string
|
||||||
|
emitterFunc event.EmitterFunc
|
||||||
|
pfx []byte
|
||||||
// accountsSession map[string]string
|
// accountsSession map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevAccountService(ctx context.Context, d string) *DevAccountService {
|
func NewDevAccountService(ctx context.Context, ss storage.StorageService) *DevAccountService {
|
||||||
svc := &DevAccountService{
|
svc := &DevAccountService{
|
||||||
dir: d,
|
|
||||||
db: fsdb.NewFsDb(),
|
|
||||||
accounts: make(map[string]Account),
|
accounts: make(map[string]Account),
|
||||||
accountsTrack: make(map[string]string),
|
accountsTrack: make(map[string]string),
|
||||||
accountsAlias: make(map[string]string),
|
accountsAlias: make(map[string]string),
|
||||||
@ -90,23 +118,42 @@ func NewDevAccountService(ctx context.Context, d string) *DevAccountService {
|
|||||||
txsTrack: make(map[string]string),
|
txsTrack: make(map[string]string),
|
||||||
autoVoucherValue: make(map[string]int),
|
autoVoucherValue: make(map[string]int),
|
||||||
defaultAccount: zeroAddress,
|
defaultAccount: zeroAddress,
|
||||||
|
pfx: []byte("__"),
|
||||||
|
}
|
||||||
|
if ss != nil {
|
||||||
|
var err error
|
||||||
|
svc.db, err = ss.GetUserdataDb(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
svc.db.SetSession("")
|
||||||
|
svc.db.SetPrefix(db.DATATYPE_USERDATA)
|
||||||
|
err = svc.loadAll(ctx)
|
||||||
|
if err != nil {
|
||||||
|
logg.DebugCtxf(ctx, "loadall error", "err", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
acc := Account{
|
acc := Account{
|
||||||
Address: zeroAddress,
|
Address: zeroAddress,
|
||||||
}
|
}
|
||||||
svc.accounts[acc.Address] = acc
|
svc.accounts[acc.Address] = acc
|
||||||
err := svc.db.Connect(ctx, d)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
svc.db.SetPrefix(db.DATATYPE_USERDATA)
|
|
||||||
err = svc.loadAll(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return svc
|
return svc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (das *DevAccountService) WithEmitter(fn event.EmitterFunc) *DevAccountService {
|
||||||
|
das.emitterFunc = fn
|
||||||
|
return das
|
||||||
|
}
|
||||||
|
|
||||||
|
func (das *DevAccountService) WithPrefix(pfx []byte) *DevAccountService {
|
||||||
|
das.pfx = pfx
|
||||||
|
return das
|
||||||
|
}
|
||||||
|
|
||||||
|
func (das *DevAccountService) prefixKeyFor(k string, v string) []byte {
|
||||||
|
return append(das.pfx, []byte(k + "_" + v)...)
|
||||||
|
}
|
||||||
|
|
||||||
func (das *DevAccountService) loadAccount(ctx context.Context, pubKey string, v []byte) error {
|
func (das *DevAccountService) loadAccount(ctx context.Context, pubKey string, v []byte) error {
|
||||||
var acc Account
|
var acc Account
|
||||||
|
|
||||||
@ -139,7 +186,7 @@ func (das *DevAccountService) loadTx(ctx context.Context, hsh string, v []byte)
|
|||||||
func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte) error {
|
func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte) error {
|
||||||
var err error
|
var err error
|
||||||
s := string(k)
|
s := string(k)
|
||||||
ss := strings.SplitN(s, "_", 2)
|
ss := strings.SplitN(s[2:], "_", 2)
|
||||||
if len(ss) != 2 {
|
if len(ss) != 2 {
|
||||||
return fmt.Errorf("malformed key: %s", s)
|
return fmt.Errorf("malformed key: %s", s)
|
||||||
}
|
}
|
||||||
@ -147,6 +194,8 @@ func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte)
|
|||||||
err = das.loadAccount(ctx, ss[1], v)
|
err = das.loadAccount(ctx, ss[1], v)
|
||||||
} else if ss[0] == "tx" {
|
} else if ss[0] == "tx" {
|
||||||
err = das.loadTx(ctx, ss[1], v)
|
err = das.loadTx(ctx, ss[1], v)
|
||||||
|
} else {
|
||||||
|
logg.ErrorCtxf(ctx, "unknown double underscore key", "key", ss[0])
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -154,18 +203,19 @@ func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte)
|
|||||||
// TODO: Add connect tx and account
|
// TODO: Add connect tx and account
|
||||||
// TODO: update balance
|
// TODO: update balance
|
||||||
func (das *DevAccountService) loadAll(ctx context.Context) error {
|
func (das *DevAccountService) loadAll(ctx context.Context) error {
|
||||||
d, err := os.ReadDir(das.dir)
|
dumper, err := das.db.Dump(ctx, []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, v := range(d) {
|
for true {
|
||||||
// TODO: move decoding to vise
|
k, v := dumper.Next(ctx)
|
||||||
fp := v.Name()
|
if k == nil {
|
||||||
k := []byte(fp[1:])
|
break
|
||||||
v, err := das.db.Get(ctx, k)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
if !bytes.HasPrefix(k, das.pfx) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
err = das.loadItem(ctx, k, v)
|
err = das.loadItem(ctx, k, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -263,11 +313,16 @@ func (das *DevAccountService) balanceAuto(ctx context.Context, pubKey string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (das *DevAccountService) saveAccount(ctx context.Context, acc Account) error {
|
func (das *DevAccountService) saveAccount(ctx context.Context, acc Account) error {
|
||||||
k := "account_" + acc.Address
|
if das.db == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
k := das.prefixKeyFor("account", acc.Address)
|
||||||
v, err := json.Marshal(acc)
|
v, err := json.Marshal(acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
das.db.SetSession("")
|
||||||
|
das.db.SetPrefix(db.DATATYPE_USERDATA)
|
||||||
return das.db.Put(ctx, []byte(k), v)
|
return das.db.Put(ctx, []byte(k), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +361,17 @@ func (das *DevAccountService) CreateAccount(ctx context.Context) (*models.Accoun
|
|||||||
das.defaultAccount = pubKey
|
das.defaultAccount = pubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
logg.InfoCtxf(ctx, "account created", "account", acc)
|
if das.emitterFunc != nil {
|
||||||
|
msg := event.Msg{
|
||||||
|
Typ: event.EventRegistrationTag,
|
||||||
|
Item: acc,
|
||||||
|
}
|
||||||
|
err = das.emitterFunc(ctx, msg)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "emitter returned error", "err", err, "msg", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logg.TraceCtxf(ctx, "account created", "account", acc)
|
||||||
|
|
||||||
return &models.AccountResult{
|
return &models.AccountResult{
|
||||||
PublicKey: pubKey,
|
PublicKey: pubKey,
|
||||||
@ -396,11 +461,13 @@ func (das *DevAccountService) VoucherData(ctx context.Context, address string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (das *DevAccountService) saveTokenTransfer(ctx context.Context, mytx Tx) error {
|
func (das *DevAccountService) saveTokenTransfer(ctx context.Context, mytx Tx) error {
|
||||||
k := "tx_" + mytx.Hsh
|
k := das.prefixKeyFor("tx", mytx.Hsh)
|
||||||
v, err := json.Marshal(mytx)
|
v, err := json.Marshal(mytx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
das.db.SetSession("")
|
||||||
|
das.db.SetPrefix(db.DATATYPE_USERDATA)
|
||||||
return das.db.Put(ctx, []byte(k), v)
|
return das.db.Put(ctx, []byte(k), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,13 +525,23 @@ func (das *DevAccountService) TokenTransfer(ctx context.Context, amount, from, t
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
das.txs[hsh] = mytx
|
das.txs[hsh] = mytx
|
||||||
logg.InfoCtxf(ctx, "token transfer created", "tx", mytx)
|
if das.emitterFunc != nil {
|
||||||
|
msg := event.Msg{
|
||||||
|
Typ: event.EventTokenTransferTag,
|
||||||
|
Item: mytx,
|
||||||
|
}
|
||||||
|
err = das.emitterFunc(ctx, msg)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "emitter returned error", "err", err, "msg", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logg.TraceCtxf(ctx, "token transfer created", "tx", mytx)
|
||||||
return &models.TokenTransferResponse{
|
return &models.TokenTransferResponse{
|
||||||
TrackingId: uid.String(),
|
TrackingId: uid.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (das *DevAccountService) CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error) {
|
func (das *DevAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
addr, ok := das.accountsAlias[alias]
|
addr, ok := das.accountsAlias[alias]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("alias %s not found", alias)
|
return nil, fmt.Errorf("alias %s not found", alias)
|
||||||
@ -473,7 +550,52 @@ func (das *DevAccountService) CheckAliasAddress(ctx context.Context, alias strin
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("alias %s found but does not resolve", alias)
|
return nil, fmt.Errorf("alias %s found but does not resolve", alias)
|
||||||
}
|
}
|
||||||
return &dataserviceapi.AliasAddress{
|
return &models.AliasAddress{
|
||||||
Address: acc.Address,
|
Address: acc.Address,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (das *DevAccountService) applyPhoneAlias(ctx context.Context, publicKey string, phoneNumber string) (bool, error) {
|
||||||
|
if phoneNumber[0] == '+' {
|
||||||
|
if !phone.IsValidPhoneNumber(phoneNumber) {
|
||||||
|
return false, fmt.Errorf("Invalid phoneNumber number: %v", phoneNumber)
|
||||||
|
}
|
||||||
|
logg.DebugCtxf(ctx, "matched phoneNumber alias", "phoneNumber", phoneNumber, "address", publicKey)
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (das *DevAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
|
var alias string
|
||||||
|
if !aliasRegex.MatchString(hint) {
|
||||||
|
return nil, fmt.Errorf("alias hint does not match: %s", publicKey)
|
||||||
|
}
|
||||||
|
acc, ok := das.accounts[publicKey]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("address %s not found", publicKey)
|
||||||
|
}
|
||||||
|
alias = hint
|
||||||
|
isPhone, err := das.applyPhoneAlias(ctx, publicKey, alias)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("phone parser error: %v", err)
|
||||||
|
}
|
||||||
|
if !isPhone {
|
||||||
|
for true {
|
||||||
|
addr, ok := das.accountsAlias[alias]
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if addr == publicKey {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
alias += "x"
|
||||||
|
}
|
||||||
|
acc.Alias = alias
|
||||||
|
das.accountsAlias[alias] = publicKey
|
||||||
|
}
|
||||||
|
logg.DebugCtxf(ctx, "set alias", "addr", publicKey, "alias", alias)
|
||||||
|
return &models.RequestAliasResult{
|
||||||
|
Alias: alias,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
75
dev/api_test.go
Normal file
75
dev/api_test.go
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package dev
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestApiRequestAlias(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
storageService := mocks.NewMemStorageService(ctx)
|
||||||
|
svc := NewDevAccountService(ctx, storageService)
|
||||||
|
ra, err := svc.CreateAccount(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
addr := ra.PublicKey
|
||||||
|
|
||||||
|
_, err = svc.RequestAlias(ctx, addr, "+254f00")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error")
|
||||||
|
}
|
||||||
|
alias := "+254712345678"
|
||||||
|
rb, err := svc.RequestAlias(ctx, addr, alias)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if rb.Alias != alias {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", alias, rb.Alias)
|
||||||
|
}
|
||||||
|
_, err = svc.CheckAliasAddress(ctx, alias)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error")
|
||||||
|
}
|
||||||
|
|
||||||
|
alias = "foo"
|
||||||
|
rb, err = svc.RequestAlias(ctx, addr, alias)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if rb.Alias != alias {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", alias, rb.Alias)
|
||||||
|
}
|
||||||
|
rc, err := svc.CheckAliasAddress(ctx, alias)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if rc.Address != addr {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", addr, rc.Address)
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a second account
|
||||||
|
ra, err = svc.CreateAccount(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
addr = ra.PublicKey
|
||||||
|
|
||||||
|
rb, err = svc.RequestAlias(ctx, addr, alias)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
alias = "foox"
|
||||||
|
if rb.Alias != alias {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", alias, rb.Alias)
|
||||||
|
}
|
||||||
|
rc, err = svc.CheckAliasAddress(ctx, alias)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if rc.Address != addr {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", addr, rc.Address)
|
||||||
|
}
|
||||||
|
}
|
66
event/msg.go
Normal file
66
event/msg.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package event
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// TODO: integrate with sarafu-vise-events
|
||||||
|
EventTokenTransferTag = "TOKEN_TRANSFER"
|
||||||
|
EventTokenMintTag = "TOKEN_MINT"
|
||||||
|
EventRegistrationTag = "CUSTODIAL_REGISTRATION"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Msg struct {
|
||||||
|
Typ string
|
||||||
|
Item any
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmitterFunc func(context.Context, Msg) error
|
||||||
|
|
||||||
|
// fields used for handling custodial registration event.
|
||||||
|
type EventCustodialRegistration struct {
|
||||||
|
Account string
|
||||||
|
}
|
||||||
|
|
||||||
|
// fields used for handling token transfer event.
|
||||||
|
type EventTokenTransfer struct {
|
||||||
|
To string
|
||||||
|
Value int
|
||||||
|
VoucherAddress string
|
||||||
|
TxHash string
|
||||||
|
From string
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventTokenMint struct {
|
||||||
|
To string
|
||||||
|
Value int
|
||||||
|
TxHash string
|
||||||
|
VoucherAddress string
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventsHandlerFunc func(context.Context, any) error
|
||||||
|
|
||||||
|
type EventsHandler struct {
|
||||||
|
handlers map[string]EventsHandlerFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEventsHandler() *EventsHandler {
|
||||||
|
return &EventsHandler{
|
||||||
|
handlers: make(map[string]EventsHandlerFunc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (eh *EventsHandler) WithHandler(tag string, fn EventsHandlerFunc) *EventsHandler {
|
||||||
|
eh.handlers[tag] = fn
|
||||||
|
return eh
|
||||||
|
}
|
||||||
|
|
||||||
|
func (eh *EventsHandler) Handle(ctx context.Context, tag string, o any) error {
|
||||||
|
fn, ok := eh.handlers[tag]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Handler not registered for tag: %s", tag)
|
||||||
|
}
|
||||||
|
return fn(ctx, o)
|
||||||
|
}
|
19
go.mod
19
go.mod
@ -3,8 +3,9 @@ module git.grassecon.net/grassrootseconomics/sarafu-api
|
|||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
|
git.defalsify.org/vise.git v0.2.3-0.20250114225117-3b5fc85b650b
|
||||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893
|
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
|
||||||
|
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63
|
||||||
github.com/gofrs/uuid v4.4.0+incompatible
|
github.com/gofrs/uuid v4.4.0+incompatible
|
||||||
github.com/grassrootseconomics/eth-custodial v1.3.0-beta
|
github.com/grassrootseconomics/eth-custodial v1.3.0-beta
|
||||||
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta
|
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta
|
||||||
@ -14,8 +15,22 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c // indirect
|
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c // indirect
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
|
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
|
||||||
|
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 // indirect
|
||||||
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
|
github.com/jackc/pgx/v5 v5.7.1 // indirect
|
||||||
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/joho/godotenv v1.5.1 // indirect
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 // indirect
|
||||||
github.com/stretchr/objx v0.5.2 // indirect
|
github.com/stretchr/objx v0.5.2 // indirect
|
||||||
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
|
golang.org/x/crypto v0.32.0 // indirect
|
||||||
|
golang.org/x/sync v0.10.0 // indirect
|
||||||
|
golang.org/x/text v0.21.0 // indirect
|
||||||
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
54
go.sum
54
go.sum
@ -1,26 +1,70 @@
|
|||||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSGhfOdcj7kc555f8dc9DmMd2YAyC2AMw=
|
git.defalsify.org/vise.git v0.2.3-0.20250114225117-3b5fc85b650b h1:rwWXMtNSn7aqhb4p1oVZkCA1vC7pVdohwW61QQM8fUs=
|
||||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
git.defalsify.org/vise.git v0.2.3-0.20250114225117-3b5fc85b650b/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893 h1:MyDINzwY1sjfXkIFoc+6T5lXF/1xdFV6yjHrpSNZzWM=
|
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 h1:BenzGx6aDHKDwE23/mWIFD2InYIXyzHroZWV3MF5WUk=
|
||||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U=
|
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||||
|
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 h1:bX7klKZpX+ZZu1LKbtOXDAhV/KK0YwExehiIi0jusAM=
|
||||||
|
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63/go.mod h1:Syw9TZyigPAM7t9FvicOm36iUnidt45f0SxzT2JniQ8=
|
||||||
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c h1:H9Nm+I7Cg/YVPpEV1RzU3Wq2pjamPc/UtHDgItcb7lE=
|
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c h1:H9Nm+I7Cg/YVPpEV1RzU3Wq2pjamPc/UtHDgItcb7lE=
|
||||||
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7o6KPeJ+hyBpHfhi4v7blx9sf+QsHsA7KAsdN6U=
|
github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c/go.mod h1:rGod7o6KPeJ+hyBpHfhi4v7blx9sf+QsHsA7KAsdN6U=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
|
||||||
|
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
|
||||||
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
|
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
|
||||||
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
github.com/grassrootseconomics/eth-custodial v1.3.0-beta h1:twrMBhl89GqDUL9PlkzQxMP/6OST1BByrNDj+rqXDmU=
|
github.com/grassrootseconomics/eth-custodial v1.3.0-beta h1:twrMBhl89GqDUL9PlkzQxMP/6OST1BByrNDj+rqXDmU=
|
||||||
github.com/grassrootseconomics/eth-custodial v1.3.0-beta/go.mod h1:7uhRcdnJplX4t6GKCEFkbeDhhjlcaGJeJqevbcvGLZo=
|
github.com/grassrootseconomics/eth-custodial v1.3.0-beta/go.mod h1:7uhRcdnJplX4t6GKCEFkbeDhhjlcaGJeJqevbcvGLZo=
|
||||||
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta h1:fn1gwbWIwHVEBtUC2zi5OqTlfI/5gU1SMk0fgGixIXk=
|
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta h1:fn1gwbWIwHVEBtUC2zi5OqTlfI/5gU1SMk0fgGixIXk=
|
||||||
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta/go.mod h1:omfI0QtUwIdpu9gMcUqLMCG8O1XWjqJGBx1qUMiGWC0=
|
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta/go.mod h1:omfI0QtUwIdpu9gMcUqLMCG8O1XWjqJGBx1qUMiGWC0=
|
||||||
|
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 h1:U4kkNYryi/qfbBF8gh7Vsbuz+cVmhf5kt6pE9bYYyLo=
|
||||||
|
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4/go.mod h1:zpZDgZFzeq9s0MIeB1P50NIEWDFFHSFBohI/NbaTD/Y=
|
||||||
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
|
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
|
||||||
|
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
|
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a h1:0Q3H0YXzMHiciXtRcM+j0jiCe8WKPQHoRgQiRTnfcLY=
|
||||||
|
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a/go.mod h1:CdTTBOYzS5E4mWS1N8NWP6AHI19MP0A2B18n3hLzRMk=
|
||||||
|
github.com/pashagolub/pgxmock/v4 v4.3.0 h1:DqT7fk0OCK6H0GvqtcMsLpv8cIwWqdxWgfZNLeHCb/s=
|
||||||
|
github.com/pashagolub/pgxmock/v4 v4.3.0/go.mod h1:9VoVHXwS3XR/yPtKGzwQvwZX1kzGB9sM8SviDcHDa3A=
|
||||||
|
github.com/peteole/testdata-loader v0.3.0 h1:8jckE9KcyNHgyv/VPoaljvKZE0Rqr8+dPVYH6rfNr9I=
|
||||||
|
github.com/peteole/testdata-loader v0.3.0/go.mod h1:Mt0ZbRtb56u8SLJpNP+BnQbENljMorYBpqlvt3cS83U=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||||
|
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||||
|
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||||
|
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||||
|
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||||
|
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc=
|
||||||
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1/go.mod h1:X1WlGDeAFIYsW6GjgMm4VwUwZ2XjI7Zan2InxSUQWrU=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
9
models/alias_response.go
Normal file
9
models/alias_response.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type RequestAliasResult struct {
|
||||||
|
Alias string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AliasAddress struct {
|
||||||
|
Address string
|
||||||
|
}
|
@ -15,5 +15,6 @@ type AccountService interface {
|
|||||||
FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error)
|
FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error)
|
||||||
VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error)
|
VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error)
|
||||||
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
|
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
|
||||||
CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error)
|
CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error)
|
||||||
|
RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package http
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
@ -202,8 +203,8 @@ func (as *HTTPAccountService) TokenTransfer(ctx context.Context, amount, from, t
|
|||||||
// CheckAliasAddress retrieves the address of an alias from the API endpoint.
|
// CheckAliasAddress retrieves the address of an alias from the API endpoint.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// - alias: The alias of the user.
|
// - alias: The alias of the user.
|
||||||
func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error) {
|
func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
var r dataserviceapi.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 {
|
||||||
@ -219,6 +220,10 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin
|
|||||||
return &r, err
|
return &r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
|
return nil, fmt.Errorf("not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
var okResponse api.OKResponse
|
var okResponse api.OKResponse
|
||||||
|
65
testutil/mocks/api_mock.go
Normal file
65
testutil/mocks/api_mock.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.defalsify.org/vise.git/logging"
|
||||||
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
logg = logging.NewVanilla().WithDomain("sarafu-vise-events.testutil")
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AliceChecksum = "0xeae046BF396e91f5A8D74f863dC57c107c8a4a70"
|
||||||
|
BobChecksum = "0xB3117202371853e24B725d4169D87616A7dDb127"
|
||||||
|
AliceSession = "5553425"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MockApi struct {
|
||||||
|
TransactionsContent []dataserviceapi.Last10TxResponse
|
||||||
|
VouchersContent []dataserviceapi.TokenHoldings
|
||||||
|
VoucherDataContent *models.VoucherDataResult
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) CheckBalance(ctx context.Context, publicKey string) (*models.BalanceResult, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) CreateAccount(ctx context.Context) (*models.AccountResult, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) TrackAccountStatus(ctx context.Context, publicKey string) (*models.TrackStatusResult, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
||||||
|
logg.DebugCtxf(ctx, "mockapi fetchvouchers", "key", publicKey)
|
||||||
|
return m.VouchersContent, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error) {
|
||||||
|
logg.DebugCtxf(ctx, "mockapi fetchtransactions", "key", publicKey)
|
||||||
|
return m.TransactionsContent, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||||
|
return m.VoucherDataContent, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockApi) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +48,12 @@ func (m *MockAccountService) TokenTransfer(ctx context.Context, amount, from, to
|
|||||||
return args.Get(0).(*models.TokenTransferResponse), args.Error(1)
|
return args.Get(0).(*models.TokenTransferResponse), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAccountService) CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error) {
|
func (m *MockAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
args := m.Called(alias)
|
args := m.Called(alias)
|
||||||
return args.Get(0).(*dataserviceapi.AliasAddress), args.Error(1)
|
return args.Get(0).(*models.AliasAddress), args.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func(m MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
|
args := m.Called(publicKey, hint)
|
||||||
|
return args.Get(0).(*models.RequestAliasResult), args.Error(1)
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,10 @@ func (tas *TestAccountService) TokenTransfer(ctx context.Context, amount, from,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error) {
|
func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
|
||||||
return &dataserviceapi.AliasAddress{}, nil
|
return &models.AliasAddress{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
|
return &models.RequestAliasResult{}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user