@functionland/react-native-fula 1.46.0 → 1.53.0

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 (49) hide show
  1. package/README.md +19 -1
  2. package/android/build.gradle +12 -7
  3. package/android/gradle.properties +4 -4
  4. package/android/src/main/java/land/fx/fula/FulaModule.java +113 -4
  5. package/ios/Fula.mm +20 -2
  6. package/ios/Fula.swift +99 -7
  7. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  8. package/lib/commonjs/interfaces/lookup.js +0 -1
  9. package/lib/commonjs/interfaces/lookup.js.map +1 -1
  10. package/lib/commonjs/protocols/blockchain.js +33 -5
  11. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  12. package/lib/commonjs/protocols/chain-api.js +5 -5
  13. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  14. package/lib/commonjs/protocols/fula.js +77 -5
  15. package/lib/commonjs/protocols/fula.js.map +1 -1
  16. package/lib/commonjs/protocols/fxblox.js +25 -1
  17. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  18. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  19. package/lib/module/interfaces/lookup.js +0 -2
  20. package/lib/module/interfaces/lookup.js.map +1 -1
  21. package/lib/module/protocols/blockchain.js +30 -3
  22. package/lib/module/protocols/blockchain.js.map +1 -1
  23. package/lib/module/protocols/chain-api.js +5 -5
  24. package/lib/module/protocols/chain-api.js.map +1 -1
  25. package/lib/module/protocols/fula.js +73 -3
  26. package/lib/module/protocols/fula.js.map +1 -1
  27. package/lib/module/protocols/fxblox.js +23 -0
  28. package/lib/module/protocols/fxblox.js.map +1 -1
  29. package/lib/typescript/interfaces/fulaNativeModule.d.ts +6 -3
  30. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
  31. package/lib/typescript/protocols/blockchain.d.ts +5 -3
  32. package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
  33. package/lib/typescript/protocols/fula.d.ts +9 -0
  34. package/lib/typescript/protocols/fula.d.ts.map +1 -1
  35. package/lib/typescript/protocols/fxblox.d.ts +1 -0
  36. package/lib/typescript/protocols/fxblox.d.ts.map +1 -1
  37. package/lib/typescript/types/blockchain.d.ts +5 -0
  38. package/lib/typescript/types/blockchain.d.ts.map +1 -1
  39. package/lib/typescript/types/fxblox.d.ts +7 -0
  40. package/lib/typescript/types/fxblox.d.ts.map +1 -1
  41. package/package.json +2 -2
  42. package/src/interfaces/fulaNativeModule.ts +14 -10
  43. package/src/interfaces/lookup.ts +1 -1
  44. package/src/protocols/blockchain.ts +56 -14
  45. package/src/protocols/chain-api.ts +5 -5
  46. package/src/protocols/fula.ts +84 -4
  47. package/src/protocols/fxblox.ts +25 -0
  48. package/src/types/blockchain.ts +9 -3
  49. package/src/types/fxblox.ts +8 -0
@@ -10,7 +10,7 @@ const types = {
10
10
  };
11
11
 
