@functionland/react-native-fula 1.36.2 → 1.36.3

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.
@@ -1,419 +1,426 @@
1
- import Fula from '../interfaces/fulaNativeModule';
2
- import {
3
- init as chainApiInit,
4
- batchUploadManifest,
5
- checkAccountBalance,
6
- getAccountIdFromSeed,
7
- } from './chain-api';
8
- import { ApiPromise } from '@polkadot/api';
9
-
10
- /**
11
- * Get gets the value corresponding to the given key from the local datastore.
12
- // The key must be a valid ipld.Link.
13
- * @param config
14
- * @returns boolean
15
- */
16
-
17
- export const init = (
18
- identity: string, //privateKey of did identity
19
- storePath: string,
20
- bloxAddr: string,
21
- exchange: string,
22
- autoFlush: boolean = false,
23
- rootCid: string | null = null,
24
- useRelay: boolean = true,
25
- refresh: boolean = false
26
- ): Promise<{ peerId: string; rootCid: string }> => {
27
- console.log(
28
- 'init in react-native started',
29
- identity,
30
- storePath,
31
- bloxAddr,
32
- exchange,
33
- autoFlush,
34
- useRelay
35
- );
36
- return Fula.initFula(
37
- identity,
38
- storePath,
39
- bloxAddr,
40
- exchange,
41
- autoFlush,
42
- rootCid,
43
- useRelay,
44
- refresh
45
- );
46
- };
47
-
48
- /**
49
- * Get gets the value corresponding to the given key from the local datastore.
50
- // The key must be a valid ipld.Link.
51
- * @param config
52
- * @returns boolean
53
- */
54
-
55
- export const newClient = (
56
- identity: string, //privateKey of did identity
57
- storePath: string,
58
- bloxAddr: string,
59
- exchange: string,
60
- autoFlush: boolean = false,
61
- useRelay: boolean = true,
62
- refresh: boolean = false
63
- ): Promise<string> => {
64
- console.log(
65
- 'newClient in react-native started',
66
- identity,
67
- storePath,
68
- bloxAddr,
69
- exchange,
70
- autoFlush,
71
- useRelay,
72
- refresh
73
- );
74
- return Fula.newClient(
75
- identity,
76
- storePath,
77
- bloxAddr,
78
- exchange,
79
- autoFlush,
80
- useRelay,
81
- refresh
82
- );
83
- };
84
-
85
- /**
86
- * rm removes all data
87
- * @param path
88
- * @returns string: new cid of the root
89
- */
90
- export const logout = (
91
- identity: string,
92
- storePath: string
93
- ): Promise<boolean> => {
94
- return Fula.logout(identity, storePath);
95
- };
96
-
97
- /**
98
- * Checks if there are any un-synced changes on the device
99
- */
100
- export const checkFailedActions = (
101
- retry: boolean = false,
102
- timeout: number = 20
103
- ): Promise<boolean> => {
104
- return Fula.checkFailedActions(retry, timeout);
105
- };
106
-
107
- /**
108
- * Lists the cids that failed to be sent to backend and are kept only locally
109
- */
110
- export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
111
- return Fula.listFailedActions(cids);
112
- };
113
-
114
- /**
115
- * Lists the cids that are recent
116
- */
117
- export const listRecentCidsAsString = (): Promise<string[]> => {
118
- return Fula.listRecentCidsAsString();
119
- };
120
-
121
- /**
122
- * Clears the cids that ar recent
123
- */
124
- export const clearCidsFromRecent = (cids: string[] = []): Promise<boolean> => {
125
- return Fula.clearCidsFromRecent(cids);
126
- };
127
-
128
- /**
129
- * Checks if there are any un-synced changes on the device
130
- */
131
- export const checkConnection = (timeout: number = 20): Promise<boolean> => {
132
- return Fula.checkConnection(timeout);
133
- };
134
-
135
- /**
136
- * Get gets the value corresponding to the given key from the local datastore.
137
- // The key must be a valid ipld.Link.
138
- * @param key
139
- * @returns value
140
- */
141
- export const get = (key: string): Promise<string> => {
142
- return Fula.get(key);
143
- };
144
-
145
- /**
146
- * Has checks whether the value corresponding to the given key is present in the local datastore.
147
- // The key must be a valid ipld.Link.
148
- * @param key
149
- * @returns boolean
150
- */
151
- export const has = (key: Uint8Array): Promise<boolean> => {
152
- return Fula.has(key);
153
- };
154
-
155
- /**
156
- * Push requests the given addr to download the root cid from this node.
157
- // The addr must be a valid multiaddr that includes peer ID.
158
- // this function.
159
- * @param addr
160
- * @returns null or error
161
- */
162
- export const push = (): Promise<string> => {
163
- return Fula.push();
164
- };
165
-
166
- //This method sends some test data to backedn
167
- export const testData = (
168
- identity: string,
169
- bloxAddr: string
170
- ): Promise<string> => {
171
- return Fula.testData(identity, bloxAddr);
172
- };
173
-
174
- /**
175
- * Put stores the given key value onto the local datastore.
176
- // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
177
- // to the given key.
178
- * @param key, value
179
- * @returns null or string
180
- */
181
- export const put = (value: string, codec: string): Promise<string> => {
182
- return Fula.put(value, codec);
183
- };
184
-
185
- /**
186
- * mkdir creates a directory at the given path.
187
- * @param path
188
- * @returns string: new cid of the root
189
- */
190
- export const mkdir = (path: string): Promise<string> => {
191
- return Fula.mkdir(path);
192
- };
193
-
194
- /**
195
- * writeFileContent writes content at a given path
196
- * @param path
197
- * @returns string: new cid of the root
198
- */
199
- export const writeFileContent = (
200
- path: string,
201
- content: string
202
- ): Promise<string> => {
203
- return Fula.writeFileContent(path, content);
204
- };
205
-
206
- /*
207
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
208
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
209
- // It keeps the original file modiifcation date
210
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
211
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
212
- // Returns: new cid of the root after this file is placed in the tree
213
- */
214
- export const writeFile = (
215
- fulaTargetFilename: string,
216
- localFilename: string
217
- ): Promise<string> => {
218
- return Fula.writeFile(fulaTargetFilename, localFilename);
219
- };
220
-
221
- /**
222
- * ls lists the name of files and folders at a given path
223
- * @param path
224
- * @returns string: list of items
225
- * TODO: Findout how is the string and convert to array
226
- */
227
- export const ls = (path: string): Promise<void | JSON> => {
228
- return Fula.ls(path)
229
- .then((res) => {
230
- let lsResult = [];
231
- let lsRows = res.split('!!!');
232
- for (const element of lsRows) {
233
- let rowItems = element.split('???');
234
- if (rowItems && rowItems[0]) {
235
- let item = {
236
- name: '',
237
- created: '',
238
- modified: '',
239
- };
240
- item.name = rowItems[0];
241
- if (rowItems[1]) {
242
- item.created = rowItems[1];
243
- }
244
- if (rowItems[2]) {
245
- item.modified = rowItems[2];
246
- }
247
- lsResult.push(item);
248
- }
249
- }
250
- let jsonRes = JSON.parse(JSON.stringify(lsResult));
251
- return jsonRes;
252
- })
253
- .catch((e) => {
254
- return e;
255
- });
256
- };
257
-
258
- /**
259
- * rm removes all files and folders at a given path
260
- * @param path
261
- * @returns string: new cid of the root
262
- */
263
- export const rm = (path: string): Promise<string> => {
264
- return Fula.rm(path);
265
- };
266
-
267
- /**
268
- * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
269
- * @param sourcePath, targetPath
270
- * @returns string: new cid of the root
271
- */
272
- export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
273
- return Fula.cp(sourcePath, targetPath);
274
- };
275
-
276
- /**
277
- * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
278
- * @param sourcePath, targetPath
279
- * @returns string: new cid of the root
280
- */
281
- export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
282
- return Fula.mv(sourcePath, targetPath);
283
- };
284
-
285
- /*
286
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
287
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
288
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
289
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
290
- // Returns: new cid of the root after this file is placed in the tree
291
- */
292
- export const readFile = (
293
- fulaTargetFilename: string,
294
- localFilename: string
295
- ): Promise<string> => {
296
- return Fula.readFile(fulaTargetFilename, localFilename);
297
- };
298
-
299
- /**
300
- * readFile reads content of a given path
301
- * @param path
302
- * @returns string: cotent
303
- */
304
- export const readFileContent = (path: string): Promise<string> => {
305
- return Fula.readFileContent(path);
306
- };
307
-
308
- /**
309
- * Shutdown closes all resources used by Client.
310
- // After calling this function Client must be discarded.
311
- * @param
312
- * @returns
313
- */
314
- export const shutdown = (): Promise<void> => {
315
- return Fula.shutdown();
316
- };
317
-
318
- /**
319
- * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
320
- * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
321
- * @param peerId, allow
322
- * @returns boolean: true if successful or false if not
323
- */
324
- export const setAuth = (peerId: string, allow: boolean): Promise<boolean> => {
325
- return Fula.setAuth(peerId, allow);
326
- };
327
-
328
- /**
329
- * isReady checks if the connection is ready to be used.
330
- * @param filesystemCheck: also check if the wnfs is ready
331
- * @returns boolean: true if ready or false if not
332
- */
333
- export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
334
- return Fula.isReady(filesystemCheck);
335
- };
336
-
337
- /**
338
- * replicate replicates data on the nework
339
- */
340
- export const replicateRecentCids = async (
341
- api: ApiPromise,
342
- seed: string,
343
- poolId: number,
344
- replicationNo: number = 4
345
- ): Promise<{ status: boolean; msg: string }> => {
346
- let status = true;
347
- let msg = '';
348
- if (!api) {
349
- api = await chainApiInit();
350
- }
351
- if (api) {
352
- console.log('uploading manifests');
353
- try {
354
- let account = await getAccountIdFromSeed(seed);
355
- console.log('account: ' + account);
356
- const accountBal = await checkAccountBalance(api, account);
357
- console.log('account balance: ' + accountBal);
358
- if (accountBal !== '0') {
359
- const recentCids = await listRecentCidsAsString();
360
- console.log(recentCids);
361
- if (recentCids) {
362
- console.log({
363
- api,
364
- seed,
365
- recentCids,
366
- poolId,
367
- replicationNo,
368
- });
369
- const res = await batchUploadManifest(
370
- api,
371
- seed,
372
- recentCids,
373
- poolId,
374
- replicationNo
375
- );
376
- console.log('batchUploadManifest res received');
377
- console.log(res);
378
- if (res && res.hash) {
379
- const signedBlock = await api.rpc.chain.getBlock(res.hash);
380
- if (signedBlock?.block?.extrinsics?.length) {
381
- await clearCidsFromRecent(recentCids);
382
- msg = res.hash;
383
- } else {
384
- status = false;
385
- msg = 'block data is not found';
386
- }
387
- } else {
388
- status = false;
389
- msg = 'hash is not returned';
390
- }
391
- } else {
392
- status = false;
393
- msg = 'No recent Cids found';
394
- }
395
- } else {
396
- status = false;
397
- msg = 'Account balance is not enough or account does not exists';
398
- }
399
- } catch (e: any) {
400
- console.log('res failed');
401
- console.log(e);
402
- let errorMessage = '';
403
-
404
- if (e instanceof Error) {
405
- // If it's an Error instance, use the message property
406
- errorMessage = e.message;
407
- } else {
408
- // If it's not an Error instance, convert it to string
409
- errorMessage = e.toString();
410
- }
411
- status = false;
412
- msg = errorMessage;
413
- }
414
- }
415
-
416
- // Return a value (true/false) depending on the outcome of the function
417
- // For example:
418
- return { status: status, msg: msg }; // or false, depending on your logic
419
- };
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+ import {
3
+ init as chainApiInit,
4
+ batchUploadManifest,
5
+ checkAccountBalance,
6
+ getAccountIdFromSeed,
7
+ } from './chain-api';
8
+ import { ApiPromise } from '@polkadot/api';
9
+
10
+ /**
11
+ * Register the app's lifecycle listeners to handle foreground, background, and termination states.
12
+ */
13
+ export const registerLifecycleListener = (): Promise<void> => {
14
+ return Fula.registerLifecycleListener();
15
+ };
16
+
17
+ /**
18
+ * Get gets the value corresponding to the given key from the local datastore.
19
+ // The key must be a valid ipld.Link.
20
+ * @param config
21
+ * @returns boolean
22
+ */
23
+
24
+ export const init = (
25
+ identity: string, //privateKey of did identity
26
+ storePath: string,
27
+ bloxAddr: string,
28
+ exchange: string,
29
+ autoFlush: boolean = false,
30
+ rootCid: string | null = null,
31
+ useRelay: boolean = true,
32
+ refresh: boolean = false
33
+ ): Promise<{ peerId: string; rootCid: string }> => {
34
+ console.log(
35
+ 'init in react-native started',
36
+ identity,
37
+ storePath,
38
+ bloxAddr,
39
+ exchange,
40
+ autoFlush,
41
+ useRelay
42
+ );
43
+ return Fula.initFula(
44
+ identity,
45
+ storePath,
46
+ bloxAddr,
47
+ exchange,
48
+ autoFlush,
49
+ rootCid,
50
+ useRelay,
51
+ refresh
52
+ );
53
+ };
54
+
55
+ /**
56
+ * Get gets the value corresponding to the given key from the local datastore.
57
+ // The key must be a valid ipld.Link.
58
+ * @param config
59
+ * @returns boolean
60
+ */
61
+
62
+ export const newClient = (
63
+ identity: string, //privateKey of did identity
64
+ storePath: string,
65
+ bloxAddr: string,
66
+ exchange: string,
67
+ autoFlush: boolean = false,
68
+ useRelay: boolean = true,
69
+ refresh: boolean = false
70
+ ): Promise<string> => {
71
+ console.log(
72
+ 'newClient in react-native started',
73
+ identity,
74
+ storePath,
75
+ bloxAddr,
76
+ exchange,
77
+ autoFlush,
78
+ useRelay,
79
+ refresh
80
+ );
81
+ return Fula.newClient(
82
+ identity,
83
+ storePath,
84
+ bloxAddr,
85
+ exchange,
86
+ autoFlush,
87
+ useRelay,
88
+ refresh
89
+ );
90
+ };
91
+
92
+ /**
93
+ * rm removes all data
94
+ * @param path
95
+ * @returns string: new cid of the root
96
+ */
97
+ export const logout = (
98
+ identity: string,
99
+ storePath: string
100
+ ): Promise<boolean> => {
101
+ return Fula.logout(identity, storePath);
102
+ };
103
+
104
+ /**
105
+ * Checks if there are any un-synced changes on the device
106
+ */
107
+ export const checkFailedActions = (
108
+ retry: boolean = false,
109
+ timeout: number = 20
110
+ ): Promise<boolean> => {
111
+ return Fula.checkFailedActions(retry, timeout);
112
+ };
113
+
114
+ /**
115
+ * Lists the cids that failed to be sent to backend and are kept only locally
116
+ */
117
+ export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
118
+ return Fula.listFailedActions(cids);
119
+ };
120
+
121
+ /**
122
+ * Lists the cids that are recent
123
+ */
124
+ export const listRecentCidsAsString = (): Promise<string[]> => {
125
+ return Fula.listRecentCidsAsString();
126
+ };
127
+
128
+ /**
129
+ * Clears the cids that ar recent
130
+ */
131
+ export const clearCidsFromRecent = (cids: string[] = []): Promise<boolean> => {
132
+ return Fula.clearCidsFromRecent(cids);
133
+ };
134
+
135
+ /**
136
+ * Checks if there are any un-synced changes on the device
137
+ */
138
+ export const checkConnection = (timeout: number = 20): Promise<boolean> => {
139
+ return Fula.checkConnection(timeout);
140
+ };
141
+
142
+ /**
143
+ * Get gets the value corresponding to the given key from the local datastore.
144
+ // The key must be a valid ipld.Link.
145
+ * @param key
146
+ * @returns value
147
+ */
148
+ export const get = (key: string): Promise<string> => {
149
+ return Fula.get(key);
150
+ };
151
+
152
+ /**
153
+ * Has checks whether the value corresponding to the given key is present in the local datastore.
154
+ // The key must be a valid ipld.Link.
155
+ * @param key
156
+ * @returns boolean
157
+ */
158
+ export const has = (key: Uint8Array): Promise<boolean> => {
159
+ return Fula.has(key);
160
+ };
161
+
162
+ /**
163
+ * Push requests the given addr to download the root cid from this node.
164
+ // The addr must be a valid multiaddr that includes peer ID.
165
+ // this function.
166
+ * @param addr
167
+ * @returns null or error
168
+ */
169
+ export const push = (): Promise<string> => {
170
+ return Fula.push();
171
+ };
172
+
173
+ //This method sends some test data to backedn
174
+ export const testData = (
175
+ identity: string,
176
+ bloxAddr: string
177
+ ): Promise<string> => {
178
+ return Fula.testData(identity, bloxAddr);
179
+ };
180
+
181
+ /**
182
+ * Put stores the given key value onto the local datastore.
183
+ // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
184
+ // to the given key.
185
+ * @param key, value
186
+ * @returns null or string
187
+ */
188
+ export const put = (value: string, codec: string): Promise<string> => {
189
+ return Fula.put(value, codec);
190
+ };
191
+
192
+ /**
193
+ * mkdir creates a directory at the given path.
194
+ * @param path
195
+ * @returns string: new cid of the root
196
+ */
197
+ export const mkdir = (path: string): Promise<string> => {
198
+ return Fula.mkdir(path);
199
+ };
200
+
201
+ /**
202
+ * writeFileContent writes content at a given path
203
+ * @param path
204
+ * @returns string: new cid of the root
205
+ */
206
+ export const writeFileContent = (
207
+ path: string,
208
+ content: string
209
+ ): Promise<string> => {
210
+ return Fula.writeFileContent(path, content);
211
+ };
212
+
213
+ /*
214
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
215
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
216
+ // It keeps the original file modiifcation date
217
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
218
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
219
+ // Returns: new cid of the root after this file is placed in the tree
220
+ */
221
+ export const writeFile = (
222
+ fulaTargetFilename: string,
223
+ localFilename: string
224
+ ): Promise<string> => {
225
+ return Fula.writeFile(fulaTargetFilename, localFilename);
226
+ };
227
+
228
+ /**
229
+ * ls lists the name of files and folders at a given path
230
+ * @param path
231
+ * @returns string: list of items
232
+ * TODO: Findout how is the string and convert to array
233
+ */
234
+ export const ls = (path: string): Promise<void | JSON> => {
235
+ return Fula.ls(path)
236
+ .then((res) => {
237
+ let lsResult = [];
238
+ let lsRows = res.split('!!!');
239
+ for (const element of lsRows) {
240
+ let rowItems = element.split('???');
241
+ if (rowItems && rowItems[0]) {
242
+ let item = {
243
+ name: '',
244
+ created: '',
245
+ modified: '',
246
+ };
247
+ item.name = rowItems[0];
248
+ if (rowItems[1]) {
249
+ item.created = rowItems[1];
250
+ }
251
+ if (rowItems[2]) {
252
+ item.modified = rowItems[2];
253
+ }
254
+ lsResult.push(item);
255
+ }
256
+ }
257
+ let jsonRes = JSON.parse(JSON.stringify(lsResult));
258
+ return jsonRes;
259
+ })
260
+ .catch((e) => {
261
+ return e;
262
+ });
263
+ };
264
+
265
+ /**
266
+ * rm removes all files and folders at a given path
267
+ * @param path
268
+ * @returns string: new cid of the root
269
+ */
270
+ export const rm = (path: string): Promise<string> => {
271
+ return Fula.rm(path);
272
+ };
273
+
274
+ /**
275
+ * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
276
+ * @param sourcePath, targetPath
277
+ * @returns string: new cid of the root
278
+ */
279
+ export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
280
+ return Fula.cp(sourcePath, targetPath);
281
+ };
282
+
283
+ /**
284
+ * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
285
+ * @param sourcePath, targetPath
286
+ * @returns string: new cid of the root
287
+ */
288
+ export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
289
+ return Fula.mv(sourcePath, targetPath);
290
+ };
291
+
292
+ /*
293
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
294
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
295
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
296
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
297
+ // Returns: new cid of the root after this file is placed in the tree
298
+ */
299
+ export const readFile = (
300
+ fulaTargetFilename: string,
301
+ localFilename: string
302
+ ): Promise<string> => {
303
+ return Fula.readFile(fulaTargetFilename, localFilename);
304
+ };
305
+
306
+ /**
307
+ * readFile reads content of a given path
308
+ * @param path
309
+ * @returns string: cotent
310
+ */
311
+ export const readFileContent = (path: string): Promise<string> => {
312
+ return Fula.readFileContent(path);
313
+ };
314
+
315
+ /**
316
+ * Shutdown closes all resources used by Client.
317
+ // After calling this function Client must be discarded.
318
+ * @param
319
+ * @returns
320
+ */
321
+ export const shutdown = (): Promise<void> => {
322
+ return Fula.shutdown();
323
+ };
324
+
325
+ /**
326
+ * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
327
+ * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
328
+ * @param peerId, allow
329
+ * @returns boolean: true if successful or false if not
330
+ */
331
+ export const setAuth = (peerId: string, allow: boolean): Promise<boolean> => {
332
+ return Fula.setAuth(peerId, allow);
333
+ };
334
+
335
+ /**
336
+ * isReady checks if the connection is ready to be used.
337
+ * @param filesystemCheck: also check if the wnfs is ready
338
+ * @returns boolean: true if ready or false if not
339
+ */
340
+ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
341
+ return Fula.isReady(filesystemCheck);
342
+ };
343
+
344
+ /**
345
+ * replicate replicates data on the nework
346
+ */
347
+ export const replicateRecentCids = async (
348
+ api: ApiPromise,
349
+ seed: string,
350
+ poolId: number,
351
+ replicationNo: number = 4
352
+ ): Promise<{ status: boolean; msg: string }> => {
353
+ let status = true;
354
+ let msg = '';
355
+ if (!api) {
356
+ api = await chainApiInit();
357
+ }
358
+ if (api) {
359
+ console.log('uploading manifests');
360
+ try {
361
+ let account = await getAccountIdFromSeed(seed);
362
+ console.log('account: ' + account);
363
+ const accountBal = await checkAccountBalance(api, account);
364
+ console.log('account balance: ' + accountBal);
365
+ if (accountBal !== '0') {
366
+ const recentCids = await listRecentCidsAsString();
367
+ console.log(recentCids);
368
+ if (recentCids) {
369
+ console.log({
370
+ api,
371
+ seed,
372
+ recentCids,
373
+ poolId,
374
+ replicationNo,
375
+ });
376
+ const res = await batchUploadManifest(
377
+ api,
378
+ seed,
379
+ recentCids,
380
+ poolId,
381
+ replicationNo
382
+ );
383
+ console.log('batchUploadManifest res received');
384
+ console.log(res);
385
+ if (res && res.hash) {
386
+ const signedBlock = await api.rpc.chain.getBlock(res.hash);
387
+ if (signedBlock?.block?.extrinsics?.length) {
388
+ await clearCidsFromRecent(recentCids);
389
+ msg = res.hash;
390
+ } else {
391
+ status = false;
392
+ msg = 'block data is not found';
393
+ }
394
+ } else {
395
+ status = false;
396
+ msg = 'hash is not returned';
397
+ }
398
+ } else {
399
+ status = false;
400
+ msg = 'No recent Cids found';
401
+ }
402
+ } else {
403
+ status = false;
404
+ msg = 'Account balance is not enough or account does not exists';
405
+ }
406
+ } catch (e: any) {
407
+ console.log('res failed');
408
+ console.log(e);
409
+ let errorMessage = '';
410
+
411
+ if (e instanceof Error) {
412
+ // If it's an Error instance, use the message property
413
+ errorMessage = e.message;
414
+ } else {
415
+ // If it's not an Error instance, convert it to string
416
+ errorMessage = e.toString();
417
+ }
418
+ status = false;
419
+ msg = errorMessage;
420
+ }
421
+ }
422
+
423
+ // Return a value (true/false) depending on the outcome of the function
424
+ // For example:
425
+ return { status: status, msg: msg }; // or false, depending on your logic
426
+ };