1
0

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