Update to deps refactor, tests now failing
This commit is contained in:
parent
214715746a
commit
3d8b228c0a
38
cmd/main.go
38
cmd/main.go
@ -8,42 +8,32 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/initializers"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/term/config"
|
||||
"git.grassecon.net/term/event/nats"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event/nats"
|
||||
)
|
||||
|
||||
func init() {
|
||||
initializers.LoadEnvVariables()
|
||||
}
|
||||
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var database string
|
||||
var dbDir string
|
||||
var connStr string
|
||||
|
||||
flag.StringVar(&database, "db", "gdbm", "database to be used")
|
||||
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.Parse()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
// db := mem.NewMemDb()
|
||||
// err := db.Connect(ctx, "")
|
||||
// if err != nil {
|
||||
// fmt.Fprintf(os.Stderr, "Db connect err: %v", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
|
||||
menuStorageService := common.NewStorageService(dbDir)
|
||||
err := menuStorageService.EnsureDbDir()
|
||||
if connStr != "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(connData, "")
|
||||
|
||||
n := nats.NewNatsSubscription(menuStorageService)
|
||||
err = n.Connect(ctx, config.JetstreamURL)
|
||||
if err != nil {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
urdtconfig "git.grassecon.net/urdt/ussd/config"
|
||||
"git.grassecon.net/urdt/ussd/initializers"
|
||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/env"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -10,10 +10,23 @@ var (
|
||||
JetstreamClientName string
|
||||
)
|
||||
|
||||
const (
|
||||
defaultJetstreamURL string = "localhost:4222"
|
||||
defaultJetstreamClientName string = "omnom"
|
||||
)
|
||||
|
||||
func LoadConfig() {
|
||||
urdtconfig.LoadConfig()
|
||||
|
||||
JetstreamURL = initializers.GetEnv("NATS_JETSTREAM_URL", "localhost:4222")
|
||||
JetstreamClientName = initializers.GetEnv("NATS_JETSTREAM_CLIENT_NAME", "omnom")
|
||||
func LoadConfig() error {
|
||||
err := viseconfig.LoadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
JetstreamURL = env.GetEnv("NATS_JETSTREAM_URL", defaultJetstreamURL)
|
||||
JetstreamClientName = env.GetEnv("NATS_JETSTREAM_CLIENT_NAME", defaultJetstreamClientName)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DbConn() string {
|
||||
return viseconfig.DbConn
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/term/lookup"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -41,8 +41,8 @@ func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistrati
|
||||
// TODO: implement account created in userstore instead, so that
|
||||
// the need for persister and state use here is eliminated (it
|
||||
// introduces concurrency risks)
|
||||
func handleCustodialRegistration(ctx context.Context, store *common.UserDataStore, pr *persist.Persister, ev *eventCustodialRegistration) error {
|
||||
identity, err := lookup.IdentityFromAddress(ctx, store, ev.Account)
|
||||
func handleCustodialRegistration(ctx context.Context, userStore *store.UserDataStore, pr *persist.Persister, ev *eventCustodialRegistration) error {
|
||||
identity, err := lookup.IdentityFromAddress(ctx, userStore, ev.Account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -9,9 +9,11 @@ import (
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
"git.defalsify.org/vise.git/state"
|
||||
"git.defalsify.org/vise.git/cache"
|
||||
"git.grassecon.net/urdt/ussd/config"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/term/internal/testutil"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
||||
)
|
||||
|
||||
func TestCustodialRegistration(t *testing.T) {
|
||||
@ -27,18 +29,18 @@ func TestCustodialRegistration(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
alice, err := common.NormalizeHex(testutil.AliceChecksum)
|
||||
alice, err := hex.NormalizeHex(testutil.AliceChecksum)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
userDb.SetSession(alice)
|
||||
userDb.SetPrefix(db.DATATYPE_USERDATA)
|
||||
err = userDb.Put(ctx, common.PackKey(common.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
err = userDb.Put(ctx, storedb.PackKey(storedb.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := common.UserDataStore{
|
||||
store := store.UserDataStore{
|
||||
Db: userDb,
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@ import (
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/term/event"
|
||||
"git.grassecon.net/term/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -31,7 +31,7 @@ type NatsSubscription struct {
|
||||
}
|
||||
|
||||
// NewNatsSubscription creates a new NatsSubscription with the given user store.
|
||||
func NewNatsSubscription(store common.StorageServices) *NatsSubscription {
|
||||
func NewNatsSubscription(store storage.StorageService) *NatsSubscription {
|
||||
return &NatsSubscription{
|
||||
Router: event.Router{
|
||||
Store: store,
|
||||
|
@ -13,12 +13,14 @@ import (
|
||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||
"git.defalsify.org/vise.git/db"
|
||||
memdb "git.defalsify.org/vise.git/db/mem"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/urdt/ussd/config"
|
||||
"git.grassecon.net/urdt/ussd/models"
|
||||
"git.grassecon.net/term/lookup"
|
||||
"git.grassecon.net/term/event"
|
||||
"git.grassecon.net/term/internal/testutil"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event"
|
||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -109,7 +111,8 @@ func TestHandleMsg(t *testing.T) {
|
||||
api.VoucherDataContent = &models.VoucherDataResult{
|
||||
TokenSymbol: tokenSymbol,
|
||||
TokenName: tokenName,
|
||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||
TokenDecimals: tokenDecimals,
|
||||
SinkAddress: sinkAddress,
|
||||
}
|
||||
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
||||
@ -129,14 +132,14 @@ func TestHandleMsg(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
alice, err := common.NormalizeHex(testutil.AliceChecksum)
|
||||
alice, err := hex.NormalizeHex(testutil.AliceChecksum)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
userDb.SetSession(alice)
|
||||
userDb.SetPrefix(db.DATATYPE_USERDATA)
|
||||
err = userDb.Put(ctx, common.PackKey(common.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
err = userDb.Put(ctx, storedb.PackKey(storedb.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -164,10 +167,10 @@ func TestHandleMsg(t *testing.T) {
|
||||
}
|
||||
sub.handleEvent(msg)
|
||||
|
||||
store := common.UserDataStore{
|
||||
userStore := store.UserDataStore{
|
||||
Db: userDb,
|
||||
}
|
||||
v, err := store.ReadEntry(ctx, testutil.AliceSession, common.DATA_ACTIVE_SYM)
|
||||
v, err := userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_ACTIVE_SYM)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -175,7 +178,7 @@ func TestHandleMsg(t *testing.T) {
|
||||
t.Fatalf("expected '%s', got %s", tokenSymbol, v)
|
||||
}
|
||||
|
||||
v, err = store.ReadEntry(ctx, testutil.AliceSession, common.DATA_ACTIVE_BAL)
|
||||
v, err = userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_ACTIVE_BAL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -183,7 +186,7 @@ func TestHandleMsg(t *testing.T) {
|
||||
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
||||
}
|
||||
|
||||
v, err = store.ReadEntry(ctx, testutil.AliceSession, common.DATA_TRANSACTIONS)
|
||||
v, err = userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_TRANSACTIONS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import (
|
||||
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -16,7 +17,7 @@ var (
|
||||
|
||||
// Router is responsible for invoking handlers corresponding to events.
|
||||
type Router struct {
|
||||
Store common.StorageServices
|
||||
Store storage.StorageService
|
||||
}
|
||||
|
||||
// Route parses an event from the event stream, and resolves the handler
|
||||
@ -26,12 +27,12 @@ type Router struct {
|
||||
// handler fails to successfully execute.
|
||||
func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error {
|
||||
logg.DebugCtxf(ctx, "have event", "ev", gev)
|
||||
store, err := r.Store.GetUserdataDb(ctx)
|
||||
userDb, err := r.Store.GetUserdataDb(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userStore := &common.UserDataStore{
|
||||
Db: store,
|
||||
userStore := &store.UserDataStore{
|
||||
Db: userDb,
|
||||
}
|
||||
evCC, ok := asCustodialRegistrationEvent(gev)
|
||||
if ok {
|
||||
|
@ -10,13 +10,15 @@ import (
|
||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/term/lookup"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||
)
|
||||
|
||||
const (
|
||||
evTokenTransfer = "TOKEN_TRANSFER"
|
||||
// TODO: export from urdt storage package
|
||||
// TODO: export from visedriver storage package
|
||||
DATATYPE_USERSUB = 64
|
||||
)
|
||||
|
||||
@ -45,7 +47,7 @@ func formatTransaction(idx int, tx dataserviceapi.Last10TxResponse) string {
|
||||
}
|
||||
|
||||
// refresh and store transaction history.
|
||||
func updateTokenTransferList(ctx context.Context, store *common.UserDataStore, identity lookup.Identity) error {
|
||||
func updateTokenTransferList(ctx context.Context, userStore *store.UserDataStore, identity lookup.Identity) error {
|
||||
var r []string
|
||||
|
||||
txs, err := lookup.Api.FetchTransactions(ctx, identity.ChecksumAddress)
|
||||
@ -59,45 +61,43 @@ func updateTokenTransferList(ctx context.Context, store *common.UserDataStore, i
|
||||
|
||||
s := strings.Join(r, "\n")
|
||||
|
||||
return store.WriteEntry(ctx, identity.SessionId, common.DATA_TRANSACTIONS, []byte(s))
|
||||
return userStore.WriteEntry(ctx, identity.SessionId, storedb.DATA_TRANSACTIONS, []byte(s))
|
||||
}
|
||||
|
||||
// refresh and store token list.
|
||||
//
|
||||
// TODO: when subprefixdb has been exported, can use function in ...urdt/ussd/common/ instead
|
||||
func updateTokenList(ctx context.Context, store *common.UserDataStore, identity lookup.Identity) error {
|
||||
func updateTokenList(ctx context.Context, userStore *store.UserDataStore, identity lookup.Identity) error {
|
||||
holdings, err := lookup.Api.FetchVouchers(ctx, identity.ChecksumAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metadata := common.ProcessVouchers(holdings)
|
||||
metadata := store.ProcessVouchers(holdings)
|
||||
_ = metadata
|
||||
|
||||
// TODO: make sure subprefixdb is thread safe when using gdbm
|
||||
// TODO: why is address session here unless explicitly set
|
||||
store.Db.SetSession(identity.SessionId)
|
||||
store.Db.SetPrefix(DATATYPE_USERSUB)
|
||||
userStore.Db.SetSession(identity.SessionId)
|
||||
userStore.Db.SetPrefix(DATATYPE_USERSUB)
|
||||
|
||||
k := append([]byte("vouchers"), []byte("sym")...)
|
||||
err = store.Db.Put(ctx, k, []byte(metadata.Symbols))
|
||||
err = userStore.Db.Put(ctx, k, []byte(metadata.Symbols))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logg.TraceCtxf(ctx, "processvoucher", "key", k)
|
||||
k = append([]byte("vouchers"), []byte("bal")...)
|
||||
err = store.Db.Put(ctx, k, []byte(metadata.Balances))
|
||||
err = userStore.Db.Put(ctx, k, []byte(metadata.Balances))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
k = append([]byte("vouchers"), []byte("deci")...)
|
||||
err = store.Db.Put(ctx, k, []byte(metadata.Decimals))
|
||||
err = userStore.Db.Put(ctx, k, []byte(metadata.Decimals))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
k = append([]byte("vouchers"), []byte("addr")...)
|
||||
err = store.Db.Put(ctx, k, []byte(metadata.Addresses))
|
||||
err = userStore.Db.Put(ctx, k, []byte(metadata.Addresses))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -106,14 +106,14 @@ func updateTokenList(ctx context.Context, store *common.UserDataStore, identity
|
||||
}
|
||||
|
||||
// set default token to given symbol.
|
||||
func updateDefaultToken(ctx context.Context, store *common.UserDataStore, identity lookup.Identity, activeSym string) error {
|
||||
pfxDb := common.StoreToPrefixDb(store, []byte("vouchers"))
|
||||
func updateDefaultToken(ctx context.Context, userStore *store.UserDataStore, identity lookup.Identity, activeSym string) error {
|
||||
pfxDb := store.StoreToPrefixDb(userStore, []byte("vouchers"))
|
||||
// TODO: the activeSym input should instead be newline separated list?
|
||||
tokenData, err := common.GetVoucherData(ctx, pfxDb, activeSym)
|
||||
tokenData, err := store.GetVoucherData(ctx, pfxDb, activeSym)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return common.UpdateVoucherData(ctx, store, identity.SessionId, tokenData)
|
||||
return store.UpdateVoucherData(ctx, userStore, identity.SessionId, tokenData)
|
||||
}
|
||||
|
||||
// waiter to check whether object is available on dependency endpoints.
|
||||
@ -131,14 +131,14 @@ func toSym(ctx context.Context, address string) ([]byte, error) {
|
||||
}
|
||||
|
||||
// execute all
|
||||
func updateToken(ctx context.Context, store *common.UserDataStore, identity lookup.Identity, tokenAddress string) error {
|
||||
err := updateTokenList(ctx, store, identity)
|
||||
func updateToken(ctx context.Context, userStore *store.UserDataStore, identity lookup.Identity, tokenAddress string) error {
|
||||
err := updateTokenList(ctx, userStore, identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
store.Db.SetSession(identity.SessionId)
|
||||
activeSym, err := store.ReadEntry(ctx, identity.SessionId, common.DATA_ACTIVE_SYM)
|
||||
userStore.Db.SetSession(identity.SessionId)
|
||||
activeSym, err := userStore.ReadEntry(ctx, identity.SessionId, storedb.DATA_ACTIVE_SYM)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
@ -153,12 +153,12 @@ func updateToken(ctx context.Context, store *common.UserDataStore, identity look
|
||||
}
|
||||
logg.Debugf("barfoo")
|
||||
|
||||
err = updateDefaultToken(ctx, store, identity, string(activeSym))
|
||||
err = updateDefaultToken(ctx, userStore, identity, string(activeSym))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = updateTokenTransferList(ctx, store, identity)
|
||||
err = updateTokenTransferList(ctx, userStore, identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -186,7 +186,7 @@ func asTokenTransferEvent(gev *geEvent.Event) (*eventTokenTransfer, bool) {
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
ev.TxHash, err = common.NormalizeHex(gev.TxHash)
|
||||
ev.TxHash, err = hex.NormalizeHex(gev.TxHash)
|
||||
if err != nil {
|
||||
logg.Errorf("could not decode tx hash", "tx", gev.TxHash, "err", err)
|
||||
return nil, false
|
||||
@ -210,27 +210,27 @@ func asTokenTransferEvent(gev *geEvent.Event) (*eventTokenTransfer, bool) {
|
||||
// handle token transfer.
|
||||
//
|
||||
// if from and to are NOT the same, handle code will be executed once for each side of the transfer.
|
||||
func handleTokenTransfer(ctx context.Context, store *common.UserDataStore, ev *eventTokenTransfer) error {
|
||||
identity, err := lookup.IdentityFromAddress(ctx, store, ev.From)
|
||||
func handleTokenTransfer(ctx context.Context, userStore *store.UserDataStore, ev *eventTokenTransfer) error {
|
||||
identity, err := lookup.IdentityFromAddress(ctx, userStore, ev.From)
|
||||
if err != nil {
|
||||
if !db.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = updateToken(ctx, store, identity, ev.VoucherAddress)
|
||||
err = updateToken(ctx, userStore, identity, ev.VoucherAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Compare(ev.To, ev.From) != 0 {
|
||||
identity, err = lookup.IdentityFromAddress(ctx, store, ev.To)
|
||||
identity, err = lookup.IdentityFromAddress(ctx, userStore, ev.To)
|
||||
if err != nil {
|
||||
if !db.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = updateToken(ctx, store, identity, ev.VoucherAddress)
|
||||
err = updateToken(ctx, userStore, identity, ev.VoucherAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -241,14 +241,14 @@ func handleTokenTransfer(ctx context.Context, store *common.UserDataStore, ev *e
|
||||
}
|
||||
|
||||
// handle token mint.
|
||||
func handleTokenMint(ctx context.Context, store *common.UserDataStore, ev *eventTokenMint) error {
|
||||
identity, err := lookup.IdentityFromAddress(ctx, store, ev.To)
|
||||
func handleTokenMint(ctx context.Context, userStore *store.UserDataStore, ev *eventTokenMint) error {
|
||||
identity, err := lookup.IdentityFromAddress(ctx, userStore, ev.To)
|
||||
if err != nil {
|
||||
if !db.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = updateToken(ctx, store, identity, ev.VoucherAddress)
|
||||
err = updateToken(ctx, userStore, identity, ev.VoucherAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -11,11 +11,13 @@ import (
|
||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||
"git.defalsify.org/vise.git/db"
|
||||
memdb "git.defalsify.org/vise.git/db/mem"
|
||||
"git.grassecon.net/urdt/ussd/config"
|
||||
"git.grassecon.net/urdt/ussd/models"
|
||||
"git.grassecon.net/term/lookup"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/term/internal/testutil"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -53,7 +55,8 @@ func TestTokenTransfer(t *testing.T) {
|
||||
api.VoucherDataContent = &models.VoucherDataResult{
|
||||
TokenSymbol: tokenSymbol,
|
||||
TokenName: tokenName,
|
||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||
TokenDecimals: tokenDecimals,
|
||||
SinkAddress: sinkAddress,
|
||||
}
|
||||
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
||||
@ -73,7 +76,7 @@ func TestTokenTransfer(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
alice, err := common.NormalizeHex(testutil.AliceChecksum)
|
||||
alice, err := hex.NormalizeHex(testutil.AliceChecksum)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -81,11 +84,11 @@ func TestTokenTransfer(t *testing.T) {
|
||||
// TODO: deduplicate test setup
|
||||
userDb.SetSession(alice)
|
||||
userDb.SetPrefix(db.DATATYPE_USERDATA)
|
||||
err = userDb.Put(ctx, common.PackKey(common.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
err = userDb.Put(ctx, storedb.PackKey(storedb.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := common.UserDataStore{
|
||||
userStore := store.UserDataStore{
|
||||
Db: userDb,
|
||||
}
|
||||
|
||||
@ -94,12 +97,12 @@ func TestTokenTransfer(t *testing.T) {
|
||||
To: testutil.AliceChecksum,
|
||||
Value: txValue,
|
||||
}
|
||||
err = handleTokenTransfer(ctx, &store, ev)
|
||||
err = handleTokenTransfer(ctx, &userStore, ev)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
v, err := store.ReadEntry(ctx, testutil.AliceSession, common.DATA_ACTIVE_SYM)
|
||||
v, err := userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_ACTIVE_SYM)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -107,7 +110,7 @@ func TestTokenTransfer(t *testing.T) {
|
||||
t.Fatalf("expected '%s', got %s", tokenSymbol, v)
|
||||
}
|
||||
|
||||
v, err = store.ReadEntry(ctx, testutil.AliceSession, common.DATA_ACTIVE_BAL)
|
||||
v, err = userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_ACTIVE_BAL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -115,7 +118,7 @@ func TestTokenTransfer(t *testing.T) {
|
||||
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
||||
}
|
||||
|
||||
v, err = store.ReadEntry(ctx, testutil.AliceSession, common.DATA_TRANSACTIONS)
|
||||
v, err = userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_TRANSACTIONS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -133,8 +136,6 @@ func TestTokenTransfer(t *testing.T) {
|
||||
if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
|
||||
t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func TestTokenMint(t *testing.T) {
|
||||
@ -159,7 +160,8 @@ func TestTokenMint(t *testing.T) {
|
||||
api.VoucherDataContent = &models.VoucherDataResult{
|
||||
TokenSymbol: tokenSymbol,
|
||||
TokenName: tokenName,
|
||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||
TokenDecimals: tokenDecimals,
|
||||
SinkAddress: sinkAddress,
|
||||
}
|
||||
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
||||
@ -179,18 +181,18 @@ func TestTokenMint(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
alice, err := common.NormalizeHex(testutil.AliceChecksum)
|
||||
alice, err := hex.NormalizeHex(testutil.AliceChecksum)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
userDb.SetSession(alice)
|
||||
userDb.SetPrefix(db.DATATYPE_USERDATA)
|
||||
err = userDb.Put(ctx, common.PackKey(common.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
err = userDb.Put(ctx, storedb.PackKey(storedb.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(testutil.AliceSession))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := common.UserDataStore{
|
||||
userStore := store.UserDataStore{
|
||||
Db: userDb,
|
||||
}
|
||||
|
||||
@ -198,12 +200,12 @@ func TestTokenMint(t *testing.T) {
|
||||
To: testutil.AliceChecksum,
|
||||
Value: txValue,
|
||||
}
|
||||
err = handleTokenMint(ctx, &store, ev)
|
||||
err = handleTokenMint(ctx, &userStore, ev)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
v, err := store.ReadEntry(ctx, testutil.AliceSession, common.DATA_ACTIVE_SYM)
|
||||
v, err := userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_ACTIVE_SYM)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -211,7 +213,7 @@ func TestTokenMint(t *testing.T) {
|
||||
t.Fatalf("expected '%s', got %s", tokenSymbol, v)
|
||||
}
|
||||
|
||||
v, err = store.ReadEntry(ctx, testutil.AliceSession, common.DATA_ACTIVE_BAL)
|
||||
v, err = userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_ACTIVE_BAL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -219,7 +221,7 @@ func TestTokenMint(t *testing.T) {
|
||||
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
||||
}
|
||||
|
||||
v, err = store.ReadEntry(ctx, testutil.AliceSession, common.DATA_TRANSACTIONS)
|
||||
v, err = userStore.ReadEntry(ctx, testutil.AliceSession, storedb.DATA_TRANSACTIONS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -237,5 +239,4 @@ func TestTokenMint(t *testing.T) {
|
||||
if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
|
||||
t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
|
||||
}
|
||||
|
||||
}
|
||||
|
23
go.mod
23
go.mod
@ -1,12 +1,15 @@
|
||||
module git.grassecon.net/term
|
||||
module git.grassecon.net/grassrootseconomics/sarafu-vise-events
|
||||
|
||||
go 1.23.2
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed
|
||||
git.grassecon.net/urdt/ussd v0.0.0-20241104231804-859de0513ae5
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112121504-be11eea04bc1
|
||||
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250112121425-f089822300c5
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1
|
||||
github.com/grassrootseconomics/eth-tracker v1.3.0-rc
|
||||
github.com/grassrootseconomics/ussd-data-service v0.0.0-20241003123429-4904b4438a3a
|
||||
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta
|
||||
github.com/nats-io/nats.go v1.37.0
|
||||
)
|
||||
|
||||
@ -21,11 +24,13 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/klauspost/compress v1.17.2 // indirect
|
||||
github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a // indirect
|
||||
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||
github.com/nats-io/nuid v1.0.1 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
golang.org/x/crypto v0.27.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
golang.org/x/crypto v0.32.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 // indirect
|
||||
)
|
||||
|
40
go.sum
40
go.sum
@ -1,7 +1,13 @@
|
||||
git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed h1:4TrsfbK7NKgsa7KjMPlnV/tjYTkAAXP5PWAZzUfzCdI=
|
||||
git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/urdt/ussd v0.0.0-20241104231804-859de0513ae5 h1:BNj1ym9I3AzMwc5yjmfKueLCCW/2IfrYa7WuvHYDLBo=
|
||||
git.grassecon.net/urdt/ussd v0.0.0-20241104231804-859de0513ae5/go.mod h1:ADB/wpwvI6umvYzGqpJGm/GYj8msxYGiczzWCCdXegs=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSGhfOdcj7kc555f8dc9DmMd2YAyC2AMw=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9 h1:dQ8DtiOUPzzXYgZw6REnIc1dhb3PzCEfN01Rd7Pbw+o=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112121504-be11eea04bc1 h1:by6Qw5q4Bsbio92NolxMXzbxsX3VUeAxVadTzXynOAo=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112121504-be11eea04bc1/go.mod h1:SiWT0rbK9QhFpmpAbXOtararIKDmiaAcFLHMCqKibKg=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250112121425-f089822300c5 h1:ZcwIwrjimtjMdt5qpqSpyIoZ1GR8TARQP6vSdp0kqZA=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250112121425-f089822300c5/go.mod h1:dIkSSoB16SHk0Gu/TBH63FohyjTZAJ1voywBsRYscuI=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1 h1:RfU5/WFfPxDptlkyx4MT+4YmO79sY6HvIngUq5uwQPU=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U=
|
||||
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
|
||||
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
|
||||
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
|
||||
@ -17,8 +23,8 @@ github.com/grassrootseconomics/eth-custodial v1.3.0-beta h1:twrMBhl89GqDUL9PlkzQ
|
||||
github.com/grassrootseconomics/eth-custodial v1.3.0-beta/go.mod h1:7uhRcdnJplX4t6GKCEFkbeDhhjlcaGJeJqevbcvGLZo=
|
||||
github.com/grassrootseconomics/eth-tracker v1.3.0-rc h1:iYe2rwCBrU5O8x0+HSJRjcPT1h68k/uGd3i/cJJQuTQ=
|
||||
github.com/grassrootseconomics/eth-tracker v1.3.0-rc/go.mod h1:rLXM5u8FDHnMEdah8ACgo/wfawu4o2sljHGkky2rQKE=
|
||||
github.com/grassrootseconomics/ussd-data-service v0.0.0-20241003123429-4904b4438a3a h1:q/YH7nE2j8epNmFnTu0tU1vwtCxtQ6nH+d7hRVV5krU=
|
||||
github.com/grassrootseconomics/ussd-data-service v0.0.0-20241003123429-4904b4438a3a/go.mod h1:hdKaKwqiW6/kphK4j/BhmuRlZDLo1+DYo3gYw5O0siw=
|
||||
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/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/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||
@ -35,6 +41,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4=
|
||||
github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
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/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE=
|
||||
github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
|
||||
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
||||
@ -43,6 +51,8 @@ github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
@ -53,15 +63,17 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
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.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
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/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
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/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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||
"git.grassecon.net/urdt/ussd/models"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("term-testutiL")
|
||||
logg = logging.NewVanilla().WithDomain("sarafu-vise-events.testutil")
|
||||
)
|
||||
|
||||
const (
|
||||
@ -49,3 +49,11 @@ func(m MockApi) FetchTransactions(ctx context.Context, publicKey string) ([]data
|
||||
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) (*dataserviceapi.AliasAddress, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func(m MockApi) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -14,22 +14,22 @@ type TestStorageService struct {
|
||||
Store db.Db
|
||||
}
|
||||
|
||||
// GetUserdataDb implements urdt/ussd/common.StorageServices.
|
||||
// GetUserdataDb implements grassrootseconomics/visedriver/storage.StorageService.
|
||||
func(ss *TestStorageService) GetUserdataDb(ctx context.Context) (db.Db, error) {
|
||||
return ss.Store, nil
|
||||
}
|
||||
|
||||
// GetPersister implements urdt/ussd/common.StorageServices.
|
||||
// GetPersister implements grassrootseconomics/visedriver/storage.StorageService.
|
||||
func(ts *TestStorageService) GetPersister(ctx context.Context) (*persist.Persister, error) {
|
||||
return persist.NewPersister(ts.Store), nil
|
||||
}
|
||||
|
||||
// GetResource implements urdt/ussd/common.StorageServices.
|
||||
// GetResource implements grassrootseconomics/visedriver/storage.StorageService.
|
||||
func(ts *TestStorageService) GetResource(ctx context.Context) (resource.Resource, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
// EnsureDbDir implements urdt/ussd/common.StorageServices.
|
||||
// EnsureDbDir implements grassrootseconomics/visedriver/storage.StorageService.
|
||||
func(ss *TestStorageService) EnsureDbDir() error {
|
||||
return nil
|
||||
}
|
||||
|
18
lookup/db.go
18
lookup/db.go
@ -5,7 +5,9 @@ import (
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -25,16 +27,16 @@ type Identity struct {
|
||||
//
|
||||
// It is the caller's responsibility to ensure that a valid checksum address
|
||||
// is passed.
|
||||
func IdentityFromAddress(ctx context.Context, store *common.UserDataStore, address string) (Identity, error) {
|
||||
func IdentityFromAddress(ctx context.Context, userStore *store.UserDataStore, address string) (Identity, error) {
|
||||
var err error
|
||||
var ident Identity
|
||||
|
||||
ident.ChecksumAddress = address
|
||||
ident.NormalAddress, err = common.NormalizeHex(ident.ChecksumAddress)
|
||||
ident.NormalAddress, err = hex.NormalizeHex(ident.ChecksumAddress)
|
||||
if err != nil {
|
||||
return ident, err
|
||||
}
|
||||
ident.SessionId, err = getSessionIdByAddress(ctx, store, ident.NormalAddress)
|
||||
ident.SessionId, err = getSessionIdByAddress(ctx, userStore, ident.NormalAddress)
|
||||
if err != nil {
|
||||
return ident, err
|
||||
}
|
||||
@ -42,12 +44,12 @@ func IdentityFromAddress(ctx context.Context, store *common.UserDataStore, addre
|
||||
}
|
||||
|
||||
// load matching session from address from db store.
|
||||
func getSessionIdByAddress(ctx context.Context, store *common.UserDataStore, address string) (string, error) {
|
||||
func getSessionIdByAddress(ctx context.Context, userStore *store.UserDataStore, address string) (string, error) {
|
||||
// TODO: replace with userdatastore when double sessionid issue fixed
|
||||
//r, err := store.ReadEntry(ctx, address, common.DATA_PUBLIC_KEY_REVERSE)
|
||||
store.Db.SetPrefix(db.DATATYPE_USERDATA)
|
||||
store.Db.SetSession(address)
|
||||
r, err := store.Db.Get(ctx, common.PackKey(common.DATA_PUBLIC_KEY_REVERSE, []byte{}))
|
||||
userStore.Db.SetPrefix(db.DATATYPE_USERDATA)
|
||||
userStore.Db.SetSession(address)
|
||||
r, err := userStore.Db.Get(ctx, storedb.PackKey(storedb.DATA_PUBLIC_KEY_REVERSE, []byte{}))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package lookup
|
||||
|
||||
import (
|
||||
"git.grassecon.net/urdt/ussd/remote"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
)
|
||||
|
||||
var (
|
||||
// Api provides the api implementation for all external lookups.
|
||||
Api remote.AccountServiceInterface = &remote.AccountService{}
|
||||
Api remote.AccountService = &http.HTTPAccountService{}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user