store json record requests

This commit is contained in:
ThomasV 2015-06-07 21:52:23 +02:00
parent bf755f8ac0
commit 3bb00f0006
2 changed files with 74 additions and 67 deletions

View file

@ -542,17 +542,16 @@ class Commands:
} }
# check if bip70 file exists # check if bip70 file exists
rdir = self.config.get('requests_dir') rdir = self.config.get('requests_dir')
if rdir:
path = os.path.join(rdir, key + '.bip70') path = os.path.join(rdir, key + '.bip70')
if os.path.exists(path): if rdir and os.path.exists(path):
out['path'] = path out['path'] = path
url = 'file://' + path baseurl = 'file://' + rdir
r = self.config.get('url_rewrite') rewrite = self.config.get('url_rewrite')
if r: if rewrite:
a, b = r baseurl = baseurl.replace(*rewrite)
url = url.replace(a, b) out['request_url'] = os.path.join(baseurl, key + '.bip70')
out['request_url'] = url out['URI'] += '&r=' + out['request_url']
out['URI'] += '&r=' + url out['index_url'] = os.path.join(baseurl, 'index.html') + '?id=' + key
return out return out
@ -575,16 +574,22 @@ class Commands:
return map(self._format_request, self.wallet.get_sorted_requests()) return map(self._format_request, self.wallet.get_sorted_requests())
@command('w') @command('w')
def addrequest(self, requested_amount, reason='', expiration=None): def addrequest(self, requested_amount, reason='', expiration=60*60):
"""Create a payment request.""" """Create a payment request."""
amount = int(Decimal(requested_amount)*COIN) amount = int(Decimal(requested_amount)*COIN)
key = self.wallet.add_payment_request(amount, reason, expiration) key = self.wallet.add_payment_request(amount, reason, expiration)
if key is None: if key is None:
return return
# create file
req = self.wallet.get_payment_request(key) req = self.wallet.get_payment_request(key)
paymentrequest.publish_request(self.config, key, req) rdir = self.config.get('requests_dir')
return self._format_request(req) if rdir:
path = paymentrequest.publish_request(self.config, key, req)
req['path'] = path
req = self._format_request(req)
if rdir:
with open(os.path.join(rdir, key + '.json'), 'w') as f:
f.write(json.dumps(req))
return req
@command('w') @command('w')
def rmrequest(self, address): def rmrequest(self, address):

View file

@ -2,37 +2,46 @@
<html> <html>
<head> <head>
<title>Payment request</title> <title>Payment request</title>
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type="text/javascript" charset="utf-8" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/datagraph/jquery-jsonrpc/master/jquery.jsonrpc.js"></script> <script type="text/javascript" src="https://raw.github.com/datagraph/jquery-jsonrpc/master/jquery.jsonrpc.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/davidshimjs/qrcodejs/master/qrcode.js"></script> <script type="text/javascript" src="https://raw.githubusercontent.com/davidshimjs/qrcodejs/master/qrcode.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css"> <script type="text/javascript" src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { function getUrlParameter(sParam)
$.jsonRPC.setup({ {
endPoint : "http://localhost:7777", var sPageURL = window.location.search.substring(1);
namespace : "" var sURLVariables = sPageURL.split('&');
}); for (var i = 0; i < sURLVariables.length; i++)
if (window.location.hash) { {
$.jsonRPC.request('getrequest', { var sParameterName = sURLVariables[i].split('=');
params : [window.location.hash.substr(1)], if (sParameterName[0] == sParam)
success : function(data) { {
new QRCode(document.getElementById("qrcode"), data.result.URI); return sParameterName[1];
$("<p />").text(data.result.reason).appendTo($("p#reason")); }
$("<p />").text(data.result.amount + "BTC").appendTo($("p#amount")); }
$("a").attr("href", data.result.URI); }
$("<p />").text("Powered by Electrum").appendTo($("p#powered"));
var id = getUrlParameter('id');
if (id) {
var jqxhr = $.getJSON(id + ".json", function() {
console.log( "success" );
})
.done( function(data) {
new QRCode(document.getElementById("qrcode"), data.URI);
$("<p />").text(data.reason).appendTo($("p#reason"));
$("<p />").text(data.amount + "BTC").appendTo($("p#amount"));
$("a").attr("href", data.URI);
$("<p />").text("Powered by Electrum").appendTo($("p#powered"));
$(function () { $(function () {
var current; var current;
var max = 100; var max = 100;
var initial = data.result.timestamp; var initial = data.timestamp;
var duration = data.result.expiration; var duration = data.expiration;
var current = 100 * (Math.floor(Date.now()/1000) - initial)/duration; var current = 100 * (Math.floor(Date.now()/1000) - initial)/duration;
$("#progressbar").progressbar({ $("#progressbar").progressbar({
value: current, value: current,
@ -43,24 +52,18 @@ $(function () {
$("#progressbar").progressbar({ $("#progressbar").progressbar({
value: current value: current
}); });
if (duration && current >= max) { if (current >= max) {
$("#container").html("expired:", duration); $("#container").html("expired:", duration);
} }
if(!duration) clearInterval(interval);
}; };
var interval = setInterval(update, 1000); var interval = setInterval(update, 1000);
}); });
})
}, .fail(function() {
error : function(data) { console.log( "error fail" );
$("<p />").text("error").appendTo($("p#error")); $("<p />").text("error").appendTo($("p#error"));
$("<p />").text(data.error.message).appendTo($("p#error"));
}
});
}
}); });
};
</script> </script>
</head> </head>
<body> <body>
@ -79,4 +82,3 @@ $(function () {
</body> </body>
</html> </html>