lash/export-to-term #157

Merged
lash merged 92 commits from lash/export-to-term into master 2024-11-04 13:54:59 +01:00
5 changed files with 44 additions and 5 deletions
Showing only changes of commit 0506a8c452 - Show all commits

View File

@ -2,6 +2,8 @@ package common
import ( import (
"encoding/binary" "encoding/binary"
"git.defalsify.org/vise.git/logging"
) )
type DataTyp uint16 type DataTyp uint16
@ -33,6 +35,10 @@ const (
DATA_TRANSACTIONS DATA_TRANSACTIONS
) )
var (
logg = logging.NewVanilla().WithDomain("urdt-common")
)
func typToBytes(typ DataTyp) []byte { func typToBytes(typ DataTyp) []byte {
var b [2]byte var b [2]byte
binary.BigEndian.PutUint16(b[:], uint16(typ)) binary.BigEndian.PutUint16(b[:], uint16(typ))

View File

@ -84,6 +84,7 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol,
decList := strings.Split(decimals, "\n") decList := strings.Split(decimals, "\n")
addrList := strings.Split(addresses, "\n") addrList := strings.Split(addresses, "\n")
logg.Tracef("found" , "symlist", symList, "syms", symbols, "input", input)
for i, sym := range symList { for i, sym := range symList {
parts := strings.SplitN(sym, ":", 2) parts := strings.SplitN(sym, ":", 2)
@ -136,6 +137,7 @@ func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId str
// UpdateVoucherData sets the active voucher data and clears the temporary voucher data in the DataStore. // UpdateVoucherData sets the active voucher data and clears the temporary voucher data in the DataStore.
func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error { func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
logg.TraceCtxf(ctx, "dtal", "data", data)
// Active voucher data entries // Active voucher data entries
activeEntries := map[DataTyp][]byte{ activeEntries := map[DataTyp][]byte{
DATA_ACTIVE_SYM: []byte(data.TokenSymbol), DATA_ACTIVE_SYM: []byte(data.TokenSymbol),

View File

@ -13,6 +13,7 @@ const (
trackPath = "/api/v2/account/status" trackPath = "/api/v2/account/status"
voucherHoldingsPathPrefix = "/api/v1/holdings" voucherHoldingsPathPrefix = "/api/v1/holdings"
voucherTransfersPathPrefix = "/api/v1/transfers/last10" voucherTransfersPathPrefix = "/api/v1/transfers/last10"
voucherDataPathPrefix = "/api/v1/token"
) )
var ( var (
@ -29,6 +30,7 @@ var (
TrackURL string TrackURL string
VoucherHoldingsURL string VoucherHoldingsURL string
VoucherTransfersURL string VoucherTransfersURL string
VoucherDataURL string
) )
func setBase() error { func setBase() error {
@ -62,6 +64,7 @@ func LoadConfig() error {
TrackURL, _ = url.JoinPath(custodialURLBase, trackPath) TrackURL, _ = url.JoinPath(custodialURLBase, trackPath)
VoucherHoldingsURL, _ = url.JoinPath(dataURLBase, voucherHoldingsPathPrefix) VoucherHoldingsURL, _ = url.JoinPath(dataURLBase, voucherHoldingsPathPrefix)
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix) VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
return nil return nil
} }

View File

@ -2,13 +2,20 @@ package models
import dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" import dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
type VoucherHoldingResponse struct { //type VoucherHoldingResponse struct {
Ok bool `json:"ok"` // Ok bool `json:"ok"`
Description string `json:"description"` // Description string `json:"description"`
Result VoucherResult `json:"result"` // Result VoucherResult `json:"result"`
} //}
// VoucherResult holds the list of token holdings // VoucherResult holds the list of token holdings
type VoucherResult struct { type VoucherResult struct {
Holdings []dataserviceapi.TokenHoldings `json:"holdings"` Holdings []dataserviceapi.TokenHoldings `json:"holdings"`
} }
type VoucherDataResult struct {
TokenName string `json:"tokenName"`
TokenSymbol string `json:"tokenSymbol"`
TokenDecimals string `json:"tokenDecimals"`
SinkAddress string `json:"sinkAddress"`
}

View File

@ -23,6 +23,7 @@ type AccountServiceInterface interface {
TrackAccountStatus(ctx context.Context, publicKey string) (*models.TrackStatusResult, error) TrackAccountStatus(ctx context.Context, publicKey string) (*models.TrackStatusResult, error)
FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error)
FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error) FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error)
VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error)
} }
type AccountService struct { type AccountService struct {
@ -151,6 +152,26 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin
} }
// VoucherData retrieves voucher metadata from the data indexer API endpoint.
// Parameters:
// - address: The voucher address.
func (as *AccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
var voucherDataResult models.VoucherDataResult
ep, err := url.JoinPath(config.VoucherDataURL, address)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", ep, nil)
if err != nil {
return nil, err
}
_, err = doCustodialRequest(ctx, req, &voucherDataResult)
return &voucherDataResult, err
}
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) { func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
var okResponse api.OKResponse var okResponse api.OKResponse
var errResponse api.ErrResponse var errResponse api.ErrResponse