12
12
  export const init = async (
13
- wsAddress: string = 'wss://node3.functionyard.fula.network'
13
+ wsAddress: string = 'wss://node3.test.fula.network'
14
14
  ): Promise<ApiPromise> => {
15
15
  const provider = new WsProvider(wsAddress);
16
16
  const api = await ApiPromise.create({ types, provider }).catch((err) => {
@@ -57,7 +57,7 @@ function createManifest(
57
57
  const serializedManifest = manifest_metadata.map((item) => serialize(item)); // Implement `serialize` accordingly
58
58
 
59
59
  // Serialize cids to Uint8Array or string
60
- const serializedCids = cids.map((cid) => serialize(cid)); // Implement `serialize` accordingly
60
+ //const serializedCids = cids.map((cid) => serialize(cid)); // Implement `serialize` accordingly
61
61
 
62
62
  // Create arrays for `poolId` and `replicationFactor`
63
63
  const poolIds = new Array(cids.length).fill(poolId);
@@ -65,7 +65,7 @@ function createManifest(
65
65
 
66
66
  const batchUploadManifest = {
67
67
  manifest: serializedManifest,
68
- cids: serializedCids,
68
+ cids: cids,
69
69
  poolId: poolIds,
70
70
  replicationFactor: replicationFactors,
71
71
  };
@@ -111,11 +111,11 @@ export const batchUploadManifest = async (
111
111
  return new Promise<{ hash: string }>((resolve, reject) => {
112
112
  submitExtrinsic
113
113
  .signAndSend(userKey, { nonce: -1 }, ({ status }) => {
114
- if (status.isInBlock || status.isFinalized) {
114
+ if (status.isFinalized) {
115
115
  if (unsub) {
116
116
  unsub(); // Call unsub before resolving the promise
117
117
  }
118
- resolve({ hash: status.asInBlock.toString() });
118
+ resolve({ hash: status.asFinalized.toString() });
119
119
  }
120
120
  })
121
121
  .then((unsubFn) => {
@@ -1,10 +1,11 @@
1
1
  import Fula from '../interfaces/fulaNativeModule';
2
2
  import {
3
3
  init as chainApiInit,
4
- batchUploadManifest,
5
4
  checkAccountBalance,
6
5
  getAccountIdFromSeed,
6
+ batchUploadManifest,
7
7
  } from './chain-api';
8
+ import { batchUploadManifest as batchUploadManifestBlox } from './blockchain';
8
9
  import { ApiPromise } from '@polkadot/api';
9
10
 
10
11
  /**
@@ -126,6 +127,10 @@ export const listRecentCidsAsString = (): Promise<string[]> => {
126
127
  return Fula.listRecentCidsAsString();
127
128
  };
128
129
 
130
+ export const listRecentCidsAsStringWithChildren = (): Promise<string[]> => {
131
+ return Fula.listRecentCidsAsStringWithChildren();
132
+ };
133
+
129
134
  /**
130
135
  * Clears the cids that ar recent
131
136
  */
@@ -350,9 +355,10 @@ export const replicateRecentCids = async (
350
355
  seed: string,
351
356
  poolId: number,
352
357
  replicationNo: number = 4
353
- ): Promise<{ status: boolean; msg: string }> => {
358
+ ): Promise<{ status: boolean; msg: string; cids: string[] }> => {
354
359
  let status = true;
355
360
  let msg = '';
361
+ let recentCids: string[] = [];
356
362
  if (!api) {
357
363
  api = await chainApiInit();
358
364
  }
@@ -364,7 +370,7 @@ export const replicateRecentCids = async (
364
370
  const accountBal = await checkAccountBalance(api, account);
365
371
  console.log('account balance: ' + accountBal);
366
372
  if (accountBal !== '0') {
367
- const recentCids = await listRecentCidsAsString();
373
+ recentCids = await listRecentCidsAsStringWithChildren();
368
374
  console.log(recentCids);
369
375
  if (recentCids) {
370
376
  console.log({
@@ -383,7 +389,7 @@ export const replicateRecentCids = async (
383
389
  );
384
390
  console.log('batchUploadManifest res received');
385
391
  console.log(res);
386
- if (res && res.hash) {
392
+ if (res?.hash) {
387
393
  const signedBlock = await api.rpc.chain.getBlock(res.hash);
388
394
  if (signedBlock?.block?.extrinsics?.length) {
389
395
  await clearCidsFromRecent(recentCids);
@@ -421,6 +427,80 @@ export const replicateRecentCids = async (
421
427
  }
422
428
  }
423
429
 
430
+ // Return a value (true/false) depending on the outcome of the function
431
+ // For example:
432
+ return { status: status, msg: msg, cids: recentCids }; // or false, depending on your logic
433
+ };
434
+
435
+ /**
436
+ * replicate replicates data on the nework
437
+ */
438
+ export const replicateRecentCidsBlox = async (
439
+ api: ApiPromise | undefined,
440
+ seed: string,
441
+ poolId: number,
442
+ replicationNo: number = 6
443
+ ): Promise<{ status: boolean; msg: string }> => {
444
+ let status = true;
445
+ let msg = '';
446
+ console.log('uploading manifests');
447
+ try {
448
+ //TODO: Implement getting SUGAR balance of blox
449
+ //const accountBal = await getAccountBalanceBlox();
450
+ const accountBal = '1';
451
+ console.log('account balance: ' + accountBal);
452
+ const recentCids = await listRecentCidsAsStringWithChildren();
453
+ console.log(recentCids);
454
+ if (recentCids) {
455
+ console.log({
456
+ api,
457
+ seed,
458
+ recentCids,
459
+ poolId,
460
+ replicationNo,
461
+ });
462
+ const res = await batchUploadManifestBlox(
463
+ api,
464
+ seed,
465
+ recentCids,
466
+ poolId,
467
+ replicationNo
468
+ );
469
+ console.log('batchUploadManifest res received');
470
+ console.log(res);
471
+ if (res) {
472
+ if (typeof res === 'object' && 'pool_id' in res) {
473
+ msg = res.storer;
474
+ } else {
475
+ status = false;
476
+ msg =
477
+ 'Unexpected response from batchUploadManifestBlox: ' +
478
+ JSON.stringify(res);
479
+ }
480
+ } else {
481
+ status = false;
482
+ msg = 'hash is not returned';
483
+ }
484
+ } else {
485
+ status = false;
486
+ msg = 'No recent Cids found';
487
+ }
488
+ } catch (e: any) {
489
+ console.log('res failed');
490
+ console.log(e);
491
+ let errorMessage = '';
492
+
493
+ if (e instanceof Error) {
494
+ // If it's an Error instance, use the message property
495
+ errorMessage = e.message;
496
+ } else {
497
+ // If it's not an Error instance, convert it to string
498
+ errorMessage = e.toString();
499
+ }
500
+ status = false;
501
+ msg = errorMessage;
502
+ }
503
+
424
504
  // Return a value (true/false) depending on the outcome of the function
425
505
  // For example:
426
506
  return { status: status, msg: msg }; // or false, depending on your logic
@@ -144,3 +144,28 @@ export const getFolderSize = (
144
144
  });
145
145
  return res;
146
146
  };
147
+
148
+ export const getDatastoreSize = (): Promise<BType.GetDatastoreSizeResponse> => {
149
+ console.log('getDatastoreSize in react-native started');
150
+ let res = Fula.getDatastoreSize()
151
+ .then((res1) => {
152
+ try {
153
+ console.log('res1 received');
154
+ console.log(res1);
155
+ let jsonRes: BType.GetDatastoreSizeResponse = JSON.parse(res1);
156
+ return jsonRes;
157
+ } catch (e) {
158
+ try {
159
+ return JSON.parse(res1);
160
+ } catch (e1) {
161
+ console.error('Error parsing res in getDatastoreSize:', e1);
162
+ throw e1; // Rethrow the error to maintain the rejection state
163
+ }
164
+ }
165
+ })
166
+ .catch((err) => {
167
+ console.error('Error getDatastoreSize:', err);
168
+ throw err; // Rethrow the error to maintain the rejection state
169
+ });
170
+ return res;
171
+ };
@@ -9,9 +9,9 @@ export interface AccountExistsResponse {
9
9
  }
10
10
 
11
11
  export interface AccountFundResponse {
12
- from: string;
13
- to: string;
14
- amount: string;
12
+ from: string;
13
+ to: string;
14
+ amount: string;
15
15
  }
16
16
 
17
17
  export interface PoolCreateResponse {
@@ -67,6 +67,12 @@ export interface ManifestUploadResponse {
67
67
  poolID: number;
68
68
  }
69
69
 
70
+ export interface ManifestBatchUploadResponse {
71
+ storer: string;
72
+ cid: string[];
73
+ pool_id: number;
74
+ }
75
+
70
76
  export interface PoolRequest {
71
77
  poolID: number;
72
78
  account: string;
@@ -25,3 +25,11 @@ export interface GetFolderPathResponse {
25
25
  folder_path: string;
26
26
  size: string;
27
27
  }
28
+
29
+ export interface GetDatastoreSizeResponse {
30
+ size: string;
31
+ storage_max: string;
32
+ count: string;
33
+ folder_path: string;
34
+ version: string;
35
+ }