Compare commits

..

2 Commits

Author SHA1 Message Date
lash
e0a3410f36
Set active / default voucher on first tx 2024-11-02 23:43:28 +00:00
lash
98c65bc1b1
Include tx hash in token event 2024-11-02 22:58:09 +00:00
4 changed files with 58 additions and 16 deletions

View File

@ -6,9 +6,9 @@ import (
"log/slog"
"os"
"git.grassecon.net/urdt/ussd/common"
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
"git.grassecon.net/urdt/ussd/common"
)
// TODO: this vocabulary should be public in and provided by the eth-tracker repo

View File

@ -4,6 +4,9 @@ import (
"context"
"fmt"
"strings"
"strconv"
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
"git.defalsify.org/vise.git/db"
"git.grassecon.net/urdt/ussd/common"
@ -12,7 +15,7 @@ import (
)
const (
evTransfer = "TOKEN_TRANSFER"
evTokenTransfer = "TOKEN_TRANSFER"
// TODO: use export from urdt storage
DATATYPE_USERSUB = 64
)
@ -24,7 +27,8 @@ func renderTx() {
type eventTokenTransfer struct {
From string
To string
Value string
Value int
TxHash string
}
func updateTokenTransferList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, identity lookup.Identity) error {
@ -91,7 +95,17 @@ func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, st
// return nil
//}
//
func updateDefaultToken(ctx context.Context, store *common.UserDataStore, identity lookup.Identity, activeSym string) error {
pfxDb := common.StoreToPrefixDb(store, []byte("vouchers"))
tokenData, err := common.GetVoucherData(ctx, pfxDb, activeSym)
if err != nil {
return err
}
return common.UpdateVoucherData(ctx, store, identity.SessionId, tokenData)
}
func updateWait(ctx context.Context, api remote.AccountServiceInterface) error {
return nil
}
@ -116,18 +130,46 @@ func updateToken(ctx context.Context, store *common.UserDataStore, identity look
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 asTokenTransferEvent(gev *geEvent.Event) (*eventTokenTransfer, bool) {
var err error
var ok bool
var ev eventTokenTransfer
if gev.TxType != evTokenTransfer {
return nil, false
}
pl := gev.Payload
// assuming from and to are checksum addresses
ev.From, ok = pl["from"].(string)
if !ok {
return nil, false
}
ev.To, ok = pl["to"].(string)
if !ok {
return nil, false
}
ev.TxHash, err = common.NormalizeHex(gev.TxHash)
if err != nil {
logg.Error("could not decode tx hash", "tx", gev.TxHash, "err", err)
return nil, false
}
value, ok := pl["value"].(string)
if !ok {
return nil, false
}
ev.Value, err = strconv.Atoi(value)
if err != nil {
logg.Error("could not decode value", "value", value, "err", err)
return nil, false
}
return &ev, true
}
func handleTokenTransfer(ctx context.Context, store *common.UserDataStore, ev *eventTokenTransfer) error {
identity, err := lookup.IdentityFromAddress(ctx, store, ev.From)
if err != nil {

2
go.mod
View File

@ -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-20241102164250-3a8a5f40baa5
git.grassecon.net/urdt/ussd v0.0.0-20241102234108-dae12ac4989e
github.com/grassrootseconomics/eth-tracker v1.3.0-rc
github.com/nats-io/nats.go v1.37.0
)

4
go.sum
View File

@ -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-20241102164250-3a8a5f40baa5 h1:B+2YYPw8REXOuEL0PgS5Mzky253wrwWYL9mpD5CmGW4=
git.grassecon.net/urdt/ussd v0.0.0-20241102164250-3a8a5f40baa5/go.mod h1:ADB/wpwvI6umvYzGqpJGm/GYj8msxYGiczzWCCdXegs=
git.grassecon.net/urdt/ussd v0.0.0-20241102234108-dae12ac4989e h1:YOEAjTrlyDRm0E63fEq8HbMp7oUCyc3vbAPOIw0xNWA=
git.grassecon.net/urdt/ussd v0.0.0-20241102234108-dae12ac4989e/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=