Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vincentmele fix/tokens by acct #3966

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/apps/chifra/internal/tokens/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ import (

func (opts *TokensOptions) HandleShow(rCtx *output.RenderCtx) error {
chain := opts.Globals.Chain
tokenAddr := base.HexToAddress(opts.Addrs[0])

var singleAddr base.Address
var addrRange []string

if opts.ByAcct {
singleAddr = base.HexToAddress(opts.Addrs[len(opts.Addrs)-1]) // by_acct case. Last address is for balance, all others are token addresses.
addrRange = opts.Addrs[:len(opts.Addrs)-1]
} else {
singleAddr = base.HexToAddress(opts.Addrs[0]) // normal case. First address is token, the rest are addresses for balances.
addrRange = opts.Addrs[1:]
}

fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
for _, address := range opts.Addrs[1:] {
addr := base.HexToAddress(address)
for _, address := range addrRange {
currentBn := base.Blknum(0)
currentTs := base.Timestamp(0)
for _, br := range opts.BlockIds {
Expand All @@ -32,7 +41,14 @@ func (opts *TokensOptions) HandleShow(rCtx *output.RenderCtx) error {
}

for _, bn := range blockNums {
if balance, err := opts.Conn.GetBalanceAtToken(tokenAddr, addr, fmt.Sprintf("0x%x", bn)); balance == nil {
tokenAddr := singleAddr
holder := base.HexToAddress(address)
if opts.ByAcct {
tokenAddr = base.HexToAddress(address)
holder = singleAddr
}

if balance, err := opts.Conn.GetBalanceAtToken(tokenAddr, holder, fmt.Sprintf("0x%x", bn)); balance == nil {
errorChan <- err
} else {
if opts.Globals.Verbose {
Expand All @@ -42,7 +58,7 @@ func (opts *TokensOptions) HandleShow(rCtx *output.RenderCtx) error {
currentBn = bn
}
s := &types.Token{
Holder: addr,
Holder: holder,
Address: tokenAddr,
Balance: *balance,
BlockNumber: bn,
Expand Down
Loading