Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version = 1

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
65 changes: 65 additions & 0 deletions contrib/slp_validation_proxy_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SLP Token Validation Proxy Server

Electron-Cash-SLP can be run in daemon mode to serve token validation requests using the JSON RPC interface. The following instructions explain how to set this service up using Ubuntu with nginx reverse proxy server.

## Docker

The validation server can be run as a docker container. See the `docker` folder for Dockerfiles for both mainnet and testnet.

For mainnet SLP validator use:
- `docker build -t ec-slp .`
- `docker run -d -p 5111:5111 --restart "always" ec-slp`
- Test: `curl --data-binary '{"jsonrpc": "2.0", "id":"testing", "method": "slpvalidate", "params": ["2504b5b6a6ec42b040a71abce1acd71592f7e2a3e33ffa9c415f91a6b76deb45", false, false] }' -H 'content-type: text/plain;' 0.0.0.0:5111`

For testnet SLP validator use:
- `docker build -t ec-slp-testnet .`
- `docker run -d -p 5112:5112 --restart "always" ec-slp-test`
- Test: `curl --data-binary '{"jsonrpc": "2.0", "id":"testing", "method": "slpvalidate", "params": ["5e9454840d838c81ac0c41f0754df239f1c1012623161359fbf6e22599605c25", false, false] }' -H 'content-type: text/plain;' 0.0.0.0:5112`

Skip steps 1 & 2 if you're using docker.

## 1) Initial Server Config Steps

1) Setup an Ubuntu vps.

2) Clone this project into the home directory (i.e. `~/`) & cd into the `Electron-Cash-SLP` directory.

3) Run the proper Electron Cash installation commands as described in the README for this project.

4) Open `~/.electron-cash/config` and set `rpcport` to some constant port number & `rpcpassword=""`.

5) Run `./elctron-cash create` to create a new wallet file. This wallet should not be used to store any funds, it is only used to store SLP validation data for cache purposes.

## 2) Creating a persistent service with systemd

1) Copy the file named `slpvalidate.service` into `/lib/systemd/system/` directory. Make sure the paths within the `slpvalidate.serice` file match the location of your Electron-Cash-SLP directory.

2) Run `sudo systemctl enable slpvalidate`

3) Run `sudo systemctl start slpvalidate`

4) Check that the service is running via `sudo systemctl status slpvalidate`

## 3) Setting up the reverse proxy server for this validation service.

1) Setup an nginx server per these instructions: https://linuxize.com/post/how-to-install-nginx-on-ubuntu-18-04/

2) Do an initial Setup for SSL via "Let's Enctypy" using these instructions but for your desired domain: https://linuxize.com/post/secure-nginx-with-let-s-encrypt-on-ubuntu-18-04/

3) Use the Nginx Server block file named `simpleledger.info`. Update the contents of the file to reflect your specific domain / sub-domain. Rename the file to reflect your specific domain / sub-domain. Then copy this file into your `/etc/nginx/sites-available/` directory.

4) Run `sudo ln -s /etc/nginx/sites-available/<your-domain> /etc/nginx/sites-enabled/`

5) Check that the syntax is all good: `sudo nginx -t`

6) Restart Nginx: `sudo systemctl restart nginx`

7) Test that the service is working via: `curl --data-binary '{"jsonrpc": "2.0", "id":"testing", "method": "slpvalidate", "params": ["2504b5b6a6ec42b040a71abce1acd71592f7e2a3e33ffa9c415f91a6b76deb45", false, false] }' -H 'content-type: text/plain;' https://validate.simpleledger.info`. Replace `validate.simpleledger.info` with your own domain.

## Other notes & warnings

* You can speed up your SLP validation server by also installing ElectrumX side-by-side and connecting to it directly.

* Running multiple instances of EC SLP using a load balancer can be accomplished using `electron-cash daemon --dir=<unuiqe-application-directory-per-instance>`, where the directory is just a copy of the `~/.electron-cash` directory.

