diff --git a/apps/klesia/src/index.spec.ts b/apps/klesia/src/index.spec.ts index 53a6a5a..95ccfc8 100644 --- a/apps/klesia/src/index.spec.ts +++ b/apps/klesia/src/index.spec.ts @@ -53,6 +53,6 @@ describe("Mina Devnet RPC", () => { // biome-ignore lint/suspicious/noExplicitAny: TODO const { result } = (await response.json()) as any; expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0); - expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0); + expect(BigInt(result.balance.total)).toBeGreaterThanOrEqual(0); }); }); diff --git a/apps/klesia/src/methods/mina.spec.ts b/apps/klesia/src/methods/mina.spec.ts index a3cd1aa..db59be0 100644 --- a/apps/klesia/src/methods/mina.spec.ts +++ b/apps/klesia/src/methods/mina.spec.ts @@ -26,5 +26,5 @@ it("should return network id", async () => { it("should get account info", async () => { const result = await mina.getAccount({ publicKey: TEST_PKEY }); expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0); - expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0); + expect(BigInt(result.balance.total)).toBeGreaterThanOrEqual(0); }); diff --git a/apps/klesia/src/methods/mina.ts b/apps/klesia/src/methods/mina.ts index 4effa54..70f1f93 100644 --- a/apps/klesia/src/methods/mina.ts +++ b/apps/klesia/src/methods/mina.ts @@ -1,42 +1,42 @@ import { - SendTransactionBodySchema, - SendZkAppBodySchema, - type Sendable, + SendTransactionBodySchema, + SendZkAppBodySchema, + type Sendable, } from "@mina-js/utils"; import { gql } from "@urql/core"; import { match } from "ts-pattern"; import { getNodeClient } from "../utils/node"; export const PRIORITY = { - low: 0.25, - medium: 0.5, - high: 0.75, + low: 0.25, + medium: 0.5, + high: 0.75, } as Record; const getTransactionCount = async ({ publicKey }: { publicKey: string }) => { - const client = getNodeClient(); - try { - const { data } = await client.query( - gql` + const client = getNodeClient(); + try { + const { data } = await client.query( + gql` query { account(publicKey: $publicKey) { nonce } } `, - { publicKey }, - ); - return data.account.nonce; - } catch { - return "0"; - } + { publicKey }, + ); + return data.account.nonce; + } catch { + return "0"; + } }; const getBalance = async ({ publicKey }: { publicKey: string }) => { - const client = getNodeClient(); - try { - const { data } = await client.query( - gql` + const client = getNodeClient(); + try { + const { data } = await client.query( + gql` query { account(publicKey: $publicKey) { balance { @@ -45,56 +45,56 @@ const getBalance = async ({ publicKey }: { publicKey: string }) => { } } `, - { publicKey }, - ); - return data.account.balance.total; - } catch { - return "0"; - } + { publicKey }, + ); + return data.account.balance.total; + } catch { + return "0"; + } }; const blockHash = async () => { - const client = getNodeClient(); - const { data } = await client.query( - gql` + const client = getNodeClient(); + const { data } = await client.query( + gql` query { daemonStatus { stateHash } } `, - {}, - ); - return data.daemonStatus.stateHash; + {}, + ); + return data.daemonStatus.stateHash; }; const networkId = async () => { - const client = getNodeClient(); - const { data } = await client.query( - gql` + const client = getNodeClient(); + const { data } = await client.query( + gql` query { networkID } `, - {}, - ); - return data.networkID === "mina:testnet" ? "mina:devnet" : data.networkID; + {}, + ); + return data.networkID === "mina:testnet" ? "mina:devnet" : data.networkID; }; const sendTransaction = async ({ - signedTransaction, - type, + signedTransaction, + type, }: { - signedTransaction: Sendable; - type: "payment" | "delegation" | "zkapp"; + signedTransaction: Sendable; + type: "payment" | "delegation" | "zkapp"; }) => { - const client = getNodeClient(); - return match(type) - .with("payment", async () => { - const { signature, input } = - SendTransactionBodySchema.parse(signedTransaction); - const { data } = await client.mutation( - gql` + const client = getNodeClient(); + return match(type) + .with("payment", async () => { + const { signature, input } = + SendTransactionBodySchema.parse(signedTransaction); + const { data } = await client.mutation( + gql` mutation { sendPayment(signature: $signature, input: $input) { payment { @@ -103,15 +103,15 @@ const sendTransaction = async ({ } } `, - { signature, input }, - ); - return data.sendPayment.payment.hash; - }) - .with("delegation", async () => { - const { signature, input } = - SendTransactionBodySchema.parse(signedTransaction); - const { data } = await client.mutation( - gql` + { signature, input }, + ); + return data.sendPayment.payment.hash; + }) + .with("delegation", async () => { + const { signature, input } = + SendTransactionBodySchema.parse(signedTransaction); + const { data } = await client.mutation( + gql` mutation { sendDelegation(signature: $signature, input: $input) { delegation { @@ -120,14 +120,14 @@ const sendTransaction = async ({ } } `, - { signature, input }, - ); - return data.sendDelegation.delegation.hash; - }) - .with("zkapp", async () => { - const { input } = SendZkAppBodySchema.parse(signedTransaction); - const { data } = await client.mutation( - gql` + { signature, input }, + ); + return data.sendDelegation.delegation.hash; + }) + .with("zkapp", async () => { + const { input } = SendZkAppBodySchema.parse(signedTransaction); + const { data } = await client.mutation( + gql` mutation { sendZkapp(input: $input) { zkapp { @@ -136,46 +136,84 @@ const sendTransaction = async ({ } } `, - { input }, - ); - return data.sendZkapp.zkapp.hash; - }) - .exhaustive(); + { input }, + ); + return data.sendZkapp.zkapp.hash; + }) + .exhaustive(); }; const getAccount = async ({ publicKey }: { publicKey: string }) => { - const client = getNodeClient(); - try { - const { data } = await client.query( - gql` + const client = getNodeClient(); + try { + const { data } = await client.query( + gql` query { account(publicKey: $publicKey) { + publicKey + token nonce balance { total } + tokenSymbol + receiptChainHash + timing { + initialMinimumBalance + cliffTime + cliffAmount + vestingPeriod + vestingIncrement + } + permissions { + editState + access + send + receive + setDelegate + setPermissions + setVerificationKey { + auth + txnVersion + } + setZkappUri + editActionState + setTokenSymbol + incrementNonce + setVotingFor + setTiming + } + delegateAccount { publicKey } + votingFor + zkappState + verificationKey { + verificationKey + hash + } + actionState + provedState + zkappUri } } `, - { publicKey }, - ); - return { - nonce: data.account.nonce, - balance: data.account.balance.total, - }; - } catch { - return { - nonce: "0", - balance: "0", - }; - } + { publicKey }, + ); + return data.account; + } catch { + return { + nonce: "0", + balance: { + total: "0", + }, + }; + } }; export const mina = { - getTransactionCount, - getBalance, - blockHash, - networkId, - sendTransaction, - getAccount, + getTransactionCount, + getBalance, + blockHash, + networkId, + sendTransaction, + getAccount, };