-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjuno.certify.ts
More file actions
81 lines (68 loc) · 1.89 KB
/
juno.certify.ts
File metadata and controls
81 lines (68 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { defineRun } from "@junobuild/config";
import type { SatelliteDid } from "@junobuild/ic-client/actor";
import { fromNullable, nonNullish, toNullable } from "@dfinity/utils";
import { Actor, ActorSubclass, HttpAgent } from "@icp-sdk/core/agent";
import {
idlFactorySatellite,
type SatelliteActor,
} from "@junobuild/ic-client/actor";
export const onRun = defineRun(({ mode }) => ({
run: async ({ satelliteId, identity, container }) => {
const agent = await HttpAgent.create({
identity,
host: container,
shouldFetchRootKey: mode === "development",
});
const actor: ActorSubclass<SatelliteActor> = await Actor.createActor(
idlFactorySatellite,
{
agent,
canisterId: satelliteId,
},
);
console.log("Certifying heap assets...");
await certifyChunks({
actor,
cursor: { Heap: { offset: 0n } },
strategy: { Clear: null },
});
console.log("Heap done.");
console.log("Certifying stable assets...");
await certifyChunks({
actor,
cursor: { Stable: { key: [] } },
strategy: { AppendWithRouting: null },
});
console.log("Stable done.");
},
}));
const certifyChunks = async ({
actor,
cursor,
strategy,
appendStrategy = { AppendWithRouting: null },
chunk = 0,
}: {
actor: SatelliteActor;
cursor: SatelliteDid.CertifyAssetsCursor;
strategy: SatelliteDid.CertifyAssetsStrategy;
appendStrategy?: SatelliteDid.CertifyAssetsStrategy;
chunk?: number;
}) => {
const { certify_assets_chunk } = actor;
console.log(` Chunk ${chunk}...`);
const result = await certify_assets_chunk({
cursor,
chunk_size: toNullable(), // default to 1000
strategy,
});
const next = fromNullable(result.next_cursor);
if (nonNullish(next)) {
await certifyChunks({
actor,
cursor: next,
strategy: appendStrategy,
chunk: chunk + 1,
});
}
};