@@ -2,13 +2,13 @@ import {invariant} from "@onflow/util-invariant"
2
2
import { v4 as uuidv4 } from "uuid"
3
3
import { log , LEVELS } from "@onflow/util-logger"
4
4
5
- import { InteractionAccount , ACCOUNT , PARAM , ARGUMENT , UNKNOWN , OK , Interaction , AUTHORIZER , PAYER , SCRIPT , TRANSACTION , GET_TRANSACTION_STATUS , GET_TRANSACTION , GET_ACCOUNT , GET_EVENTS , PING , GET_BLOCK , GET_BLOCK_HEADER , GET_COLLECTION , GET_NETWORK_PARAMETERS , BAD , PROPOSER } from "@onflow/typedefs" ;
5
+ import { TransactionRole , Interaction , InteractionAccount , InteractionResolverKind , InteractionStatus , InteractionTag } from "@onflow/typedefs" ;
6
6
7
7
type AcctFn = ( acct : InteractionAccount ) => InteractionAccount ;
8
8
type AccountFn = AcctFn & Partial < InteractionAccount > ;
9
9
10
10
const ACCT = `{
11
- "kind":"${ ACCOUNT } ",
11
+ "kind":"${ InteractionResolverKind . ACCOUNT } ",
12
12
"tempId":null,
13
13
"addr":null,
14
14
"keyId":null,
@@ -24,18 +24,8 @@ const ACCT = `{
24
24
}
25
25
}`
26
26
27
- const PRM = `{
28
- "kind":"${ PARAM } ",
29
- "tempId":null,
30
- "key":null,
31
- "value":null,
32
- "asParam":null,
33
- "xform":null,
34
- "resolve": null
35
- }`
36
-
37
27
const ARG = `{
38
- "kind":"${ ARGUMENT } ",
28
+ "kind":"${ InteractionResolverKind . ARGUMENT } ",
39
29
"tempId":null,
40
30
"value":null,
41
31
"asArgument":null,
@@ -45,9 +35,9 @@ const ARG = `{
45
35
}`
46
36
47
37
const IX = `{
48
- "tag":"${ UNKNOWN } ",
38
+ "tag":"${ InteractionTag . UNKNOWN } ",
49
39
"assigns":{},
50
- "status":"${ OK } ",
40
+ "status":"${ InteractionStatus . OK } ",
51
41
"reason":null,
52
42
"accounts":{},
53
43
"params":{},
@@ -118,17 +108,17 @@ export const isInteraction = (ix: Interaction) => {
118
108
}
119
109
120
110
export const Ok = ( ix : Interaction ) => {
121
- ix . status = OK
111
+ ix . status = InteractionStatus . OK
122
112
return ix
123
113
}
124
114
125
115
export const Bad = ( ix : Interaction , reason : string ) => {
126
- ix . status = BAD
116
+ ix . status = InteractionStatus . BAD
127
117
ix . reason = reason
128
118
return ix
129
119
}
130
120
131
- const makeIx = ( wat : string ) => ( ix : Interaction ) => {
121
+ const makeIx = ( wat : InteractionTag ) => ( ix : Interaction ) => {
132
122
ix . tag = wat
133
123
return Ok ( ix )
134
124
}
@@ -145,7 +135,7 @@ const prepAccountKeyId = (acct: Partial<InteractionAccount> | AccountFn): Partia
145
135
}
146
136
147
137
interface IPrepAccountOpts {
148
- role ?: typeof AUTHORIZER | typeof PAYER | typeof PROPOSER | null
138
+ role ?: TransactionRole | null
149
139
}
150
140
151
141
export const initAccount = ( ) : InteractionAccount => JSON . parse ( ACCT )
@@ -187,9 +177,9 @@ export const prepAccount = (acct: InteractionAccount | AccountFn, opts: IPrepAcc
187
177
} ,
188
178
}
189
179
190
- if ( role === AUTHORIZER ) {
180
+ if ( role === TransactionRole . AUTHORIZER ) {
191
181
ix . authorizations . push ( tempId )
192
- } else if ( role === PAYER ) {
182
+ } else if ( role === TransactionRole . PAYER ) {
193
183
ix . payer . push ( tempId )
194
184
} else if ( role ) {
195
185
ix [ role ] = tempId
@@ -215,41 +205,40 @@ export const makeArgument = (arg: Record<string, any>) => (ix: Interaction) =>
215
205
return Ok ( ix )
216
206
}
217
207
218
- export const makeUnknown /* */ = makeIx ( UNKNOWN )
219
- export const makeScript /* */ = makeIx ( SCRIPT )
220
- export const makeTransaction /* */ = makeIx ( TRANSACTION )
221
- export const makeGetTransactionStatus /* */ = makeIx ( GET_TRANSACTION_STATUS )
222
- export const makeGetTransaction /* */ = makeIx ( GET_TRANSACTION )
223
- export const makeGetAccount /* */ = makeIx ( GET_ACCOUNT )
224
- export const makeGetEvents /* */ = makeIx ( GET_EVENTS )
225
- export const makePing /* */ = makeIx ( PING )
226
- export const makeGetBlock /* */ = makeIx ( GET_BLOCK )
227
- export const makeGetBlockHeader /* */ = makeIx ( GET_BLOCK_HEADER )
228
- export const makeGetCollection /* */ = makeIx ( GET_COLLECTION )
229
- export const makeGetNetworkParameters /* */ = makeIx ( GET_NETWORK_PARAMETERS )
230
-
231
- const is = ( wat : string ) => ( ix : Interaction ) => ix . tag === wat
232
-
233
- export const isUnknown /* */ = is ( UNKNOWN )
234
- export const isScript /* */ = is ( SCRIPT )
235
- export const isTransaction /* */ = is ( TRANSACTION )
236
- export const isGetTransactionStatus /* */ = is ( GET_TRANSACTION_STATUS )
237
- export const isGetTransaction /* */ = is ( GET_TRANSACTION )
238
- export const isGetAccount /* */ = is ( GET_ACCOUNT )
239
- export const isGetEvents /* */ = is ( GET_EVENTS )
240
- export const isPing /* */ = is ( PING )
241
- export const isGetBlock /* */ = is ( GET_BLOCK )
242
- export const isGetBlockHeader /* */ = is ( GET_BLOCK_HEADER )
243
- export const isGetCollection /* */ = is ( GET_COLLECTION )
244
- export const isGetNetworkParameters /* */ = is ( GET_NETWORK_PARAMETERS )
245
-
246
- export const isOk /* */ = ( ix : Interaction ) => ix . status === OK
247
- export const isBad /* */ = ( ix : Interaction ) => ix . status === BAD
208
+ export const makeUnknown /* */ = makeIx ( InteractionTag . UNKNOWN )
209
+ export const makeScript /* */ = makeIx ( InteractionTag . SCRIPT )
210
+ export const makeTransaction /* */ = makeIx ( InteractionTag . TRANSACTION )
211
+ export const makeGetTransactionStatus /* */ = makeIx ( InteractionTag . GET_TRANSACTION_STATUS )
212
+ export const makeGetTransaction /* */ = makeIx ( InteractionTag . GET_TRANSACTION )
213
+ export const makeGetAccount /* */ = makeIx ( InteractionTag . GET_ACCOUNT )
214
+ export const makeGetEvents /* */ = makeIx ( InteractionTag . GET_EVENTS )
215
+ export const makePing /* */ = makeIx ( InteractionTag . PING )
216
+ export const makeGetBlock /* */ = makeIx ( InteractionTag . GET_BLOCK )
217
+ export const makeGetBlockHeader /* */ = makeIx ( InteractionTag . GET_BLOCK_HEADER )
218
+ export const makeGetCollection /* */ = makeIx ( InteractionTag . GET_COLLECTION )
219
+ export const makeGetNetworkParameters /* */ = makeIx ( InteractionTag . GET_NETWORK_PARAMETERS )
220
+
221
+ const is = ( wat : InteractionTag ) => ( ix : Interaction ) => ix . tag === wat
222
+
223
+ export const isUnknown /* */ = is ( InteractionTag . UNKNOWN )
224
+ export const isScript /* */ = is ( InteractionTag . SCRIPT )
225
+ export const isTransaction /* */ = is ( InteractionTag . TRANSACTION )
226
+ export const isGetTransactionStatus /* */ = is ( InteractionTag . GET_TRANSACTION_STATUS )
227
+ export const isGetTransaction /* */ = is ( InteractionTag . GET_TRANSACTION )
228
+ export const isGetAccount /* */ = is ( InteractionTag . GET_ACCOUNT )
229
+ export const isGetEvents /* */ = is ( InteractionTag . GET_EVENTS )
230
+ export const isPing /* */ = is ( InteractionTag . PING )
231
+ export const isGetBlock /* */ = is ( InteractionTag . GET_BLOCK )
232
+ export const isGetBlockHeader /* */ = is ( InteractionTag . GET_BLOCK_HEADER )
233
+ export const isGetCollection /* */ = is ( InteractionTag . GET_COLLECTION )
234
+ export const isGetNetworkParameters /* */ = is ( InteractionTag . GET_NETWORK_PARAMETERS )
235
+
236
+ export const isOk /* */ = ( ix : Interaction ) => ix . status === InteractionStatus . OK
237
+ export const isBad /* */ = ( ix : Interaction ) => ix . status === InteractionStatus . BAD
248
238
export const why /* */ = ( ix : Interaction ) => ix . reason
249
239
250
- export const isAccount /* */ = ( account : Record < string , any > ) => account . kind === ACCOUNT
251
- export const isParam /* */ = ( param : Record < string , any > ) => param . kind === PARAM
252
- export const isArgument /* */ = ( argument : Record < string , any > ) => argument . kind === ARGUMENT
240
+ export const isAccount /* */ = ( account : Record < string , any > ) => account . kind === InteractionResolverKind . ACCOUNT
241
+ export const isArgument /* */ = ( argument : Record < string , any > ) => argument . kind === InteractionResolverKind . ARGUMENT
253
242
254
243
const hardMode = ( ix : Interaction ) => {
255
244
for ( let key of Object . keys ( ix ) ) {
@@ -300,6 +289,4 @@ export const update = (key: string, fn = identity) => (ix: Interaction) => {
300
289
export const destroy = ( key : string ) => ( ix : Interaction ) => {
301
290
delete ix . assigns [ key ]
302
291
return Ok ( ix )
303
- }
304
-
305
- export * from "@onflow/typedefs"
292
+ }
0 commit comments