Skip to content

Commit

Permalink
chore: In gnoclient.Client.QueryAccount, param addr should be crypto.…
Browse files Browse the repository at this point in the history
…Address, not string

Signed-off-by: Jeff Thompson <jeff@thefirst.org>
  • Loading branch information
jefft0 committed Nov 23, 2023
1 parent dcb7d43 commit 8abebbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions gno.land/pkg/gnoclient/client_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/gnolang/gno/tm2/pkg/amino"
rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
ctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/errors"
"github.com/gnolang/gno/tm2/pkg/std"
)
Expand Down Expand Up @@ -35,18 +36,21 @@ func (c Client) Query(cfg QueryCfg) (*ctypes.ResultABCIQuery, error) {
}

// QueryAccount retrieves account information for a given address.
func (c Client) QueryAccount(addr string) (*std.BaseAccount, *ctypes.ResultABCIQuery, error) {
func (c Client) QueryAccount(addr crypto.Address) (*std.BaseAccount, *ctypes.ResultABCIQuery, error) {
if err := c.validateRPCClient(); err != nil {
return nil, nil, err
}

path := fmt.Sprintf("auth/accounts/%s", addr)
path := fmt.Sprintf("auth/accounts/%s", crypto.AddressToBech32(addr))
data := []byte{}

qres, err := c.RPCClient.ABCIQuery(path, data)
if err != nil {
return nil, nil, errors.Wrap(err, "query account")
}
if qres.Response.Data == nil || len(qres.Response.Data) == 0 || string(qres.Response.Data) == "null" {
return nil, nil, std.ErrUnknownAddress("unknown address: " + crypto.AddressToBech32(addr))
}

var qret struct{ BaseAccount std.BaseAccount }
err = amino.UnmarshalJSON(qres.Response.Data, &qret)
Expand Down
2 changes: 1 addition & 1 deletion gno.land/pkg/gnoclient/client_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c Client) signAndBroadcastTxCommit(tx std.Tx, accountNumber, sequenceNumbe
caller := c.Signer.Info().GetAddress()

if sequenceNumber == 0 || accountNumber == 0 {
account, _, err := c.QueryAccount(caller.String())
account, _, err := c.QueryAccount(caller)
if err != nil {
return nil, errors.Wrap(err, "query account")
}
Expand Down

0 comments on commit 8abebbe

Please sign in to comment.