@functionland/react-native-fula 1.0.0 → 1.1.5

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 (84) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +190 -133
  3. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  4. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  5. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  6. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  7. package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
  8. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  9. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  10. package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
  11. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  12. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  13. package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
  14. package/android/.gradle/7.5.1/gc.properties +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  17. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  18. package/android/.gradle/file-system.probe +0 -0
  19. package/android/.gradle/vcs-1/gc.properties +0 -0
  20. package/android/.idea/compiler.xml +5 -5
  21. package/android/.idea/gradle.xml +18 -17
  22. package/android/.idea/jarRepositories.xml +49 -44
  23. package/android/.idea/misc.xml +9 -9
  24. package/android/.idea/sonarlint/issuestore/index.pb +0 -0
  25. package/android/.idea/vcs.xml +5 -5
  26. package/android/build.gradle +69 -69
  27. package/android/gradle/wrapper/gradle-wrapper.properties +7 -7
  28. package/android/gradle.properties +1 -1
  29. package/android/gradlew +291 -375
  30. package/android/local.properties +8 -8
  31. package/android/src/main/AndroidManifest.xml +4 -4
  32. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  33. package/android/src/main/java/land/fx/fula/Cryptography.java +47 -47
  34. package/android/src/main/java/land/fx/fula/FulaModule.java +1248 -701
  35. package/android/src/main/java/land/fx/fula/FulaPackage.java +2 -2
  36. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  37. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  38. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  39. package/ios/FulaModule.h +10 -10
  40. package/ios/FulaModule.m +149 -149
  41. package/lib/commonjs/index.js +5 -1
  42. package/lib/commonjs/index.js.map +1 -1
  43. package/lib/commonjs/interfaces/api-lookup.js +1653 -0
  44. package/lib/commonjs/interfaces/api-lookup.js.map +1 -0
  45. package/lib/commonjs/interfaces/fulaNativeModule.js +1 -1
  46. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  47. package/lib/commonjs/protocols/blockchain.js +404 -0
  48. package/lib/commonjs/protocols/blockchain.js.map +1 -0
  49. package/lib/commonjs/protocols/chain-api.js +87 -0
  50. package/lib/commonjs/protocols/chain-api.js.map +1 -0
  51. package/lib/commonjs/protocols/fula.js +139 -82
  52. package/lib/commonjs/protocols/fula.js.map +1 -1
  53. package/lib/commonjs/types/blockchain.js +2 -0
  54. package/lib/commonjs/types/blockchain.js.map +1 -0
  55. package/lib/module/index.js +4 -0
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/interfaces/api-lookup.js +1648 -0
  58. package/lib/module/interfaces/api-lookup.js.map +1 -0
  59. package/lib/module/interfaces/fulaNativeModule.js +1 -1
  60. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  61. package/lib/module/protocols/blockchain.js +383 -0
  62. package/lib/module/protocols/blockchain.js.map +1 -0
  63. package/lib/module/protocols/chain-api.js +76 -0
  64. package/lib/module/protocols/chain-api.js.map +1 -0
  65. package/lib/module/protocols/fula.js +134 -81
  66. package/lib/module/protocols/fula.js.map +1 -1
  67. package/lib/module/types/blockchain.js +2 -0
  68. package/lib/module/types/blockchain.js.map +1 -0
  69. package/lib/typescript/index.d.ts +3 -1
  70. package/lib/typescript/interfaces/api-lookup.d.ts +1643 -0
  71. package/lib/typescript/interfaces/fulaNativeModule.d.ts +58 -28
  72. package/lib/typescript/protocols/blockchain.d.ts +17 -0
  73. package/lib/typescript/protocols/chain-api.d.ts +6 -0
  74. package/lib/typescript/protocols/fula.d.ts +127 -99
  75. package/lib/typescript/types/blockchain.d.ts +68 -0
  76. package/package.json +157 -149
  77. package/react-native-fula.podspec +19 -19
  78. package/src/index.tsx +3 -1
  79. package/src/interfaces/api-lookup.ts +1647 -0
  80. package/src/interfaces/fulaNativeModule.ts +86 -52
  81. package/src/protocols/blockchain.ts +460 -0
  82. package/src/protocols/chain-api.ts +80 -0
  83. package/src/protocols/fula.ts +285 -212
  84. package/src/types/blockchain.ts +81 -0
