Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Merge pull request #2 from ser/electrum-merchant
Browse files Browse the repository at this point in the history
restored full previous merchant functionality
  • Loading branch information
ecdsa authored Feb 4, 2018
2 parents 319ca53 + ee71e71 commit 462c803
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 31 deletions.
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENCE
include README.rst
recursive-include electrum-merchant/contrib *
recursive-include electrum-merchant/simple *
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Electrum-merchant
-----------------
This is an add-on to Electrum wallet, which allows Electrum to function as a payment service.
Full documentation is available on: http://docs.electrum.org/en/latest/merchant.html
File renamed without changes.
Empty file added electrum-merchant/__init__.py
Empty file.
113 changes: 113 additions & 0 deletions electrum-merchant/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import argparse
import errno
import io
import os
import requests
import shutil
import subprocess
import sys
import tarfile
import zipfile
from electrum import SimpleConfig
from npmdownloader import NpmPackageDownloader
from .logger import log

_ROOT = os.path.abspath(os.path.dirname(__file__))

def get_data(path):
return os.path.join(_ROOT, path)

def untar(fileName):
log.info("Processing: %s into %s" % (fileName, os.path.dirname(fileName)))
tar = tarfile.open(fileName)
try:
tar.extractall(path=os.path.dirname(fileName))
log.info("Deleting %s" % fileName)
os.unlink (fileName)
except tar.TarError:
log.error("Problems with extracting JavaScript library!")
tar.close()

def walkFiles(dirName):
dirs = os.walk(dirName)
for (dirPath, dirNames, fileNames) in dirs:
for dirName in dirNames:
walkFiles(os.path.join(dirPath, dirName))
for fileName in fileNames:
if tarfile.is_tarfile(os.path.join(dirPath, fileName)):
untar(os.path.join(dirPath, fileName))

def main():
parser = argparse.ArgumentParser(description='Install merchant add on files\
for Electrum wallet running in daemon mode.',
prog = "python3 -m electrum-merchant",
epilog = "Consult documentation on:\
http://docs.electrum.org/en/latest/merchant.html",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-f', '--flavour', nargs='?', required=False, default="simple",
help='Which merchant flavour should be installed [simple]'
)
parser.add_argument(
'-n', '--network', nargs='?', required=False, default="mainnet",
help='Coin network [mainnet, testnet]'
)
args = parser.parse_args()

log.info('Downloading and installing files into request directory')
if args.network == "mainnet":
config = SimpleConfig()
elif args.network == "testnet":
config = SimpleConfig(options = {'testnet': True})
else:
log.error("Unknown network, exiting...")
exit(1)
rdir = config.get('requests_dir')
if not rdir:
log.error("requests_dir not found in Electrum configuration, exiting...")
exit(1)
sdir = os.path.join(rdir, 'static')
if not os.path.exists(rdir):
os.mkdir(rdir)
if not os.path.exists(sdir):
os.mkdir(sdir)
# Copying the flavoured index.html
log.info("copying index.html from flavour %s" % args.flavour)
indexsrc = get_data(args.flavour + "/index.html")
indexdst = os.path.join(rdir, 'index.html')
shutil.copy(indexsrc, indexdst)
# Downloading libraries from NPM registry and unpacking them
downloader = NpmPackageDownloader(sdir)
downloader.download('jquery')
downloader.download('qrcodejs')
walkFiles(sdir)
# Downloading libraries from other sources and unpacking them
# jquery-ui
r = requests.get("https://code.jquery.com/ui/1.12.1/jquery-ui.min.js")
if r.status_code == 200:
with open(os.path.join(sdir, 'jquery-ui.min.js'), 'w') as f:
f.write(r.text)
log.info('Downloaded Jquery-UI.')
else:
log.error('Problems with downloading Jquery-UI.')
# jquery-ui-fix-3
r = requests.get("https://code.jquery.com/jquery-migrate-3.0.1.min.js")
if r.status_code == 200:
with open(os.path.join(sdir, 'jquery-migrate-3.0.1.js'), 'w') as f:
f.write(r.text)
log.info('Downloaded Jquery-UI 3.x fix.')
else:
log.error('Problems with downloading Jquery-UI.')
# jquery-ui themes
r = requests.get("https://jqueryui.com/resources/download/jquery-ui-themes-1.12.1.zip")
if r.status_code == 200:
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall(sdir)
log.info('Downloaded Jquery-UI themes.')
else:
log.error('Problems with downloading Jquery-UI themes.')
# Finally :-)
log.info('Finished.')

if __name__ == '__main__':
main()
10 changes: 10 additions & 0 deletions electrum-merchant/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import logging

_console_handler = logging.StreamHandler()
_console_handler.setLevel(logging.DEBUG)
_formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s')
_console_handler.setFormatter(_formatter)

log = logging.getLogger('electrum-merchant')
log.setLevel(logging.DEBUG)
log.addHandler(_console_handler)
20 changes: 15 additions & 5 deletions index.html → electrum-merchant/simple/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Payment request</title>
<script type="text/javascript" charset="utf-8" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="qrcode.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jquery-ui.css">
<script type="text/javascript">
<script type="text/javascript" charset="utf-8"
src="static/jquery/package/dist/jquery.js">
</script>
<script type="text/javascript"
src="static/jquery-migrate-3.0.1.js">
</script>
<script type="text/javascript"
src="static/jquery-ui.min.js">
</script>
<script type="text/javascript"
src="static/qrcodejs/package/qrcode.js">
</script>
<link rel="stylesheet" type="text/css"
href="static/jquery-ui-themes-1.12.1/themes/smoothness/jquery-ui.min.css">

function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
Expand Down
61 changes: 35 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import argparse
import os
import platform
import sys
from setuptools import setup, find_packages

import urllib, shutil, os
from electrum import SimpleConfig
appname = "electrum-merchant"

if sys.version_info[:3] < (3, 5, 0):
sys.exit("Error: electrum-merchant requires Python version >= 3.5.0...")

if __name__ == "__main__":
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

config= SimpleConfig()
rdir = config.get('requests_dir')
if not rdir:
print("requests_dir not found in Electrum configuration")
exit(1)
if not os.path.exists(rdir):
os.mkdir(rdir)
index = os.path.join(rdir, 'index.html')
print("copying index.html")
src = os.path.join(os.path.dirname(__file__), 'www', 'index.html')
shutil.copy(src, index)
files = [
"https://code.jquery.com/jquery-1.9.1.min.js",
"https://raw.githubusercontent.com/davidshimjs/qrcodejs/master/qrcode.js",
"https://code.jquery.com/ui/1.10.3/jquery-ui.js",
"https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"
setup(
name=appname,
packages=['electrum-merchant',],
version='0.1',
description='Electrum wallet - merchant add-ons',
long_description=read('README.rst'),
author='Thomas Voegtlin, Serge Victor',
author_email='[email protected]',
url='https://github.com/spesmilo/electrum-merchant',
license='MIT',
keywords='electrum, bitcoin, payment, merchant',
zip_safe=False,
include_package_data=True,
platforms='any',
download_url = 'https://github.com/spesmilo/electrum-merchant/tarball/0.1',
classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development',
]
for URL in files:
path = urllib.parse.urlsplit(URL).path
filename = os.path.basename(path)
path = os.path.join(rdir, filename)
if not os.path.exists(path):
print("downloading ", URL)
urllib.request.urlretrieve(URL, path)
)

0 comments on commit 462c803

Please sign in to comment.