Add identity struct, WIP implement token event

This commit is contained in:
lash 2024-11-02 15:38:23 +00:00
parent 51389476ca
commit a414327dc5
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
10 changed files with 274 additions and 55 deletions

21
.env.example Normal file
View File

@ -0,0 +1,21 @@
#Serve Http
PORT=7123
HOST=127.0.0.1
#PostgreSQL
DB_HOST=localhost
DB_USER=postgres
#DB_PASSWORD=strongpass
#DB_NAME=urdt_ussd
DB_NAME=visedb3
DB_PORT=5432
DB_SSLMODE=disable
DB_TIMEZONE=Africa/Nairobi
#DB_SCHEMA=vvise
#External API Calls
#CREATE_ACCOUNT_URL=/api/account/create
#TRACK_STATUS_URL=/api/track/
#BALANCE_URL=/api/account/status/
#CUSTODIAL_URL_BASE=http://localhost:5003
#DATA_URL_BASE=http://localhost:5006

View File

@ -7,15 +7,31 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"git.defalsify.org/vise.git/db/mem"
"git.grassecon.net/urdt/ussd/config"
"git.grassecon.net/urdt/ussd/initializers"
"git.grassecon.net/term/event/nats" "git.grassecon.net/term/event/nats"
) )
func init() {
initializers.LoadEnvVariables()
}
func main() { func main() {
config.LoadConfig()
ctx := context.Background() ctx := context.Background()
n := nats.NewNatsSubscription() db := mem.NewMemDb()
err := n.Connect(ctx, "localhost:4222") err := db.Connect(ctx, "")
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Connect err: %v", err) fmt.Fprintf(os.Stderr, "Db connect err: %v", err)
os.Exit(1)
}
n := nats.NewNatsSubscription(db)
err = n.Connect(ctx, "localhost:4222")
if err != nil {
fmt.Fprintf(os.Stderr, "Stream connect err: %v", err)
os.Exit(1) os.Exit(1)
} }
defer n.Close() defer n.Close()

View File

@ -1,7 +1,12 @@
package event package event
import ( import (
"context"
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event" geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
"git.grassecon.net/urdt/ussd/common"
"git.grassecon.net/term/lookup"
) )
const ( const (
@ -9,7 +14,7 @@ const (
) )
type eventCustodialRegistration struct { type eventCustodialRegistration struct {
account string Account string
} }
func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistration, bool) { func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistration, bool) {
@ -19,7 +24,7 @@ func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistrati
return nil, false return nil, false
} }
pl := gev.Payload pl := gev.Payload
ev.account, ok = pl["account"].(string) ev.Account, ok = pl["account"].(string)
if !ok { if !ok {
return nil, false return nil, false
} }
@ -27,6 +32,11 @@ func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistrati
return &ev, true return &ev, true
} }
func handleCustodialRegistration(ev *eventCustodialRegistration) error { func handleCustodialRegistration(ctx context.Context, store common.UserDataStore, ev *eventCustodialRegistration) error {
identity, err := lookup.IdentityFromAddress(ctx, store, ev.Account)
if err != nil {
return err
}
_ = identity
return nil return nil
} }

View File

