@functionland/react-native-fula 1.14.7 → 1.19.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 (141) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +226 -214
  3. package/android/build.gradle +110 -110
  4. package/android/gradle.properties +5 -5
  5. package/android/src/main/AndroidManifest.xml +3 -3
  6. package/android/src/main/AndroidManifestNew.xml +2 -2
  7. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  8. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  9. package/android/src/main/java/land/fx/fula/FulaModule.java +1435 -1466
  10. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  11. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  12. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  13. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  14. package/ios/Cryptography.swift +49 -49
  15. package/ios/Fula-Bridging-Header.h +3 -3
  16. package/ios/Fula.mm +197 -199
  17. package/ios/Fula.swift +1221 -1221
  18. package/ios/UserDataHelper.swift +143 -143
  19. package/lib/commonjs/index.js +2 -2
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-errors.js +4 -0
  22. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -0
  23. package/lib/commonjs/interfaces/augment-api-rpc.js +4 -0
  24. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -0
  25. package/lib/commonjs/interfaces/augment-api-runtime.js +4 -0
  26. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -0
  27. package/lib/commonjs/interfaces/augment-api.js +10 -0
  28. package/lib/commonjs/interfaces/augment-api.js.map +1 -0
  29. package/lib/commonjs/interfaces/augment-types.js +4 -0
  30. package/lib/commonjs/interfaces/augment-types.js.map +1 -0
  31. package/lib/commonjs/interfaces/fulaNativeModule.js +1 -2
  32. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  33. package/lib/commonjs/interfaces/index.js +6 -0
  34. package/lib/commonjs/interfaces/index.js.map +1 -0
  35. package/lib/commonjs/interfaces/{api-lookup.js → lookup.js} +623 -382
  36. package/lib/commonjs/interfaces/lookup.js.map +1 -0
  37. package/lib/commonjs/interfaces/registry.js +4 -0
  38. package/lib/commonjs/interfaces/registry.js.map +1 -0
  39. package/lib/commonjs/interfaces/types-lookup.js +4 -0
  40. package/lib/commonjs/interfaces/types-lookup.js.map +1 -0
  41. package/lib/commonjs/interfaces/types.js +4 -0
  42. package/lib/commonjs/interfaces/types.js.map +1 -0
  43. package/lib/commonjs/protocols/blockchain.js +123 -76
  44. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  45. package/lib/commonjs/protocols/chain-api.js +151 -37
  46. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  47. package/lib/commonjs/protocols/fula.js +195 -99
  48. package/lib/commonjs/protocols/fula.js.map +1 -1
  49. package/lib/commonjs/protocols/fxblox.js +3 -3
  50. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  51. package/lib/commonjs/types/blockchain.js.map +1 -1
  52. package/lib/commonjs/types/fxblox.js.map +1 -1
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/interfaces/augment-api-errors.js +9 -0
  55. package/lib/module/interfaces/augment-api-errors.js.map +1 -0
  56. package/lib/module/interfaces/augment-api-rpc.js +9 -0
  57. package/lib/module/interfaces/augment-api-rpc.js.map +1 -0
  58. package/lib/module/interfaces/augment-api-runtime.js +9 -0
  59. package/lib/module/interfaces/augment-api-runtime.js.map +1 -0
  60. package/lib/module/interfaces/augment-api.js +11 -0
  61. package/lib/module/interfaces/augment-api.js.map +1 -0
  62. package/lib/module/interfaces/augment-types.js +9 -0
  63. package/lib/module/interfaces/augment-types.js.map +1 -0
  64. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  65. package/lib/module/interfaces/index.js +5 -0
  66. package/lib/module/interfaces/index.js.map +1 -0
  67. package/lib/module/interfaces/{api-lookup.js → lookup.js} +622 -380
  68. package/lib/module/interfaces/lookup.js.map +1 -0
  69. package/lib/module/interfaces/registry.js +9 -0
  70. package/lib/module/interfaces/registry.js.map +1 -0
  71. package/lib/module/interfaces/types-lookup.js +9 -0
  72. package/lib/module/interfaces/types-lookup.js.map +1 -0
  73. package/lib/module/interfaces/types.js +3 -0
  74. package/lib/module/interfaces/types.js.map +1 -0
  75. package/lib/module/protocols/blockchain.js +120 -75
  76. package/lib/module/protocols/blockchain.js.map +1 -1
  77. package/lib/module/protocols/chain-api.js +142 -31
  78. package/lib/module/protocols/chain-api.js.map +1 -1
  79. package/lib/module/protocols/fula.js +191 -99
  80. package/lib/module/protocols/fula.js.map +1 -1
  81. package/lib/module/protocols/fxblox.js +3 -3
  82. package/lib/module/protocols/fxblox.js.map +1 -1
  83. package/lib/module/types/blockchain.js.map +1 -1
  84. package/lib/module/types/fxblox.js.map +1 -1
  85. package/lib/typescript/interfaces/augment-api-errors.d.ts +442 -0
  86. package/lib/typescript/interfaces/augment-api-errors.d.ts.map +1 -0
  87. package/lib/typescript/interfaces/augment-api-rpc.d.ts +680 -0
  88. package/lib/typescript/interfaces/augment-api-rpc.d.ts.map +1 -0
  89. package/lib/typescript/interfaces/augment-api-runtime.d.ts +248 -0
  90. package/lib/typescript/interfaces/augment-api-runtime.d.ts.map +1 -0
  91. package/lib/typescript/interfaces/augment-api.d.ts +8 -0
  92. package/lib/typescript/interfaces/augment-api.d.ts.map +1 -0
  93. package/lib/typescript/interfaces/augment-types.d.ts +1224 -0
  94. package/lib/typescript/interfaces/augment-types.d.ts.map +1 -0
  95. package/lib/typescript/interfaces/fulaNativeModule.d.ts +7 -3
  96. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
  97. package/lib/typescript/interfaces/index.d.ts +1 -0
  98. package/lib/typescript/interfaces/index.d.ts.map +1 -0
  99. package/lib/typescript/interfaces/{api-lookup.d.ts → lookup.d.ts} +441 -199
  100. package/lib/typescript/interfaces/lookup.d.ts.map +1 -0
  101. package/lib/typescript/interfaces/registry.d.ts +146 -0
  102. package/lib/typescript/interfaces/registry.d.ts.map +1 -0
  103. package/lib/typescript/interfaces/types-lookup.d.ts +1910 -0
  104. package/lib/typescript/interfaces/types-lookup.d.ts.map +1 -0
  105. package/lib/typescript/interfaces/types.d.ts +1 -0
  106. package/lib/typescript/interfaces/types.d.ts.map +1 -0
  107. package/lib/typescript/protocols/blockchain.d.ts +5 -3
  108. package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
  109. package/lib/typescript/protocols/chain-api.d.ts +5 -0
  110. package/lib/typescript/protocols/chain-api.d.ts.map +1 -1
  111. package/lib/typescript/protocols/fula.d.ts +16 -0
  112. package/lib/typescript/protocols/fula.d.ts.map +1 -1
  113. package/lib/typescript/types/blockchain.d.ts +6 -0
  114. package/lib/typescript/types/blockchain.d.ts.map +1 -1
  115. package/package.json +178 -172
  116. package/react-native-fula.podspec +47 -47
  117. package/src/index.tsx +4 -4
  118. package/src/interfaces/augment-api-errors.ts +449 -0
  119. package/src/interfaces/augment-api-rpc.ts +617 -0
  120. package/src/interfaces/augment-api-runtime.ts +224 -0
  121. package/src/interfaces/augment-api.ts +10 -0
  122. package/src/interfaces/augment-types.ts +1230 -0
  123. package/src/interfaces/fulaNativeModule.ts +130 -122
  124. package/src/interfaces/index.ts +4 -0
  125. package/src/interfaces/{api-lookup.ts → lookup.ts} +1889 -1647
  126. package/src/interfaces/registry.ts +152 -0
  127. package/src/interfaces/types-lookup.ts +2043 -0
  128. package/src/interfaces/types.ts +3 -0
  129. package/src/protocols/blockchain.ts +549 -504
  130. package/src/protocols/chain-api.ts +148 -24
  131. package/src/protocols/fula.ts +419 -314
  132. package/src/protocols/fxblox.ts +49 -49
  133. package/src/types/blockchain.ts +89 -81
  134. package/src/types/fxblox.ts +8 -8
  135. package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  136. package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  137. package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  138. package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  139. package/lib/commonjs/interfaces/api-lookup.js.map +0 -1
  140. package/lib/module/interfaces/api-lookup.js.map +0 -1
  141. package/lib/typescript/interfaces/api-lookup.d.ts.map +0 -1
