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

modify query balance #484

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 10 additions & 7 deletions helpers/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"strconv"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
tmclient "github.com/cosmos/ibc-go/v2/modules/light-clients/07-tendermint/types"
Expand Down Expand Up @@ -42,16 +43,18 @@ func QueryBalance(chain *relayer.Chain, address string, showDenoms bool) (sdk.Co
continue
}

for i, d := range dts.DenomTraces {
if c.Denom == d.IBCDenom() {
out = append(out, sdk.Coin{Denom: d.GetFullDenomPath(), Amount: c.Amount})
break
}
// splitting denom to get hash
denomSplit := strings.Split(c.Denom, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can assume an account only has IBC tokens. We need to check if the prefix of the coin is ibc/. I added an issue on ibc-go since there should be a helper function for this

It also seems odd to me that we need to parse out ibc before doing the QueryDenomTrace, so I added another issue

I'm okay actually closing this issue and leaving the code as is until we fix the above issues upstream. I'd like a function that looks something like this:

for _, c := range coins {
    if IsIBCDenom(c.Denom) {
        dt, err := chain.QueryDenomTrace(c.Denom)
        if err != nil {
            return fmt.Errorf("unregistered token in balance")
        }
        
        out = append(out, NewToken(dt.DenomTrace.GetFullDenomPath(), c.Amount)
    } else {
         out = append(out, c)
    }
}


if i == len(dts.DenomTraces)-1 {
out = append(out, c)
if len(denomSplit) > 1 {
dt, err := chain.QueryDenomTrace(denomSplit[1])
if err == nil {
out = append(out, sdk.Coin{Denom: dt.DenomTrace.GetFullDenomPath(), Amount: c.Amount})
continue
}
}

out = append(out, c)
}
return out, nil
}
Expand Down