@ -8,9 +8,9 @@ import (
nats "github.com/nats-io/nats.go" nats "github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream" "github.com/nats-io/nats.go/jetstream"
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event" geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
"git.defalsify.org/vise.git/db"
"git.grassecon.net/urdt/ussd/common"
"git.grassecon.net/term/event" "git.grassecon.net/term/event"
) )
@ -27,8 +27,14 @@ type NatsSubscription struct {
cctx jetstream.ConsumeContext cctx jetstream.ConsumeContext
} }
func NewNatsSubscription() *NatsSubscription { func NewNatsSubscription(store db.Db) *NatsSubscription {
return &NatsSubscription{} return &NatsSubscription{
Router: event.Router{
Store: common.UserDataStore{
Db: store,
},
},
}
} }
func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error { func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
@ -86,7 +92,7 @@ func(n *NatsSubscription) handleEvent(m jetstream.Msg) {
logg.Error("nats msg deserialize fail", "err", err) logg.Error("nats msg deserialize fail", "err", err)
//fail(m) //fail(m)
} else { } else {
err = n.Route(&ev) err = n.Route(n.ctx, &ev)
if err != nil { if err != nil {
logg.Error("handler route fail", "err", err) logg.Error("handler route fail", "err", err)
//fail(m) //fail(m)

View File

@ -1,10 +1,13 @@
package event package event
import ( import (
"context"
"fmt" "fmt"
"log/slog" "log/slog"
"os" "os"
"git.grassecon.net/urdt/ussd/common"
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event" geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
) )
@ -18,13 +21,14 @@ var (
) )
type Router struct { type Router struct {
Store common.UserDataStore
} }
func(r *Router) Route(gev *geEvent.Event) error { func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error {
logg.Debug("have event", "ev", gev) logg.Debug("have event", "ev", gev)
evCC, ok := asCustodialRegistrationEvent(gev) evCC, ok := asCustodialRegistrationEvent(gev)
if ok { if ok {
return handleCustodialRegistration(evCC) return handleCustodialRegistration(ctx, r.Store, evCC)
} }
return fmt.Errorf("unexpected message") return fmt.Errorf("unexpected message")
} }

101
event/token.go Normal file
View File

@ -0,0 +1,101 @@
package event
import (
"context"
"git.defalsify.org/vise.git/db"
"git.grassecon.net/urdt/ussd/common"
"git.grassecon.net/urdt/ussd/remote"
"git.grassecon.net/term/lookup"
)
const (
evTransfer = "TOKEN_TRANSFER"
)
type eventTokenTransfer struct {
From string
To string
Value string
}
//func updateTokenTransferList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, sessionId string) error {
// return nil
//}
func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, identity lookup.Identity) error {
api.FetchVouchers(ctx, identity.ChecksumAddress)
return nil
}
//func updateTokenBalance(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, sessionId string) error {
// r, err := api.CheckBalance(ctx, sessionId)
// if err != nil {
// return err
// }
// //store.WriteEntry()
// return nil
//}
//
//func updateDefaultToken(ctx context.Context, store common.UserDataStore, sessionId string, activeSym string) {
//
//}
func updateToken(ctx context.Context, store common.UserDataStore, identity lookup.Identity) error {
var api remote.AccountService
err := updateTokenList(ctx, &api, store, identity)
if err != nil {
return err
}
// activeSym, err := store.ReadEntry(common.DATA_ACTIVE_ADDRESS)
// if err == nil {
// return nil
// }
// if !db.IsNotFound(err) {
// return err
// }
//
// err = updateDefaultToken(ctx, store, sessionId, string(activeSym))
// if err != nil {
// return err
// }
// err = updateTokenBalance(ctx, &api, store, sessionId)
// if err != nil {
// return err
// }
// err = updateTokenTransferList(ctx, &api, store, sessionId)
// if err != nil {
// return err
// }
//
return nil
}
func handleTokenTransfer(ctx context.Context, store common.UserDataStore, ev *eventTokenTransfer) error {
identity, err := lookup.IdentityFromAddress(ctx, store, ev.From)
if err != nil {
if !db.IsNotFound(err) {
return err
}
} else {
err = updateToken(ctx, store, identity)
if err != nil {
return err
}
}
identity, err = lookup.IdentityFromAddress(ctx, store, ev.To)
if err != nil {
if !db.IsNotFound(err) {
return err
}
} else {
err = updateToken(ctx, store, identity)
if err != nil {
return err
}
}
return nil
}

20
go.mod
View File

@ -3,17 +3,29 @@ module git.grassecon.net/term
go 1.23.2 go 1.23.2
require ( require (
git.defalsify.org/vise.git v0.2.0 git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed
git.grassecon.net/urdt/ussd v0.0.0-20241102140016-35a090ef423c
github.com/grassrootseconomics/eth-tracker v1.3.0-rc github.com/grassrootseconomics/eth-tracker v1.3.0-rc
github.com/nats-io/nats.go v1.37.0 github.com/nats-io/nats.go v1.37.0
) )
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/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/grassrootseconomics/eth-custodial v1.3.0-beta // indirect
github.com/grassrootseconomics/ussd-data-service v0.0.0-20241003123429-4904b4438a3a // 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/klauspost/compress v1.17.2 // indirect github.com/klauspost/compress v1.17.2 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect github.com/nats-io/nuid v1.0.1 // indirect
golang.org/x/crypto v0.26.0 // indirect github.com/x448/float16 v0.8.4 // indirect
golang.org/x/sys v0.24.0 // indirect golang.org/x/crypto v0.27.0 // indirect
golang.org/x/text v0.17.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
) )

