diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44e207b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +main diff --git a/event/custodial_registration.go b/event/custodial_registration.go index ad9b05a..8c71515 100644 --- a/event/custodial_registration.go +++ b/event/custodial_registration.go @@ -32,7 +32,7 @@ func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistrati return &ev, true } -func handleCustodialRegistration(ctx context.Context, store common.UserDataStore, 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 diff --git a/event/nats/nats.go b/event/nats/nats.go index 9eea570..8511401 100644 --- a/event/nats/nats.go +++ b/event/nats/nats.go @@ -30,7 +30,7 @@ type NatsSubscription struct { func NewNatsSubscription(store db.Db) *NatsSubscription { return &NatsSubscription{ Router: event.Router{ - Store: common.UserDataStore{ + Store: &common.UserDataStore{ Db: store, }, }, diff --git a/event/route.go b/event/route.go index c328971..5b7c655 100644 --- a/event/route.go +++ b/event/route.go @@ -21,7 +21,7 @@ var ( ) type Router struct { - Store common.UserDataStore + Store *common.UserDataStore } func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error { diff --git a/event/token.go b/event/token.go index 35b3b56..e9825e3 100644 --- a/event/token.go +++ b/event/token.go @@ -11,6 +11,8 @@ import ( const ( evTransfer = "TOKEN_TRANSFER" + // TODO: use export from urdt storage + DATATYPE_USERSUB = 64 ) type eventTokenTransfer struct { @@ -23,8 +25,42 @@ type eventTokenTransfer struct { // return nil //} -func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, identity lookup.Identity) error { - api.FetchVouchers(ctx, identity.ChecksumAddress) +func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, store *common.UserDataStore, identity lookup.Identity) error { + holdings, err := api.FetchVouchers(ctx, identity.ChecksumAddress) + if err != nil { + return err + } + metadata := common.ProcessVouchers(holdings) + _ = metadata + + // TODO: export subprefixdb and use that instead + // TODO: make sure subprefixdb is thread safe when using gdbm + store.Db.SetPrefix(DATATYPE_USERSUB) + + k := append([]byte("vouchers"), []byte("sym")...) + err = store.Db.Put(ctx, k, []byte(metadata.Symbols)) + if err != nil { + return err + } + + k = append([]byte("vouchers"), []byte("bal")...) + err = store.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)) + if err != nil { + return err + } + + k = append([]byte("vouchers"), []byte("addr")...) + err = store.Db.Put(ctx, k, []byte(metadata.Addresses)) + if err != nil { + return err + } + return nil } @@ -41,7 +77,7 @@ func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, st // //} -func updateToken(ctx context.Context, store common.UserDataStore, identity lookup.Identity) error { +func updateToken(ctx context.Context, store *common.UserDataStore, identity lookup.Identity) error { var api remote.AccountService err := updateTokenList(ctx, &api, store, identity) @@ -73,7 +109,7 @@ func updateToken(ctx context.Context, store common.UserDataStore, identity looku return nil } -func handleTokenTransfer(ctx context.Context, store common.UserDataStore, ev *eventTokenTransfer) error { +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) { diff --git a/go.mod b/go.mod index 8f13e73..ff5c05b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.2 require ( git.defalsify.org/vise.git v0.2.1-0.20241031204035-b588301738ed - git.grassecon.net/urdt/ussd v0.0.0-20241102140016-35a090ef423c + git.grassecon.net/urdt/ussd v0.0.0-20241102154646-e29a24b376cf github.com/grassrootseconomics/eth-tracker v1.3.0-rc github.com/nats-io/nats.go v1.37.0 ) diff --git a/go.sum b/go.sum index c112953..6342e04 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ 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-20241102140016-35a090ef423c h1:agAldZOfFqph8fSbI/fRcRVma975W0kokqSsz4lnZHk= -git.grassecon.net/urdt/ussd v0.0.0-20241102140016-35a090ef423c/go.mod h1:ADB/wpwvI6umvYzGqpJGm/GYj8msxYGiczzWCCdXegs= +git.grassecon.net/urdt/ussd v0.0.0-20241102154646-e29a24b376cf h1:w7uWGBu+qlXzbR2j7h/kIuXJ3dWsfjxDT07l7NccibM= +git.grassecon.net/urdt/ussd v0.0.0-20241102154646-e29a24b376cf/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= diff --git a/lookup/db.go b/lookup/db.go index e4bb682..012a2a0 100644 --- a/lookup/db.go +++ b/lookup/db.go @@ -12,7 +12,7 @@ type Identity struct { SessionId string } -func IdentityFromAddress(ctx context.Context, store common.UserDataStore, address string) (Identity, error) { +func IdentityFromAddress(ctx context.Context, store *common.UserDataStore, address string) (Identity, error) { var err error var ident Identity @@ -28,7 +28,7 @@ func IdentityFromAddress(ctx context.Context, store common.UserDataStore, addres return ident, nil } -func getSessionIdByAddress(ctx context.Context, store common.UserDataStore, address string) (string, error) { +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 {