electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 4a40b3a0b2522e6adad58631eba4f57341907d44
parent 453cc263f7d1bb637eb31bc38a1e7b27d939be3e
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 12 Jan 2018 10:37:14 +0100

separate merchant UI from main project

Diffstat:
Melectrum | 8++++++--
Mlib/util.py | 22----------------------
Dlib/www/example.php | 17-----------------
Dlib/www/index.html | 111-------------------------------------------------------------------------------
4 files changed, 6 insertions(+), 152 deletions(-)

diff --git a/electrum b/electrum @@ -92,7 +92,7 @@ from electrum import SimpleConfig, Network from electrum.wallet import Wallet, Imported_Wallet from electrum.storage import WalletStorage from electrum.util import print_msg, print_stderr, json_encode, json_decode -from electrum.util import set_verbosity, InvalidPassword, check_www_dir +from electrum.util import set_verbosity, InvalidPassword from electrum.commands import get_parser, known_commands, Commands, config_variables from electrum import daemon from electrum import keystore @@ -399,7 +399,11 @@ if __name__ == '__main__': from electrum import websockets websockets.WebSocketServer(config, d.network).start() if config.get('requests_dir'): - check_www_dir(config.get('requests_dir')) + path = os.path.join(config.get('requests_dir'), 'index.html') + if not os.path.exists(path): + print("Requests directory not configured.") + print("You can configure it using https://github.com/spesmilo/electrum-merchant") + sys.exit(1) d.join() sys.exit(0) else: diff --git a/lib/util.py b/lib/util.py @@ -703,25 +703,3 @@ class QueuePipe: self.send(request) -def check_www_dir(rdir): - import urllib, shutil, os - if not os.path.exists(rdir): - os.mkdir(rdir) - index = os.path.join(rdir, 'index.html') - if not os.path.exists(index): - print_error("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" - ] - 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_error("downloading ", URL) - urllib.request.urlretrieve(URL, path) diff --git a/lib/www/example.php b/lib/www/example.php @@ -1,17 +0,0 @@ -<?php - -require_once 'jsonRPCClient.php'; -$electrum = new jsonRPCClient('http://localhost:7777'); - -echo '<b>Wallet balance</b><br />'."\n"; -try { - - $balance = $electrum->getbalance(); - echo 'confirmed: <i>'.$balance['confirmed'].'</i><br />'."\n"; - echo 'unconfirmed: <i>'.$balance['unconfirmed'].'</i><br />'."\n"; - -} catch (Exception $e) { - echo nl2br($e->getMessage()).'<br />'."\n"; -} - -?> diff --git a/lib/www/index.html b/lib/www/index.html @@ -1,111 +0,0 @@ -<!DOCTYPE HTML> -<html> - <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"> -function getUrlParameter(sParam) -{ - var sPageURL = window.location.search.substring(1); - var sURLVariables = sPageURL.split('&'); - for (var i = 0; i < sURLVariables.length; i++) - { - var sParameterName = sURLVariables[i].split('='); - if (sParameterName[0] == sParam) - { - return sParameterName[1]; - } - } -} - -var id = getUrlParameter('id'); - -if (id) { - var uri_path = location.pathname; - var jqxhr = $.getJSON(uri_path.replace("index.html", "req/"+ id[0] + "/"+ id[1] + "/"+ id + "/"+ id + ".json"), function() { - console.log("getJSON:success"); - }) - .done( function(data) { - new QRCode(document.getElementById("qrcode"), data.URI); - $("<p />").text(data.memo).appendTo($("p#reason")); - $("<p />").text(data.amount/100000000 + "BTC").appendTo($("p#amount")); - $("a").attr("href", data.URI); - $("<p />").text("Powered by Electrum").appendTo($("p#powered")); - var websocket_server = data.websocket_server; - var websocket_port = data.websocket_port; - $(function () { - var current; - var max = 100; - var initial = data.time; - var duration = data.exp; - if(duration){ - var current = 100 * (Math.floor(Date.now()/1000) - initial)/duration; - $("#progressbar").progressbar({ - value: current, - max: max - }); - function update() { - current = 100 * (Math.floor(Date.now()/1000) - initial)/duration; - $("#progressbar").progressbar({ - value: current - }); - if (current >= max) { - $("#container").html("This invoice has expired"); - } - }; - var interval = setInterval(update, 1000); - } - }); - - var wss_address = "wss://" + websocket_server + ":" + websocket_port +"/"; - console.log("Opening WSS: " + wss_address) - var ws = new WebSocket(wss_address); - - ws.onopen = function() { - ws.send('id:' + id); - }; - ws.onmessage = function (evt) { - var received_msg = evt.data; - if(received_msg == 'paid'){ - $("#container").html("This invoice has been paid."); - } - else alert("Message is received:"+ received_msg); - }; - - }) - .fail(function() { - console.log("error fail"); - $("<p />").text("error").appendTo($("p#error")); - }); -}; - -// See http://stackoverflow.com/questions/29186154/chrome-clicking-mailto-links-closes-websocket-connection -$(document).on('click', 'a[href^="bitcoin:"]', function (e) { - e.preventDefault(); - var btcWindow = window.open($(e.currentTarget).attr('href')); - btcWindow.close(); - return false; -}); - -</script> - </head> - <body> - <div id="container" style="width:20em; text-align:center; margin:auto; font-family:arial, serif;"> - <p id="error"></p> - <p id="reason"></p> - <p id="amount"></p> - <div style="background-color:#7777aa; border-radius: 5px; padding:10px;"> - <a style="color:#ffffff; text-decoration:none;" id="paylink" target="_blank">Pay with Bitcoin</a> - </div> - <br/> - <div id="qrcode" align="center"></div> - <p id="powered" style="font-size:80%;"></p> - <div id="progressbar"></div> - </div> - - </body> -</html>