Skip to content

Commit 7d4d77a

Browse files
committed
feat: include all account object properties in GraphQL response for getAccount API query
1 parent 05cdbc4 commit 7d4d77a

File tree

3 files changed

+133
-95
lines changed

3 files changed

+133
-95
lines changed

apps/klesia/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ describe("Mina Devnet RPC", () => {
5353
// biome-ignore lint/suspicious/noExplicitAny: TODO
5454
const { result } = (await response.json()) as any;
5555
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
56-
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
56+
expect(BigInt(result.balance.total)).toBeGreaterThanOrEqual(0);
5757
});
5858
});

apps/klesia/src/methods/mina.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ it("should return network id", async () => {
2626
it("should get account info", async () => {
2727
const result = await mina.getAccount({ publicKey: TEST_PKEY });
2828
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
29-
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
29+
expect(BigInt(result.balance.total)).toBeGreaterThanOrEqual(0);
3030
});

apps/klesia/src/methods/mina.ts

Lines changed: 131 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
import {
2-
SendTransactionBodySchema,
3-
SendZkAppBodySchema,
4-
type Sendable,
2+
SendTransactionBodySchema,
3+
SendZkAppBodySchema,
4+
type Sendable,
55
} from "@mina-js/utils";
66
import { gql } from "@urql/core";
77
import { match } from "ts-pattern";
88
import { getNodeClient } from "../utils/node";
99

1010
export const PRIORITY = {
11-
low: 0.25,
12-
medium: 0.5,
13-
high: 0.75,
11+
low: 0.25,
12+
medium: 0.5,
13+
high: 0.75,
1414
} as Record<string, number>;
1515

1616
const getTransactionCount = async ({ publicKey }: { publicKey: string }) => {
17-
const client = getNodeClient();
18-
try {
19-
const { data } = await client.query(
20-
gql`
17+
const client = getNodeClient();
18+
try {
19+
const { data } = await client.query(
20+
gql`
2121
query {
2222
account(publicKey: $publicKey) {
2323
nonce
2424
}
2525
}
2626
`,
27-
{ publicKey },
28-
);
29-
return data.account.nonce;
30-
} catch {
31-
return "0";
32-
}
27+
{ publicKey },
28+
);
29+
return data.account.nonce;
30+
} catch {
31+
return "0";
32+
}
3333
};
3434

3535
const getBalance = async ({ publicKey }: { publicKey: string }) => {
36-
const client = getNodeClient();
37-
try {
38-
const { data } = await client.query(
39-
gql`
36+
const client = getNodeClient();
37+
try {
38+
const { data } = await client.query(
39+
gql`
4040
query {
4141
account(publicKey: $publicKey) {
4242
balance {
@@ -45,56 +45,56 @@ const getBalance = async ({ publicKey }: { publicKey: string }) => {
4545
}
4646
}
4747
`,
48-
{ publicKey },
49-
);
50-
return data.account.balance.total;
51-
} catch {
52-
return "0";
53-
}
48+
{ publicKey },
49+
);
50+
return data.account.balance.total;
51+
} catch {
52+
return "0";
53+
}
5454
};
5555

5656
const blockHash = async () => {
57-
const client = getNodeClient();
58-
const { data } = await client.query(
59-
gql`
57+
const client = getNodeClient();
58+
const { data } = await client.query(
59+
gql`
6060
query {
6161
daemonStatus {
6262
stateHash
6363
}
6464
}
6565
`,
66-
{},
67-
);
68-
return data.daemonStatus.stateHash;
66+
{},
67+
);
68+
return data.daemonStatus.stateHash;
6969
};
7070

7171
const networkId = async () => {
72-
const client = getNodeClient();
73-
const { data } = await client.query(
74-
gql`
72+
const client = getNodeClient();
73+
const { data } = await client.query(
74+
gql`
7575
query {
7676
networkID
7777
}
7878
`,
79-
{},
80-
);
81-
return data.networkID === "mina:testnet" ? "mina:devnet" : data.networkID;
79+
{},
80+
);
81+
return data.networkID === "mina:testnet" ? "mina:devnet" : data.networkID;
8282
};
8383

8484
const sendTransaction = async ({
85-
signedTransaction,
86-
type,
85+
signedTransaction,
86+
type,
8787
}: {
88-
signedTransaction: Sendable;
89-
type: "payment" | "delegation" | "zkapp";
88+
signedTransaction: Sendable;
89+
type: "payment" | "delegation" | "zkapp";
9090
}) => {
91-
const client = getNodeClient();
92-
return match(type)
93-
.with("payment", async () => {
94-
const { signature, input } =
95-
SendTransactionBodySchema.parse(signedTransaction);
96-
const { data } = await client.mutation(
97-
gql`
91+
const client = getNodeClient();
92+
return match(type)
93+
.with("payment", async () => {
94+
const { signature, input } =
95+
SendTransactionBodySchema.parse(signedTransaction);
96+
const { data } = await client.mutation(
97+
gql`
9898
mutation {
9999
sendPayment(signature: $signature, input: $input) {
100100
payment {
@@ -103,15 +103,15 @@ const sendTransaction = async ({
103103
}
104104
}
105105
`,
106-
{ signature, input },
107-
);
108-
return data.sendPayment.payment.hash;
109-
})
110-
.with("delegation", async () => {
111-
const { signature, input } =
112-
SendTransactionBodySchema.parse(signedTransaction);
113-
const { data } = await client.mutation(
114-
gql`
106+
{ signature, input },
107+
);
108+
return data.sendPayment.payment.hash;
109+
})
110+
.with("delegation", async () => {
111+
const { signature, input } =
112+
SendTransactionBodySchema.parse(signedTransaction);
113+
const { data } = await client.mutation(
114+
gql`
115115
mutation {
116116
sendDelegation(signature: $signature, input: $input) {
117117
delegation {
@@ -120,14 +120,14 @@ const sendTransaction = async ({
120120
}
121121
}
122122
`,
123-
{ signature, input },
124-
);
125-
return data.sendDelegation.delegation.hash;
126-
})
127-
.with("zkapp", async () => {
128-
const { input } = SendZkAppBodySchema.parse(signedTransaction);
129-
const { data } = await client.mutation(
130-
gql`
123+
{ signature, input },
124+
);
125+
return data.sendDelegation.delegation.hash;
126+
})
127+
.with("zkapp", async () => {
128+
const { input } = SendZkAppBodySchema.parse(signedTransaction);
129+
const { data } = await client.mutation(
130+
gql`
131131
mutation {
132132
sendZkapp(input: $input) {
133133
zkapp {
@@ -136,46 +136,84 @@ const sendTransaction = async ({
136136
}
137137
}
138138
`,
139-
{ input },
140-
);
141-
return data.sendZkapp.zkapp.hash;
142-
})
143-
.exhaustive();
139+
{ input },
140+
);
141+
return data.sendZkapp.zkapp.hash;
142+
})
143+
.exhaustive();
144144
};
145145

146146
const getAccount = async ({ publicKey }: { publicKey: string }) => {
147-
const client = getNodeClient();
148-
try {
149-
const { data } = await client.query(
150-
gql`
147+
const client = getNodeClient();
148+
try {
149+
const { data } = await client.query(
150+
gql`
151151
query {
152152
account(publicKey: $publicKey) {
153+
publicKey
154+
token
153155
nonce
154156
balance {
155157
total
156158
}
159+
tokenSymbol
160+
receiptChainHash
161+
timing {
162+
initialMinimumBalance
163+
cliffTime
164+
cliffAmount
165+
vestingPeriod
166+
vestingIncrement
167+
}
168+
permissions {
169+
editState
170+
access
171+
send
172+
receive
173+
setDelegate
174+
setPermissions
175+
setVerificationKey {
176+
auth
177+
txnVersion
178+
}
179+
setZkappUri
180+
editActionState
181+
setTokenSymbol
182+
incrementNonce
183+
setVotingFor
184+
setTiming
185+
}
186+
delegateAccount { publicKey }
187+
votingFor
188+
zkappState
189+
verificationKey {
190+
verificationKey
191+
hash
192+
}
193+
actionState
194+
provedState
195+
zkappUri
157196
}
158197
}
159198
`,
160-
{ publicKey },
161-
);
162-
return {
163-
nonce: data.account.nonce,
164-
balance: data.account.balance.total,
165-
};
166-
} catch {
167-
return {
168-
nonce: "0",
169-
balance: "0",
170-
};
171-
}
199+
{ publicKey },
200+
);
201+
return data.account;
202+
} catch {
203+
return {
204+
nonce: "0",
205+
balance: {
206+
total: "0",
207+
},
208+
};
209+
}
172210
};
173211

174212
export const mina = {
175-
getTransactionCount,
176-
getBalance,
177-
blockHash,
178-
networkId,
179-
sendTransaction,
180-
getAccount,
213+
getTransactionCount,
214+
getBalance,
215+
blockHash,
216+
networkId,
217+
sendTransaction,
218+
getAccount,
181219
};

0 commit comments

Comments
 (0)