Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Initial sources (v 0.9.0)
  • Loading branch information
Bertrand256 authored Mar 19, 2017
1 parent 8343914 commit b333c05
Show file tree
Hide file tree
Showing 29 changed files with 4,967 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dash_masternode_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
import PyQt5.QtWidgets as qwi
from PyQt5.QtGui import QIcon
from src import wnd_main


if __name__ == '__main__':
if getattr(sys, 'frozen', False):
app_path = base_path = sys._MEIPASS
else:
app_path = os.path.dirname(__file__)

app = qwi.QApplication(sys.argv)
window = qwi.QMainWindow()
ui = wnd_main.Ui_MainWindow(app_path)
ui.setupUi(window)
window.show()

try:
ico_path = os.path.join(app_path, 'img', 'dmt.ico')
if os.path.exists(ico_path):
app_icon = QIcon(ico_path)
app.setWindowIcon(app_icon)
except:
pass
sys.exit(app.exec_())

48 changes: 48 additions & 0 deletions dash_masternode_tool_mac.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- mode: python -*-
import sys
import os

block_cipher = None

lib_path = os.path.join(os.path.dirname(os.path.realpath('__file__')), 'venv3/lib/python3.5/site-packages')

add_files = [
(os.path.join(lib_path, 'bitcoin/english.txt'),'/bitcoin'),
('img/dash-logo.png','/img'),
('img/dmt.png','/img'),
('img/dash.ico','/img'),
('img/dmt.ico','/img'),
('version.txt', '')
]

a = Analysis(['dash_masternode_tool.py'],
pathex=[os.path.dirname(os.path.realpath('__file__'))],
binaries=[],
datas=add_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='DashMasternodeTool',
debug=False,
strip=False,
upx=True,
console=False,
icon='img/dmt.icns' )

app = BUNDLE(exe,
name='DashMasternodeTool.app',
icon='img/dmt.icns',
bundle_identifier=None)
43 changes: 43 additions & 0 deletions dash_masternode_tool_win.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- mode: python -*-
import sys
import os

block_cipher = None

lib_path = os.path.join(os.path.dirname(os.path.realpath('__file__')), 'venv3\\Lib\\site-packages')
qt5_path = os.path.join(lib_path, 'PyQt5\\Qt\\bin')

sys.path.append(qt5_path)
add_files = [
(os.path.join(lib_path, 'bitcoin/english.txt'),'/bitcoin'),
('img/dash-logo.png','/img'),
('img/dmt.png','/img'),
('img/dmt.ico','/img'),
('version.txt', '')
]

a = Analysis(['dash_masternode_tool.py'],
pathex=[os.path.dirname(os.path.realpath('__file__'))],
binaries=[],
datas=add_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='DashMasternodeTool',
debug=False,
strip=False,
upx=True,
console=False,
icon='img\\dmt.ico' )

Binary file added img/dash.icns
Binary file not shown.
Binary file added img/dash.ico
Binary file not shown.
Binary file added img/dmt.icns
Binary file not shown.
Binary file added img/dmt.ico
Binary file not shown.
Binary file added img/dmt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 143 additions & 0 deletions src/app_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Bertrand256
# Created on: 2017-03

import os
import re
from configparser import ConfigParser
from os.path import expanduser


APP_NAME_SHORT = 'DashMasternodeTool'
APP_NAME_LONG = 'Dash Masternode Tool'


class AppConfig(object):
def __init__(self):
self.dashd_connect_method = 'rpc' # values: 'rpc', 'rpc_ssh'
self.rpc_user = ''
self.rpc_password = ''
self.rpc_ip = '127.0.0.1'
self.rpc_port = '9998'

# configuration for RPC over SSH mode
self.ros_ssh_host = ''
self.ros_ssh_port = '22'
self.ros_ssh_username = ''
self.ros_rpc_bind_ip = ''
self.ros_rpc_bind_port = '9998'
self.ros_rpc_username = ''
self.ros_rpc_password = ''

self.masternodes = []
self.last_bip32_base_path = ''
self.bip32_recursive_search = True
self.modified = False
home_dir = expanduser('~')
app_user_dir = os.path.join(home_dir, APP_NAME_SHORT)
if not os.path.exists(app_user_dir):
os.makedirs(app_user_dir)
self.app_config_file_name = os.path.join(app_user_dir, 'config.ini')

