Include tx hash in token event
This commit is contained in:
parent
123a79450c
commit
98c65bc1b1
@ -6,9 +6,9 @@ import (
|
|||||||
"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"
|
||||||
|
|
||||||
|
"git.grassecon.net/urdt/ussd/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: this vocabulary should be public in and provided by the eth-tracker repo
|
// TODO: this vocabulary should be public in and provided by the eth-tracker repo
|
||||||
|
@ -4,6 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.grassecon.net/urdt/ussd/common"
|
"git.grassecon.net/urdt/ussd/common"
|
||||||
@ -12,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
evTransfer = "TOKEN_TRANSFER"
|
evTokenTransfer = "TOKEN_TRANSFER"
|
||||||
// TODO: use export from urdt storage
|
// TODO: use export from urdt storage
|
||||||
DATATYPE_USERSUB = 64
|
DATATYPE_USERSUB = 64
|
||||||
)
|
)
|
||||||
@ -24,7 +27,8 @@ func renderTx() {
|
|||||||
type eventTokenTransfer struct {
|
type eventTokenTransfer struct {
|
||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
Value string
|
Value int
|
||||||
|
TxHash string
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateTokenTransferList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, identity lookup.Identity) error {
|
func updateTokenTransferList(ctx context.Context, api remote.AccountServiceInterface, store common.UserDataStore, identity lookup.Identity) error {
|
||||||
@ -95,6 +99,10 @@ func updateDefaultToken(ctx context.Context, store *common.UserDataStore, identi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateWait(ctx context.Context, api remote.AccountServiceInterface) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
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
|
var api remote.AccountService
|
||||||
|
|
||||||
@ -128,6 +136,43 @@ func updateToken(ctx context.Context, store *common.UserDataStore, identity look
|
|||||||
return nil
|
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 {
|
func handleTokenTransfer(ctx context.Context, store *common.UserDataStore, ev *eventTokenTransfer) error {
|
||||||
identity, err := lookup.IdentityFromAddress(ctx, store, ev.From)
|
identity, err := lookup.IdentityFromAddress(ctx, store, ev.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user