mirror of
https://github.com/jwinterm/cryptonoteRPCwalletGUI.git
synced 2026-10-17 05:51:33 +02:00
Major update to cryptonoteRPCwalletGUI
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
serverURL = 'http://localhost:19091/json_rpc'
|
||||
headers = {'content-type': 'application/json'}
|
||||
payload1 = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "getbalance",
|
||||
"params": {}
|
||||
})
|
||||
payload2 = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "getaddress",
|
||||
"params": {}
|
||||
})
|
||||
|
||||
def balancecheck(jobqueue, resultsqueue):
|
||||
"""function to make rpc call to simplewallet to get current balance"""
|
||||
kivysignal = True
|
||||
while kivysignal:
|
||||
time.sleep(2)
|
||||
walletrunning, kivysignal = jobqueue.get()
|
||||
if walletrunning:
|
||||
#print 'attempting rpc call'
|
||||
try:
|
||||
#Make rpc call
|
||||
resp1 = requests.get(serverURL, headers=headers, data=payload1)
|
||||
output1 = json.loads(resp1.text)
|
||||
|
||||
#Parse json data to get balance info
|
||||
rawbalance = str(output1[u'result'][u'balance']/1e12)
|
||||
rawunlockedbalance = str(output1[u'result'][u'unlocked_balance']/1e12)
|
||||
|
||||
#Format data for kivy
|
||||
balance = '[color=00ff00]'+rawbalance+'[/color]'
|
||||
unlockedbalance = '[color=00ff00]'+rawunlockedbalance+'[/color]'
|
||||
|
||||
resp2 = requests.get(serverURL, headers=headers, data=payload2)
|
||||
output2 = json.loads(resp2.text)
|
||||
address = str(output2[u'result'][u'address'])
|
||||
|
||||
except:
|
||||
#Return out of sync if bitmonerod is not ready
|
||||
balance = '[color=ff0000]out of sync[/color]'
|
||||
unlockedbalance = '[color=ff0000]out of sync[/color]'
|
||||
address = '[color=ff0000]out of sync[/color]'
|
||||
|
||||
resultsqueue.put((balance, unlockedbalance, address))
|
||||
@@ -0,0 +1,16 @@
|
||||
import subprocess
|
||||
from sys import platform
|
||||
import os
|
||||
|
||||
def bitmonerodloader():
|
||||
"""Start bitmonerod and/or simplewallet and collect wallet name and address"""
|
||||
print "Start daemon button pressed..."
|
||||
#Start bitmonerod daemon if not running
|
||||
if platform == 'win32':
|
||||
daemonproc = subprocess.Popen("start bitmonerod.exe --rpc-bind-port 18081 --log-level 0",
|
||||
shell=True)
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'linux32':
|
||||
# print "linux!"
|
||||
daemonproc = subprocess.Popen('xterm -bg black -e "./bitmonerod --rpc-bind-port 18081 --log-level 0"',
|
||||
shell=True)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
serverURL = 'http://localhost:8082/json_rpc'
|
||||
|
||||
|
||||
def checkbalancerpccall():
|
||||
"""function to make rpc call to simplewallet to get current balance"""
|
||||
payload = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "getbalance",
|
||||
"params": {}
|
||||
})
|
||||
print 'attempting rpc call'
|
||||
try:
|
||||
#Make rpc call
|
||||
headers = {'content-type': 'application/json'}
|
||||
resp = requests.get(serverURL, headers=headers, data=payload)
|
||||
output = json.loads(resp.text)
|
||||
|
||||
#Parse json data to get balance info
|
||||
rawbalance = str(output[u'result'][u'balance']/1e12)
|
||||
rawunlockedbalance = str(output[u'result'][u'unlocked_balance']/1e12)
|
||||
|
||||
#Format data for kivy
|
||||
balance = '[color=00ff00]'+rawbalance+'[/color]'
|
||||
unlockedbalance = '[color=00ff00]'+rawunlockedbalance+'[/color]'
|
||||
return balance, unlockedbalance
|
||||
|
||||
|
||||
except:
|
||||
#Return out of sync if bitmonerod is not ready
|
||||
return '[color=ff0000]out of sync[/color]', '[color=ff0000]out of sync[/color]'
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
checkbalance()
|
||||
@@ -0,0 +1,55 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
import datetime
|
||||
|
||||
serverURL = 'http://localhost:18081/json_rpc'
|
||||
|
||||
headers = {'content-type': 'application/json'}
|
||||
|
||||
payload = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"id": "test",
|
||||
"method": "getlastblockheader"
|
||||
})
|
||||
|
||||
|
||||
def checklastblock(jobqueue, resultsqueue):
|
||||
"""Try and get last block info and return formatted text"""
|
||||
kivysignal = True
|
||||
while kivysignal:
|
||||
time.sleep(1)
|
||||
daemonrunning, kivysignal = jobqueue.get()
|
||||
if daemonrunning:
|
||||
try:
|
||||
resp = requests.get(serverURL, headers=headers, data=payload)
|
||||
output = json.loads(resp.text)
|
||||
# print(output)
|
||||
reward = output[u'result'][u'block_header'][u'reward']
|
||||
linuxblocktime = output[u'result'][u'block_header'][u'timestamp']
|
||||
linuxtimenow = time.time()
|
||||
timesince = linuxtimenow - linuxblocktime
|
||||
localtime = datetime.datetime.fromtimestamp(int(linuxblocktime
|
||||
)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
blocktext = "Last block height: [color=00ffff]{0}[/color]".format(
|
||||
output[u'result'][u'block_header'][u'height'])
|
||||
rewardtext = "Last block reward: [color=00ffff]{0:2.2f}[/color] XMR".format(float(reward)/1e12)
|
||||
timetext = "Last block time: [color=00ffff]{0}[/color]".format(localtime)
|
||||
timesincetext = "Time since last block: [color=00ffff]{0:4.2f} s[/color]".format(timesince)
|
||||
difftext = "Difficulty: [color=00ffff]{0}[/color]".format(
|
||||
output[u'result'][u'block_header'][u'difficulty'])
|
||||
orphantext = "Orphan status: [color=00ffff]{0}[/color]".format(
|
||||
output[u'result'][u'block_header'][u'orphan_status'])
|
||||
|
||||
except:
|
||||
blocktext = "Last block height: Not connected to daemon..."
|
||||
rewardtext = "Last block reward: Not connected to daemon..."
|
||||
timetext = "Last block time: Not connected to daemon..."
|
||||
timesincetext = "Time since last block: Not connected to daemon..."
|
||||
difftext = "Difficulty: Not connected to daemon..."
|
||||
orphantext = "Orphan status: connected to daemon..."
|
||||
|
||||
daemoninfo_labeltext = "[b]Last block info:[/b]\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}".format(
|
||||
blocktext, rewardtext, timetext, timesincetext, difftext, orphantext)
|
||||
resultsqueue.put(daemoninfo_labeltext)
|
||||
@@ -0,0 +1,22 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
serverURL = 'http://localhost:8082/json_rpc'
|
||||
|
||||
payload = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "store",
|
||||
"params": {}
|
||||
})
|
||||
|
||||
|
||||
def checkwalletrpccall():
|
||||
headers = {'content-type': 'application/json'}
|
||||
resp = requests.get(serverURL, headers=headers, data=payload)
|
||||
output = json.loads(resp.text)
|
||||
print output
|
||||
|
||||
# return output[u'result'][u'balance'], output[u'result'][u'unlocked_balance']
|
||||
|
||||
if __name__ == "__main__":
|
||||
checkwallet()
|
||||
@@ -0,0 +1,16 @@
|
||||
import subprocess
|
||||
from sys import platform
|
||||
|
||||
|
||||
def cpuminerloader(minerurl, user, pw, threads):
|
||||
"""Start cpuminer"""
|
||||
print "Start miner button pressed..."
|
||||
#Start cpuminer daemon if not running
|
||||
if platform == 'win32':
|
||||
daemonproc = subprocess.Popen("start minerd.exe -a cryptonight -o {0} -u {1} -p {2} -t {3}".format(
|
||||
minerurl, user, pw, threads), shell=True)
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'linux32':
|
||||
print "linux!"
|
||||
daemonproc = subprocess.Popen('xterm -bg black -e "./minerd -a cryptonight -o {0} -u {1} -p {2} -t {3}"'.format(
|
||||
minerurl, user, pw, threads), shell=True)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/python
|
||||
from sys import platform
|
||||
import subprocess as sub
|
||||
import time
|
||||
from lib.checklastblock import checklastblock
|
||||
|
||||
|
||||
def runningcheck():
|
||||
"""Function to check if daemon is running"""
|
||||
daemonrunning = False
|
||||
if platform == 'win32':
|
||||
import wmi
|
||||
wmi = wmi.WMI ()
|
||||
for process in wmi.Win32_Process(name='bitmonerod.exe'):
|
||||
#print process.ProcessId, process.Name
|
||||
if process.Name:
|
||||
daemonrunning = True
|
||||
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'linux32':
|
||||
p = sub.Popen("ps -A | grep bitmonerod", shell=True, stdout=sub.PIPE, stderr=sub.PIPE)
|
||||
output, errors = p.communicate()
|
||||
if output:
|
||||
daemonrunning = True
|
||||
return daemonrunning
|
||||
|
||||
def daemoncheck(queue):
|
||||
"""Check if bitmonerod daemon is running and return values to kivy"""
|
||||
print "Starting checkdaemon thread on: {0}".format(platform)
|
||||
|
||||
while True:
|
||||
daemonrunning = runningcheck()
|
||||
if daemonrunning:
|
||||
try:
|
||||
checklastblockoutput = checklastblock()
|
||||
|
||||
except:
|
||||
checklastblockoutput = 'error'
|
||||
else:
|
||||
checklastblockoutput = 'daemon not running'
|
||||
queue.put((daemonrunning, checklastblockoutput))
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
daemoncheck()
|
||||
@@ -0,0 +1,58 @@
|
||||
# !/usr/bin/python
|
||||
from sys import platform
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
def runningcheck():
|
||||
"""Function to check if daemon is running"""
|
||||
daemonrunning, walletrunning, minerrunning = False, False, False
|
||||
if platform == 'win32':
|
||||
import wmi
|
||||
|
||||
wmi = wmi.WMI()
|
||||
for process in wmi.Win32_Process():
|
||||
# print process.ProcessId, process.Name
|
||||
if process.Name == 'bitmonerod.exe':
|
||||
daemonrunning = True
|
||||
# print 'daemon'
|
||||
if process.Name == 'simplewallet.exe':
|
||||
walletrunning = True
|
||||
# print 'wallet'
|
||||
if process.Name == 'minerd.exe':
|
||||
minerrunning = True
|
||||
# print 'miner'
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'darwin':
|
||||
p = subprocess.Popen("ps -A", shell=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
output, errors = p.communicate()
|
||||
if 'bitmonerod' in output:
|
||||
daemonrunning = True
|
||||
if 'simplewallet' in output:
|
||||
walletrunning = True
|
||||
if 'minerd' in output:
|
||||
minerrunning = True
|
||||
return daemonrunning, walletrunning, minerrunning
|
||||
|
||||
|
||||
def isrunning(jobqueue, resultsqueue):
|
||||
"""Check if bitmonerod daemon is running and return values to kivy"""
|
||||
print "Starting checkdaemon thread on: {0}".format(platform)
|
||||
kivysignal = True
|
||||
while kivysignal:
|
||||
try:
|
||||
daemonrunning, walletrunning, minerrunning = runningcheck()
|
||||
if daemonrunning:
|
||||
daemoncheckerlabeltext = "[color=00ff00]It appears the bitmonerod daemon is running.[/color]"
|
||||
else:
|
||||
daemoncheckerlabeltext = "[color=ff0000]Click the [b]Start network daemon[/b] button to load bitmonerod.[/color]"
|
||||
if walletrunning:
|
||||
walletcheckerlabeltext = "[color=00ff00]It appears the simplewallet daemon is running.[/color]"
|
||||
else:
|
||||
walletcheckerlabeltext = "[color=00ff00]Click the [b]Initialize wallet file[/b] button to load simplewallet.[/color]"
|
||||
resultsqueue.put((daemonrunning, daemoncheckerlabeltext, walletrunning,
|
||||
walletcheckerlabeltext, minerrunning))
|
||||
except:
|
||||
pass
|
||||
time.sleep(0.1)
|
||||
kivysignal = jobqueue.get(kivysignal)
|
||||
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
def namecheck(jobqueue, resultsqueue):
|
||||
kivysignal = True
|
||||
while kivysignal:
|
||||
try:
|
||||
walletname, kivysignal = jobqueue.get()
|
||||
# print walletname
|
||||
if walletname == "No filename":
|
||||
message = "Please input a wallet file name..."
|
||||
isname = None
|
||||
elif os.path.isfile(walletname):
|
||||
message = "Wallet file {0} exists in local directory.\nPlease press [b]Initialize wallet file[/b] to [color=00ff00]load wallet file[/color].".format(walletname)
|
||||
isname = True
|
||||
if not os.path.isfile(walletname):
|
||||
message = "Wallet file {0} does not exist in your local directory.\nPlease press [b]Initialize wallet file[/b] to [color=00ff00]generate new wallet file[/color].".format(walletname)
|
||||
isname = False
|
||||
resultsqueue.put((isname, message))
|
||||
except:
|
||||
pass
|
||||
time.sleep(0.1)
|
||||
@@ -0,0 +1,26 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
serverURL = 'http://localhost:18081/save_bc'
|
||||
|
||||
headers = {'content-type': 'application/json'}
|
||||
|
||||
# payload = json.dumps({
|
||||
# "jsonrpc": "2.0",
|
||||
# "id": "test",
|
||||
# "method": "save_bc"
|
||||
# })
|
||||
|
||||
|
||||
def save_bc():
|
||||
#resp = requests.get(serverURL, headers=headers, data=payload)
|
||||
resp = requests.get(serverURL)
|
||||
# try:
|
||||
# output = json.loads(resp.text)
|
||||
# print output
|
||||
# except:
|
||||
# print "Waiting for bitmonerod client to sync with network..."
|
||||
# output = "Waiting for bitmonerod client to sync with network..."
|
||||
|
||||
print resp.text
|
||||
@@ -0,0 +1,25 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
serverURL = 'http://localhost:19091/json_rpc'
|
||||
|
||||
headers = {'content-type': 'application/json'}
|
||||
|
||||
payload = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "store",
|
||||
"params": {}
|
||||
})
|
||||
|
||||
|
||||
def storewallet():
|
||||
resp = requests.get(serverURL, headers=headers, data=payload)
|
||||
try:
|
||||
output = json.loads(resp.text)
|
||||
print output
|
||||
except:
|
||||
print "Waiting for bitmonerod client to sync with network..."
|
||||
output = "Waiting for bitmonerod client to sync with network..."
|
||||
|
||||
print output
|
||||
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
from sys import platform
|
||||
|
||||
|
||||
def simplewalletloader(walletname, walletpw, isname):
|
||||
"""Function to create and/or open wallet in simplewallet rpc mode"""
|
||||
# Launch simplewallet in rpc mode if wallet file exists
|
||||
if isname == True:
|
||||
# os.remove(walletname)
|
||||
print "***Opening ___" + walletname + "___ wallet file rpc interface***"
|
||||
if platform == 'win32':
|
||||
subprocess.Popen(
|
||||
"start simplewallet.exe --wallet-file {0} --password {1} --rpc-bind-port 19091 --set_log 0\r\nnpause".format(
|
||||
walletname, walletpw), shell=True)
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'darwin':
|
||||
subprocess.Popen(
|
||||
'xterm -bg black -hold -e "./simplewallet --wallet-file {0} --password {1} --rpc-bind-port 19091"'.format(
|
||||
walletname, walletpw))
|
||||
|
||||
# Generate and then launch if wallet file doesn't exist
|
||||
elif isname == False:
|
||||
print "Generating wallet file " + walletname
|
||||
if platform == 'win32':
|
||||
walletgen = subprocess.Popen(
|
||||
"simplewallet.exe --generate-new-wallet {0} --password {1} --set_log 0".format(
|
||||
walletname, walletpw), shell=True, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'darwin':
|
||||
walletgen = subprocess.Popen(
|
||||
"./simplewallet --generate-new-wallet {0} --password {1} --set_log 0".format(
|
||||
walletname, walletpw), shell=True, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
print "Wallet gen'ed"
|
||||
time.sleep(5)
|
||||
#print walletgen.stdout.read()
|
||||
#print walletgen.communicate('exit')
|
||||
walletgen.terminate()
|
||||
if platform == 'win32':
|
||||
os.system("taskkill /im simplewallet.exe /f")
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'darwin':
|
||||
p = subprocess.Popen("pgrep simplewallet", shell=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
output, errors = p.communicate()
|
||||
output = output.split('\n')
|
||||
for i in output:
|
||||
os.system("kill -9 {0}".format(i))
|
||||
# Launch simplewallet in rpc mode now that wallet file exists
|
||||
print "***Opening ___" + walletname + "___ wallet file rpc interface***"
|
||||
if platform == 'win32':
|
||||
subprocess.Popen(
|
||||
"start simplewallet --wallet-file {0} --password {1} --rpc-bind-port 19091 --set_log 0\r\nnpause".format(
|
||||
walletname, walletpw), shell=True)
|
||||
elif platform == 'linux' or platform == 'linux2' or platform == 'linux32':
|
||||
subprocess.Popen(
|
||||
'xterm -bg black -hold -e "./simplewallet --wallet-file {0} --password {1} --rpc-bind-port 19091 --set_log 0"'.format(
|
||||
walletname, walletpw), shell=True)
|
||||
|
||||
|
||||
elif isname == None:
|
||||
pass
|
||||
@@ -0,0 +1,64 @@
|
||||
import requests
|
||||
import json
|
||||
from ctypes import c_uint64
|
||||
|
||||
serverURL = 'http://localhost:19091/json_rpc'
|
||||
|
||||
|
||||
def transferfundsrpccall(amount, address, mixin, paymentid):
|
||||
"""function to transfer funds to a single address"""
|
||||
atomicamount = c_uint64(int((float(amount)*1e12)-1e6))
|
||||
address = str(address)
|
||||
mixin = int(mixin)
|
||||
paymentid = str(paymentid)
|
||||
mro_fee = c_uint64(int(5e9))
|
||||
if len(paymentid) > 1:
|
||||
payload = json.dumps({
|
||||
"jsonrpc":"2.0",
|
||||
"method":"transfer",
|
||||
"params":{
|
||||
"destinations":[
|
||||
{
|
||||
"amount":atomicamount.value,
|
||||
"address":address
|
||||
}
|
||||
],
|
||||
"fee":mro_fee.value,
|
||||
"mixin":mixin,
|
||||
"unlock_time":0,
|
||||
"payment_id":paymentid
|
||||
}
|
||||
})
|
||||
else:
|
||||
payload = json.dumps({
|
||||
"jsonrpc":"2.0",
|
||||
"method":"transfer",
|
||||
"params":{
|
||||
"destinations":[
|
||||
{
|
||||
"amount":atomicamount.value,
|
||||
"address":address
|
||||
}
|
||||
],
|
||||
"fee":mro_fee.value,
|
||||
"mixin":mixin,
|
||||
"unlock_time":0
|
||||
}
|
||||
})
|
||||
print payload
|
||||
|
||||
try:
|
||||
headers = {'content-type': 'application/json'}
|
||||
resp = requests.get(serverURL, headers=headers, data=payload)
|
||||
output = json.loads(resp.text)
|
||||
print output
|
||||
txid = output[u'result'][u'tx_hash']
|
||||
return txid
|
||||
|
||||
except:
|
||||
print "transfer error :0 !!!"
|
||||
return "error"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
checkbalance()
|
||||
Reference in New Issue
Block a user