@functionland/react-native-fula 1.55.0 → 1.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +20 -20
  2. package/android/build.gradle +114 -115
  3. package/android/gradle.properties +8 -8
  4. package/android/src/main/AndroidManifest.xml +3 -3
  5. package/android/src/main/AndroidManifestNew.xml +2 -2
  6. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  7. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  8. package/android/src/main/java/land/fx/fula/FulaModule.java +1991 -1868
  9. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  10. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  11. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  12. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  13. package/ios/Cryptography.swift +59 -59
  14. package/ios/Fula-Bridging-Header.h +3 -3
  15. package/ios/UserDataHelper.swift +143 -143
  16. package/lib/commonjs/index.js +3 -1
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/interfaces/augment-api-consts.js.map +1 -1
  19. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
  20. package/lib/commonjs/interfaces/augment-api-events.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-query.js.map +1 -1
  22. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
  23. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
  24. package/lib/commonjs/interfaces/augment-api-tx.js.map +1 -1
  25. package/lib/commonjs/interfaces/augment-api.js.map +1 -1
  26. package/lib/commonjs/interfaces/augment-types.js.map +1 -1
  27. package/lib/commonjs/interfaces/definitions.js.map +1 -1
  28. package/lib/commonjs/interfaces/defintions.js.map +1 -1
  29. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  30. package/lib/commonjs/interfaces/index.js.map +1 -1
  31. package/lib/commonjs/interfaces/lookup.js +300 -300
  32. package/lib/commonjs/interfaces/lookup.js.map +1 -1
  33. package/lib/commonjs/interfaces/registry.js.map +1 -1
  34. package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
  35. package/lib/commonjs/interfaces/types.js.map +1 -1
  36. package/lib/commonjs/protocols/blockchain.js +66 -66
  37. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  38. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  39. package/lib/commonjs/protocols/fula.js.map +1 -1
  40. package/lib/commonjs/protocols/fx-ai.js +103 -0
  41. package/lib/commonjs/protocols/fx-ai.js.map +1 -0
  42. package/lib/commonjs/protocols/fxblox.js +3 -3
  43. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  44. package/lib/commonjs/types/blockchain.js.map +1 -1
  45. package/lib/commonjs/types/fxblox.js.map +1 -1
  46. package/lib/module/index.js +1 -0
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/interfaces/augment-api-consts.js.map +1 -1
  49. package/lib/module/interfaces/augment-api-errors.js.map +1 -1
  50. package/lib/module/interfaces/augment-api-events.js.map +1 -1
  51. package/lib/module/interfaces/augment-api-query.js.map +1 -1
  52. package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
  53. package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
  54. package/lib/module/interfaces/augment-api-tx.js.map +1 -1
  55. package/lib/module/interfaces/augment-api.js.map +1 -1
  56. package/lib/module/interfaces/augment-types.js.map +1 -1
  57. package/lib/module/interfaces/definitions.js.map +1 -1
  58. package/lib/module/interfaces/defintions.js.map +1 -1
  59. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  60. package/lib/module/interfaces/index.js.map +1 -1
  61. package/lib/module/interfaces/lookup.js +300 -300
  62. package/lib/module/interfaces/lookup.js.map +1 -1
  63. package/lib/module/interfaces/registry.js.map +1 -1
  64. package/lib/module/interfaces/types-lookup.js.map +1 -1
  65. package/lib/module/interfaces/types.js.map +1 -1
  66. package/lib/module/protocols/blockchain.js +66 -66
  67. package/lib/module/protocols/blockchain.js.map +1 -1
  68. package/lib/module/protocols/chain-api.js.map +1 -1
  69. package/lib/module/protocols/fula.js.map +1 -1
  70. package/lib/module/protocols/fx-ai.js +93 -0
  71. package/lib/module/protocols/fx-ai.js.map +1 -0
  72. package/lib/module/protocols/fxblox.js +3 -3
  73. package/lib/module/protocols/fxblox.js.map +1 -1
  74. package/lib/module/types/blockchain.js.map +1 -1
  75. package/lib/module/types/fxblox.js.map +1 -1
  76. package/package.json +176 -176
  77. package/react-native-fula.podspec +47 -47
  78. package/src/index.tsx +5 -4
  79. package/src/interfaces/augment-api-consts.ts +273 -273
  80. package/src/interfaces/augment-api-errors.ts +474 -474
  81. package/src/interfaces/augment-api-events.ts +448 -448
  82. package/src/interfaces/augment-api-query.ts +466 -466
  83. package/src/interfaces/augment-api-rpc.ts +617 -617
  84. package/src/interfaces/augment-api-runtime.ts +223 -223
  85. package/src/interfaces/augment-api-tx.ts +709 -709
  86. package/src/interfaces/augment-api.ts +9 -9
  87. package/src/interfaces/augment-types.ts +1322 -1322
  88. package/src/interfaces/definitions.ts +1 -1
  89. package/src/interfaces/defintions.ts +1 -1
  90. package/src/interfaces/fulaNativeModule.ts +175 -168
  91. package/src/interfaces/index.ts +3 -3
  92. package/src/interfaces/lookup.ts +2011 -2011
  93. package/src/interfaces/registry.ts +163 -163
  94. package/src/interfaces/types-lookup.ts +2165 -2165
  95. package/src/interfaces/types.ts +2 -2
  96. package/src/protocols/blockchain.ts +644 -644
  97. package/src/protocols/fx-ai.ts +111 -0
  98. package/src/protocols/fxblox.ts +443 -443
