@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.
- package/LICENSE +20 -20
- package/README.md +226 -214
- package/android/build.gradle +110 -110
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/AndroidManifestNew.xml +2 -2
- package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
- package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
- package/android/src/main/java/land/fx/fula/FulaModule.java +1435 -1466
- package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
- package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
- package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
- package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
- package/ios/Cryptography.swift +49 -49
- package/ios/Fula-Bridging-Header.h +3 -3
- package/ios/Fula.mm +197 -199
- package/ios/Fula.swift +1221 -1221
- package/ios/UserDataHelper.swift +143 -143
- package/lib/commonjs/index.js +2 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-errors.js +4 -0
- package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -0
- package/lib/commonjs/interfaces/augment-api-rpc.js +4 -0
- package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -0
- package/lib/commonjs/interfaces/augment-api-runtime.js +4 -0
- package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -0
- package/lib/commonjs/interfaces/augment-api.js +10 -0
- package/lib/commonjs/interfaces/augment-api.js.map +1 -0
- package/lib/commonjs/interfaces/augment-types.js +4 -0
- package/lib/commonjs/interfaces/augment-types.js.map +1 -0
- package/lib/commonjs/interfaces/fulaNativeModule.js +1 -2
- package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/commonjs/interfaces/index.js +6 -0
- package/lib/commonjs/interfaces/index.js.map +1 -0
- package/lib/commonjs/interfaces/{api-lookup.js → lookup.js} +623 -382
- package/lib/commonjs/interfaces/lookup.js.map +1 -0
- package/lib/commonjs/interfaces/registry.js +4 -0
- package/lib/commonjs/interfaces/registry.js.map +1 -0
- package/lib/commonjs/interfaces/types-lookup.js +4 -0
- package/lib/commonjs/interfaces/types-lookup.js.map +1 -0
- package/lib/commonjs/interfaces/types.js +4 -0
- package/lib/commonjs/interfaces/types.js.map +1 -0
- package/lib/commonjs/protocols/blockchain.js +123 -76
- package/lib/commonjs/protocols/blockchain.js.map +1 -1
- package/lib/commonjs/protocols/chain-api.js +151 -37
- package/lib/commonjs/protocols/chain-api.js.map +1 -1
- package/lib/commonjs/protocols/fula.js +195 -99
- package/lib/commonjs/protocols/fula.js.map +1 -1
- package/lib/commonjs/protocols/fxblox.js +3 -3
- package/lib/commonjs/protocols/fxblox.js.map +1 -1
- package/lib/commonjs/types/blockchain.js.map +1 -1
- package/lib/commonjs/types/fxblox.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/interfaces/augment-api-errors.js +9 -0
- package/lib/module/interfaces/augment-api-errors.js.map +1 -0
- package/lib/module/interfaces/augment-api-rpc.js +9 -0
- package/lib/module/interfaces/augment-api-rpc.js.map +1 -0
- package/lib/module/interfaces/augment-api-runtime.js +9 -0
- package/lib/module/interfaces/augment-api-runtime.js.map +1 -0
- package/lib/module/interfaces/augment-api.js +11 -0
- package/lib/module/interfaces/augment-api.js.map +1 -0
- package/lib/module/interfaces/augment-types.js +9 -0
- package/lib/module/interfaces/augment-types.js.map +1 -0
- package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/module/interfaces/index.js +5 -0
- package/lib/module/interfaces/index.js.map +1 -0
- package/lib/module/interfaces/{api-lookup.js → lookup.js} +622 -380
- package/lib/module/interfaces/lookup.js.map +1 -0
- package/lib/module/interfaces/registry.js +9 -0
- package/lib/module/interfaces/registry.js.map +1 -0
- package/lib/module/interfaces/types-lookup.js +9 -0
- package/lib/module/interfaces/types-lookup.js.map +1 -0
- package/lib/module/interfaces/types.js +3 -0
- package/lib/module/interfaces/types.js.map +1 -0
- package/lib/module/protocols/blockchain.js +120 -75
- package/lib/module/protocols/blockchain.js.map +1 -1
- package/lib/module/protocols/chain-api.js +142 -31
- package/lib/module/protocols/chain-api.js.map +1 -1
- package/lib/module/protocols/fula.js +191 -99
- package/lib/module/protocols/fula.js.map +1 -1
- package/lib/module/protocols/fxblox.js +3 -3
- package/lib/module/protocols/fxblox.js.map +1 -1
- package/lib/module/types/blockchain.js.map +1 -1
- package/lib/module/types/fxblox.js.map +1 -1
- package/lib/typescript/interfaces/augment-api-errors.d.ts +442 -0
- package/lib/typescript/interfaces/augment-api-errors.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-api-rpc.d.ts +680 -0
- package/lib/typescript/interfaces/augment-api-rpc.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-api-runtime.d.ts +248 -0
- package/lib/typescript/interfaces/augment-api-runtime.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-api.d.ts +8 -0
- package/lib/typescript/interfaces/augment-api.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-types.d.ts +1224 -0
- package/lib/typescript/interfaces/augment-types.d.ts.map +1 -0
- package/lib/typescript/interfaces/fulaNativeModule.d.ts +7 -3
- package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
- package/lib/typescript/interfaces/index.d.ts +1 -0
- package/lib/typescript/interfaces/index.d.ts.map +1 -0
- package/lib/typescript/interfaces/{api-lookup.d.ts → lookup.d.ts} +441 -199
- package/lib/typescript/interfaces/lookup.d.ts.map +1 -0
- package/lib/typescript/interfaces/registry.d.ts +146 -0
- package/lib/typescript/interfaces/registry.d.ts.map +1 -0
- package/lib/typescript/interfaces/types-lookup.d.ts +1910 -0
- package/lib/typescript/interfaces/types-lookup.d.ts.map +1 -0
- package/lib/typescript/interfaces/types.d.ts +1 -0
- package/lib/typescript/interfaces/types.d.ts.map +1 -0
- package/lib/typescript/protocols/blockchain.d.ts +5 -3
- package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
- package/lib/typescript/protocols/chain-api.d.ts +5 -0
- package/lib/typescript/protocols/chain-api.d.ts.map +1 -1
- package/lib/typescript/protocols/fula.d.ts +16 -0
- package/lib/typescript/protocols/fula.d.ts.map +1 -1
- package/lib/typescript/types/blockchain.d.ts +6 -0
- package/lib/typescript/types/blockchain.d.ts.map +1 -1
- package/package.json +178 -172
- package/react-native-fula.podspec +47 -47
- package/src/index.tsx +4 -4
- package/src/interfaces/augment-api-errors.ts +449 -0
- package/src/interfaces/augment-api-rpc.ts +617 -0
- package/src/interfaces/augment-api-runtime.ts +224 -0
- package/src/interfaces/augment-api.ts +10 -0
- package/src/interfaces/augment-types.ts +1230 -0
- package/src/interfaces/fulaNativeModule.ts +130 -122
- package/src/interfaces/index.ts +4 -0
- package/src/interfaces/{api-lookup.ts → lookup.ts} +1889 -1647
- package/src/interfaces/registry.ts +152 -0
- package/src/interfaces/types-lookup.ts +2043 -0
- package/src/interfaces/types.ts +3 -0
- package/src/protocols/blockchain.ts +549 -504
- package/src/protocols/chain-api.ts +148 -24
- package/src/protocols/fula.ts +419 -314
- package/src/protocols/fxblox.ts +49 -49
- package/src/types/blockchain.ts +89 -81
- package/src/types/fxblox.ts +8 -8
- package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/lib/commonjs/interfaces/api-lookup.js.map +0 -1
- package/lib/module/interfaces/api-lookup.js.map +0 -1
- package/lib/typescript/interfaces/api-lookup.d.ts.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { default as EventTypes } from '../interfaces/
|
|
1
|
+
import { default as EventTypes } from '../interfaces/lookup';
|
|
2
2
|
|
|
3
3
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
4
|
-
|
|
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.
|
|
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
|
-
|
|
32
|
+
createManifest: This function batch uploads manifests
|
|
28
33
|
*/
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
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
|
|
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
|
+
};
|