Add processvoucher routine
This commit is contained in:
		
							parent
							
								
									a414327dc5
								
							
						
					
					
						commit
						d3d42ec6a2
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
.env
 | 
			
		||||
main
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								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=
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user