Skip to content

Commit

Permalink
that was wrong, apparently we want nil acctID for not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jchappelow committed Jan 22, 2025
1 parent 693a2ce commit b06239c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 3 additions & 6 deletions cmd/kwil-cli/cmds/account/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ func balanceCmd() *cobra.Command {
return display.PrintErr(cmd, fmt.Errorf("get account failed: %w", err))
}
// NOTE: empty acct.Identifier means it doesn't even have a record
// on the network. Perhaps we convey that to the caller? Their
// balance is zero regardless, assuming it's the correct acct ID.
// on the network. We now convey that to the caller.

resp := &respAccount{
Identifier: acct.ID.Identifier,
KeyType: acct.ID.KeyType.String(),
Balance: acct.Balance.String(),
Nonce: acct.Nonce,
Balance: acct.Balance.String(),
Nonce: acct.Nonce,
}

if acct.ID != nil { // only add identifier for the existing accounts
Expand Down
5 changes: 5 additions & 0 deletions cmd/kwil-cli/cmds/account/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (r *respAccount) MarshalText() ([]byte, error) {
Balance: %s
Nonce: %d
`, addr, r.KeyType, r.Balance, r.Nonce)
} else if len(r.Identifier) == 0 {
msg = fmt.Sprintf(`%s
Balance: %s
Nonce: %d
`, "[Account not found]", r.Balance, r.Nonce)
} else {
msg = fmt.Sprintf(`%x (%s)
Balance: %s
Expand Down
3 changes: 1 addition & 2 deletions core/rpc/client/user/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ func (cl *Client) GetAccount(ctx context.Context, account *types.AccountID, stat
// return nil, err
// }

// BUG: res.ID is not set!
return &types.Account{
ID: account,
ID: res.ID, // WARNING: may be nil if account is not found
Balance: balance,
Nonce: res.Nonce,
}, nil
Expand Down

0 comments on commit b06239c

Please sign in to comment.