-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneration-vote-quorum.js
More file actions
281 lines (231 loc) · 10.7 KB
/
generation-vote-quorum.js
File metadata and controls
281 lines (231 loc) · 10.7 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
const fs = require('fs')
const Wallet = require('ethereumjs-wallet')
const EthereumTx = require('ethereumjs-tx').Transaction
const Common = require('ethereumjs-common')
const w3 = require("web3")
const readline = require('readline')
// Sample params, can change to do with arguments
//const web3 = new w3(new w3.providers.HttpProvider("http://127.0.0.1:8545"))
const web3 = new w3(new w3.providers.WebsocketProvider("ws://127.0.0.1:8546"))
function shuffle(array) {
var i = array.length,
j = 0,
temp;
while (i--) {
j = Math.floor(Math.random() * (i+1));
// swap randomly chosen element with current element
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
async function send(){
const NUMTX = 1000
//const destinationAcccount = "0xBce16ea55bB357B038e612b1722A88879c665a31"
const startBalance = "0xfffc3b15f9926687d2c40534fdb564000000000000"
var abiArray = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"invoke","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes[]","name":"","type":"bytes[]"}],"name":"notify","type":"event"},{"inputs":[{"internalType":"uint256","name":"votes","type":"uint256"},{"internalType":"uint256","name":"members","type":"uint256"}],"name":"addIp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"chairperson","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"candidates","type":"bytes[]"}],"name":"createCommittee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"selected","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"}]
//[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes[]","name":"","type":"bytes[]"}],"name":"notify","type":"event"},{"inputs":[{"internalType":"bytes[]","name":"ip","type":"bytes[]"},{"internalType":"uint256","name":"members","type":"uint256"},{"internalType":"address[]","name":"wallets","type":"address[]"}],"name":"addIp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"chairperson","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"candidates","type":"bytes[]"}],"name":"createCommittee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"selected","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"}]
//[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"name":"notify","type":"event"},{"inputs":[{"internalType":"bytes32[]","name":"ip","type":"bytes32[]"},{"internalType":"uint256","name":"members","type":"uint256"},{"internalType":"address[]","name":"wallets","type":"address[]"}],"name":"addIp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"chairperson","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"candidates","type":"bytes32[]"}],"name":"createCommittee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"selected","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"}]
//var CONTRACTDATA = '0x608060405234801561001057600080fd5b50610115806100206000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063bcdfe0d514604e578063e21f37ce14607e575b600080fd5b348015605957600080fd5b50606060ae565b60405180826000191660001916815260200191505060405180910390f35b348015608957600080fd5b50609060e3565b60405180826000191660001916815260200191505060405180910390f35b60007f48656c6c6f20576f726c6400000000000000000000000000000000000000000060008160001916905550600054905090565b600054815600a165627a7a72305820b0a2937f6533d228be0d96647486f95ce839a6f35d9625a73696ae2b9d2dd58b0029'
let rawdata = fs.readFileSync('Votes.json');
let data = JSON.parse(rawdata);
vote=[]
vote1=[]
vote2=[]
vote3=[]
votes=[]
myvote=[]
//remove duplicates from the array
for(val=0; val<1000; val++){
myvote.push(web3.utils.asciiToHex(data[0][val]))
}
/*uniquemyvote = myvote.filter(function(elem, pos) {
return myArray.indexOf(elem) == pos;
})*/
var uSet = new Set(myvote);
uniquemyvote=[...uSet];
console.log("the unique vote length is:", uniquemyvote.length)
for(let i=0; i<125;i++){
vote.push(uniquemyvote[i])
}
for(let i=125; i<250;i++){
vote1.push(uniquemyvote[i])
}
for(let i=250; i<375;i++){
vote2.push(uniquemyvote[i])
}
for(let i=375; i<500;i++){
vote3.push(uniquemyvote[i])
}
//console.log("added to vote arrays")
voteAdd=[]
for(let j=0; j<250;j++){
//for(let i=0; i<125;i++){
// votes.push(data[j])
// vote.push(web3.utils.asciiToHex(data[j][i]))
//voteAdd.push(shuffle(vote)) //create random vote from first 125
//}
votes.push(shuffle(vote))
//voteAdd=[]
}
for(let j=0; j<250;j++){
//for(let i=0; i<125;i++){
// votes.push(data[j])
// vote.push(web3.utils.asciiToHex(data[j][i]))
//voteAdd.push(shuffle(vote1)) //create random vote from first 125
//}
votes.push(shuffle(vote1))
//voteAdd=[]
}
for(let j=0; j<250;j++){
//for(let i=0; i<125;i++){
// votes.push(data[j])
// vote.push(web3.utils.asciiToHex(data[j][i]))
// voteAdd.push(shuffle(vote2)) //create random vote from first 125
//}
votes.push(shuffle(vote2))
//voteAdd=[]
}
for(let j=0; j<250;j++){
//for(let i=0; i<125;i++){
// votes.push(data[j])
// vote.push(web3.utils.asciiToHex(data[j][i]))
// voteAdd.push(shuffle(vote3)) //create random vote from first 125
//}
votes.push(shuffle(vote3))
//voteAdd=[]
}
//console.log("worked")
//vote= [];
//votes=[];
/*for(let j=0; j<1000;j++){
for(let i=0; i<125;i++){
// votes.push(data[j])
vote.push(web3.utils.asciiToHex(data[j][i]))
}
votes.push(vote)
vote=[]
}*/
/*for(let j=0; j<10;j++){
for(let i=0; i<10;i++){
// votes.push(data[j])
vote.push(web3.utils.asciiToHex(data[j][i]))
}
votes.push(vote)
vote=[]
}*/
//console.log(voters);
console.log(votes)
var address
var temp
//console.log(contractAddress)
var contractAddress='0x2D45727A40FDa2AC9Fa6460AA2abA9791000959B'
var MyContract = new web3.eth.Contract(abiArray, contractAddress)
contractDatas=[]
for(let k=0; k<1000;k++){
//var DATA= await MyContract.methods.addIp(voters, committeesize, wallets)
var DATA = await MyContract.methods.createCommittee(votes[k])
var CONTRACTDATA = DATA.encodeABI()
contractDatas.push(CONTRACTDATA)
}
console.log('works')
//var DATA = await MyContract.methods.createCommittee(['0x3139322e3136382e322e313135', '0x3139322e3136382e322e313839', '0x3139322e3136382e342e3436', '0x3139322e3136382e322e3830', '0x3139322e3136382e312e323534', '0x3139322e3136382e312e313630', '0x3139322e3136382e322e313536', '0x3139322e3136382e332e3430', '0x3139322e3136382e342e313030', '0x3139322e3136382e332e313439', '0x3139322e3136382e332e3634'])
//var CONTRACTDATA = DATA.encodeABI()
//console.log("reached here");
let rawTransactions = []
let allocDict = {}
// helper function
let getGenesisTemplate = () => {
return JSON.parse(fs.readFileSync('./genesis_template.json'))
}
const customCommon = Common.default.forCustomChain(
'mainnet',
{
name: 'custom-benchmark-chain',
networkId: 10,
chainId: 161,
},
'petersburg'
)
//});
me=[]
const data1 = fs.readFileSync('new.log', 'UTF-8');
const lines1 = data1.split(/\r?\n/);
lines1.forEach((address) => {
//console.log(address)
me.push(address)
});
//});
var privkey = fs.readFileSync('priv-keys.log').toString().split("\n");
//console.log(privkey[0])
console.log("[*] Generating " + NUMTX + " transactions and accounts")
let gas = 0
for (let i = 1; i < NUMTX; i++) {
//gas = gas + 0xff184e72a;
const txParams = {
nonce: '0x00',
gasPrice: '0x00',
gasLimit: '0xffffffffff',
to: '0x2D45727A40FDa2AC9Fa6460AA2abA9791000959B',
data: contractDatas[i],
value: '0x0',
chainId: 161
}
let newTx = {...txParams}
// addresses taken from new.log
newTx["from"] = me[i]
// generate the transaction and sign it
let tx = new EthereumTx(txParams, {common: customCommon})
// sign using the private keys of the generated accounts (remove 0x from the priv key file)
var privateKey = Buffer.from(privkey[i], 'hex')
tx.sign(privateKey)
rawTransactions.push(
{
'hash': tx.hash().toString('hex'),
'serialized': (tx.serialize()).toString('hex')
}
)
}
///////////////////////////////////////////////second set of 1000 txs
/*for (let i = 1; i < NUMTX; i++) {
gas = gas + 0xff184e72a;
const txParams = {
nonce: '0x01',
gasPrice: gas,
gasLimit: '0xffffffffff',
to: '0x2D45727A40FDa2AC9Fa6460AA2abA9791000959B',
data: contractDatas[i],
value: '0x0',
chainId: 161
}
let newTx = {...txParams}
// addresses taken from new.log
newTx["from"] = me[i]
// generate the transaction and sign it
let tx = new EthereumTx(txParams, {common: customCommon})
// sign using the private keys of the generated accounts (remove 0x from the priv key file)
var privateKey = Buffer.from(privkey[i], 'hex')
tx.sign(privateKey)
rawTransactions.push(
{
'hash': tx.hash().toString('hex'),
'serialized': (tx.serialize()).toString('hex')
}
)
}*/
/////////////////////////////////////////
console.log('[*] Done!')
//console.log('[*] Done!')
console.log('[*] Generating Transaction file')
b = Buffer.from(JSON.stringify(rawTransactions))
try {
fs.writeFileSync('txs-vote.json', b)
} catch(error) {
console.log(error);
}
console.log('[*] Done! Printing to stdout for sanity')
//console.log(JSON.stringify(genTemplateCopy, null, 4))
//console.log(JSON.stringify(rawTransactions, null, 2))
}
send();