Skip to content

Commit 0130118

Browse files
committed
Update query account
1 parent b665a0e commit 0130118

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

cmd/handler/query.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/gnolang/gno/pkgs/amino"
1212
"github.com/gnolang/gno/pkgs/bft/rpc/client"
13+
"github.com/gnolang/gno/pkgs/crypto"
1314
"github.com/gnolang/gno/pkgs/std"
1415

1516
"github.com/gorilla/mux"
@@ -35,16 +36,15 @@ type AuthAccount struct {
3536
}
3637

3738
type CosmosAccount struct {
38-
Type string `json:"@type"`
39-
Address string `json:"address"`
40-
PubKey AuthKey `json:"pub_key"`
41-
AccountNumber string `json:"account_number"`
42-
Sequence string `json:"sequence"`
39+
Type string `json:"@type"`
40+
Address crypto.Address `json:"address"`
41+
PubKey crypto.PubKey `json:"pub_key"`
42+
AccountNumber uint64 `json:"account_number"`
43+
Sequence uint64 `json:"sequence"`
4344
}
4445

45-
type AuthKey struct {
46-
Type string `json:"@type"`
47-
Key string `json:"key"`
46+
type GnoAccount struct {
47+
std.BaseAccount
4848
}
4949

5050
func GnoRenderQueryHandler(cli client.ABCIClient) http.HandlerFunc {
@@ -82,33 +82,32 @@ func AuthQueryHandler(cli client.ABCIClient) http.HandlerFunc {
8282
return
8383
}
8484

85-
var account std.Account
85+
var account GnoAccount
8686
err = amino.UnmarshalJSON(res.Response.Data, &account)
8787
if err != nil {
8888
writeError(w, err)
8989
return
9090
}
9191

92-
if account == nil {
92+
if account.Address.IsZero() {
9393
w.WriteHeader(http.StatusNotFound)
9494
return
9595
}
9696

9797
result := AuthAccount{
9898
Account: CosmosAccount{
99-
Type: "/cosmos.auth.v1beta1.BaseAccount",
100-
Address: account.GetAddress().String(),
101-
PubKey: AuthKey{
102-
Type: "/tm.PubKeySecp256k1",
103-
Key: base64.StdEncoding.EncodeToString(account.GetPubKey().Bytes()),
104-
},
105-
AccountNumber: strconv.FormatUint(account.GetAccountNumber(), 10),
106-
Sequence: strconv.FormatUint(account.GetSequence(), 10),
99+
Type: "/cosmos.auth.v1beta1.BaseAccount",
100+
Address: account.GetAddress(),
101+
PubKey: account.GetPubKey(),
102+
AccountNumber: account.GetAccountNumber(),
103+
Sequence: account.GetSequence(),
107104
},
108105
}
106+
107+
json, _ := amino.MarshalJSONIndent(result, "", " ")
109108
w.WriteHeader(http.StatusOK)
110109
w.Header().Set("Content-Type", "application/json")
111-
json.NewEncoder(w).Encode(result)
110+
fmt.Fprint(w, string(json))
112111
}
113112
}
114113

0 commit comments

Comments
 (0)