forked from Joystream/community-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget-media-change.ts
More file actions
100 lines (95 loc) · 3.3 KB
/
get-media-change.ts
File metadata and controls
100 lines (95 loc) · 3.3 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { WsProvider, ApiPromise } from "@polkadot/api";
import { types } from "@joystream/types";
import { Vec } from "@polkadot/types";
import { EventRecord, Hash } from "@polkadot/types/interfaces";
import { getChangeAction } from "./functions";
async function main() {
// Initialise the provider to connect to the local node
const provider = new WsProvider("ws://127.0.0.1:9944");
const api = await ApiPromise.create({ provider, types });
const firstBlock = 4191207; // first block after the upgrade to the new Content Directory
const lastBlock = 4551590;
// note that with this blockheight, you will see a lot of jsgenesis initialization and uploads
for (let blockHeight = firstBlock; blockHeight < lastBlock; blockHeight++) {
const blockHash = (await api.rpc.chain.getBlockHash(blockHeight)) as Hash;
try {
const events = (await api.query.system.events.at(
blockHash
)) as Vec<EventRecord>;
const eventsArray: EventRecord[] = [];
let eventIndex = 0;
for (let i = 0; i < events.length; i++) {
const section = events[i].event.section;
const method = events[i].event.method;
if (section == "content") {
console.log(`Event section=${section}, Event method=${method}`);
eventsArray.push(events[i]);
if (method == "VideoCreated") {
eventIndex += 1;
const cdChange = await getChangeAction(
api,
"createVideo",
blockHeight,
blockHash,
eventIndex,
events[i]
);
console.log("Change", JSON.stringify(cdChange, null, 4));
}
if (method == "VideoUpdated") {
eventIndex += 1;
const cdChange = await getChangeAction(
api,
"updateVideo",
blockHeight,
blockHash,
eventIndex,
events[i]
);
console.log("Change", JSON.stringify(cdChange, null, 4));
}
if (method == "VideoDeleted") {
eventIndex += 1;
const cdChange = await getChangeAction(
api,
"deleteVideo",
blockHeight,
blockHash,
eventIndex,
events[i]
);
console.log("Change", JSON.stringify(cdChange, null, 4));
}
if (method == "ChannelCreated") {
eventIndex += 1;
const cdChange = await getChangeAction(
api,
"createChannel",
blockHeight,
blockHash,
eventIndex,
events[i]
);
console.log("Change", JSON.stringify(cdChange, null, 4));
}
if (method == "ChannelUpdated") {
eventIndex += 1;
const cdChange = await getChangeAction(
api,
"updateChannel",
blockHeight,
blockHash,
eventIndex,
events[i]
);
console.log("Change", JSON.stringify(cdChange, null, 4));
}
}
}
}catch (e) {
console.error(`Unable to get events at block: ${blockHeight}`)
}
}
await api.disconnect();
}
main();