-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
587 lines (473 loc) · 36.2 KB
/
main.go
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
// loadbot script to generate public address
// this is done by sending(celo) transactions from a single address to different addresses
package main
import (
"context"
"crypto/ecdsa"
"crypto/rand"
"fmt"
"log"
"math/big"
"os"
"path/filepath"
"strconv"
"sync"
"time"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/joho/godotenv"
hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
)
const (
storageContractByteCode = "0x60806040523480156200001157600080fd5b506040518060400160405280600781526020017f4d79546f6b656e000000000000000000000000000000000000000000000000008152506040518060400160405280600381526020017f4d544b000000000000000000000000000000000000000000000000000000000081525081600090816200008f919062000412565b508060019081620000a1919062000412565b505050620000c4620000b8620000ca60201b60201c565b620000d260201b60201c565b620004f9565b600033905090565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200021a57607f821691505b60208210810362000230576200022f620001d2565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026200029a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826200025b565b620002a686836200025b565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620002f3620002ed620002e784620002be565b620002c8565b620002be565b9050919050565b6000819050919050565b6200030f83620002d2565b620003276200031e82620002fa565b84845462000268565b825550505050565b600090565b6200033e6200032f565b6200034b81848462000304565b505050565b5b8181101562000373576200036760008262000334565b60018101905062000351565b5050565b601f821115620003c2576200038c8162000236565b62000397846200024b565b81016020851015620003a7578190505b620003bf620003b6856200024b565b83018262000350565b50505b505050565b600082821c905092915050565b6000620003e760001984600802620003c7565b1980831691505092915050565b6000620004028383620003d4565b9150826002028217905092915050565b6200041d8262000198565b67ffffffffffffffff811115620004395762000438620001a3565b5b62000445825462000201565b6200045282828562000377565b600060209050601f8311600181146200048a576000841562000475578287015190505b620004818582620003f4565b865550620004f1565b601f1984166200049a8662000236565b60005b82811015620004c4578489015182556001820191506020850194506020810190506200049d565b86831015620004e45784890151620004e0601f891682620003d4565b8355505b6001600288020188555050505b505050505050565b61289980620005096000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c806370a08231116100a2578063a22cb46511610071578063a22cb465146102bb578063b88d4fde146102d7578063c87b56dd146102f3578063e985e9c514610323578063f2fde38b1461035357610116565b806370a0823114610245578063715018a6146102755780638da5cb5b1461027f57806395d89b411461029d57610116565b806323b872dd116100e957806323b872dd146101b557806334c73884146101d157806342842e0e146101db57806360081912146101f75780636352211e1461021557610116565b806301ffc9a71461011b57806306fdde031461014b578063081812fc14610169578063095ea7b314610199575b600080fd5b61013560048036038101906101309190611a97565b61036f565b6040516101429190611adf565b60405180910390f35b610153610451565b6040516101609190611b8a565b60405180910390f35b610183600480360381019061017e9190611be2565b6104e3565b6040516101909190611c50565b60405180910390f35b6101b360048036038101906101ae9190611c97565b610529565b005b6101cf60048036038101906101ca9190611cd7565b610640565b005b6101d96106a0565b005b6101f560048036038101906101f09190611cd7565b6106c5565b005b6101ff6106e5565b60405161020c9190611d39565b60405180910390f35b61022f600480360381019061022a9190611be2565b6106f1565b60405161023c9190611c50565b60405180910390f35b61025f600480360381019061025a9190611d54565b610777565b60405161026c9190611d39565b60405180910390f35b61027d61082e565b005b610287610842565b6040516102949190611c50565b60405180910390f35b6102a561086c565b6040516102b29190611b8a565b60405180910390f35b6102d560048036038101906102d09190611dad565b6108fe565b005b6102f160048036038101906102ec9190611f22565b610914565b005b61030d60048036038101906103089190611be2565b610976565b60405161031a9190611b8a565b60405180910390f35b61033d60048036038101906103389190611fa5565b6109de565b60405161034a9190611adf565b60405180910390f35b61036d60048036038101906103689190611d54565b610a72565b005b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061043a57507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b8061044a575061044982610af5565b5b9050919050565b60606000805461046090612014565b80601f016020809104026020016040519081016040528092919081815260200182805461048c90612014565b80156104d95780601f106104ae576101008083540402835291602001916104d9565b820191906000526020600020905b8154815290600101906020018083116104bc57829003601f168201915b5050505050905090565b60006104ee82610b5f565b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000610534826106f1565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036105a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161059b906120b7565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166105c3610baa565b73ffffffffffffffffffffffffffffffffffffffff1614806105f257506105f1816105ec610baa565b6109de565b5b610631576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161062890612149565b60405180910390fd5b61063b8383610bb2565b505050565b61065161064b610baa565b82610c6b565b610690576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610687906121db565b60405180910390fd5b61069b838383610d00565b505050565b60006106ac6007610ff9565b90506106b86007611007565b6106c2338261101d565b50565b6106e083838360405180602001604052806000815250610914565b505050565b60078060000154905081565b6000806106fd8361103b565b9050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361076e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161076590612247565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16036107e7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107de906122d9565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610836611078565b61084060006110f6565b565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606001805461087b90612014565b80601f01602080910402602001604051908101604052809291908181526020018280546108a790612014565b80156108f45780601f106108c9576101008083540402835291602001916108f4565b820191906000526020600020905b8154815290600101906020018083116108d757829003601f168201915b5050505050905090565b610910610909610baa565b83836111bc565b5050565b61092561091f610baa565b83610c6b565b610964576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161095b906121db565b60405180910390fd5b61097084848484611328565b50505050565b606061098182610b5f565b600061098b611384565b905060008151116109ab57604051806020016040528060008152506109d6565b806109b58461139b565b6040516020016109c6929190612335565b6040516020818303038152906040525b915050919050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b610a7a611078565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610ae9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ae0906123cb565b60405180910390fd5b610af2816110f6565b50565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b610b6881611469565b610ba7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b9e90612247565b60405180910390fd5b50565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16610c25836106f1565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600080610c77836106f1565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480610cb95750610cb881856109de565b5b80610cf757508373ffffffffffffffffffffffffffffffffffffffff16610cdf846104e3565b73ffffffffffffffffffffffffffffffffffffffff16145b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff16610d20826106f1565b73ffffffffffffffffffffffffffffffffffffffff1614610d76576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d6d9061245d565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610de5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ddc906124ef565b60405180910390fd5b610df283838360016114aa565b8273ffffffffffffffffffffffffffffffffffffffff16610e12826106f1565b73ffffffffffffffffffffffffffffffffffffffff1614610e68576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e5f9061245d565b60405180910390fd5b6004600082815260200190815260200160002060006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4610ff483838360016114b0565b505050565b600081600001549050919050565b6001816000016000828254019250508190555050565b6110378282604051806020016040528060008152506114b6565b5050565b60006002600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b611080610baa565b73ffffffffffffffffffffffffffffffffffffffff1661109e610842565b73ffffffffffffffffffffffffffffffffffffffff16146110f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110eb9061255b565b60405180910390fd5b565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361122a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611221906125c7565b60405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405161131b9190611adf565b60405180910390a3505050565b611333848484610d00565b61133f84848484611511565b61137e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161137590612659565b60405180910390fd5b50505050565b606060405180602001604052806000815250905090565b6060600060016113aa84611698565b01905060008167ffffffffffffffff8111156113c9576113c8611df7565b5b6040519080825280601f01601f1916602001820160405280156113fb5781602001600182028036833780820191505090505b509050600082602001820190505b60011561145e578080600190039150507f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a858161145257611451612679565b5b04945060008503611409575b819350505050919050565b60008073ffffffffffffffffffffffffffffffffffffffff1661148b8361103b565b73ffffffffffffffffffffffffffffffffffffffff1614159050919050565b50505050565b50505050565b6114c083836117eb565b6114cd6000848484611511565b61150c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161150390612659565b60405180910390fd5b505050565b60006115328473ffffffffffffffffffffffffffffffffffffffff16611a08565b1561168b578373ffffffffffffffffffffffffffffffffffffffff1663150b7a0261155b610baa565b8786866040518563ffffffff1660e01b815260040161157d94939291906126fd565b6020604051808303816000875af19250505080156115b957506040513d601f19601f820116820180604052508101906115b6919061275e565b60015b61163b573d80600081146115e9576040519150601f19603f3d011682016040523d82523d6000602084013e6115ee565b606091505b506000815103611633576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161162a90612659565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050611690565b600190505b949350505050565b600080600090507a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106116f6577a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083816116ec576116eb612679565b5b0492506040810190505b6d04ee2d6d415b85acef81000000008310611733576d04ee2d6d415b85acef8100000000838161172957611728612679565b5b0492506020810190505b662386f26fc10000831061176257662386f26fc10000838161175857611757612679565b5b0492506010810190505b6305f5e100831061178b576305f5e100838161178157611780612679565b5b0492506008810190505b61271083106117b05761271083816117a6576117a5612679565b5b0492506004810190505b606483106117d357606483816117c9576117c8612679565b5b0492506002810190505b600a83106117e2576001810190505b80915050919050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361185a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611851906127d7565b60405180910390fd5b61186381611469565b156118a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161189a90612843565b60405180910390fd5b6118b16000838360016114aa565b6118ba81611469565b156118fa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118f190612843565b60405180910390fd5b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4611a046000838360016114b0565b5050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6000604051905090565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b611a7481611a3f565b8114611a7f57600080fd5b50565b600081359050611a9181611a6b565b92915050565b600060208284031215611aad57611aac611a35565b5b6000611abb84828501611a82565b91505092915050565b60008115159050919050565b611ad981611ac4565b82525050565b6000602082019050611af46000830184611ad0565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611b34578082015181840152602081019050611b19565b60008484015250505050565b6000601f19601f8301169050919050565b6000611b5c82611afa565b611b668185611b05565b9350611b76818560208601611b16565b611b7f81611b40565b840191505092915050565b60006020820190508181036000830152611ba48184611b51565b905092915050565b6000819050919050565b611bbf81611bac565b8114611bca57600080fd5b50565b600081359050611bdc81611bb6565b92915050565b600060208284031215611bf857611bf7611a35565b5b6000611c0684828501611bcd565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000611c3a82611c0f565b9050919050565b611c4a81611c2f565b82525050565b6000602082019050611c656000830184611c41565b92915050565b611c7481611c2f565b8114611c7f57600080fd5b50565b600081359050611c9181611c6b565b92915050565b60008060408385031215611cae57611cad611a35565b5b6000611cbc85828601611c82565b9250506020611ccd85828601611bcd565b9150509250929050565b600080600060608486031215611cf057611cef611a35565b5b6000611cfe86828701611c82565b9350506020611d0f86828701611c82565b9250506040611d2086828701611bcd565b9150509250925092565b611d3381611bac565b82525050565b6000602082019050611d4e6000830184611d2a565b92915050565b600060208284031215611d6a57611d69611a35565b5b6000611d7884828501611c82565b91505092915050565b611d8a81611ac4565b8114611d9557600080fd5b50565b600081359050611da781611d81565b92915050565b60008060408385031215611dc457611dc3611a35565b5b6000611dd285828601611c82565b9250506020611de385828601611d98565b9150509250929050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611e2f82611b40565b810181811067ffffffffffffffff82111715611e4e57611e4d611df7565b5b80604052505050565b6000611e61611a2b565b9050611e6d8282611e26565b919050565b600067ffffffffffffffff821115611e8d57611e8c611df7565b5b611e9682611b40565b9050602081019050919050565b82818337600083830152505050565b6000611ec5611ec084611e72565b611e57565b905082815260208101848484011115611ee157611ee0611df2565b5b611eec848285611ea3565b509392505050565b600082601f830112611f0957611f08611ded565b5b8135611f19848260208601611eb2565b91505092915050565b60008060008060808587031215611f3c57611f3b611a35565b5b6000611f4a87828801611c82565b9450506020611f5b87828801611c82565b9350506040611f6c87828801611bcd565b925050606085013567ffffffffffffffff811115611f8d57611f8c611a3a565b5b611f9987828801611ef4565b91505092959194509250565b60008060408385031215611fbc57611fbb611a35565b5b6000611fca85828601611c82565b9250506020611fdb85828601611c82565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061202c57607f821691505b60208210810361203f5761203e611fe5565b5b50919050565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b60006120a1602183611b05565b91506120ac82612045565b604082019050919050565b600060208201905081810360008301526120d081612094565b9050919050565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60008201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c000000602082015250565b6000612133603d83611b05565b915061213e826120d7565b604082019050919050565b6000602082019050818103600083015261216281612126565b9050919050565b7f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560008201527f72206f7220617070726f76656400000000000000000000000000000000000000602082015250565b60006121c5602d83611b05565b91506121d082612169565b604082019050919050565b600060208201905081810360008301526121f4816121b8565b9050919050565b7f4552433732313a20696e76616c696420746f6b656e2049440000000000000000600082015250565b6000612231601883611b05565b915061223c826121fb565b602082019050919050565b6000602082019050818103600083015261226081612224565b9050919050565b7f4552433732313a2061646472657373207a65726f206973206e6f74206120766160008201527f6c6964206f776e65720000000000000000000000000000000000000000000000602082015250565b60006122c3602983611b05565b91506122ce82612267565b604082019050919050565b600060208201905081810360008301526122f2816122b6565b9050919050565b600081905092915050565b600061230f82611afa565b61231981856122f9565b9350612329818560208601611b16565b80840191505092915050565b60006123418285612304565b915061234d8284612304565b91508190509392505050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006123b5602683611b05565b91506123c082612359565b604082019050919050565b600060208201905081810360008301526123e4816123a8565b9050919050565b7f4552433732313a207472616e736665722066726f6d20696e636f72726563742060008201527f6f776e6572000000000000000000000000000000000000000000000000000000602082015250565b6000612447602583611b05565b9150612452826123eb565b604082019050919050565b600060208201905081810360008301526124768161243a565b9050919050565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b60006124d9602483611b05565b91506124e48261247d565b604082019050919050565b60006020820190508181036000830152612508816124cc565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000612545602083611b05565b91506125508261250f565b602082019050919050565b6000602082019050818103600083015261257481612538565b9050919050565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b60006125b1601983611b05565b91506125bc8261257b565b602082019050919050565b600060208201905081810360008301526125e0816125a4565b9050919050565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b6000612643603283611b05565b915061264e826125e7565b604082019050919050565b6000602082019050818103600083015261267281612636565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600081519050919050565b600082825260208201905092915050565b60006126cf826126a8565b6126d981856126b3565b93506126e9818560208601611b16565b6126f281611b40565b840191505092915050565b60006080820190506127126000830187611c41565b61271f6020830186611c41565b61272c6040830185611d2a565b818103606083015261273e81846126c4565b905095945050505050565b60008151905061275881611a6b565b92915050565b60006020828403121561277457612773611a35565b5b600061278284828501612749565b91505092915050565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b60006127c1602083611b05565b91506127cc8261278b565b602082019050919050565b600060208201905081810360008301526127f0816127b4565b9050919050565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b600061282d601c83611b05565b9150612838826127f7565b602082019050919050565b6000602082019050818103600083015261285c81612820565b905091905056fea2646970667358221220a39eae0c1a8e954c5b2add7ac299eff8138d924c1cb4156eda6d793d6b4c2ef964736f6c63430008120033"
storageContractTxCallData = "0x34c73884"
storageCallTxGas = 120000
testGas = 2800000
)
var RPC_SERVER string
var MNEMONIC string
var SK string
var N int
var MAX_ACCOUNTS int
var MAX_SIZE int
var DATA_PATH string
var CURRENT_ITERATIONS int = 0
var Nonce uint64 = 0
var INITIAL_SIZE int64
var CONTRACTS string
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Some error occured. Err: %s", err)
}
RPC_SERVER = os.Getenv("RPC_SERVER")
if len(RPC_SERVER) == 0 {
fmt.Println("Invalid RPC_SERVER flag")
return
}
MNEMONIC = os.Getenv("MNEMONIC")
if len(MNEMONIC) == 0 {
fmt.Println("Invalid MNEMONIC flag")
return
}
SK = os.Getenv("SK")
if len(SK) == 0 {
fmt.Println("Invalid SK flag")
return
}
TPS := os.Getenv("SPEED")
if len(TPS) == 0 {
N = 100
} else {
i, err := strconv.Atoi(TPS)
if err != nil {
fmt.Println("Invalid TPS flag")
return
}
N = i
}
acc := os.Getenv("MAX_ACCOUNTS")
size := os.Getenv("MAX_SIZE")
if len(acc) == 0 && len(size) == 0 {
fmt.Println("Both MAX_ACCOUNTS and MAX_SIZE flags cannot be empty")
return
}
if len(size) != 0 {
i, err := strconv.Atoi(size)
if err != nil {
fmt.Println("Invalid MAX_SIZE flag")
return
}
MAX_SIZE = i
}
if len(acc) != 0 {
i, err := strconv.Atoi(acc)
if err != nil {
fmt.Println("Invalid MAX_ACCOUNTS flag")
return
}
MAX_ACCOUNTS = i
}
DATA_PATH = os.Getenv("DATA_PATH")
if len(DATA_PATH) == 0 {
fmt.Println("Invalid DATA_PATH flag")
return
}
CONTRACTS = os.Getenv("CONTRACTS")
fmt.Println("RPC_SERVER: ", RPC_SERVER)
fmt.Println("MNEMONIC: ", MNEMONIC)
fmt.Println("SK: ", SK)
fmt.Println("N: ", N)
fmt.Println("MAX_ACCOUNTS: ", MAX_ACCOUNTS)
fmt.Println("MAX_SIZE: ", MAX_SIZE)
fmt.Println("DATA_PATH: ", DATA_PATH)
fmt.Println("CONTRACTS: ", CONTRACTS)
main1()
}
func main1() {
fmt.Printf("script started \n")
ctx := context.Background()
cl, err := ethclient.Dial(RPC_SERVER)
if err != nil {
log.Println("Error in dial connection: ", err)
}
chainID, err := cl.ChainID(ctx)
if err != nil {
log.Println("Error in fetching chainID: ", err)
}
fmt.Println("Chain ID: ", chainID)
sk := crypto.ToECDSAUnsafe(common.FromHex(SK))
ksOpts, err := bind.NewKeyedTransactorWithChainID(sk, chainID)
if err != nil {
log.Println("Error in getting ksOpts: ", err)
}
add := crypto.PubkeyToAddress(sk.PublicKey)
balance, err := cl.BalanceAt(ctx, add, nil)
if err != nil {
log.Println("Error in checking balance: ", err)
}
fmt.Println("Balance: ", balance)
nonce, err := cl.PendingNonceAt(ctx, add)
if err != nil {
log.Fatalln("Error in getting pendingNonce: ", nonce)
} else {
Nonce = nonce
}
fmt.Println("Nonce: ", Nonce)
generatedAccounts := generateAccountsUsingMnemonic(ctx, cl)
fund := os.Getenv("FUND")
if fund == "true" {
fundAccounts(ctx, cl, generatedAccounts, chainID, add, ksOpts)
}
INITIAL_SIZE = checkChainData()
fmt.Println("Preparing")
if fund == "true" {
fmt.Println("Loadbot Starting in 15 secs")
time.Sleep(15 * time.Second)
} else {
time.Sleep(2 * time.Second)
}
if CONTRACTS == "true" {
nonce, err := cl.PendingNonceAt(ctx, add)
if err != nil {
fmt.Printf("failed to retrieve pending nonce for account %s: %v", add.String(), err)
}
contractAddr, _ := deploySmartContract(ctx, cl, chainID, add, nonce, ksOpts)
time.Sleep(5 * time.Second)
startContractsLoadbot(ctx, cl, chainID, generatedAccounts, contractAddr)
} else {
startLoadbot(ctx, cl, chainID, generatedAccounts)
}
}
type Account struct {
key *ecdsa.PrivateKey
addr common.Address
}
type Accounts []Account
func generateAccountsUsingMnemonic(ctx context.Context, client *ethclient.Client) (accounts Accounts) {
wallet, err := hdwallet.NewFromMnemonic(MNEMONIC)
if err != nil {
log.Fatal(err)
}
for i := 1; i <= N; i++ {
var dpath string = "m/44'/60'/0'/0/" + strconv.Itoa(i)
path := hdwallet.MustParseDerivationPath(dpath)
account, err := wallet.Derive(path, false)
if err != nil {
log.Fatal(err)
}
log.Println("Account", i, ":", account.Address)
privKey, err := wallet.PrivateKey(account)
if err != nil {
log.Fatal(err)
}
accounts = append(accounts, Account{key: privKey, addr: account.Address})
}
return accounts
}
func fundAccounts(ctx context.Context, client *ethclient.Client, genAccounts Accounts, chainID *big.Int,
senderAddress common.Address, opts *bind.TransactOpts) {
for i := 0; i < N; i++ {
fmt.Println("Reqd nonce: ", Nonce+uint64(i))
runTransaction(ctx, client, genAccounts[i].addr, chainID, senderAddress, opts, Nonce+uint64(i), 10000000000000000)
}
}
func runTransaction(ctx context.Context, Clients *ethclient.Client, recipient common.Address, chainID *big.Int,
senderAddress common.Address, opts *bind.TransactOpts, nonce uint64, value int64) {
fmt.Println("Running transaction : ", nonce)
var data []byte
gasLimit := uint64(21000)
gasPrice := big.NewInt(2200000000)
val := big.NewInt(value)
tx := types.NewTransaction(nonce, recipient, val, gasLimit, gasPrice, data)
signedTx, err := opts.Signer(senderAddress, tx)
if err != nil {
log.Fatal("Error in signing tx: ", err)
}
err = Clients.SendTransaction(ctx, signedTx)
if err != nil {
log.Fatal("Error in sending tx: ", err)
}
}
func createAccount() Account {
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
}
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}
address := crypto.PubkeyToAddress(*publicKeyECDSA)
account := Account{key: privateKey, addr: address}
return account
}
type Nonces struct {
mu sync.Mutex
nonces []uint64
}
func startContractsLoadbot(ctx context.Context, client *ethclient.Client, chainID *big.Int, genAccounts Accounts, contractAddr common.Address) {
if MAX_SIZE > 0 && INITIAL_SIZE > 0 {
go func() {
for {
currentSize := checkChainData()
if (currentSize - INITIAL_SIZE) > int64(MAX_SIZE) {
fmt.Println("Size limit reached!!!")
os.Exit(0)
}
time.Sleep(10 * time.Second)
}
}()
}
fmt.Printf("Loadbot started \n")
noncesStruct := &Nonces{
nonces: make([]uint64, N),
}
flag := 0
for i, a := range genAccounts {
if flag >= N {
break
}
flag++
fmt.Printf("i is %v \n", i)
go func(i int, a Account, m *sync.Mutex) {
nonce, err := client.PendingNonceAt(ctx, a.addr)
if err != nil {
fmt.Printf("failed to retrieve pending nonce for account %s: %v", a.addr.String(), err)
}
m.Lock()
noncesStruct.nonces[i] = nonce
m.Unlock()
}(i, a, &noncesStruct.mu)
}
fmt.Printf("intialization completed \n")
recpIdx := 0
sendIdx := 0
// Fire off transactions
period := 1 * time.Second / time.Duration(N)
ticker := time.NewTicker(period)
for {
select {
case <-ticker.C:
if CURRENT_ITERATIONS%100 == 0 && CURRENT_ITERATIONS > 0 {
fmt.Println("CURRENT_ACCOUNTS: ", CURRENT_ITERATIONS)
}
if MAX_ACCOUNTS > 0 && CURRENT_ITERATIONS >= MAX_ACCOUNTS {
os.Exit(0)
}
recpIdx++
sendIdx++
sender := genAccounts[sendIdx%N] //cfg.Accounts[sendIdx%len(cfg.Accounts)]
nonce := noncesStruct.nonces[sendIdx%N]
go func(sender Account, nonce uint64) error {
for i := 0; i < 5; i++ {
err := runBotTransaction(ctx, client, contractAddr, chainID, sender, nonce+uint64(i), 0, common.FromHex(storageContractTxCallData))
if err != nil {
return err
}
}
return nil
}(sender, nonce)
noncesStruct.nonces[sendIdx%N] = noncesStruct.nonces[sendIdx%N] + 5
case <-ctx.Done():
// return group.Wait()
}
}
}
func startLoadbot(ctx context.Context, client *ethclient.Client, chainID *big.Int,
genAccounts Accounts) {
if MAX_SIZE > 0 && INITIAL_SIZE > 0 {
go func() {
for {
currentSize := checkChainData()
if (currentSize - INITIAL_SIZE) > int64(MAX_SIZE) {
fmt.Println("Size limit reached!!!")
os.Exit(0)
}
time.Sleep(10 * time.Second)
}
}()
}
fmt.Printf("Loadbot started \n")
noncesStruct := &Nonces{
nonces: make([]uint64, N),
}
flag := 0
for i, a := range genAccounts {
if flag >= N {
break
}
flag++
fmt.Printf("i is %v \n", i)
go func(i int, a Account, m *sync.Mutex) {
nonce, err := client.PendingNonceAt(ctx, a.addr)
if err != nil {
fmt.Printf("failed to retrieve pending nonce for account %s: %v", a.addr.String(), err)
}
m.Lock()
noncesStruct.nonces[i] = nonce
m.Unlock()
}(i, a, &noncesStruct.mu)
}
fmt.Printf("intialization completed \n")
recpIdx := 0
sendIdx := 0
// Fire off transactions
period := 1 * time.Second / time.Duration(N)
ticker := time.NewTicker(period)
for {
select {
case <-ticker.C:
if CURRENT_ITERATIONS%100 == 0 && CURRENT_ITERATIONS > 0 {
fmt.Println("CURRENT_ACCOUNTS: ", CURRENT_ITERATIONS)
}
if MAX_ACCOUNTS > 0 && CURRENT_ITERATIONS >= MAX_ACCOUNTS {
os.Exit(0)
}
recpIdx++
sendIdx++
sender := genAccounts[sendIdx%N] //cfg.Accounts[sendIdx%len(cfg.Accounts)]
nonce := noncesStruct.nonces[sendIdx%N]
go func(sender Account, nonce uint64) error {
recpointer := createAccount()
recipient := recpointer.addr
recpointer2 := createAccount()
recipient2 := recpointer2.addr
recpointer3 := createAccount()
recipient3 := recpointer3.addr
recpointer4 := createAccount()
recipient4 := recpointer4.addr
recpointer5 := createAccount()
recipient5 := recpointer5.addr
err := runBotTransaction(ctx, client, recipient, chainID, sender, nonce, 1, []byte{})
if err != nil {
return err
}
err = runBotTransaction(ctx, client, recipient2, chainID, sender, nonce+1, 1, []byte{})
if err != nil {
return err
}
err = runBotTransaction(ctx, client, recipient3, chainID, sender, nonce+2, 1, []byte{})
if err != nil {
return err
}
err = runBotTransaction(ctx, client, recipient4, chainID, sender, nonce+3, 1, []byte{})
if err != nil {
return err
}
err = runBotTransaction(ctx, client, recipient5, chainID, sender, nonce+4, 1, []byte{})
if err != nil {
return err
}
return nil
}(sender, nonce)
noncesStruct.nonces[sendIdx%N] = noncesStruct.nonces[sendIdx%N] + 5
case <-ctx.Done():
// return group.Wait()
}
}
}
func genRandomGas(min int64, max int64) *big.Int {
bg := big.NewInt(max - min)
n, err := rand.Int(rand.Reader, bg)
if err != nil {
panic(err)
}
return big.NewInt(n.Int64() + min)
}
func deploySmartContract(ctx context.Context, Clients *ethclient.Client, chainID *big.Int, sender common.Address, nonce uint64, opts *bind.TransactOpts) (common.Address, error) {
var data = common.FromHex(storageContractByteCode)
gasPrice := big.NewInt(2200000000)
tx, _ := types.NewContractCreation(nonce, big.NewInt(0), testGas, gasPrice, data), types.HomesteadSigner{}
signedTx, err := opts.Signer(sender, tx)
if err != nil {
log.Fatal("Error in signing tx: ", err)
}
err = Clients.SendTransaction(ctx, signedTx)
if err != nil {
fmt.Printf("Error in sending deployment tx: %s, From : %s\n", err, sender)
}
fmt.Println("Contract Deployemennt Attempted")
contractAddr := crypto.CreateAddress(sender, nonce)
return contractAddr, err
}
func runBotTransaction(ctx context.Context, Clients *ethclient.Client, recipient common.Address, chainID *big.Int,
sender Account, nonce uint64, value int64, data []byte) error {
gasLimit := uint64(storageCallTxGas)
var gasPrice *big.Int
r := nonce % 6
switch r {
case 0:
gasPrice = genRandomGas(2320000000, 2340000000)
case 1:
gasPrice = genRandomGas(2220000000, 2240000000)
case 2:
gasPrice = genRandomGas(2280000000, 2300000000)
case 3:
gasPrice = genRandomGas(2260000000, 2280000000)
case 4:
gasPrice = genRandomGas(2200000000, 2240000000)
case 5:
gasPrice = genRandomGas(2300000000, 2320000000)
}
val := big.NewInt(value)
tx := types.NewTransaction(nonce, recipient, val, gasLimit, gasPrice, data)
sk := crypto.ToECDSAUnsafe(crypto.FromECDSA(sender.key)) // Sign the transaction
opts, err := bind.NewKeyedTransactorWithChainID(sk, chainID)
if err != nil {
log.Fatal("Error in creating signer: ", err)
}
signedTx, err := opts.Signer(sender.addr, tx)
if err != nil {
log.Fatal("Error in signing tx: ", err)
}
err = Clients.SendTransaction(ctx, signedTx)
if err != nil {
fmt.Printf("Error in sending tx: %s, From : %s, To : %s\n", err, sender.addr, recipient.Hash())
}
// Nonce++
CURRENT_ITERATIONS++
return err
}
func checkChainData() int64 {
var size int64
err := filepath.Walk(DATA_PATH, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += info.Size()
}
return err
})
if err != nil {
fmt.Println("Error in getting chaindata size: ", err)
return -1
}
fmt.Print("chaindata size: ", size/1024, "KB\n\n") // Originally the size is in returned in bytes
return size / 1024
}