Fixed indent and node running script.

This commit is contained in:
Fillerino 2017-09-05 20:56:29 +02:00
parent 25e083be75
commit d05ad11855
2 changed files with 18 additions and 8 deletions

View file

@ -16,4 +16,4 @@
- git: repo=https://github.com/lbryio/lighthouse.git dest=~/lighthouse
- raw: cd ~/lighthouse/decoder && pip install -r requirements.txt && screen -S decoder -d -m python decoder.py && sleep 2
- raw: cd ~/lighthouse && yarn install --production=false && yarn global add forever
- raw: forever start -c "npm run prod" ~/lighthouse
- raw: cd ~/lighthouse && yarn run build && cd dist && forever start index.js

View file

@ -1,9 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
from bitcoinrpc.authproxy import AuthServiceProxy
from lbryschema.decode import smart_decode
from flask import Flask, url_for
app = Flask(__name__)
def get_lbrycrdd_connection_details():
with open('config.json', 'r') as f:
config = json.load(f)
@ -11,13 +14,16 @@ def get_lbrycrdd_connection_details():
rpc_pass = config['rpc_password']
rpc_port = config['rpc_port']
rpc_url = config['rpc_url']
return "http://%s:%s@%s:%i" % (rpc_user, rpc_pass, rpc_url, rpc_port)
return 'http://%s:%s@%s:%i' % (rpc_user, rpc_pass, rpc_url,
rpc_port)
@app.errorhandler(500)
def internal_error(error):
return 'error when decoding claims'
@app.route('/claim_decode/<txid>/<nout>')
def api_decode(txid, nout):
connection_string = get_lbrycrdd_connection_details()
@ -29,21 +35,25 @@ def api_decode(txid, nout):
claim = claim_out
break
if claim:
converted = "".join([chr(ord(i)) for i in claim['value']])
decoded = smart_decode(converted) # Decode the claims and dump them back to logstash plugin
converted = ''.join([chr(ord(i)) for i in claim['value']])
decoded = smart_decode(converted)
claim['value'] = decoded.claim_dict
return json.dumps(claim)
@app.route('/claim_decodeinv/<claimid>')
def api_decodebyclaim(claimid):
connection_string = get_lbrycrdd_connection_details()
rpc = AuthServiceProxy(connection_string)
claim = rpc.getvalueforname(claimid)
if claim:
converted = "".join([chr(ord(i)) for i in claim['value']])
decoded = smart_decode(converted) # Decode the claims and dump them back to logstash plugin
claim['value'] = decoded.claim_dict
converted = ''.join([chr(ord(i)) for i in claim['value']])
decoded = smart_decode(converted)
claim['value'] = decoded.claim_dict
return json.dumps(claim)
if __name__ == '__main__':
app.run(host='127.0.0.1')
app.run(host='127.0.0.1')