-
Notifications
You must be signed in to change notification settings - Fork 7
/
instantiate_tournaments.js
94 lines (82 loc) · 3.7 KB
/
instantiate_tournaments.js
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
/**
* Truffle script to create new tornaments.
*
* Usage:
* truffle exec <script> --network <network> --level <level> --commit-duration <duration>
*/
const contract = require("@truffle/contract");
const program = require("commander");
const MatchManagerInstantiator = contract(require("@cartesi/tournament/build/contracts/MatchManagerInstantiator.json"));
const RevealInstantiator = contract(require("@cartesi/tournament/build/contracts/RevealInstantiator.json"));
const Step = contract(require("@cartesi/machine-solidity-step/build/contracts/Step.json"));
const DApp = contract(require("./build/contracts/DApp.json"));
program
.option('-n, --network <network>', 'Specify the network to use, using artifacts specific to that network. Network name must exist in the configuration')
.option('-c, --compile', 'Compile contracts before executing the script')
.option('-l, --level <level>', 'Level number [0-7]', 0)
.option('-a, --account <account>', 'Account sender of transaction')
.option('--commit-duration <duration>', 'Duration in seconds of commit phase', 200)
.option('--reveal-duration <duration>', 'Duration in seconds of reveal phase', 200)
.option('--round-duration <duration>', 'Duration in seconds of round phase', 45);
module.exports = async (callback) => {
program.parse(process.argv);
console.log(`Creating tournament for level ${program.level} with commit duration of ${program.commitDuration} seconds`);
try {
const networkId = await web3.eth.net.getId();
let fromAddress = undefined;
if (program.account) {
fromAddress = program.account;
} else {
const accounts = await web3.eth.personal.getAccounts();
fromAddress = accounts[0];
}
const contracts = [
MatchManagerInstantiator,
RevealInstantiator,
Step,
DApp
];
contracts.forEach(contract => {
contract.setNetwork(networkId);
contract.setProvider(web3.currentProvider);
console.log(`${contract.contract_name} => ${contract.address}`);
});
const commitDuration = program.commitDuration;
const revealDuration = program.revealDuration;
const roundDuration = program.roundDuration;
const scoreDriveLogSize = 3;
const logDriveLogSize = 20;
const finalTime = 1e13;
const setupHashes = [
"0x375fb938dcff562818779bc0dc4689a713a61d89659c8a9274a53551c7bc464c",
"0xb58562a821fd887ee508da7bc0926ce75a461ebd45d35c8e1ed7caa906559e5c",
"0x5dde12fc07c72c146848be21c85c13071630b59c8dc915d46e0f4528eaf45111",
"0x37edf1fda365aa316374aed600b4bc7b981ab9cb7952b6f0e68bb362f93abd0d",
"0xefe6f44a51e45045e50dcb1fcd1388a550b822ad9b2bdf4ccef01292720c02c4",
"0x1e9b8a93e65a51509dcab1c1444d0fc7deb14589972bf58ca6708a56aca0ef3b",
"0x2098fbf4c6a46e0586a55def8229f8ef5c5972c6032fcb344f9b434be4e5a4a7",
"0x872f44b8a31938ceacfbd7d537de344fc0a5657a26b8e15276324a1d73cd420b"
];
const dapp = await DApp.deployed();
const hash = setupHashes[program.level];
const transaction = await dapp.instantiate(
RevealInstantiator.address,
MatchManagerInstantiator.address,
commitDuration,
revealDuration,
scoreDriveLogSize,
logDriveLogSize,
hash,
program.level,
roundDuration,
finalTime,
Step.address,
{ from: fromAddress }
);
console.log(`Tournament created: ${transaction.tx}`);
callback();
} catch (e) {
console.error(e);
callback(e);
}
};