diff --git a/event/token.go b/event/token.go index e9825e3..1bad2cd 100644 --- a/event/token.go +++ b/event/token.go @@ -2,6 +2,8 @@ package event import ( "context" + "fmt" + "strings" "git.defalsify.org/vise.git/db" "git.grassecon.net/urdt/ussd/common" @@ -15,15 +17,31 @@ const ( DATATYPE_USERSUB = 64 ) +func renderTx() { + +} + 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 updateTokenTransferList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, identity lookup.Identity) error { + var r []string + + txs, err := api.FetchTransactions(ctx, identity.ChecksumAddress) + if err != nil { + return err + } + + for i, tx := range(txs) { + r = append(r, fmt.Sprintf("%d %s %s", i, tx.DateBlock, tx.TxHash[:10])) + } + + s := strings.Join(r, "\n") + return store.WriteEntry(ctx, identity.SessionId, common.DATA_TRANSACTIONS, []byte(s)) +} func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, store *common.UserDataStore, identity lookup.Identity) error { holdings, err := api.FetchVouchers(ctx, identity.ChecksumAddress) @@ -73,9 +91,9 @@ func updateTokenList(ctx context.Context, api remote.AccountServiceInterface, st // return nil //} // -//func updateDefaultToken(ctx context.Context, store common.UserDataStore, sessionId string, activeSym string) { -// -//} +func updateDefaultToken(ctx context.Context, store *common.UserDataStore, identity lookup.Identity, activeSym string) error { + return nil +} func updateToken(ctx context.Context, store *common.UserDataStore, identity lookup.Identity) error { var api remote.AccountService @@ -85,18 +103,19 @@ func updateToken(ctx context.Context, store *common.UserDataStore, identity look 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 -// } + activeSym, err := store.ReadEntry(ctx, identity.SessionId, common.DATA_ACTIVE_ADDRESS) + if err == nil { + return nil + } + if !db.IsNotFound(err) { + return err + } + + err = updateDefaultToken(ctx, store, identity, string(activeSym)) + if err != nil { + return err + } + // err = updateTokenBalance(ctx, &api, store, sessionId) // if err != nil { // return err diff --git a/go.mod b/go.mod index ff5c05b..e9860b8 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-20241102154646-e29a24b376cf + git.grassecon.net/urdt/ussd v0.0.0-20241102164250-3a8a5f40baa5 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 6342e04..df0a41d 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-20241102154646-e29a24b376cf h1:w7uWGBu+qlXzbR2j7h/kIuXJ3dWsfjxDT07l7NccibM= -git.grassecon.net/urdt/ussd v0.0.0-20241102154646-e29a24b376cf/go.mod h1:ADB/wpwvI6umvYzGqpJGm/GYj8msxYGiczzWCCdXegs= +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= 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=