feat: add holders count in token info

This commit is contained in:
Gaze
2024-04-18 01:37:22 +07:00
parent b307b68c70
commit a28e062fa5
2 changed files with 14 additions and 2 deletions

View File

@@ -58,7 +58,7 @@ type getTokenInfoResult struct {
DeployedAtHeight uint64 `json:"deployedAtHeight"`
CompletedAt *uint64 `json:"completedAt"` // unix timestamp
CompletedAtHeight *uint64 `json:"completedAtHeight"`
HoldersCount uint64 `json:"holdersCount"`
HoldersCount int `json:"holdersCount"`
Extend tokenInfoExtend `json:"extend"`
}
@@ -98,6 +98,10 @@ func (h *HttpHandler) GetTokenInfo(ctx *fiber.Ctx) (err error) {
if err != nil {
return errors.Wrap(err, "error during GetTokenInfoByHeight")
}
holdingBalances, err := h.usecase.GetBalancesByRuneId(ctx.UserContext(), runeId, blockHeight)
if err != nil {
return errors.Wrap(err, "error during GetBalancesByRuneId")
}
totalSupply, err := runeEntry.Supply()
if err != nil {
@@ -123,7 +127,7 @@ func (h *HttpHandler) GetTokenInfo(ctx *fiber.Ctx) (err error) {
DeployedAtHeight: runeEntry.EtchingBlock,
CompletedAt: lo.Ternary(runeEntry.CompletedAt.IsZero(), nil, lo.ToPtr(uint64(runeEntry.CompletedAt.Unix()))),
CompletedAtHeight: runeEntry.CompletedAtHeight,
HoldersCount: 0, // TODO: fetch holder count
HoldersCount: len(holdingBalances),
Extend: tokenInfoExtend{
Entry: entry{
Divisibility: runeEntry.Divisibility,

View File

@@ -15,3 +15,11 @@ func (u *Usecase) GetBalancesByPkScript(ctx context.Context, pkScript []byte, bl
}
return balances, nil
}
func (u *Usecase) GetBalancesByRuneId(ctx context.Context, runeId runes.RuneId, blockHeight uint64) ([]*entity.Balance, error) {
balances, err := u.runesDg.GetBalancesByRuneId(ctx, runeId, blockHeight)
if err != nil {
return nil, errors.Wrap(err, "failed to get rune holders by rune id")
}
return balances, nil
}