-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wallet.py
278 lines (251 loc) · 12.9 KB
/
Wallet.py
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
import discord
import requests
import json
from discord.ext import commands, tasks
with open('settings.txt', 'r') as file:
lines = file.readlines()
settings = {line.split('=')[0]: line.split('=')[1].strip() for line in lines}
intents = discord.Intents.all()
client = commands.Bot(command_prefix='.', intents=intents)
cryptocompare_apikey = settings['cryptocompare_apikey']
btc_wallet = settings['btc_wallet']
ltc_wallet = settings['ltc_wallet']
token = settings['token']
channel_id = int(settings['channel_id'])
api=f"https://blockchain.info/rawaddr/{btc_wallet}"
btcaddy_info_api=f"https://api.blockcypher.com/v1/btc/main/addrs/{btc_wallet}"
btc_price_api='https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={cryptocompare_apikey}'
test = f"https://blockstream.info/api/address/{btc_wallet}/txs"
ltc_txhistory_api = f"https://chainz.cryptoid.info/ltc/api.dws?key=1cb5722c643e&q=multiaddr&active={ltc_wallet}"
ltchashinfo_api = "https://chainz.cryptoid.info/ltc/api.dws?q=txinfo&t="
ltc_price_api ="https://min-api.cryptocompare.com/data/price?fsym=LTC&tsyms=USD&api_key={cryptocompare_apikey}"
def fetch_btc_bal():
response = requests.get(btcaddy_info_api)
data = json.loads(response.text)
return data["balance"]
def fetch_ltc_bal():
response = requests.get(ltc_txhistory_api)
data = json.loads(response.text)
bal = data["addresses"][0]["final_balance"]
return bal
def btcprice():
response = requests.get(btc_price_api)
data = json.loads(response.text)
btcpr = data['USD']
return btcpr
def ltcprice():
response = requests.get(ltc_price_api)
data = json.loads(response.text)
ltcpr = data['USD']
return ltcpr
def get_received_btc(newh):
response = requests.get(btcaddy_info_api)
data = json.loads(response.text)
data = data['txrefs'][0]
txhash = data.get('tx_hash')
if txhash == newh:
values = data.get('value')
btcnum = 0.00000001 * values
return btcnum
@tasks.loop(seconds=90)
async def check_btc_trnscs():
response = requests.get(test)
txs = response.json()
btc_emoji = discord.utils.get(client.emojis, name='BTC')
usdt_emoji = discord.utils.get(client.emojis, name='USDT')
usd_emoji = discord.utils.get(client.emojis, name='USD')
latest_tx = txs[0]["txid"]
f = open("latestBTCtx.txt", "r")
oldh = f.readline()
f.close()
if latest_tx != oldh:
inputs = txs[0]["vin"]
outputs = txs[0]["vout"]
address_input_value = 0
address_output_value = 0
for input in inputs:
if input["prevout"]["scriptpubkey_address"] == btc_wallet:
address_input_value += input["prevout"]["value"]
for output in outputs:
if output["scriptpubkey_address"] == btc_wallet:
address_output_value += output["value"]
if address_input_value > address_output_value:
direction = "sent"
else:
direction = "received"
if direction == "sent":
value = (address_input_value - address_output_value) * 0.00000001
value = round(value,10)
usd_rate = btcprice()
finalp = usd_rate * value
finalp = round(finalp,2)
embed = discord.Embed(title="Money Sent Successfully!", color=0xff0000)
embed.set_author(name="BTC Sent!", url=f"https://blockchair.com/bitcoin/transaction/{latest_tx}", icon_url='https://cdn-icons-png.flaticon.com/512/5610/5610944.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/1888/1888486.png")
embed.add_field(name=f"{btc_emoji}BTC", value=value)
embed.add_field(name=f"{usd_emoji}Value", value=f"${finalp}", inline=True)
embed.add_field(name=f"{usdt_emoji}BTC Price", value=f"${usd_rate}", inline=True)
f = open("latestBTCtx.txt", "w")
f.write(latest_tx)
f.close()
await client.get_channel(channel_id).send(embed=embed)
else:
value = (address_output_value - address_input_value) * 0.00000001
value = round(value,10)
usd_rate = btcprice()
finalp = usd_rate * value
finalp = round(finalp,2)
embed = discord.Embed(title="Money Received Successfully!", color=0x46D117)
embed.set_author(name="BTC Received!", url=f"https://blockchair.com/bitcoin/transaction/{latest_tx}", icon_url='https://cdn-icons-png.flaticon.com/512/5610/5610944.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/1888/1888486.png")
embed.add_field(name=f"{btc_emoji}BTC", value=value)
embed.add_field(name=f"{usd_emoji}Value", value=f"${finalp}", inline=True)
embed.add_field(name=f"{usdt_emoji}BTC Price", value=f"${usd_rate}", inline=True)
f = open("latestBTCtx.txt", "w")
f.write(latest_tx)
f.close()
await client.get_channel(channel_id).send(embed=embed)
@tasks.loop(seconds=90)
async def check_ltc_trnscs():
response = requests.get(ltc_txhistory_api)
data = json.loads(response.text)
newtx = data['txs'][0]['hash']
f = open("latestLTCtx.txt", "r")
tx = f.readline()
f.close()
if newtx != tx:
response = requests.get(ltchashinfo_api + newtx)
data = json.loads(response.text)
input = data["inputs"]
for i in input:
addy = i["addr"]
if addy == ltc_wallet:
direction = "sent"
output = data["outputs"]
ltcvalue = output[-1]["amount"]
ltcvalue = round(ltcvalue,6)
usd_rate = ltcprice()
finalp = ltcvalue * usd_rate
finalp = round(finalp,2)
ltc_emoji = discord.utils.get(client.emojis, name='LTC')
usdt_emoji = discord.utils.get(client.emojis, name='USDT')
usd_emoji = discord.utils.get(client.emojis, name='USD')
embed = discord.Embed(title="Money Sent Successfully!", color=0xff0000)
embed.set_author(name="LTC Sent!", url=f"https://blockchair.com/litecoin/transaction/{newtx}", icon_url='https://cdn-icons-png.flaticon.com/512/5610/5610944.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/3938/3938179.png")
embed.add_field(name=f"{ltc_emoji}LTC", value=ltcvalue)
embed.add_field(name=f"{usd_emoji}Value", value=f"${finalp}", inline=True)
embed.add_field(name=f"{usdt_emoji}LTC Price", value=f"${usd_rate}", inline=True)
f = open("latestLTCtx.txt", "w")
f.write(newtx)
f.close()
await client.get_channel(channel_id).send(embed=embed)
else:
direction = "received"
output = data["outputs"]
for i in output:
if i['addr'] == ltc_wallet:
ltcvalue = i["amount"]
ltcvalue = round(ltcvalue,6)
usd_rate = ltcprice()
finalp = ltcvalue * usd_rate
finalp = round(finalp,2)
ltc_emoji = discord.utils.get(client.emojis, name='LTC')
usdt_emoji = discord.utils.get(client.emojis, name='USDT')
usd_emoji = discord.utils.get(client.emojis, name='USD')
embed = discord.Embed(title="Money Received Successfully!", color=0x46D117)
embed.set_author(name="LTC Received!", url=f"https://blockchair.com/litecoin/transaction/{newtx}", icon_url='https://cdn-icons-png.flaticon.com/512/5610/5610944.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/3938/3938179.png")
embed.add_field(name=f"{ltc_emoji}LTC", value=ltcvalue)
embed.add_field(name=f"{usd_emoji}Value", value=f"${finalp}", inline=True)
embed.add_field(name=f"{usdt_emoji}LTC Price", value=f"${usd_rate}", inline=True)
f = open("latestLTCtx.txt", "w")
f.write(newtx)
f.close()
await client.get_channel(channel_id).send(embed=embed)
@client.command()
async def bal(ctx,coin):
if coin == 'ltc' or coin == 'LTC' or coin == "Ltc":
current_balance = fetch_ltc_bal()
ltcvalue = current_balance *0.00000001
ltcvalue = round(ltcvalue,6)
usd_rate = ltcprice()
finalp = current_balance * usd_rate * 0.00000001
finalp = round(finalp,2)
ltc_emoji = discord.utils.get(client.emojis, name='LTC')
usdt_emoji = discord.utils.get(client.emojis, name='USDT')
usd_emoji = discord.utils.get(client.emojis, name='USD')
embed = discord.Embed(title="Current Balance💸", color=0x5217D1)
embed.set_author(name="LTC Wallet Balance", url=f"https://blockchair.com/litecoin/address/{ltc_wallet}", icon_url='https://cdn-icons-png.flaticon.com/512/3444/3444339.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/3938/3938179.png")
embed.add_field(name=f"{ltc_emoji}LTC", value=ltcvalue)
embed.add_field(name=f"{usd_emoji}Value", value=f"${finalp}", inline=True)
embed.add_field(name=f"{usdt_emoji}LTC Price", value=f"${usd_rate}", inline=True)
elif coin == 'btc' or coin =='BTC' or coin == 'Btc':
current_balance = fetch_btc_bal()
usd_rate = btcprice()
btcvalue = current_balance * 0.00000001
btcvalue = round(btcvalue,10)
finalp=current_balance * 0.00000001* usd_rate
finalp = round(finalp,2)
btc_emoji = discord.utils.get(client.emojis, name='BTC')
usdt_emoji = discord.utils.get(client.emojis, name='USDT')
usd_emoji = discord.utils.get(client.emojis, name='USD')
embed = discord.Embed(title="Current Balance💸", color=0x5217D1)
embed.set_author(name="BTC Wallet Balance", url=f"https://blockchair.com/bitcoin/address/{btc_wallet}", icon_url='https://cdn-icons-png.flaticon.com/512/3444/3444339.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/5341/5341431.png")
embed.add_field(name=f"{btc_emoji}BTC", value=btcvalue)
embed.add_field(name=f"{usd_emoji}Value", value=f"${finalp}", inline=True)
embed.add_field(name=f"{usdt_emoji}BTC Price", value=f"${usd_rate}", inline=True)
elif coin == "all" or coin == "All" or coin == "ALL":
ltcbal = fetch_ltc_bal()
btcbal = fetch_btc_bal()
usd_ltc_rate = ltcprice()
usd_btc_rate = btcprice()
finalltc = ltcbal * usd_ltc_rate * 0.00000001
finalbtc= btcbal * 0.00000001* usd_btc_rate
finalltc = round(finalltc,2)
finalbtc = round(finalbtc,2)
btcvalue = btcbal * 0.00000001
btcvalue = round(btcvalue,10)
ltcvalue = ltcbal * 0.00000001
ltcvalue = round(ltcvalue,6)
walletbal = round(finalltc + finalbtc,2)
btc_emoji = discord.utils.get(client.emojis, name='BTC')
ltc_emoji = discord.utils.get(client.emojis, name='LTC')
usdt_emoji = discord.utils.get(client.emojis, name='USDT')
usd_emoji = discord.utils.get(client.emojis, name='USD')
embed = discord.Embed(title="Current Balance💸", color=0x5217D1)
embed.set_author(name="Wallet Balance", icon_url='https://cdn-icons-png.flaticon.com/512/3444/3444339.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/4825/4825188.png")
embed.add_field(name=f"{btc_emoji}BTC", value=btcvalue )
embed.add_field(name= f"{ltc_emoji}LTC", value = ltcvalue , inline=True )
embed.add_field(name=f"{usd_emoji}Value", value=f"${walletbal}", inline=True)
embed.add_field(name=f"{usdt_emoji}BTC Price", value=f"${usd_btc_rate}", inline=True)
embed.add_field(name=f"{usdt_emoji}LTC Price", value=f"${usd_ltc_rate}", inline=True)
await ctx.send(embed=embed)
@client.command()
async def price(ctx):
btc_emoji = discord.utils.get(client.emojis, name='BTC')
ltc_emoji = discord.utils.get(client.emojis, name='LTC')
embed = discord.Embed(title="Market Price💸", color=0x5217D1)
embed.set_author(name="Major Coins", icon_url='https://cdn-icons-png.flaticon.com/512/3444/3444339.png')
embed.set_thumbnail(url="https://cdn-icons-png.flaticon.com/512/9214/9214823.png")
embed.add_field(name=f"{btc_emoji}BTC", value=f"${btcprice()}" )
embed.add_field(name= f"{ltc_emoji}LTC", value = f"${ltcprice()}" , inline=True )
await ctx.send(embed=embed)
async def send_notification(message):
channel = client.get_channel(channel_id)
await channel.send(message)
@tasks.loop(seconds = 30)
async def update_status():
pr = btcprice()
intpr = int(pr)
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name = f"BTC 💰: ${intpr}"))
@client.event
async def on_ready():
print("Bot is polling...")
check_btc_trnscs.start()
check_ltc_trnscs.start()
update_status.start()
client.run(token)