* It should be noted that the Electron-Cash-SLP validator was not designed to be operated as a long running server application. In this type of operation the validator object may cause memory useage issues as the number of validation requests increases. Each time a new validation is performed the DAG and validation results are added to memory for caching purposes. Also, if the Electron-Cash-SLP daemon is not shut down via command-line, then the previously calculated validation results may not be written to the wallet file for future use. Future improvements to the validator will need to fix these issues so that the validator can be run safely as a long running process.
26 changes: 26 additions & 0 deletions contrib/slp_validation_proxy_server/docker/mainnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:18.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y git curl nano gnupg wget
RUN apt-get install -y python3-pip python3-setuptools expect

RUN git clone -b 3.4.4 https://github.com/simpleledger/Electron-Cash-SLP.git && \
cd Electron-Cash-SLP && \
python3 setup.py install && \
apt-get -y install protobuf-compiler && \
protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto

COPY ./config /Electron-Cash-SLP/config
COPY ./create_wallet.sh /Electron-Cash-SLP/create_wallet.sh
COPY ./start_daemon.sh /Electron-Cash-SLP/start_daemon.sh

WORKDIR /Electron-Cash-SLP

RUN ./create_wallet.sh

EXPOSE 5112

#CMD ["/bin/bash"]
CMD ["./start_daemon.sh"]
7 changes: 7 additions & 0 deletions contrib/slp_validation_proxy_server/docker/mainnet/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"config_version": 2,
"rpcpassword": "",
"rpcuser": "user",
"rpcport": 5111,
"rpchost": "0.0.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/expect -f
set timeout 10
spawn ./electron-cash create --dir=/Electron-Cash-SLP
expect "Password (hit return if you do not wish to encrypt your wallet):"
send "\r"
expect eof
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -m
./electron-cash daemon --dir=/Electron-Cash-SLP &
sleep 5
./electron-cash daemon --dir=/Electron-Cash-SLP load_wallet
fg %1
26 changes: 26 additions & 0 deletions contrib/slp_validation_proxy_server/docker/testnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:18.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y git curl nano gnupg wget
RUN apt-get install -y python3-pip python3-setuptools expect

RUN git clone -b 3.4.4 https://github.com/simpleledger/Electron-Cash-SLP.git && \
cd Electron-Cash-SLP && \
python3 setup.py install && \
apt-get -y install protobuf-compiler && \
protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto

COPY ./config /Electron-Cash-SLP/testnet/config
COPY ./create_wallet.sh /Electron-Cash-SLP/create_wallet.sh
COPY ./start_daemon.sh /Electron-Cash-SLP/start_daemon.sh

WORKDIR /Electron-Cash-SLP

RUN ./create_wallet.sh

EXPOSE 5112

#CMD ["/bin/bash"]
CMD ["./start_daemon.sh"]
7 changes: 7 additions & 0 deletions contrib/slp_validation_proxy_server/docker/testnet/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"config_version": 2,
"rpcpassword": "",
"rpcuser": "user",
"rpcport": 5112,
"rpchost": "0.0.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/expect -f
set timeout 10
spawn ./electron-cash create --testnet --dir=/Electron-Cash-SLP
expect "Password (hit return if you do not wish to encrypt your wallet):"
send "\r"
expect eof
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -m
./electron-cash daemon --testnet --dir=/Electron-Cash-SLP &
sleep 5
./electron-cash daemon --testnet --dir=/Electron-Cash-SLP load_wallet
fg %1
37 changes: 37 additions & 0 deletions contrib/slp_validation_proxy_server/simpleledger.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
server {
listen 80;
listen [::]:80;

server_name validate.simpleledger.info;

include snippets/letsencrypt.conf;
return 301 https://$host$request_uri;
}

log_format my_tracking $request_body;