@@ -1,52 +1,86 @@
1
- import { NativeModules, Platform } from 'react-native';
2
-
3
- interface FulaNativeModule {
4
- init: (
5
- identity: string, //Private key of did identity
6
- storePath: string, //You can leave empty
7
- bloxAddr: string, //Blox multiadddr needs to be manually entered now
8
- exchange: string, //set to 'noope' for testing
9
- rootCid: string | null //if you have the latest rootCid you can send it and it generates the private_ref for filesystem
10
- ) => Promise<{ peerId: string; rootCid: string; private_ref: string }>;
11
- logout: (identity: string, storePath: string) => Promise<boolean>;
12
- get: (key: string) => Promise<string>;
13
- has: (key: Uint8Array) => Promise<boolean>;
14
- push: () => Promise<string>;
15
- put: (content: string, codec: string) => Promise<string>;
16
- mkdir: (path: string) => Promise<string>;
17
- writeFileContent: (path: string, content: string) => Promise<string>;
18
- writeFile: (
19
- fulaTargetFilename: string,
20
- localFilename: string
21
- ) => Promise<string>;
22
- ls: (path: string) => Promise<string>;
23
- rm: (path: string) => Promise<string>;
24
- cp: (sourcePath: string, targetPath: string) => Promise<string>;
25
- mv: (sourcePath: string, targetPath: string) => Promise<string>;
26
- readFile: (
27
- fulaTargetFilename: string,
28
- localFilename: string
29
- ) => Promise<string>;
30
- readFileContent: (path: string) => Promise<string>;
31
-
32
- shutdown: () => Promise<void>;
33
- }
34
-
35
- const LINKING_ERROR =
36
- `The package 'react-native-fula' doesn't seem to be linked. Make sure: \n\n` +
37
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
38
- '- You rebuilt the app after installing the package\n' +
39
- '- You are not using Expo managed workflow\n';
40
-
41
- const Fula = NativeModules.FulaModule
42
- ? NativeModules.FulaModule
43
- : new Proxy(
44
- {},
45
- {
46
- get() {
47
- throw new Error(LINKING_ERROR);
48
- },
49
- }
50
- );
51
-
52
- export default Fula as FulaNativeModule;
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ interface FulaNativeModule {
4
+ init: (
5
+ identity: string, //Private key of did identity
6
+ storePath: string, //You can leave empty
7
+ bloxAddr: string, //Blox multiadddr needs to be manually entered now
8
+ exchange: string, //set to 'noope' for testing
9
+ autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
10
+ rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem
11
+ useRelay: boolean | null, // if true it forces the use of relay
12
+ refresh: boolean // if true it forces to refresh the fula object
13
+ ) => Promise<{ peerId: string; rootCid: string; private_ref: string }>;
14
+ newClient: (
15
+ identity: string, //Private key of did identity
16
+ storePath: string, //You can leave empty
17
+ bloxAddr: string, //Blox multiadddr needs to be manually entered now
18
+ exchange: string, //set to 'noope' for testing
19
+ autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
20
+ useRelay: boolean | null, // if true it forces the use of relay
21
+ refresh: boolean // if true it forces to refresh the fula object
22
+ ) => Promise<string>;
23
+ isReady: (filesystemCheck: boolean) => Promise<boolean>;
24
+ logout: (identity: string, storePath: string) => Promise<boolean>;
25
+ checkFailedActions: (retry: boolean) => Promise<boolean>;
26
+ checkConnection: () => Promise<boolean>;
27
+ get: (key: string) => Promise<string>;
28
+ has: (key: Uint8Array) => Promise<boolean>;
29
+ push: () => Promise<string>;
30
+ put: (content: string, codec: string) => Promise<string>;
31
+ mkdir: (path: string) => Promise<string>;
32
+ writeFileContent: (path: string, content: string) => Promise<string>;
33
+ writeFile: (
34
+ fulaTargetFilename: string,
35
+ localFilename: string
36
+ ) => Promise<string>;
37
+ ls: (path: string) => Promise<string>;
38
+ rm: (path: string) => Promise<string>;
39
+ cp: (sourcePath: string, targetPath: string) => Promise<string>;
40
+ mv: (sourcePath: string, targetPath: string) => Promise<string>;
41
+ readFile: (
42
+ fulaTargetFilename: string,
43
+ localFilename: string
44
+ ) => Promise<string>;
45
+ readFileContent: (path: string) => Promise<string>;
46
+ setAuth: (peerId: string, allow: boolean) => Promise<boolean>;
47
+
48
+ shutdown: () => Promise<void>;
49
+
50
+ //Blockchain related functions
51
+ createAccount: (seed: string) => Promise<string>;
52
+ checkAccountExists: (account: string) => Promise<string>;
53
+ createPool: (seed: string, poolName: string) => Promise<string>;
54
+ listPools: () => Promise<string>;
55
+ joinPool: (seed: string, poolID: number) => Promise<string>;
56
+ leavePool: (seed: string, poolID: number) => Promise<string>;
57
+ cancelPoolJoin: (seed: string, poolID: number) => Promise<string>;
58
+ listPoolJoinRequests: (poolID: number) => Promise<string>;
59
+ votePoolJoinRequest: (seed: string, poolID: number, account: string, accept: boolean) => Promise<string>;
60
+ newReplicationRequest: (seed: string, poolID: number, replicationFactor: number, cid: string) => Promise<string>;
61
+ newStoreRequest: (seed: string, poolID: number, uploader: string, cid: string) => Promise<string>;
62
+ listAvailableReplicationRequests: (poolID: number) => Promise<string>;
63
+ removeReplicationRequest: (seed: string, poolID: number, cid: string) => Promise<string>;
64
+ removeStorer: (seed: string, storer: string, poolID: number, cid: string) => Promise<string>;
65
+ removeStoredReplication: (seed: string, uploader: string, poolID: number, cid: string) => Promise<string>;
66
+ bloxFreeSpace: () => Promise<string>;
67
+ }
68
+
69
+ const LINKING_ERROR =
70
+ `The package 'react-native-fula/Fula' doesn't seem to be linked. Make sure: \n\n` +
71
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
72
+ '- You rebuilt the app after installing the package\n' +
73
+ '- You are not using Expo managed workflow\n';
74
+
75
+ const Fula = NativeModules.FulaModule
76
+ ? NativeModules.FulaModule
77
+ : new Proxy(
78
+ {},
79
+ {
80
+ get() {
81
+ throw new Error(LINKING_ERROR);
82
+ },
83
+ }
84
+ );
85
+
86
+ export default Fula as FulaNativeModule;
@@ -0,0 +1,460 @@
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+ import type * as BType from '../types/blockchain';
3
+
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(
11
+ 'createAccount in react-native started',
12
+ seed
13
+ );
14
+ let res = Fula.createAccount(seed).then((res) => {
15
+ try{
16
+ let jsonRes:BType.SeededResponse = JSON.parse(res);
17
+ return jsonRes;
18
+ } catch (e) {
19
+ try {
20
+ return JSON.parse(res)
21
+ } catch (e) {
22
+ return res;
23
+ }
24
+ }
25
+ }).catch((err) => {
26
+ return err;
27
+ });
28
+ return res;
29
+ };
30
+
31
+ /*
32
+ 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
33
+ */
34
+ export const checkAccountExists = (
35
+ account: string,
36
+ ): Promise<BType.AccountExistsResponse> => {
37
+ console.log(
38
+ 'checkAccountExists in react-native started',
39
+ account
40
+ );
41
+ let res = Fula.checkAccountExists(account).then((res) => {
42
+ try{
43
+ let jsonRes: BType.AccountExistsResponse = JSON.parse(res);
44
+ return jsonRes;
45
+ } catch (e) {
46
+ try {
47
+ return JSON.parse(res)
48
+ } catch (e) {
49
+ return res;
50
+ }
51
+ }
52
+ }).catch((err) => {
53
+ return err;
54
+ });
55
+ return res;
56
+ };
57
+
58
+ /*
59
+ 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.
60
+ */
61
+ export const createPool = (seed: string, poolName: string): Promise<BType.PoolCreateResponse> => {
62
+ console.log(
63
+ 'createPool in react-native started',
64
+ seed,
65
+ poolName
66
+ );
67
+ let res = Fula.createPool(seed, poolName).then((res) => {
68
+ try {
69
+ let jsonRes: BType.PoolCreateResponse = JSON.parse(res);
70
+ return jsonRes;
71
+ } catch (e) {
72
+ try {
73
+ return JSON.parse(res);
74
+ } catch (e) {
75
+ return res;
76
+ }
77
+ }
78
+ }).catch((err) => {
79
+ return err;
80
+ });
81
+ return res;
82
+ };
83
+
84
+ /*
85
+ 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
86
+ */
87
+ export const listPools = (): Promise<BType.PoolListResponse> => {
88
+ console.log(
89
+ 'listPools in react-native started'
90
+ );
91
+ let res = Fula.listPools().then((res) => {
92
+ try {
93
+ let jsonRes: BType.PoolListResponse = JSON.parse(res);
94
+ return jsonRes;
95
+ } catch (e) {
96
+ try {
97
+ return JSON.parse(res);
98
+ } catch (e) {
99
+ return res;
100
+ }
101
+ }
102
+ }).catch((err) => {
103
+ return err;
104
+ });
105
+ return res;
106
+ };
107
+
108
+ /*
109
+ 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.
110
+ */
111
+
112
+ export const joinPool = (seed: string, poolID: number): Promise<BType.PoolJoinResponse> => {
113
+ console.log(
114
+ 'joinPool in react-native started',
115
+ seed,
116
+ poolID
117
+ );
118
+ let res = Fula.joinPool(seed, poolID).then((res) => {
119
+ try {
120
+ let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
121
+ return jsonRes;
122
+ } catch (e) {
123
+ try {
124
+ return JSON.parse(res);
125
+ } catch (e) {
126
+ return res;
127
+ }
128
+ }
129
+ }).catch((err) => {
130
+ return err;
131
+ });
132
+ return res;
133
+ };
134
+
135
+ /*
136
+ 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 `
137
+ */
138
+
139
+ export const leavePool = (seed: string, poolID: number): Promise<BType.PoolLeaveResponse> => {
140
+ console.log(
141
+ 'leavePool in react-native started',
142
+ seed,
143
+ poolID
144
+ );
145
+ let res = Fula.leavePool(seed, poolID).then((res) => {
146
+ try {
147
+ let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
148
+ return jsonRes;
149
+ } catch (e) {
150
+ try {
151
+ return JSON.parse(res);
152
+ } catch (e) {
153
+ return res;
154
+ }
155
+ }
156
+ }).catch((err) => {
157
+ return err;
158
+ });
159
+ return res;
160
+ };
161
+
162
+ export const cancelPoolJoin = (seed: string, poolID: number): Promise<BType.PoolCancelJoinResponse> => {
163
+ console.log(
164
+ 'cancelPoolJoin in react-native started',
165
+ seed,
166
+ poolID
167
+ );
168
+ let res = Fula.cancelPoolJoin(seed, poolID).then((res) => {
169
+ try {
170
+ let jsonRes: BType.PoolCancelJoinResponse = JSON.parse(res);
171
+ return jsonRes;
172
+ } catch (e) {
173
+ try {
174
+ return JSON.parse(res);
175
+ } catch (e) {
176
+ return res;
177
+ }
178
+ }
179
+ }).catch((err) => {
180
+ return err;
181
+ });
182
+ return res;
183
+ };
184
+ export const listPoolJoinRequests = (poolID: number): Promise<BType.PoolRequestsResponse> => {
185
+ console.log(
186
+ 'listPoolJoinRequests in react-native started',
187
+ poolID
188
+ );
189
+ let res = Fula.listPoolJoinRequests(poolID).then((res) => {
190
+ try {
191
+ let jsonRes: BType.PoolRequestsResponse = JSON.parse(res);
192
+ return jsonRes;
193
+ } catch (e) {
194
+ try {
195
+ return JSON.parse(res);
196
+ } catch (e) {
197
+ return res;
198
+ }
199
+ }
200
+ }).catch((err) => {
201
+ return err;
202
+ });
203
+ return res;
204
+ };
205
+
206
+ /*
207
+ seed is used to authorize the request.
208
+ poolID is the ID of the pool in which the account is requesting to join.
209
+ account is the account that is requesting to join the pool.
210
+ accept is a boolean value that indicates whether to accept or reject the join request.
211
+ It returns a promise of BType.PoolVoteResponse which includes the account and poolID
212
+ */
213
+ export const votePoolJoinRequest = (seed: string, poolID: number, account: string, accept: boolean): Promise<BType.PoolVoteResponse> => {
214
+ console.log(
215
+ 'votePoolJoinRequest in react-native started',
216
+ seed,
217
+ poolID,
218
+ account,
219
+ accept
220
+ );
221
+ let res = Fula.votePoolJoinRequest(seed, poolID, account, accept).then((res) => {
222
+ try {
223
+ let jsonRes: BType.PoolVoteResponse = JSON.parse(res);
224
+ return jsonRes;
225
+ } catch (e) {
226
+ try {
227
+ return JSON.parse(res);
228
+ } catch (e) {
229
+ return res;
230
+ }
231
+ }
232
+ }).catch((err) => {
233
+ return err;
234
+ });
235
+ return res;
236
+ };
237
+
238
+
239
+ /*
240
+ It takes four arguments:
241
+
242
+ seed is used to authorize the request.
243
+ poolID is the ID of the pool in which the replication request is made.
244
+ replicationFactor is the number of copies of the content to be stored.
245
+ cid is the content identifier of the content to be replicated.
246
+ It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
247
+ */
248
+ export const newReplicationRequest = (seed: string, poolID: number, replicationFactor: number, cid: string): Promise<BType.ManifestUploadResponse> => {
249
+ console.log(
250
+ 'newReplicationRequest in react-native started',
251
+ seed,
252
+ poolID,
253
+ replicationFactor,
254
+ cid
255
+ );
256
+ let res = Fula.newReplicationRequest(seed, poolID, replicationFactor, cid).then((res) => {
257
+ try {
258
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
259
+ return jsonRes;
260
+ } catch (e) {
261
+ try {
262
+ return JSON.parse(res);
263
+ } catch (e) {
264
+ return res;
265
+ }
266
+ }
267
+ }).catch((err) => {
268
+ return err;
269
+ });
270
+ return res;
271
+ };
272
+
273
+ /*
274
+ It takes four arguments:
275
+
276
+ seed is used to authorize the request.
277
+ poolID is the ID of the pool in which the replication request is made.
278
+ uploader is the account of the user making the request
279
+ cid is the content identifier of the content to be stored.
280
+ It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
281
+ */
282
+ export const newStoreRequest = (seed: string, poolID: number, uploader: string, cid: string): Promise<BType.ManifestUploadResponse> => {
283
+ console.log(
284
+ 'newStoreRequest in react-native started',
285
+ seed,
286
+ poolID,
287
+ uploader,
288
+ cid
289
+ );
290
+ let res = Fula.newStoreRequest(seed, poolID, uploader, cid).then((res) => {
291
+ try {
292
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
293
+ return jsonRes;
294
+ } catch (e) {
295
+ try {
296
+ return JSON.parse(res);
297
+ } catch (e) {
298
+ return res;
299
+ }
300
+ }
301
+ }).catch((err) => {
302
+ return err;
303
+ });
304
+ return res;
305
+ };
306
+
307
+
308
+ /*
309
+ It takes one argument:
310
+
311
+ poolID is the ID of the pool for which the replication requests are listed
312
+ It returns a promise of BType.ManifestUploadResponse[] which is an array of the replication requests, including the uploader, storage, ManifestMetadata, and poolID
313
+ */
314
+ export const listAvailableReplicationRequests = (poolID: number): Promise<BType.ManifestUploadResponse[]> => {
315
+ console.log(
316
+ 'listAvailableReplicationRequests in react-native started',
317
+ poolID
318
+ );
319
+ let res = Fula.listAvailableReplicationRequests(poolID).then((res) => {
320
+ try {
321
+ let jsonRes: BType.ManifestUploadResponse[] = JSON.parse(res);
322
+ return jsonRes;
323
+ } catch (e) {
324
+ try {
325
+ return JSON.parse(res);
326
+ } catch (e) {
327
+ return res;
328
+ }
329
+ }
330
+ }).catch((err) => {
331
+ return err;
332
+ });
333
+ return res;
334
+ };
335
+
336
+
337
+ /*
338
+ It takes three arguments:
339
+
340
+ seed is the seed of the account that is removing the replication request
341
+ poolID is the ID of the pool for which the replication request is being removed
342
+ cid is the content ID of the replication request being removed
343
+ It returns a promise of BType.ManifestUploadResponse which is the removed replication request, including the uploader, storage, ManifestMetadata, and poolID
344
+ */
345
+ export const removeReplicationRequest = (seed: string, poolID: number, cid: string): Promise<BType.ManifestUploadResponse> => {
346
+ console.log(
347
+ 'removeReplicationRequest in react-native started',
348
+ seed,
349
+ poolID,
350
+ cid
351
+ );
352
+ let res = Fula.removeReplicationRequest(seed, poolID, cid).then((res) => {
353
+ try {
354
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
355
+ return jsonRes;
356
+ } catch (e) {
357
+ try {
358
+ return JSON.parse(res);
359
+ } catch (e) {
360
+ return res;
361
+ }
362
+ }
363
+ }).catch((err) => {
364
+ return err;
365
+ });
366
+ return res;
367
+ };
368
+
369
+ /*
370
+ It takes four arguments:
371
+
372
+ seed is the seed of the account that is removing the storer
373
+ storer is the address of the storer that is being removed
374
+ poolID is the ID of the pool for which the storer is being removed
375
+ cid is the content ID of the replication request for which the storer is being removed
376
+ 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.
377
+ */
378
+ export const removeStorer = (seed: string, storer: string, poolID: number, cid: string): Promise<BType.ManifestUploadResponse> => {
379
+ console.log(
380
+ 'removeStorer in react-native started',
381
+ seed,
382
+ storer,
383
+ poolID,
384
+ cid
385
+ );
386
+ let res = Fula.removeStorer(seed, storer, poolID, cid).then((res) => {
387
+ try {
388
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
389
+ return jsonRes;
390
+ } catch (e) {
391
+ try {
392
+ return JSON.parse(res);
393
+ } catch (e) {
394
+ return res;
395
+ }
396
+ }
397
+ }).catch((err) => {
398
+ return err;
399
+ });
400
+ return res;
401
+ };
402
+
403
+
404
+ /*
405
+ It takes four arguments:
406
+
407
+ seed is the seed of the account that is removing the stored replication
408
+ uploader is the address of the uploader that is being removed
409
+ poolID is the ID of the pool for which the stored replication is being removed
410
+ cid is the content ID of the replication request for which the stored replication is being removed
411
+ 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.
412
+ */
413
+ export const removeStoredReplication = (seed: string, uploader: string, poolID: number, cid: string): Promise<BType.ManifestUploadResponse> => {
414
+ console.log(
415
+ 'removeStoredReplication in react-native started',
416
+ seed,
417
+ uploader,
418
+ poolID,
419
+ cid
420
+ );
421
+ let res = Fula.removeStoredReplication(seed, uploader, poolID, cid).then((res) => {
422
+ try {
423
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
424
+ return jsonRes;
425
+ } catch (e) {
426
+ try {
427
+ return JSON.parse(res);
428
+ } catch (e) {
429
+ return res;
430
+ }
431
+ }
432
+ }).catch((err) => {
433
+ return err;
434
+ });
435
+ return res;
436
+ };
437
+
438
+ /*
439
+ bloxFreeSpace: This function takes no arguments and returns a promise of an object that contains the blox free space information.
440
+ */
441
+ export const bloxFreeSpace = (): Promise<BType.BloxFreeSpaceResponse> => {
442
+ console.log(
443
+ 'bloxFreeSpace in react-native started'
444
+ );
445
+ let res = Fula.bloxFreeSpace().then((res) => {
446
+ try {
447
+ let jsonRes: BType.BloxFreeSpaceResponse = JSON.parse(res);
448
+ return jsonRes;
449
+ } catch (e) {
450
+ try {
451
+ return JSON.parse(res);
452
+ } catch (e) {
453
+ return res;
454
+ }
455
+ }
456
+ }).catch((err) => {
457
+ return err;
458
+ });
459
+ return res;
460
+ };
@@ -0,0 +1,80 @@
1
+ import { default as EventTypes } from '../interfaces/api-lookup';
2
+
3
+ import { ApiPromise, WsProvider } from '@polkadot/api';
4
+ import type * as BType from '../types/blockchain';
5
+
6
+ const types = {
7
+ FulaPoolPool: EventTypes.FulaPoolPool,
8
+ }
9
+
10
+ export const init = async (wsAddress: string = 'wss://node.testnet.fx.land'): Promise<ApiPromise> => {
11
+ const provider = new WsProvider(wsAddress);
12
+ const api = await ApiPromise.create({ types, provider }).catch((err) => {
13
+ console.log(err);
14
+ return Promise.reject(err);
15
+ });
16
+ return api;
17
+ };
18
+
19
+ export const disconnectApi = async (api: ApiPromise): Promise<void> => {
20
+ await api.disconnect();
21
+ };
22
+
23
+ /*
24
+ listPools: This function takes start index and length 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
25
+ */
26
+ export const listPools = async (api: ApiPromise|undefined, start: number=1, length: number=10): Promise<BType.PoolListResponse> => {
27
+ console.log(
28
+ 'listPools in react-native started'
29
+ );
30
+ try {
31
+ if(api == undefined) {
32
+ api = await init();
33
+ }
34
+ const pools: BType.PoolListResponse = { pools: [] };
35
+ const lastPoolId = await api.query.pool.lastPoolId();
36
+ let finalReturnedId: number = Number(lastPoolId.toHuman());
37
+ if (Number(lastPoolId.toHuman()) > start + length) {
38
+ finalReturnedId = start + length;
39
+ }
40
+ for(let i=start; i<=finalReturnedId;i++) {
41
+ const poolInfo = await api.query.pool
42
+ .pools(i).catch((err) => {
43
+ console.log(err);
44
+ return Promise.reject(err);
45
+ });
46
+ if(poolInfo != null) {
47
+ let formattedPoolInfo: BType.Pool = JSON.parse(JSON.stringify(poolInfo.toHuman()));
48
+ pools.pools.push(formattedPoolInfo);
49
+ }
50
+ }
51
+ return Promise.resolve(pools);
52
+ } catch (err) {
53
+ return Promise.reject(err);
54
+ }
55
+ }
56
+
57
+ /*
58
+ checkJoinRequest: This function takes poolId and AccontId and returns a promise of an object that contains request to the pools.
59
+ */
60
+ export const checkJoinRequest = async (api: ApiPromise|undefined, poolId: number, accountId: string): Promise<BType.PoolRequest|null> => {
61
+ console.log(
62
+ 'checkJoinRequest in react-native started'
63
+ );
64
+ try {
65
+ if(api == undefined) {
66
+ api = await init();
67
+ }
68
+
69
+ const poolRequest = await api.query.pool.poolRequests(poolId, accountId);
70
+
71
+ if(poolRequest != null) {
72
+ let formattedPoolRequest: BType.PoolRequest = JSON.parse(JSON.stringify(poolRequest.toHuman()));
73
+ return Promise.resolve(formattedPoolRequest);
74
+ }
75
+ return Promise.resolve(null);
76
+
77
+ } catch (err) {
78
+ return Promise.reject(err);
79
+ }
80
+ }