def read_from_file(self):
if os.path.exists(self.app_config_file_name):
config = ConfigParser()
try:
section = 'CONFIG'
config.read(self.app_config_file_name)
self.dashd_connect_method = config.get(section, 'dashd_connect_method', fallback='rpc')
self.rpc_user = config.get(section, 'rpc_user', fallback='')
self.rpc_password = config.get(section, 'rpc_password', fallback='')
self.rpc_ip = config.get(section, 'rpc_ip', fallback='')
self.rpc_port = config.get(section, 'rpc_port', fallback='8889')
self.ros_ssh_host = config.get(section, 'ros_ssh_host', fallback='')
self.ros_ssh_port = config.get(section, 'ros_ssh_port', fallback='22')
self.ros_ssh_username = config.get(section, 'ros_ssh_username', fallback='')
self.ros_rpc_bind_ip = config.get(section, 'ros_rpc_bind_ip', fallback='127.0.0.1')
self.ros_rpc_bind_port = config.get(section, 'ros_rpc_bind_port', fallback='9998')
self.ros_rpc_username = config.get(section, 'ros_rpc_username', fallback='')
self.ros_rpc_password = config.get(section, 'ros_rpc_password', fallback='')
self.last_bip32_base_path = config.get(section, 'bip32_base_path', fallback="44'/5'/0'/0/0")
if not self.last_bip32_base_path:
self.last_bip32_base_path = "44'/5'/0'/0/0/0"
self.bip32_recursive_search = config.getboolean(section, 'bip32_recursive', fallback=True)

for section in config.sections():
if re.match('MN\d', section):
mn = MasterNodeConfig()
mn.name = config.get(section, 'name', fallback='')
mn.ip = config.get(section, 'ip', fallback='')
mn.port = config.get(section, 'port', fallback='')
mn.privateKey = config.get(section, 'private_key', fallback='')
mn.collateralBip32Path = config.get(section, 'collateral_bip32_path', fallback='')
mn.collateralAddress = config.get(section, 'collateral_address', fallback='')
mn.collateralTx = config.get(section, 'collateral_tx', fallback='')
mn.collateralTxIndex = config.get(section, 'collateral_tx_index', fallback='')
self.masternodes.append(mn)
except Exception as e:
pass

def save_to_file(self):
section = 'CONFIG'
config = ConfigParser()
config.add_section(section)
config.set(section, 'dashd_connect_method', self.dashd_connect_method)
config.set(section, 'rpc_user', self.rpc_user)
config.set(section, 'rpc_password', self.rpc_password)
config.set(section, 'rpc_ip', self.rpc_ip)
config.set(section, 'rpc_port', str(self.rpc_port))
config.set(section, 'ros_ssh_host', str(self.ros_ssh_host))
config.set(section, 'ros_ssh_port', str(self.ros_ssh_port))
config.set(section, 'ros_ssh_username', str(self.ros_ssh_username))
config.set(section, 'ros_rpc_bind_ip', str(self.ros_rpc_bind_ip))
config.set(section, 'ros_rpc_bind_port', str(self.ros_rpc_bind_port))
config.set(section, 'ros_rpc_username', str(self.ros_rpc_username))
config.set(section, 'ros_rpc_password', str(self.ros_rpc_password))
config.set(section, 'bip32_base_path', self.last_bip32_base_path)

for idx, mn in enumerate(self.masternodes):
section = 'MN' + str(idx+1)
config.add_section(section)
config.set(section, 'name', mn.name)
config.set(section, 'ip', mn.ip)
config.set(section, 'port', str(mn.port))
config.set(section, 'private_key', mn.privateKey)
config.set(section, 'collateral_bip32_path', mn.collateralBip32Path)
config.set(section, 'collateral_address', mn.collateralAddress)
config.set(section, 'collateral_tx', mn.collateralTx)
config.set(section, 'collateral_tx_index', str(mn.collateralTxIndex))
mn.modified = False

with open(self.app_config_file_name, 'w') as f_ptr:
config.write(f_ptr)
self.modified = False

def is_config_complete(self):
if self.dashd_connect_method == 'rpc':
if self.rpc_user and self.rpc_password and self.rpc_ip and self.rpc_port:
return True
elif self.dashd_connect_method == 'rpc_ssh':
if self.ros_ssh_host and self.ros_ssh_port and self.ros_ssh_username and self.ros_rpc_bind_ip \
and self.ros_rpc_bind_port and self.ros_rpc_username and self.ros_rpc_password:
return True
return False