@@ -1,7 +1,8 @@
1
- import { default as EventTypes } from '../interfaces/api-lookup';
1
+ import { default as EventTypes } from '../interfaces/lookup';
2
2
 
3
3
  import { ApiPromise, WsProvider } from '@polkadot/api';
4
- //import { Keyring } from '@polkadot/keyring';
4
+ import { Keyring } from '@polkadot/keyring';
5
+ const { cryptoWaitReady } = require('@polkadot/util-crypto');
5
6
  import type * as BType from '../types/blockchain';
6
7
 
7
8
  const types = {
@@ -9,7 +10,7 @@ const types = {
9
10
  };
10
11
 
11
12
  export const init = async (
12
- wsAddress: string = 'wss://node3.functionyard.fx.land'
13
+ wsAddress: string = 'wss://node3.functionyard.fula.network'
13
14
  ): Promise<ApiPromise> => {
14
15
  const provider = new WsProvider(wsAddress);
15
16
  const api = await ApiPromise.create({ types, provider }).catch((err) => {
@@ -23,14 +24,68 @@ export const disconnectApi = async (api: ApiPromise): Promise<void> => {
23
24
  await api.disconnect();
24
25
  };
25
26
 
27
+ /*function addDoubleSlashToSeed(seed: string): string {
28
+ return seed.startsWith('//') ? seed : '//' + seed;
29
+ }*/
30
+
26
31
  /*
27
- createAccount: This function takes a seed and returns am account
32
+ createManifest: This function batch uploads manifests
28
33
  */
29
- /*export const uploadManifest = async (
34
+ function serialize(obj: any): string {
35
+ return JSON.stringify(obj);
36
+ }
37
+
38
+ function createManifest(
39
+ cids: string[],
40
+ poolId: number,
41
+ replicationFactor: number = 4
42
+ ): {
43
+ manifest: string[]; // or string[]
44
+ cids: string[]; // or string[]
45
+ poolId: number[];
46
+ replicationFactor: number[];
47
+ } {
48
+ const manifest_metadata = cids.map((cid) => ({
49
+ job: {
50
+ work: 'Storage',
51
+ engine: 'IPFS',
52
+ uri: cid,
53
+ },
54
+ }));
55
+
56
+ // Serialize manifest_metadata to Uint8Array or string
57
+ const serializedManifest = manifest_metadata.map((item) => serialize(item)); // Implement `serialize` accordingly
58
+
59
+ // Serialize cids to Uint8Array or string
60
+ const serializedCids = cids.map((cid) => serialize(cid)); // Implement `serialize` accordingly
61
+
62
+ // Create arrays for `poolId` and `replicationFactor`
63
+ const poolIds = new Array(cids.length).fill(poolId);
64
+ const replicationFactors = new Array(cids.length).fill(replicationFactor);
65
+
66
+ const batchUploadManifest = {
67
+ manifest: serializedManifest,
68
+ cids: serializedCids,
69
+ poolId: poolIds,
70
+ replicationFactor: replicationFactors,
71
+ };
72
+
73
+ return batchUploadManifest;
74
+ }
75
+
76
+ export const batchUploadManifest = async (
30
77
  api: ApiPromise | undefined,
31
78
  seed: string,
32
- manifest: typeof EventTypes.FunctionlandFulaCall._enum.upload_manifest
33
- ): Promise<BType.ManifestUploadResponse> => {
79
+ cids_i: string[],
80
+ poolId_i: number,
81
+ replicationFactor_i: number = 4
82
+ ): Promise<{ hash: string }> => {
83
+ const { manifest, cids, poolId, replicationFactor } = createManifest(
84
+ cids_i,
85
+ poolId_i,
86
+ replicationFactor_i
87
+ );
88
+
34
89
  console.log('uploadManifest in react-native started');
35
90
  try {
36
91
  if (api === undefined) {
@@ -39,27 +94,51 @@ export const disconnectApi = async (api: ApiPromise): Promise<void> => {
39
94
 
40
95
  // Simple transaction
41
96
  const keyring = new Keyring({ type: 'sr25519' });
42
- const userKey = keyring.addFromUri(seed, { name: 'account' });
97
+ const userKey = keyring.addFromUri(seed, { name: 'account' }, 'sr25519');
43
98
  console.log(
44
99
  `${userKey.meta.name}: has address ${userKey.address} with publicKey [${userKey.publicKey}]`
45
100
  );
46
- const submitExtrinsic = await api.tx.manifest.upload(manifest);
47
- const unsub = await submitExtrinsic
48
- .signAndSend(userKey, ({ status, events }) => {
49
- if (status.isInBlock || status.isFinalized) {
50
- console.log(events);
51
- unsub();
52
- return Promise.resolve({ success: true });
53
- }
54
- })
55
- .catch((error) => {
56
- console.log(':( transaction failed', error);
57
- return Promise.reject(error);
58
- });
101
+ if (api?.tx?.fula?.batchUploadManifest) {
102
+ const submitExtrinsic = api.tx.fula.batchUploadManifest(
103
+ manifest,
104
+ cids,
105
+ poolId,
106
+ replicationFactor
107
+ );
108
+ let unsub: () => void; // Define a variable to hold the unsub function
109
+
110
+ if (submitExtrinsic) {
111
+ return new Promise<{ hash: string }>((resolve, reject) => {
112
+ submitExtrinsic
113
+ .signAndSend(userKey, ({ status }) => {
114
+ if (status.isInBlock || status.isFinalized) {
115
+ if (unsub) {
116
+ unsub(); // Call unsub before resolving the promise
117
+ }
118
+ resolve({ hash: status.asInBlock.toString() });
119
+ }
120
+ })
121
+ .then((unsubFn) => {
122
+ unsub = unsubFn; // Store the unsub function once it becomes available
123
+ })
124
+ .catch((error) => {
125
+ if (unsub) {
126
+ unsub(); // Call unsub before rejecting the promise
127
+ }
128
+ console.log(':( transaction failed', error);
129
+ reject(error);
130
+ });
131
+ });
132
+ } else {
133
+ return Promise.reject(new TypeError('submitExtrinsic not constructed'));
134
+ }
135
+ } else {
136
+ return Promise.reject(new TypeError('api not initialized'));
137
+ }
59
138
  } catch (err) {
60
139
  return Promise.reject(err);
61
140
  }
62
- };*/
141
+ };
63
142
 
64
143
  /*
65
144
  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
@@ -75,7 +154,7 @@ export const listPools = async (
75
154
  api = await init();
76
155
  }
77
156
  // Type guard to assure TypeScript that api is not undefined
78
- if (!api || !api.query || !api.query.pool || !api.query.pool.lastPoolId || !api.query.pool.pools) {
157
+ if (!api?.query?.pool?.lastPoolId || !api?.query?.pool?.pools) {
79
158
  throw new Error('Failed to initialize api or api.query.pool');
80
159
  }
81
160
  const pools: BType.PoolListResponse = { pools: [] };
@@ -116,7 +195,7 @@ export const checkJoinRequest = async (
116
195
  api = await init();
117
196
  }
118
197
  // Type guard to assure TypeScript that api is not undefined
119
- if (!api || !api.query || !api.query.pool || !api.query.pool.poolRequests) {
198
+ if (!api?.query?.pool?.poolRequests) {
120
199
  throw new Error('Failed to initialize api or api.query.pool');
121
200
  }
122
201
 
@@ -133,3 +212,48 @@ export const checkJoinRequest = async (
133
212
  return Promise.reject(err);
134
213
  }
135
214
  };
215
+
216
+ function isAccountInfo(obj: any): obj is { data: { free: any } } {
217
+ return 'data' in obj && 'free' in obj.data;
218
+ }
219
+ /*
220
+ checkAccountExsists: This function takes accountId and checks if the account exists
221
+ */
222
+ export const checkAccountBalance = async (
223
+ api: ApiPromise | undefined,
224
+ accountId: string
225
+ ): Promise<string> => {
226
+ console.log('checkAcocuntExsists in react-native started');
227
+ try {
228
+ if (api === undefined) {
229
+ api = await init();
230
+ }
231
+ // Type guard to assure TypeScript that api is not undefined
232
+ if (!api?.query?.system?.account) {
233
+ throw new Error('Failed to initialize api or api.query.account');
234
+ }
235
+ let balance: any;
236
+ let accountInfo = await api.query.system.account(accountId);
237
+ if (isAccountInfo(accountInfo)) {
238
+ balance = accountInfo.data.free;
239
+ }
240
+
241
+ if (balance && balance !== '0' && balance > 0) {
242
+ return Promise.resolve(balance.toHuman());
243
+ }
244
+ return Promise.resolve('0');
245
+ } catch (err) {
246
+ return Promise.reject(err);
247
+ }
248
+ };
249
+
250
+ export const getAccountIdFromSeed = async (seed: string): Promise<string> => {
251
+ try {
252
+ await cryptoWaitReady();
253
+ const keyring = new Keyring({ type: 'sr25519' });
254
+ const account = keyring.addFromUri(seed, { name: 'account' }, 'sr25519');
255
+ return Promise.resolve(account.address);
256
+ } catch (err) {
257
+ return Promise.reject(err);
258
+ }
259
+ };