From bc9d365fbbe59efe3e126ec09fc317f11a6e73b6 Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 12 Jan 2025 17:18:55 +0000 Subject: [PATCH] Add voucher data handler --- dev/api.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dev/api.go b/dev/api.go index 872ffb5..85b2f2a 100644 --- a/dev/api.go +++ b/dev/api.go @@ -35,13 +35,18 @@ type account struct { } type voucher struct { + name string address string symbol string decimals int + sink string + commodity string + location string } var ( vouchers = make(map[string]voucher) + vouchersAddress = make(map[string]string) ) type DevAccountService struct { @@ -160,3 +165,23 @@ func (das *DevAccountService) FetchTransactions(ctx context.Context, publicKey s } return lasttx, nil } + +func (das *DevAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) { + sym, ok := vouchersAddress[address] + if !ok { + return nil, fmt.Errorf("voucher address %v not found", address) + } + voucher, ok := vouchers[sym] + if !ok { + return nil, fmt.Errorf("voucher address %v found but does not resolve", address) + } + return &models.VoucherDataResult{ + TokenName: voucher.name, + TokenSymbol: voucher.symbol, + TokenDecimals: voucher.decimals, + SinkAddress: voucher.sink, + TokenCommodity: voucher.commodity, + TokenLocation: voucher.location, + + }, nil +}