Add voucher data handler

This commit is contained in:
lash 2025-01-12 17:18:55 +00:00
parent c834dbb8c2
commit bc9d365fbb
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -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
}