63
go.sum
View File

@ -1,9 +1,38 @@
git.defalsify.org/vise.git v0.2.0 h1:X2ZgiGRq4C+9qOlDMP0b/oE5QHjVQNT4aEFZB88ST0Q= git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed h1:4TrsfbK7NKgsa7KjMPlnV/tjYTkAAXP5PWAZzUfzCdI=
git.defalsify.org/vise.git v0.2.0/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M= git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.grassecon.net/urdt/ussd v0.0.0-20241102140016-35a090ef423c h1:agAldZOfFqph8fSbI/fRcRVma975W0kokqSsz4lnZHk=
git.grassecon.net/urdt/ussd v0.0.0-20241102140016-35a090ef423c/go.mod h1:ADB/wpwvI6umvYzGqpJGm/GYj8msxYGiczzWCCdXegs=
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=
github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
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/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/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/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-tracker v1.3.0-rc h1:iYe2rwCBrU5O8x0+HSJRjcPT1h68k/uGd3i/cJJQuTQ= 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/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/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=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
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/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= 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/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE=
@ -12,9 +41,27 @@ github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= 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/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= github.com/pashagolub/pgxmock/v4 v4.3.0 h1:DqT7fk0OCK6H0GvqtcMsLpv8cIwWqdxWgfZNLeHCb/s=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= github.com/pashagolub/pgxmock/v4 v4.3.0/go.mod h1:9VoVHXwS3XR/yPtKGzwQvwZX1kzGB9sM8SviDcHDa3A=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
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/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=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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=

View File

@ -1,26 +0,0 @@
package handler
import (
"git.defalsify.org/vise.git/db"
"git.grassecon.net/term/common"
"git.grassecon.net/term/lookup"
)
func HandleEvReg(store db.Db, payload map[string]any) error {
var err error
address, ok := payload["address"].(string)
if !ok {
return ErrInvalidPayload
}
address, err = common.NormalizeHex(address)
if err != nil {
return err
}
sessionId, err := lookup.GetSessionIdByAddress(store, address)
if err != nil {
return err
}
_ = sessionId
return nil
}

View File

@ -1,10 +1,38 @@
package lookup package lookup
import ( import (
"git.defalsify.org/vise.git/db" "context"
"git.grassecon.net/urdt/ussd/common"
) )
func GetSessionIdByAddress(store db.Db, address string) (string, error) { type Identity struct {
var r string NormalAddress string
return r, nil ChecksumAddress string
SessionId string
}
func IdentityFromAddress(ctx context.Context, store common.UserDataStore, address string) (Identity, error) {
var err error
var ident Identity
ident.ChecksumAddress = address
ident.NormalAddress, err = common.NormalizeHex(ident.ChecksumAddress)
if err != nil {
return ident, err
}
ident.SessionId, err = getSessionIdByAddress(ctx, store, ident.NormalAddress)
if err != nil {
return ident, err
}
return ident, nil
}
func getSessionIdByAddress(ctx context.Context, store common.UserDataStore, address string) (string, error) {
r, err := store.ReadEntry(ctx, address, common.DATA_PUBLIC_KEY_REVERSE)
if err != nil {
return "", err
}
return string(r), nil
} }