server {
listen 443 ssl http2;
server_name validate.simpleledger.info;

ssl_certificate /etc/letsencrypt/live/validate.simpleledger.info/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/validate.simpleledger.info/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/validate.simpleledger.info/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;

location / {
if ($request_method != POST) {
return 405;
}

proxy_pass http://127.0.0.1:5111;

add_header X-Frame-Options "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;

access_log /var/log/nginx/simpleledger.info.access.log my_tracking;
error_log /var/log/nginx/simpleledger.info.error.log;
}
13 changes: 13 additions & 0 deletions contrib/slp_validation_proxy_server/slpvalidate.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=SLP Token Validation Service
After=network.target

[Service]
User=ubuntu
ExecStartPre=/bin/sleep 2.0
ExecStart=/home/ubuntu/Electron-Cash-SLP/electron-cash daemon -v
ExecStartPost=/bin/sleep 2.0
ExecStartPost=/home/ubuntu/Electron-Cash-SLP/electron-cash daemon load_wallet

[Install]
WantedBy=multi-user.target
8 changes: 4 additions & 4 deletions contrib/zclassic/osx.spec
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ exe = EXE(pyz,
upx=False,
console=False,
icon='icons/electrum-zclassic.ico',
name=os.path.join('build/electrum-zclassic/electrum-zclassic', cmdline_name))
name=os.path.join('build/electrum-zclassic/electrum-zslp', cmdline_name))

# trezorctl separate bin
tctl_a = Analysis([os.path.join(PY36BINDIR, 'trezorctl')],
Expand All @@ -148,10 +148,10 @@ coll = COLLECT(exe, tctl_exe,
a.datas,
strip=False,
upx=False,
name=os.path.join('dist', 'electrum-zclassic'))
name=os.path.join('dist', 'electrum-zslp'))

app = BUNDLE(coll,
name=os.path.join('dist', 'Electrum-Zclassic.app'),
appname="Electrum-Zclassic",
name=os.path.join('dist', 'Electrum-ZSLP.app'),
appname="Electrum-ZSLP",
icon='electrum-zclassic.icns',
version = 'ELECTRUM_VERSION')
2 changes: 1 addition & 1 deletion contrib/zclassic/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protobuf==3.5.0.post1
pyaes==1.6.1
PySocks==1.6.7
qrcode==5.3
requests==2.18.4
requests==2.20.0
six==1.11.0
urllib3==1.22
pyblake2==1.1.2
8 changes: 4 additions & 4 deletions contrib/zclassic/travis/travis-build-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ cp contrib/zclassic/pyi_tctl_runtimehook.py .

pyinstaller \
-y \
--name electrum-zclassic-$ELECTRUM_ZCL_VERSION.bin \
--name electrum-zslp-$ELECTRUM_ZCL_VERSION.bin \
osx.spec

sudo hdiutil create -fs HFS+ -volname "Electrum-Zclassic" \
-srcfolder dist/Electrum-Zclassic.app \
dist/electrum-zclassic-$ELECTRUM_ZCL_VERSION-macosx.dmg
sudo hdiutil create -fs HFS+ -volname "Electrum-ZSLP" \
-srcfolder dist/Electrum-ZSLP.app \
dist/electrum-zslp-$ELECTRUM_ZCL_VERSION-macosx.dmg
3 changes: 2 additions & 1 deletion electrum-zclassic.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Icon=electrum-zclassic.png
Name[en_US]=Electrum-Zclassic Wallet
Name=Electrum-Zclassic Wallet
Categories=Finance;Network;
StartupNotify=false
StartupNotify=true
StartupWMClass=Electrum Zclassic
Terminal=false
Type=Application
MimeType=x-scheme-handler/zclassic;
Expand Down
4 changes: 2 additions & 2 deletions electrum-zclassic → electrum-zslp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def run_non_RPC(config):
elif cmdname == 'create':
password = password_dialog()
passphrase = config.get('passphrase', '')
seed_type = 'standard'
seed = Mnemonic('en').make_seed(seed_type)
#seed_type = 'standard' <--- This is no longer applicable with SLP version since it only uses BIP-39
seed = Mnemonic('en').make_seed()
k = keystore.from_seed(seed, passphrase, False)
storage.put('keystore', k.dump())
storage.put('wallet_type', 'standard')
Expand Down
2 changes: 1 addition & 1 deletion gui/kivy/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def show_private_key(addr, pk_label, password):
if not self.wallet.can_export():
return
try:
key = str(self.wallet.export_private_key(addr, password)[0])
key = self.wallet.export_private_key(addr, password)
pk_label.data = key
except InvalidPassword:
self.show_error("Invalid PIN")
Expand Down
2 changes: 1 addition & 1 deletion gui/kivy/uix/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def get_new_address(self):
self.clear()
addr = self.app.wallet.get_unused_address()
if addr is None:
addr = self.app.wallet.get_receiving_address() or ''
addr = self.app.wallet.get_receiving_address_text()
b = False
else:
b = True
Expand Down
23 changes: 16 additions & 7 deletions gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def __init__(self, windows):
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.FileOpen:
if len(self.windows) >= 1:
self.windows[0].pay_to_URI(event.url().toEncoded())
return True
try:
self.windows[0].pay_to_URI(event.url().toEncoded())
return True
except:
pass
return False


