Repository navigation
Expand file tree
/
Copy pathmakechange.py
More file actions
executable file
·126 lines (96 loc) · 3.64 KB
/
Copy pathmakechange.py
File metadata and controls
executable file
·126 lines (96 loc) · 3.64 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
#!/usr/bin/env python3
'''
Usage: python3 makechange.py
Need python 3.6 as that is when secrets got added, so you might need to launch it with python3 makechange.py
Have Ubuntu? n.04 add ppa, n.10 might have already check python3 -V
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update
$ sudo apt install python3.6
$ python3.6 makechange.py
Make two wallets and fill one or both with some funds, or start mining to it.
Open the wallets with turtle-serivce like so:
./turtle-service -w walletA.wallet -p yourpass --rpc-password test --bind-port 8070
./turtle-service -w walletB.wallet -p yourpass --rpc-password test --bind-port 8071
Feel free to change these parameters if needed of course.
This script rapidly sends random amount of funds from two wallets to each
other, hopefully generating change on a new network.
For Forks, see comments for adjusting amounts especially if using more than 2 decimals.
'''
import requests
import json
import secrets
import time
import sys
from threading import Thread
# Forks adjust as needed
moveDecimal = 100 # TRTL has 2 decimals so 100 is the divide/multiply factor
minAmount = 100 * moveDecimal # min number for amount to xfer
maxAmount = 5000 * moveDecimal # max number for amount to xfer
anonymity = 3
fee = 10 # atomic units, TRTL would be 0.10 as the tx network fee
def getAddress(host, port, rpcPassword):
payload = {
'jsonrpc': '2.0',
'method': "getAddresses",
'password': rpcPassword,
'id': 'test',
'params': {}
}
url = 'http://' + host + ':' + port + '/json_rpc'
response = requests.post(
url, data=json.dumps(payload),
headers={'content-type': 'application/json'}
).json()
if 'error' in response:
print(response['error'])
print('Failed to get address, exiting')
sys.exit()
else:
return response['result']['addresses'][0]
def sendTransaction(host, port, rpcPassword, **kwargs):
payload = {
'jsonrpc': '2.0',
'method': "sendTransaction",
'password': rpcPassword,
'id': 'test',
'params': kwargs
}
url = 'http://' + host + ':' + port + '/json_rpc'
response = requests.post(
url, data=json.dumps(payload),
headers={'content-type': 'application/json'}
).json()
if 'error' in response:
response['error']['amount'] = kwargs['transfers'][0]['amount']/moveDecimal
print(response['error'])
return False
else:
response['result']['amount'] = kwargs['transfers'][0]['amount']/moveDecimal
print(response['result'])
return True
def sendTXs(host, port, rpcPassword, sender, receiver):
sleepAmount = 0.01
while True:
amount = minAmount+ secrets.randbelow(maxAmount)
params = {'transfers': [{'address': receiver, 'amount': amount}],
'fee': fee,
'anonymity': anonymity,
'changeAddress': sender}
if not sendTransaction(host, port, rpcPassword, **params):
time.sleep(sleepAmount)
print("Sleeping for " + str(sleepAmount) + " seconds...")
sleepAmount *= 2
else:
sleepAmount = 0.01
walletdHostA = "127.0.0.1"
walletdPortA = "8070"
walletdHostB = "127.0.0.1"
walletdPortB = "8071"
rpcPasswordA = "test"
rpcPasswordB = "test"
addressA = getAddress(walletdHostA, walletdPortA, rpcPasswordA)
addressB = getAddress(walletdHostB, walletdPortB, rpcPasswordB)
Thread(target=sendTXs, args=(walletdHostA, walletdPortA, rpcPasswordA,
addressA, addressB)).start()
Thread(target=sendTXs, args=(walletdHostB, walletdPortB, rpcPasswordB,
addressB, addressA)).start()