Migration script

This commit is contained in:
Richard Ramos 2018-07-12 11:24:40 -04:00
parent f60a12c32c
commit 6f93a335ab
3 changed files with 64 additions and 0 deletions

12
app/migration.html Normal file
View File

@ -0,0 +1,12 @@
<html>
<head>
<title>Status.im - Survey Migration</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app">
<h1>Open the console (F12)</h1>
</div>
<script src="js/migration.js"></script>
</body>
</html>

50
app/migration.js Normal file
View File

@ -0,0 +1,50 @@
import web3 from "Embark/web3"
import EmbarkJS from 'Embark/EmbarkJS';
import PollManager from 'Embark/contracts/PollManager';
EmbarkJS.onReady(async (err) => {
const { nPolls, poll } = PollManager.methods;
console.log("WAIT UNTIL DONE");
console.group("Polls and Votes");
const numPolls = await nPolls().call();
const polls = [];
for (let i = numPolls - 1; i >= 0; i--) {
const p = await poll(i).call();
console.log(`_polls[${i}] = Poll({canceled: ${p._canceled}, description: "${p._description}", startBlock: ${p._startBlock}, endBlock: ${p._endBlock}, qvResults: ${p._qvResults}, results: ${p._results}, voters: ${p._voters}});`);
}
const events = await PollManager.getPastEvents("allEvents", {fromBlock: 5900136, toBlock: "latest"});
let votes = [];
for (let i = 0; i < events.length; i++){
switch(events[i].event){
case 'PollCreated':
votes.push({});
break;
case 'Vote':
votes[events[i].returnValues.idPoll][events[i].returnValues._voter] = events[i].returnValues.amount;
break;
case 'Unvote':
delete votes[events[i].returnValues.idPoll][events[i].returnValues._voter];
break;
}
}
for(let i = 0; i < votes.length; i++){
for(let address in votes[i]){
console.log(`_polls[${i}].votes[${address}] = ${votes[i][address]};`);
}
}
console.groupEnd();
console.log("DONE");
})

View File

@ -2,7 +2,9 @@
"contracts": ["contracts/**"],
"app": {
"js/dapp.js": ["app/dapp.js"],
"js/migration.js": ["app/migration.js"],
"index.html": "app/index.html",
"migration.html": "app/migration.html",
"images/": ["app/images/**"]
},
"buildDir": "dist/",