Skip to content

Commit 3ca633b

Browse files
committed
Corrected the manifest upload
1 parent b275de2 commit 3ca633b

File tree

5 files changed

+1392
-1357
lines changed

5 files changed

+1392
-1357
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ const App = () => {
655655
if (api && initComplete) {
656656
console.log('replicate');
657657
fula
658-
.replicateRecentCids(api, seed, 3)
658+
.replicateRecentCids(api, seed, 1, 6)
659659
.then((res: any) => {
660660
console.log('res received');
661661
console.log(res);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
"@polkadot/keyring": "^10.2.6",
173173
"@polkadot/typegen": "^10.10.1",
174174
"@polkadot/util": "^10.2.6",
175-
"@polkadot/util-crypto": "^10.2.6"
175+
"@polkadot/util-crypto": "^10.2.6",
176+
"text-encoding": "^0.7.0"
176177
}
177178
}

src/protocols/chain-api.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
44
import { Keyring } from '@polkadot/keyring';
55
const { cryptoWaitReady } = require('@polkadot/util-crypto');
66
import type * as BType from '../types/blockchain';
7+
import { TextEncoder } from 'text-encoding';
78

89
const types = {
910
FulaPoolPool: EventTypes.FulaPoolPool,
@@ -31,13 +32,17 @@ function addDoubleSlashToSeed(seed: string): string {
3132
/*
3233
createManifest: This function batch uploads manifests
3334
*/
35+
function serialize(obj: any): string {
36+
return JSON.stringify(obj);
37+
}
38+
3439
function createManifest(
3540
cids: string[],
3641
poolId: number,
3742
replicationFactor: number = 4
3843
): {
39-
manifest: any[];
40-
cids: string[];
44+
manifest: string[]; // or string[]
45+
cids: string[]; // or string[]
4146
poolId: number[];
4247
replicationFactor: number[];
4348
} {
@@ -49,19 +54,27 @@ function createManifest(
4954
},
5055
}));
5156

52-
// Create arrays filled with `poolId` and `replicationFactor`, one element for each `cid`
57+
// Serialize manifest_metadata to Uint8Array or string
58+
const serializedManifest = manifest_metadata.map((item) => serialize(item)); // Implement `serialize` accordingly
59+
60+
// Serialize cids to Uint8Array or string
61+
const serializedCids = cids.map((cid) => serialize(cid)); // Implement `serialize` accordingly
62+
63+
// Create arrays for `poolId` and `replicationFactor`
5364
const poolIds = new Array(cids.length).fill(poolId);
5465
const replicationFactors = new Array(cids.length).fill(replicationFactor);
5566

5667
const batchUploadManifest = {
57-
manifest: manifest_metadata,
58-
cids: cids,
68+
manifest: serializedManifest,
69+
cids: serializedCids,
5970
poolId: poolIds,
6071
replicationFactor: replicationFactors,
6172
};
6273

6374
return batchUploadManifest;
6475
}
76+
77+
6578
export const batchUploadManifest = async (
6679
api: ApiPromise | undefined,
6780
seed: string,

src/protocols/fula.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
340340
export const replicateRecentCids = async (
341341
api: ApiPromise,
342342
seed: string,
343+
poolId: number,
343344
replicationNo: number = 4
344345
): Promise<{ status: boolean; msg: string }> => {
345346
let status = true;
@@ -351,22 +352,34 @@ export const replicateRecentCids = async (
351352
console.log('uploading manifests');
352353
try {
353354
let account = await getAccountIdFromSeed(seed);
355+
console.log('account: ' + account);
354356
const accountBal = await checkAccountBalance(api, account);
357+
console.log('account balance: ' + accountBal);
355358
if (accountBal !== '0') {
356359
const recentCids = await listRecentCidsAsString();
360+
console.log(recentCids);
357361
if (recentCids) {
362+
console.log({
363+
api,
364+
seed,
365+
recentCids,
366+
poolId,
367+
replicationNo,
368+
});
358369
const res = await batchUploadManifest(
359370
api,
360371
seed,
361372
recentCids,
373+
poolId,
362374
replicationNo
363375
);
364-
console.log('res received');
376+
console.log('batchUploadManifest res received');
365377
console.log(res);
366378
if (res && res.hash) {
367379
const signedBlock = await api.rpc.chain.getBlock(res.hash);
368380
if (signedBlock?.block?.extrinsics?.length) {
369381
await clearCidsFromRecent(recentCids);
382+
msg = res.hash;
370383
} else {
371384
status = false;
372385
msg = 'block data is not found';
@@ -375,6 +388,9 @@ export const replicateRecentCids = async (
375388
status = false;
376389
msg = 'hash is not returned';
377390
}
391+
} else {
392+
status = false;
393+
msg = 'No recent Cids found';
378394
}
379395
} else {
380396
status = false;

0 commit comments

Comments
 (0)