Expand All @@ -97,7 +100,7 @@ def __init__(self, config, daemon, plugins):
if hasattr(QtCore.Qt, "AA_ShareOpenGLContexts"):
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
if hasattr(QGuiApplication, 'setDesktopFileName'):
QGuiApplication.setDesktopFileName('electrum-zclassic.desktop')
QGuiApplication.setDesktopFileName('electrum-zclassic-slp.desktop')
self.config = config
self.daemon = daemon
self.plugins = plugins
Expand All @@ -111,7 +114,7 @@ def __init__(self, config, daemon, plugins):
# init tray
self.dark_icon = self.config.get("dark_icon", False)
self.tray = QSystemTrayIcon(self.tray_icon(), None)
self.tray.setToolTip('Electrum-Zclassic')
self.tray.setToolTip('Electrum-ZSLP')
self.tray.activated.connect(self.tray_activated)
self.build_tray_menu()
self.tray.show()
Expand All @@ -133,7 +136,7 @@ def build_tray_menu(self):
submenu.addAction(_("Close"), window.close)
m.addAction(_("Dark/Light"), self.toggle_tray_icon)
m.addSeparator()
m.addAction(_("Exit Electrum-Zclassic"), self.close)
m.addAction(_("Exit Electrum-ZSLP"), self.close)

def tray_icon(self):
if self.dark_icon:
Expand Down Expand Up @@ -165,7 +168,7 @@ def new_window(self, path, uri=None):

def show_network_dialog(self, parent):
if not self.daemon.network:
parent.show_warning(_('You are using Electrum-Zclassic in offline mode; restart Electrum-Zclassic if you want to get connected'), title=_('Offline'))
parent.show_warning(_('You are using Electrum-ZSLP in offline mode; restart Electrum-ZSLP if you want to get connected'), title=_('Offline'))
return
if self.nd:
self.nd.on_update()
Expand Down Expand Up @@ -197,7 +200,7 @@ def start_new_window(self, path, uri):
return
if not wallet:
storage = WalletStorage(path, manual_upgrades=True)
wizard = InstallWizard(self.config, self.app, self.plugins, storage)
wizard = InstallWizard(self.config, self.app, self.plugins, storage, 'New/Restore Wallet')
try:
wallet = wizard.run_and_get_wallet(self.daemon.get_wallet)
except UserCancelled:
Expand Down Expand Up @@ -256,6 +259,12 @@ def init_network(self):
wizard.init_network(self.daemon.network)
wizard.terminate()

def warn_if_no_network(self, parent):
if not self.daemon.network:
self.warning(message=_('You are using Electrum-ZSLP in offline mode; restart Electrum-ZSLP if you want to get connected'), title=_('Offline'), parent=parent)
return True
return False

def main(self):
try:
self.init_network()
Expand Down
Loading