class MasterNodeConfig:
def __init__(self):
self.name = ''
self.ip = ''
self.port = '9999'
self.privateKey = ''
self.collateralBip32Path = "44'/5'/0'/0/0"
self.collateralAddress = ''
self.collateralTx = ''
self.collateralTxIndex = ''
self.new = False
self.modified = False
self.lock_modified_change = False

def set_modified(self):
if not self.lock_modified_change:
self.modified = True
127 changes: 127 additions & 0 deletions src/dash_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Bertrand256
# Created on: 2017-03

import binascii
import bitcoin
from lib import base58


def pubkey_to_address(pubkey):
"""
Based on project: https://github.com/chaeplin/dashmnb with some changes related to usage of bitcoin library.
"""
pubkey_bin = bytes.fromhex(pubkey)
pub_hash = bitcoin.bin_hash160(pubkey_bin)
data = bytes([76]) + pub_hash
checksum = bitcoin.bin_dbl_sha256(data)[0:4]
return base58.b58encode(data + checksum)


def generate_privkey():
"""
Based on Andreas Antonopolous work from 'Mastering Bitcoin'.
"""
valid = False
privkey = 0
while not valid:
privkey = bitcoin.random_key()
decoded_private_key = bitcoin.decode_privkey(privkey, 'hex')
valid = 0 < decoded_private_key < bitcoin.N
data = bytes([204]) + bytes.fromhex(privkey)
checksum = bitcoin.bin_dbl_sha256(data)[0:4]
return base58.b58encode(data + checksum)


def num_to_varint(a):
"""
Based on project: https://github.com/chaeplin/dashmnb
"""
x = int(a)
if x < 253:
return x.to_bytes(1, byteorder='big')
elif x < 65536:
return int(253).to_bytes(1, byteorder='big') + \
x.to_bytes(2, byteorder='little')
elif x < 4294967296:
return int(254).to_bytes(1, byteorder='big') + \
x.to_bytes(4, byteorder='little')
else:
return int(255).to_bytes(1, byteorder='big') + \
x.to_bytes(8, byteorder='little')


def wif_to_privkey(string):
"""
Based on project: https://github.com/chaeplin/dashmnb with some changes related to usage of bitcoin library.
"""
wif_compressed = 52 == len(string)
pvkeyencoded = base58.b58decode(string).hex()
wifversion = pvkeyencoded[:2]
wif_prefix = 204
checksum = pvkeyencoded[-8:]

vs = bytes.fromhex(pvkeyencoded[:-8])
check = binascii.unhexlify(bitcoin.dbl_sha256(vs))[0:4]

if wifversion == wif_prefix.to_bytes(1, byteorder='big').hex() and checksum == check.hex():
if wif_compressed:
privkey = pvkeyencoded[2:-10]
else:
privkey = pvkeyencoded[2:-8]

return privkey
else:
return None


def from_string_to_bytes(a):
"""
Based on project: https://github.com/chaeplin/dashmnb.
"""
return a if isinstance(a, bytes) else bytes(a, 'utf-8')


def electrum_sig_hash(message):
"""
Based on project: https://github.com/chaeplin/dashmnb.
"""
padded = b"\x19DarkCoin Signed Message:\n" + \
num_to_varint(len(message)) + from_string_to_bytes(message)
return bitcoin.dbl_sha256(padded)


def ecdsa_sign(msg, priv):
"""
Based on project: https://github.com/chaeplin/dashmnb with some changes related to usage of bitcoin library.
"""
v, r, s = bitcoin.ecdsa_raw_sign(electrum_sig_hash(msg), priv)
sig = bitcoin.encode_sig(v, r, s)
pubkey = bitcoin.privkey_to_pubkey(wif_to_privkey(priv))

ok = bitcoin.ecdsa_raw_verify(electrum_sig_hash(msg), bitcoin.decode_sig(sig), pubkey)
if not ok:
raise Exception('Bad signature!')
return sig


def serialize_input_str(tx, prevout_n, sequence, script_sig):
"""
Based on project: https://github.com/chaeplin/dashmnb.
"""
s = ['CTxIn(']
s.append('COutPoint(%s, %s)' % (tx, prevout_n))
s.append(', ')
if tx == '00' * 32 and prevout_n == 0xffffffff:
s.append('coinbase %s' % script_sig)
else:
script_sig2 = script_sig
if len(script_sig2) > 24:
script_sig2 = script_sig2[0:24]
s.append('scriptSig=%s' % script_sig2)

if sequence != 0xffffffff:
s.append(', nSequence=%d' % sequence)
s.append(')')
return ''.join(s)
Loading

0 comments on commit b333c05

Please sign in to comment.