1
1
import {
2
- SendTransactionBodySchema ,
3
- SendZkAppBodySchema ,
4
- type Sendable ,
2
+ SendTransactionBodySchema ,
3
+ SendZkAppBodySchema ,
4
+ type Sendable ,
5
5
} from "@mina-js/utils" ;
6
6
import { gql } from "@urql/core" ;
7
7
import { match } from "ts-pattern" ;
8
8
import { getNodeClient } from "../utils/node" ;
9
9
10
10
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 ,
14
14
} as Record < string , number > ;
15
15
16
16
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 `
21
21
query {
22
22
account(publicKey: $publicKey) {
23
23
nonce
24
24
}
25
25
}
26
26
` ,
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
+ }
33
33
} ;
34
34
35
35
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 `
40
40
query {
41
41
account(publicKey: $publicKey) {
42
42
balance {
@@ -45,56 +45,56 @@ const getBalance = async ({ publicKey }: { publicKey: string }) => {
45
45
}
46
46
}
47
47
` ,
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
+ }
54
54
} ;
55
55
56
56
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 `
60
60
query {
61
61
daemonStatus {
62
62
stateHash
63
63
}
64
64
}
65
65
` ,
66
- { } ,
67
- ) ;
68
- return data . daemonStatus . stateHash ;
66
+ { } ,
67
+ ) ;
68
+ return data . daemonStatus . stateHash ;
69
69
} ;
70
70
71
71
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 `
75
75
query {
76
76
networkID
77
77
}
78
78
` ,
79
- { } ,
80
- ) ;
81
- return data . networkID === "mina:testnet" ? "mina:devnet" : data . networkID ;
79
+ { } ,
80
+ ) ;
81
+ return data . networkID === "mina:testnet" ? "mina:devnet" : data . networkID ;
82
82
} ;
83
83
84
84
const sendTransaction = async ( {
85
- signedTransaction,
86
- type,
85
+ signedTransaction,
86
+ type,
87
87
} : {
88
- signedTransaction : Sendable ;
89
- type : "payment" | "delegation" | "zkapp" ;
88
+ signedTransaction : Sendable ;
89
+ type : "payment" | "delegation" | "zkapp" ;
90
90
} ) => {
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 `
98
98
mutation {
99
99
sendPayment(signature: $signature, input: $input) {
100
100
payment {
@@ -103,15 +103,15 @@ const sendTransaction = async ({
103
103
}
104
104
}
105
105
` ,
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 `
115
115
mutation {
116
116
sendDelegation(signature: $signature, input: $input) {
117
117
delegation {
@@ -120,14 +120,14 @@ const sendTransaction = async ({
120
120
}
121
121
}
122
122
` ,
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 `
131
131
mutation {
132
132
sendZkapp(input: $input) {
133
133
zkapp {
@@ -136,46 +136,84 @@ const sendTransaction = async ({
136
136
}
137
137
}
138
138
` ,
139
- { input } ,
140
- ) ;
141
- return data . sendZkapp . zkapp . hash ;
142
- } )
143
- . exhaustive ( ) ;
139
+ { input } ,
140
+ ) ;
141
+ return data . sendZkapp . zkapp . hash ;
142
+ } )
143
+ . exhaustive ( ) ;
144
144
} ;
145
145
146
146
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 `
151
151
query {
152
152
account(publicKey: $publicKey) {
153
+ publicKey
154
+ token
153
155
nonce
154
156
balance {
155
157
total
156
158
}
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
157
196
}
158
197
}
159
198
` ,
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
+ }
172
210
} ;
173
211
174
212
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,
181
219
} ;
0 commit comments