@@ -1,644 +1,644 @@
1
- import Fula from '../interfaces/fulaNativeModule';
2
- import type * as BType from '../types/blockchain';
3
- import { ApiPromise } from '@polkadot/api';
4
- /*
5
- createAccount: This function takes a seed argument, which is used to create an account. The seed must start with "/". The function returns a promise of an object that contains the seed and the account that was created.
6
- */
7
- export const createAccount = (
8
- seed: string //seed that is used to create the account. It must start with "/"
9
- ): Promise<BType.SeededResponse> => {
10
- console.log('createAccount in react-native started', seed);
11
- let res1 = Fula.createAccount(seed)
12
- .then((res) => {
13
- try {
14
- let jsonRes: BType.SeededResponse = JSON.parse(res);
15
- return jsonRes;
16
- } catch (e) {
17
- try {
18
- return JSON.parse(res);
19
- } catch (e2) {
20
- return res;
21
- }
22
- }
23
- })
24
- .catch((err) => {
25
- return err;
26
- });
27
- return res1;
28
- };
29
-
30
- /*
31
- checkAccountExists: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
32
- */
33
- export const checkAccountExists = (
34
- account: string
35
- ): Promise<BType.AccountExistsResponse> => {
36
- console.log('checkAccountExists in react-native started', account);
37
- let res1 = Fula.checkAccountExists(account)
38
- .then((res) => {
39
- try {
40
- let jsonRes: BType.AccountExistsResponse = JSON.parse(res);
41
- return jsonRes;
42
- } catch (e) {
43
- try {
44
- return JSON.parse(res);
45
- } catch (e2) {
46
- return res;
47
- }
48
- }
49
- })
50
- .catch((err) => {
51
- return err;
52
- });
53
- return res1;
54
- };
55
-
56
- /*
57
- accountFund: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
58
- */
59
- export const accountFund = (
60
- account: string
61
- ): Promise<BType.AccountFundResponse> => {
62
- console.log('accountFund in react-native started', account);
63
- let res1 = Fula.accountFund(account)
64
- .then((res) => {
65
- try {
66
- let jsonRes: BType.AccountFundResponse = JSON.parse(res);
67
- return jsonRes;
68
- } catch (e) {
69
- try {
70
- return JSON.parse(res);
71
- } catch (e2) {
72
- return res;
73
- }
74
- }
75
- })
76
- .catch((err) => {
77
- return err;
78
- });
79
- return res1;
80
- };
81
-
82
- /*
83
- createPool: This function takes two arguments: seed and poolName. The seed is used to identify the account that is creating the pool, and the poolName is the name of the pool being created. The function returns a promise of an object that contains the owner of the pool and the poolID of the created pool.
84
- */
85
- export const createPool = (
86
- seed: string,
87
- poolName: string
88
- ): Promise<BType.PoolCreateResponse> => {
89
- console.log('createPool in react-native started', seed, poolName);
90
- let res1 = Fula.createPool(seed, poolName)
91
- .then((res) => {
92
- try {
93
- let jsonRes: BType.PoolCreateResponse = JSON.parse(res);
94
- return jsonRes;
95
- } catch (e) {
96
- try {
97
- return JSON.parse(res);
98
- } catch (e2) {
99
- return res;
100
- }
101
- }
102
- })
103
- .catch((err) => {
104
- return err;
105
- });
106
- return res1;
107
- };
108
-
109
- /*
110
- listPools: This function takes no arguments and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool
111
- */
112
- export const listPools = (): Promise<BType.PoolListResponse> => {
113
- console.log('listPools in react-native started');
114
- let res1 = Fula.listPools()
115
- .then((res) => {
116
- try {
117
- let jsonRes: BType.PoolListResponse = JSON.parse(res);
118
- return jsonRes;
119
- } catch (e) {
120
- try {
121
- return JSON.parse(res);
122
- } catch (e2) {
123
- return res;
124
- }
125
- }
126
- })
127
- .catch((err) => {
128
- return err;
129
- });
130
- return res1;
131
- };
132
-
133
- /*
134
- joinPool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is joining the pool, and the poolID is the ID of the pool the account is joining. The function returns a promise of an object that contains the account joining the pool and the poolID of the joined pool.
135
- */
136
-
137
- export const joinPool = (poolID: number): Promise<BType.PoolJoinResponse> => {
138
- console.log('joinPool in react-native started', poolID);
139
- let res1 = Fula.joinPool(poolID.toString())
140
- .then((res) => {
141
- try {
142
- let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
143
- return jsonRes;
144
- } catch (e) {
145
- try {
146
- return JSON.parse(res);
147
- } catch (e2) {
148
- console.error('Error parsing res in joining pool:', e);
149
- return res; // Rethrow the error to maintain the rejection state
150
- }
151
- }
152
- })
153
- .catch((err) => {
154
- console.error('Error joining pool:', err);
155
- throw err; // Rethrow the error to maintain the rejection state
156
- });
157
- return res1;
158
- };
159
-
160
- /*
161
- leavePool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is leaving the pool, and the poolID is the ID of the pool the account is leaving. The function returns a promise of an object that contains the `
162
- */
163
-
164
- export const leavePool = (poolID: number): Promise<BType.PoolLeaveResponse> => {
165
- console.log('leavePool in react-native started', poolID);
166
- let res1 = Fula.leavePool(poolID.toString())
167
- .then((res) => {
168
- try {
169
- let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
170
- return jsonRes;
171
- } catch (e) {
172
- try {
173
- return JSON.parse(res);
174
- } catch (e2) {
175
- return res;
176
- }
177
- }
178
- })
179
- .catch((err) => {
180
- return err;
181
- });
182
- return res1;
183
- };
184
-
185
- export const cancelPoolJoin = (
186
- poolID: number
187
- ): Promise<BType.PoolCancelJoinResponse> => {
188
- console.log('cancelPoolJoin in react-native started', poolID);
189
- let res1 = Fula.cancelPoolJoin(poolID.toString())
190
- .then((res) => {
191
- try {
192
- let jsonRes: BType.PoolCancelJoinResponse = JSON.parse(res);
193
- return jsonRes;
194
- } catch (e) {
195
- try {
196
- return JSON.parse(res);
197
- } catch (e2) {
198
- return res;
199
- }
200
- }
201
- })
202
- .catch((err) => {
203
- return err;
204
- });
205
- return res1;
206
- };
207
- export const listPoolJoinRequests = (
208
- poolID: string
209
- ): Promise<BType.PoolRequestsResponse> => {
210
- console.log('listPoolJoinRequests in react-native started', poolID);
211
- let res1 = Fula.listPoolJoinRequests(poolID)
212
- .then((res) => {
213
- try {
214
- let jsonRes: BType.PoolRequestsResponse = JSON.parse(res);
215
- return jsonRes;
216
- } catch (e) {
217
- try {
218
- return JSON.parse(res);
219
- } catch (e2) {
220
- return res;
221
- }
222
- }
223
- })
224
- .catch((err) => {
225
- return err;
226
- });
227
- return res1;
228
- };
229
-
230
- /*
231
- seed is used to authorize the request.
232
- poolID is the ID of the pool in which the account is requesting to join.
233
- account is the account that is requesting to join the pool.
234
- accept is a boolean value that indicates whether to accept or reject the join request.
235
- It returns a promise of BType.PoolVoteResponse which includes the account and poolID
236
- */
237
- export const votePoolJoinRequest = (
238
- seed: string,
239
- poolID: number,
240
- account: string,
241
- accept: boolean
242
- ): Promise<BType.PoolVoteResponse> => {
243
- console.log(
244
- 'votePoolJoinRequest in react-native started',
245
- seed,
246
- poolID,
247
- account,
248
- accept
249
- );
250
- let res1 = Fula.votePoolJoinRequest(seed, poolID, account, accept)
251
- .then((res) => {
252
- try {
253
- let jsonRes: BType.PoolVoteResponse = JSON.parse(res);
254
- return jsonRes;
255
- } catch (e) {
256
- try {
257
- return JSON.parse(res);
258
- } catch (e2) {
259
- return res;
260
- }
261
- }
262
- })
263
- .catch((err) => {
264
- return err;
265
- });
266
- return res1;
267
- };
268
-
269
- /*
270
- It takes four arguments:
271
-
272
- seed is used to authorize the request.
273
- poolID is the ID of the pool in which the replication request is made.
274
- replicationFactor is the number of copies of the content to be stored.
275
- cid is the content identifier of the content to be replicated.
276
- It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
277
- */
278
- export const batchUploadManifest = (
279
- api: ApiPromise | undefined, //this is just for compatibility with chainAPI inputs and is not used
280
- seed: string, //this is just for compatibility with chainAPI inputs and is not used
281
- cids_i: string[],
282
- poolId_i: string | number,
283
- replicationFactor_i: string | number
284
- ): Promise<BType.ManifestBatchUploadResponse> => {
285
- console.log(
286
- 'newReplicationRequest in react-native started',
287
- api,
288
- seed,
289
- poolId_i,
290
- replicationFactor_i,
291
- cids_i
292
- );
293
- if (typeof poolId_i === 'number') {
294
- poolId_i = poolId_i.toString();
295
- }
296
- if (typeof replicationFactor_i === 'number') {
297
- replicationFactor_i = replicationFactor_i.toString();
298
- }
299
- let res1 = Fula.batchUploadManifest(cids_i, poolId_i, replicationFactor_i)
300
- .then((res) => {
301
- try {
302
- let jsonRes: BType.ManifestBatchUploadResponse = JSON.parse(res);
303
- return jsonRes;
304
- } catch (e) {
305
- try {
306
- return JSON.parse(res);
307
- } catch (e2) {
308
- return res;
309
- }
310
- }
311
- })
312
- .catch((err) => {
313
- return err;
314
- });
315
- return res1;
316
- };
317
-
318
- export const replicateInPool = (
319
- cids_i: string[],
320
- account_i: string,
321
- poolId_i: string | number
322
- ): Promise<string[]> => {
323
- console.log(
324
- 'replicateInPool in react-native started',
325
- poolId_i,
326
- account_i,
327
- cids_i
328
- );
329
- if (typeof poolId_i === 'number') {
330
- poolId_i = poolId_i.toString();
331
- }
332
-
333
- let res1 = Fula.replicateInPool(cids_i, account_i, poolId_i)
334
- .then((res) => {
335
- try {
336
- let jsonRes: string[] = JSON.parse(res);
337
- return jsonRes;
338
- } catch (e) {
339
- try {
340
- return JSON.parse(res);
341
- } catch (e2) {
342
- return res;
343
- }
344
- }
345
- })
346
- .catch((err) => {
347
- return err;
348
- });
349
- return res1;
350
- };
351
-
352
- /*
353
- It takes four arguments:
354
-
355
- seed is used to authorize the request.
356
- poolID is the ID of the pool in which the replication request is made.
357
- uploader is the account of the user making the request
358
- cid is the content identifier of the content to be stored.
359
- It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
360
- */
361
- export const newStoreRequest = (
362
- seed: string,
363
- poolID: number,
364
- uploader: string,
365
- cid: string
366
- ): Promise<BType.ManifestUploadResponse> => {
367
- console.log(
368
- 'newStoreRequest in react-native started',
369
- seed,
370
- poolID,
371
- uploader,
372
- cid
373
- );
374
- let res1 = Fula.newStoreRequest(seed, poolID, uploader, cid)
375
- .then((res) => {
376
- try {
377
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
378
- return jsonRes;
379
- } catch (e) {
380
- try {
381
- return JSON.parse(res);
382
- } catch (e2) {
383
- return res;
384
- }
385
- }
386
- })
387
- .catch((err) => {
388
- return err;
389
- });
390
- return res1;
391
- };
392
-
393
- /*
394
- It takes one argument:
395
-
396
- poolID is the ID of the pool for which the replication requests are listed
397
- It returns a promise of BType.ManifestUploadResponse[] which is an array of the replication requests, including the uploader, storage, ManifestMetadata, and poolID
398
- */
399
- export const listAvailableReplicationRequests = (
400
- poolID: string
401
- ): Promise<BType.ManifestUploadResponse[]> => {
402
- console.log(
403
- 'listAvailableReplicationRequests in react-native started',
404
- poolID
405
- );
406
- let res1 = Fula.listAvailableReplicationRequests(poolID)
407
- .then((res) => {
408
- try {
409
- let jsonRes: BType.ManifestUploadResponse[] = JSON.parse(res);
410
- return jsonRes;
411
- } catch (e) {
412
- try {
413
- return JSON.parse(res);
414
- } catch (e2) {
415
- return res;
416
- }
417
- }
418
- })
419
- .catch((err) => {
420
- return err;
421
- });
422
- return res1;
423
- };
424
-
425
- /*
426
- It takes three arguments:
427
-
428
- seed is the seed of the account that is removing the replication request
429
- poolID is the ID of the pool for which the replication request is being removed
430
- cid is the content ID of the replication request being removed
431
- It returns a promise of BType.ManifestUploadResponse which is the removed replication request, including the uploader, storage, ManifestMetadata, and poolID
432
- */
433
- export const removeReplicationRequest = (
434
- seed: string,
435
- poolID: number,
436
- cid: string
437
- ): Promise<BType.ManifestUploadResponse> => {
438
- console.log(
439
- 'removeReplicationRequest in react-native started',
440
- seed,
441
- poolID,
442
- cid
443
- );
444
- let res1 = Fula.removeReplicationRequest(seed, poolID, cid)
445
- .then((res) => {
446
- try {
447
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
448
- return jsonRes;
449
- } catch (e) {
450
- try {
451
- return JSON.parse(res);
452
- } catch (e2) {
453
- return res;
454
- }
455
- }
456
- })
457
- .catch((err) => {
458
- return err;
459
- });
460
- return res1;
461
- };
462
-
463
- /*
464
- It takes four arguments:
465
-
466
- seed is the seed of the account that is removing the storer
467
- storer is the address of the storer that is being removed
468
- poolID is the ID of the pool for which the storer is being removed
469
- cid is the content ID of the replication request for which the storer is being removed
470
- It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the storer has been removed.
471
- */
472
- export const removeStorer = (
473
- seed: string,
474
- storer: string,
475
- poolID: number,
476
- cid: string
477
- ): Promise<BType.ManifestUploadResponse> => {
478
- console.log(
479
- 'removeStorer in react-native started',
480
- seed,
481
- storer,
482
- poolID,
483
- cid
484
- );
485
- let res1 = Fula.removeStorer(seed, storer, poolID, cid)
486
- .then((res) => {
487
- try {
488
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
489
- return jsonRes;
490
- } catch (e) {
491
- try {
492
- return JSON.parse(res);
493
- } catch (e2) {
494
- return res;
495
- }
496
- }
497
- })
498
- .catch((err) => {
499
- return err;
500
- });
501
- return res1;
502
- };
503
-
504
- /*
505
- It takes four arguments:
506
-
507
- seed is the seed of the account that is removing the stored replication
508
- uploader is the address of the uploader that is being removed
509
- poolID is the ID of the pool for which the stored replication is being removed
510
- cid is the content ID of the replication request for which the stored replication is being removed
511
- It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the stored replication has been removed.
512
- */
513
- export const removeStoredReplication = (
514
- seed: string,
515
- uploader: string,
516
- poolID: number,
517
- cid: string
518
- ): Promise<BType.ManifestUploadResponse> => {
519
- console.log(
520
- 'removeStoredReplication in react-native started',
521
- seed,
522
- uploader,
523
- poolID,
524
- cid
525
- );
526
- let res1 = Fula.removeStoredReplication(seed, uploader, poolID, cid)
527
- .then((res) => {
528
- try {
529
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
530
- return jsonRes;
531
- } catch (e) {
532
- try {
533
- return JSON.parse(res);
534
- } catch (e2) {
535
- return res;
536
- }
537
- }
538
- })
539
- .catch((err) => {
540
- return err;
541
- });
542
- return res1;
543
- };
544
-
545
- /*
546
- bloxFreeSpace: This function takes no arguments and returns a promise of an object that contains the blox free space information.
547
- */
548
- export const bloxFreeSpace = (): Promise<BType.BloxFreeSpaceResponse> => {
549
- console.log('bloxFreeSpace in react-native started');
550
- let res1 = Fula.bloxFreeSpace()
551
- .then((res) => {
552
- try {
553
- let jsonRes: BType.BloxFreeSpaceResponse = JSON.parse(res);
554
- return jsonRes;
555
- } catch (e) {
556
- try {
557
- return JSON.parse(res);
558
- } catch (e2) {
559
- return res;
560
- }
561
- }
562
- })
563
- .catch((err) => {
564
- return err;
565
- });
566
- return res1;
567
- };
568
-
569
- export const getAccount = (): Promise<BType.GetAccountResponse> => {
570
- console.log('getAccount in react-native started');
571
- let res = Fula.getAccount()
572
- .then((res1) => {
573
- try {
574
- let jsonRes: BType.GetAccountResponse = JSON.parse(res1);
575
- return jsonRes;
576
- } catch (e) {
577
- try {
578
- return JSON.parse(res1);
579
- } catch (e1) {
580
- console.error('Error parsing res in get account:', e1);
581
- throw e1; // Rethrow the error to maintain the rejection state
582
- }
583
- }
584
- })
585
- .catch((err) => {
586
- console.error('Error getting account:', err);
587
- throw err; // Rethrow the error to maintain the rejection state
588
- });
589
- return res;
590
- };
591
-
592
- export const assetsBalance = (
593
- account: string,
594
- assetId: string,
595
- classId: string
596
- ): Promise<BType.AssetsBalanceResponse> => {
597
- console.log('assetsBalance in react-native started');
598
- let res = Fula.assetsBalance(account, assetId, classId)
599
- .then((res1) => {
600
- try {
601
- let jsonRes: BType.AssetsBalanceResponse = JSON.parse(res1);
602
- return jsonRes;
603
- } catch (e) {
604
- try {
605
- return JSON.parse(res1);
606
- } catch (e1) {
607
- console.error('Error parsing res in get asset balance:', e1);
608
- throw e1; // Rethrow the error to maintain the rejection state
609
- }
610
- }
611
- })
612
- .catch((err) => {
613
- console.error('Error getting asset balance:', err);
614
- throw err; // Rethrow the error to maintain the rejection state
615
- });
616
- return res;
617
- };
618
-
619
- export const transferToFula = (
620
- amount: string,
621
- wallet: string,
622
- chain: string
623
- ): Promise<BType.TransferToFulaResponse> => {
624
- console.log('transferToFula in react-native started');
625
- let res = Fula.transferToFula(amount, wallet, chain)
626
- .then((res1) => {
627
- try {
628
- let jsonRes: BType.TransferToFulaResponse = JSON.parse(res1);
629
- return jsonRes;
630
- } catch (e) {
631
- try {
632
- return JSON.parse(res1);
633
- } catch (e1) {
634
- console.error('Error parsing res in transferToFula:', e1);
635
- throw e1; // Rethrow the error to maintain the rejection state
636
- }
637
- }
638
- })
639
- .catch((err) => {
640
- console.error('Error getting transferToFula:', err);
641
- throw err; // Rethrow the error to maintain the rejection state
642
- });
643
- return res;
644
- };
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+ import type * as BType from '../types/blockchain';
3
+ import { ApiPromise } from '@polkadot/api';
4
+ /*
5
+ createAccount: This function takes a seed argument, which is used to create an account. The seed must start with "/". The function returns a promise of an object that contains the seed and the account that was created.
6
+ */
7
+ export const createAccount = (
8
+ seed: string //seed that is used to create the account. It must start with "/"
9
+ ): Promise<BType.SeededResponse> => {
10
+ console.log('createAccount in react-native started', seed);
11
+ let res1 = Fula.createAccount(seed)
12
+ .then((res) => {
13
+ try {
14
+ let jsonRes: BType.SeededResponse = JSON.parse(res);
15
+ return jsonRes;
16
+ } catch (e) {
17
+ try {
18
+ return JSON.parse(res);
19
+ } catch (e2) {
20
+ return res;
21
+ }
22
+ }
23
+ })
24
+ .catch((err) => {
25
+ return err;
26
+ });
27
+ return res1;
28
+ };
29
+
30
+ /*
31
+ checkAccountExists: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
32
+ */
33
+ export const checkAccountExists = (
34
+ account: string
35
+ ): Promise<BType.AccountExistsResponse> => {
36
+ console.log('checkAccountExists in react-native started', account);
37
+ let res1 = Fula.checkAccountExists(account)
38
+ .then((res) => {
39
+ try {
40
+ let jsonRes: BType.AccountExistsResponse = JSON.parse(res);
41
+ return jsonRes;
42
+ } catch (e) {
43
+ try {
44
+ return JSON.parse(res);
45
+ } catch (e2) {
46
+ return res;
47
+ }
48
+ }
49
+ })
50
+ .catch((err) => {
51
+ return err;
52
+ });
53
+ return res1;
54
+ };
55
+
56
+ /*
57
+ accountFund: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
58
+ */
59
+ export const accountFund = (
60
+ account: string
61
+ ): Promise<BType.AccountFundResponse> => {
62
+ console.log('accountFund in react-native started', account);
63
+ let res1 = Fula.accountFund(account)
64
+ .then((res) => {
65
+ try {
66
+ let jsonRes: BType.AccountFundResponse = JSON.parse(res);
67
+ return jsonRes;
68
+ } catch (e) {
69
+ try {
70
+ return JSON.parse(res);
71
+ } catch (e2) {
72
+ return res;
73
+ }
74
+ }
75
+ })
76
+ .catch((err) => {
77
+ return err;
78
+ });
79
+ return res1;
80
+ };
81
+
82
+ /*
83
+ createPool: This function takes two arguments: seed and poolName. The seed is used to identify the account that is creating the pool, and the poolName is the name of the pool being created. The function returns a promise of an object that contains the owner of the pool and the poolID of the created pool.
84
+ */
85
+ export const createPool = (
86
+ seed: string,
87
+ poolName: string
88
+ ): Promise<BType.PoolCreateResponse> => {
89
+ console.log('createPool in react-native started', seed, poolName);
90
+ let res1 = Fula.createPool(seed, poolName)
91
+ .then((res) => {
92
+ try {
93
+ let jsonRes: BType.PoolCreateResponse = JSON.parse(res);
94
+ return jsonRes;
95
+ } catch (e) {
96
+ try {
97
+ return JSON.parse(res);
98
+ } catch (e2) {
99
+ return res;
100
+ }
101
+ }
102
+ })
103
+ .catch((err) => {
104
+ return err;
105
+ });
106
+ return res1;
107
+ };
108
+
109
+ /*
110
+ listPools: This function takes no arguments and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool
111
+ */
112
+ export const listPools = (): Promise<BType.PoolListResponse> => {
113
+ console.log('listPools in react-native started');
114
+ let res1 = Fula.listPools()
115
+ .then((res) => {
116
+ try {
117
+ let jsonRes: BType.PoolListResponse = JSON.parse(res);
118
+ return jsonRes;
119
+ } catch (e) {
120
+ try {
121
+ return JSON.parse(res);
122
+ } catch (e2) {
123
+ return res;
124
+ }
125
+ }
126
+ })
127
+ .catch((err) => {
128
+ return err;
129
+ });
130
+ return res1;
131
+ };
132
+
133
+ /*
134
+ joinPool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is joining the pool, and the poolID is the ID of the pool the account is joining. The function returns a promise of an object that contains the account joining the pool and the poolID of the joined pool.
135
+ */
136
+
137
+ export const joinPool = (poolID: number): Promise<BType.PoolJoinResponse> => {
138
+ console.log('joinPool in react-native started', poolID);
139
+ let res1 = Fula.joinPool(poolID.toString())
140
+ .then((res) => {
141
+ try {
142
+ let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
143
+ return jsonRes;
144
+ } catch (e) {
145
+ try {
146
+ return JSON.parse(res);
147
+ } catch (e2) {
148
+ console.error('Error parsing res in joining pool:', e);
149
+ return res; // Rethrow the error to maintain the rejection state
150
+ }
151
+ }
152
+ })
153
+ .catch((err) => {
154
+ console.error('Error joining pool:', err);
155
+ throw err; // Rethrow the error to maintain the rejection state
156
+ });
157
+ return res1;
158
+ };
159
+
160
+ /*
161
+ leavePool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is leaving the pool, and the poolID is the ID of the pool the account is leaving. The function returns a promise of an object that contains the `
162
+ */
163
+
164
+ export const leavePool = (poolID: number): Promise<BType.PoolLeaveResponse> => {
165
+ console.log('leavePool in react-native started', poolID);
166
+ let res1 = Fula.leavePool(poolID.toString())
167
+ .then((res) => {
168
+ try {
169
+ let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
170
+ return jsonRes;
171
+ } catch (e) {
172
+ try {
173
+ return JSON.parse(res);
174
+ } catch (e2) {
175
+ return res;
176
+ }
177
+ }
178
+ })
179
+ .catch((err) => {
180
+ return err;
181
+ });
182
+ return res1;
183
+ };
184
+
185
+ export const cancelPoolJoin = (
186
+ poolID: number
187
+ ): Promise<BType.PoolCancelJoinResponse> => {
188
+ console.log('cancelPoolJoin in react-native started', poolID);
189
+ let res1 = Fula.cancelPoolJoin(poolID.toString())
190
+ .then((res) => {
191
+ try {
192
+ let jsonRes: BType.PoolCancelJoinResponse = JSON.parse(res);
193
+ return jsonRes;
194
+ } catch (e) {
195
+ try {
196
+ return JSON.parse(res);
197
+ } catch (e2) {
198
+ return res;
199
+ }
200
+ }
201
+ })
202
+ .catch((err) => {
203
+ return err;
204
+ });
205
+ return res1;
206
+ };
207
+ export const listPoolJoinRequests = (
208
+ poolID: string
209
+ ): Promise<BType.PoolRequestsResponse> => {
210
+ console.log('listPoolJoinRequests in react-native started', poolID);
211
+ let res1 = Fula.listPoolJoinRequests(poolID)
212
+ .then((res) => {
213
+ try {
214
+ let jsonRes: BType.PoolRequestsResponse = JSON.parse(res);
215
+ return jsonRes;
216
+ } catch (e) {
217
+ try {
218
+ return JSON.parse(res);
219
+ } catch (e2) {
220
+ return res;
221
+ }
222
+ }
223
+ })
224
+ .catch((err) => {
225
+ return err;
226
+ });
227
+ return res1;
228
+ };
229
+
230
+ /*
231
+ seed is used to authorize the request.
232
+ poolID is the ID of the pool in which the account is requesting to join.
233
+ account is the account that is requesting to join the pool.
234
+ accept is a boolean value that indicates whether to accept or reject the join request.
235
+ It returns a promise of BType.PoolVoteResponse which includes the account and poolID
236
+ */
237
+ export const votePoolJoinRequest = (
238
+ seed: string,
239
+ poolID: number,
240
+ account: string,
241
+ accept: boolean
242
+ ): Promise<BType.PoolVoteResponse> => {
243
+ console.log(
244
+ 'votePoolJoinRequest in react-native started',
245
+ seed,
246
+ poolID,
247
+ account,
248
+ accept
249
+ );
250
+ let res1 = Fula.votePoolJoinRequest(seed, poolID, account, accept)
251
+ .then((res) => {
252
+ try {
253
+ let jsonRes: BType.PoolVoteResponse = JSON.parse(res);
254
+ return jsonRes;
255
+ } catch (e) {
256
+ try {
257
+ return JSON.parse(res);
258
+ } catch (e2) {
259
+ return res;
260
+ }
261
+ }
262
+ })
263
+ .catch((err) => {
264
+ return err;
265
+ });
266
+ return res1;
267
+ };
268
+
269
+ /*
270
+ It takes four arguments:
271
+
272
+ seed is used to authorize the request.
273
+ poolID is the ID of the pool in which the replication request is made.
274
+ replicationFactor is the number of copies of the content to be stored.
275
+ cid is the content identifier of the content to be replicated.
276
+ It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
277
+ */
278
+ export const batchUploadManifest = (
279
+ api: ApiPromise | undefined, //this is just for compatibility with chainAPI inputs and is not used
280
+ seed: string, //this is just for compatibility with chainAPI inputs and is not used
281
+ cids_i: string[],
282
+ poolId_i: string | number,
283
+ replicationFactor_i: string | number
284
+ ): Promise<BType.ManifestBatchUploadResponse> => {
285
+ console.log(
286
+ 'newReplicationRequest in react-native started',
287
+ api,
288
+ seed,
289
+ poolId_i,
290
+ replicationFactor_i,
291
+ cids_i
292
+ );
293
+ if (typeof poolId_i === 'number') {
294
+ poolId_i = poolId_i.toString();
295
+ }
296
+ if (typeof replicationFactor_i === 'number') {
297
+ replicationFactor_i = replicationFactor_i.toString();
298
+ }
299
+ let res1 = Fula.batchUploadManifest(cids_i, poolId_i, replicationFactor_i)
300
+ .then((res) => {
301
+ try {
302
+ let jsonRes: BType.ManifestBatchUploadResponse = JSON.parse(res);
303
+ return jsonRes;
304
+ } catch (e) {
305
+ try {
306
+ return JSON.parse(res);
307
+ } catch (e2) {
308
+ return res;
309
+ }
310
+ }
311
+ })
312
+ .catch((err) => {
313
+ return err;
314
+ });
315
+ return res1;
316
+ };
317
+
318
+ export const replicateInPool = (
319
+ cids_i: string[],
320
+ account_i: string,
321
+ poolId_i: string | number
322
+ ): Promise<string[]> => {
323
+ console.log(
324
+ 'replicateInPool in react-native started',
325
+ poolId_i,
326
+ account_i,
327
+ cids_i
328
+ );
329
+ if (typeof poolId_i === 'number') {
330
+ poolId_i = poolId_i.toString();
331
+ }
332
+
333
+ let res1 = Fula.replicateInPool(cids_i, account_i, poolId_i)
334
+ .then((res) => {
335
+ try {
336
+ let jsonRes: string[] = JSON.parse(res);
337
+ return jsonRes;
338
+ } catch (e) {
339
+ try {
340
+ return JSON.parse(res);
341
+ } catch (e2) {
342
+ return res;
343
+ }
344
+ }
345
+ })
346
+ .catch((err) => {
347
+ return err;
348
+ });
349
+ return res1;
350
+ };
351
+
352
+ /*
353
+ It takes four arguments:
354
+
355
+ seed is used to authorize the request.
356
+ poolID is the ID of the pool in which the replication request is made.
357
+ uploader is the account of the user making the request
358
+ cid is the content identifier of the content to be stored.
359
+ It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
360
+ */
361
+ export const newStoreRequest = (
362
+ seed: string,
363
+ poolID: number,
364
+ uploader: string,
365
+ cid: string
366
+ ): Promise<BType.ManifestUploadResponse> => {
367
+ console.log(
368
+ 'newStoreRequest in react-native started',
369
+ seed,
370
+ poolID,
371
+ uploader,
372
+ cid
373
+ );
374
+ let res1 = Fula.newStoreRequest(seed, poolID, uploader, cid)
375
+ .then((res) => {
376
+ try {
377
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
378
+ return jsonRes;
379
+ } catch (e) {
380
+ try {
381
+ return JSON.parse(res);
382
+ } catch (e2) {
383
+ return res;
384
+ }
385
+ }
386
+ })
387
+ .catch((err) => {
388
+ return err;
389
+ });
390
+ return res1;
391
+ };
392
+
393
+ /*
394
+ It takes one argument:
395
+
396
+ poolID is the ID of the pool for which the replication requests are listed
397
+ It returns a promise of BType.ManifestUploadResponse[] which is an array of the replication requests, including the uploader, storage, ManifestMetadata, and poolID
398
+ */
399
+ export const listAvailableReplicationRequests = (
400
+ poolID: string
401
+ ): Promise<BType.ManifestUploadResponse[]> => {
402
+ console.log(
403
+ 'listAvailableReplicationRequests in react-native started',
404
+ poolID
405
+ );
406
+ let res1 = Fula.listAvailableReplicationRequests(poolID)
407
+ .then((res) => {
408
+ try {
409
+ let jsonRes: BType.ManifestUploadResponse[] = JSON.parse(res);
410
+ return jsonRes;
411
+ } catch (e) {
412
+ try {
413
+ return JSON.parse(res);
414
+ } catch (e2) {
415
+ return res;
416
+ }
417
+ }
418
+ })
419
+ .catch((err) => {
420
+ return err;
421
+ });
422
+ return res1;
423
+ };
424
+
425
+ /*
426
+ It takes three arguments:
427
+
428
+ seed is the seed of the account that is removing the replication request
429
+ poolID is the ID of the pool for which the replication request is being removed
430
+ cid is the content ID of the replication request being removed
431
+ It returns a promise of BType.ManifestUploadResponse which is the removed replication request, including the uploader, storage, ManifestMetadata, and poolID
432
+ */
433
+ export const removeReplicationRequest = (
434
+ seed: string,
435
+ poolID: number,
436
+ cid: string
437
+ ): Promise<BType.ManifestUploadResponse> => {
438
+ console.log(
439
+ 'removeReplicationRequest in react-native started',
440
+ seed,
441
+ poolID,
442
+ cid
443
+ );
444
+ let res1 = Fula.removeReplicationRequest(seed, poolID, cid)
445
+ .then((res) => {
446
+ try {
447
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
448
+ return jsonRes;
449
+ } catch (e) {
450
+ try {
451
+ return JSON.parse(res);
452
+ } catch (e2) {
453
+ return res;
454
+ }
455
+ }
456
+ })
457
+ .catch((err) => {
458
+ return err;
459
+ });
460
+ return res1;
461
+ };
462
+
463
+ /*
464
+ It takes four arguments:
465
+
466
+ seed is the seed of the account that is removing the storer
467
+ storer is the address of the storer that is being removed
468
+ poolID is the ID of the pool for which the storer is being removed
469
+ cid is the content ID of the replication request for which the storer is being removed
470
+ It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the storer has been removed.
471
+ */
472
+ export const removeStorer = (
473
+ seed: string,
474
+ storer: string,
475
+ poolID: number,
476
+ cid: string
477
+ ): Promise<BType.ManifestUploadResponse> => {
478
+ console.log(
479
+ 'removeStorer in react-native started',
480
+ seed,
481
+ storer,
482
+ poolID,
483
+ cid
484
+ );
485
+ let res1 = Fula.removeStorer(seed, storer, poolID, cid)
486
+ .then((res) => {
487
+ try {
488
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
489
+ return jsonRes;
490
+ } catch (e) {
491
+ try {
492
+ return JSON.parse(res);
493
+ } catch (e2) {
494
+ return res;
495
+ }
496
+ }
497
+ })
498
+ .catch((err) => {
499
+ return err;
500
+ });
501
+ return res1;
502
+ };
503
+
504
+ /*
505
+ It takes four arguments:
506
+
507
+ seed is the seed of the account that is removing the stored replication
508
+ uploader is the address of the uploader that is being removed
509
+ poolID is the ID of the pool for which the stored replication is being removed
510
+ cid is the content ID of the replication request for which the stored replication is being removed
511
+ It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the stored replication has been removed.
512
+ */
513
+ export const removeStoredReplication = (
514
+ seed: string,
515
+ uploader: string,
516
+ poolID: number,
517
+ cid: string
518
+ ): Promise<BType.ManifestUploadResponse> => {
519
+ console.log(
520
+ 'removeStoredReplication in react-native started',
521
+ seed,
522
+ uploader,
523
+ poolID,
524
+ cid
525
+ );
526
+ let res1 = Fula.removeStoredReplication(seed, uploader, poolID, cid)
527
+ .then((res) => {
528
+ try {
529
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
530
+ return jsonRes;
531
+ } catch (e) {
532
+ try {
533
+ return JSON.parse(res);
534
+ } catch (e2) {
535
+ return res;
536
+ }
537
+ }
538
+ })
539
+ .catch((err) => {
540
+ return err;
541
+ });
542
+ return res1;
543
+ };
544
+
545
+ /*
546
+ bloxFreeSpace: This function takes no arguments and returns a promise of an object that contains the blox free space information.
547
+ */
548
+ export const bloxFreeSpace = (): Promise<BType.BloxFreeSpaceResponse> => {
549
+ console.log('bloxFreeSpace in react-native started');
550
+ let res1 = Fula.bloxFreeSpace()
551
+ .then((res) => {
552
+ try {
553
+ let jsonRes: BType.BloxFreeSpaceResponse = JSON.parse(res);
554
+ return jsonRes;
555
+ } catch (e) {
556
+ try {
557
+ return JSON.parse(res);
558
+ } catch (e2) {
559
+ return res;
560
+ }
561
+ }
562
+ })
563
+ .catch((err) => {
564
+ return err;
565
+ });
566
+ return res1;
567
+ };
568
+
569
+ export const getAccount = (): Promise<BType.GetAccountResponse> => {
570
+ console.log('getAccount in react-native started');
571
+ let res = Fula.getAccount()
572
+ .then((res1) => {
573
+ try {
574
+ let jsonRes: BType.GetAccountResponse = JSON.parse(res1);
575
+ return jsonRes;
576
+ } catch (e) {
577
+ try {
578
+ return JSON.parse(res1);
579
+ } catch (e1) {
580
+ console.error('Error parsing res in get account:', e1);
581
+ throw e1; // Rethrow the error to maintain the rejection state
582
+ }
583
+ }
584
+ })
585
+ .catch((err) => {
586
+ console.error('Error getting account:', err);
587
+ throw err; // Rethrow the error to maintain the rejection state
588
+ });
589
+ return res;
590
+ };
591
+
592
+ export const assetsBalance = (
593
+ account: string,
594
+ assetId: string,
595
+ classId: string
596
+ ): Promise<BType.AssetsBalanceResponse> => {
597
+ console.log('assetsBalance in react-native started');
598
+ let res = Fula.assetsBalance(account, assetId, classId)
599
+ .then((res1) => {
600
+ try {
601
+ let jsonRes: BType.AssetsBalanceResponse = JSON.parse(res1);
602
+ return jsonRes;
603
+ } catch (e) {
604
+ try {
605
+ return JSON.parse(res1);
606
+ } catch (e1) {
607
+ console.error('Error parsing res in get asset balance:', e1);
608
+ throw e1; // Rethrow the error to maintain the rejection state
609
+ }
610
+ }
611
+ })
612
+ .catch((err) => {
613
+ console.error('Error getting asset balance:', err);
614
+ throw err; // Rethrow the error to maintain the rejection state
615
+ });
616
+ return res;
617
+ };
618
+
619
+ export const transferToFula = (
620
+ amount: string,
621
+ wallet: string,
622
+ chain: string
623
+ ): Promise<BType.TransferToFulaResponse> => {
624
+ console.log('transferToFula in react-native started');
625
+ let res = Fula.transferToFula(amount, wallet, chain)
626
+ .then((res1) => {
627
+ try {
628
+ let jsonRes: BType.TransferToFulaResponse = JSON.parse(res1);
629
+ return jsonRes;
630
+ } catch (e) {
631
+ try {
632
+ return JSON.parse(res1);
633
+ } catch (e1) {
634
+ console.error('Error parsing res in transferToFula:', e1);
635
+ throw e1; // Rethrow the error to maintain the rejection state
636
+ }
637
+ }
638
+ })
639
+ .catch((err) => {
640
+ console.error('Error getting transferToFula:', err);
641
+ throw err; // Rethrow the error to maintain the rejection state
642
+ });
643
+ return res;
644
+ };