This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbalance_node.py
135 lines (128 loc) · 5.79 KB
/
balance_node.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
#python3
import datetime
import os
import botogram
import json
from config import token, path_to_bin
bot = botogram.create(token)
bot.about = "Balance BOT for your own fullnode-masternode. \nIf you found any bugs or have suggestions for new functionalities...\nPlease contact us!"
bot.owner = "@MrSteelBCNA and/or @Raul_BitCannaES"
#==========================================================================
@bot.command("getbalance")
def getbalance_command(chat, message, args):
"""Show the balance of your wallet"""
get_balance = os.popen(path_to_bin + "/bitcanna-cli getbalance").read()
print("Result:", get_balance)
balance = str(get_balance)
chat.send("The current balance is "+balance+" BCNA")
#==========================================================================
@bot.command("getblockcount")
def getblockcount_command(chat, message, args):
"""Check this to know if your fullnode-masternode is synced"""
get_block = os.popen(path_to_bin + "/bitcanna-cli getblockcount").read()
print("Result:", get_block)
block = str(get_block)
chat.send("The current Block is "+block)
#==========================================================================
@bot.command("getlist")
def getlist_command(chat, message, args):
"""This will show the last Transactions in your wallet"""
msg = ""
get_last = os.popen(path_to_bin + "/bitcanna-cli listtransactions").read()
loaded_json = json.loads(get_last)
for tx in loaded_json:
date_time = datetime.datetime.fromtimestamp(tx['blocktime']).strftime('%c')
msg = msg + tx['category'] + " BCNA: " + str(tx['amount']) + " at " + date_time + "\n"
print (msg)
chat.send(msg)
#==========================================================================
@bot.command("getmasternode")
def getmasternode_command(chat, message, args):
"""This will show the online MASTERNODES"""
get_masternodes = os.popen(path_to_bin + "/bitcanna-cli masternode list").read()
loaded_json = json.loads(get_masternodes)
msg = ""
count = 0
chat.send ("List of online MASTERNODES")
print ("List of online MASTERNODES")
print ("==========================")
for tx in loaded_json:
msg = msg + "IP: " + tx + "\n"
count = count + 1
print (msg + "\nTotal: " + str(count))
chat.send(msg + "\nTotal: " + str(count))
#==========================================================================
@bot.command("getpeers")
def getpeers_command(chat, message, args):
"""This will show the online NODES (both)"""
get_nodes = os.popen(path_to_bin + "/bitcanna-cli getpeerinfo").read()
loaded_json = json.loads(get_nodes)
msg = ""
count = 0
file_peers = os.path.join(path_to_bin + '/peers.txt')
chat.send ("Building a list...")
print ("List of online NODES")
print ("==========================")
for tx in loaded_json:
msg = msg + "IP: " + tx["addr"] + ", version: " + tx["subver"] + "\n"
count = count + 1
print (msg + "\nTotal: " + str(count))
with open(file_peers, 'w') as f:
f.write(msg+ "\nTotal: " + str(count))
chat.send_file(path=file_peers, caption='This file contains all peers connected to your masternode/fullnode')
#==========================================================================
@bot.command("getunspent")
def getunspent_command(chat, message, args):
"""This will show amount to transfer in command-line to another address"""
total = 0
msg = ""
get_last = os.popen(path_to_bin + "/bitcanna-cli listunspent").read()
loaded_json = json.loads(get_last)
chat.send ("Unspent inputs to transfer\n======================")
for tx in loaded_json:
if tx['amount'] == 3.30000000: # > 2.6 for fullnode
msg = msg + "Mint: " + str(tx['spendable']) + " BCNA: " + str(tx['amount']) + "\n"
total = total + tx['amount']
else:
msg = msg + 'Other: ' + str(tx['spendable']) + " BCNA: " + str(tx['amount']) + "\n"
print(msg) #Is printed in console , could be saved in a file and sent by telegram
#chat.send (msg) #if there are a lot of inputs Telegram can't handle in a message
chat.send ("Make your transfer with " + (str(total)) + " BCNA")
#==========================================================================
@bot.command("startmasternode")
def startmasternode_command(chat, message, args):
"""Launch the MN start command"""
start_MN = os.popen(path_to_bin + "/bitcanna-cli masternode start-many").read()
print("Result:", start_MN)
chat.send('Output: \n' + start_MN)
#==========================================================================
@bot.command("startdaemon")
def startdaemon_command(chat, message, args):
"""Launch the BitCanna daemon"""
start_daemon= os.popen(path_to_bin + "/bitcannad -daemon").read()
print("Result:", start_daemon)
chat.send('Output: \n' + start_daemon)
#==============================================================================
@bot.prepare_memory
def init(shared):
shared["subs"] = []
@bot.command("subscribe")
def subscribe_command(shared, chat, message, args):
"""Subscribe to the hourly daemon checking"""
subs = shared["subs"]
subs.append(chat.id)
shared["subs"] = subs
@bot.timer(3600) #every hour
def checker(bot, shared):
get_info = os.popen(path_to_bin + "/bitcanna-cli getinfo").read()
if get_info == '': #-1 is running
for chat in shared["subs"]:
bot.chat(chat).send("Hey! your BitCanna daemon is down!")
#starting = os.popen(path_to_bin + "/bitcannad -daemon").read() #may cause corruption on wallet.dat
else:
print('Daemon is running')
#bot.chat(chat.id).send(starting)
#==============================================================================
# This runs the bot, until ctrl+c is pressed
if __name__ == "__main__":
bot.run()