Skip to content

Instantly share code, notes, and snippets.

@simonho288
Created July 4, 2020 02:32
Show Gist options
  • Select an option

  • Save simonho288/e80d52bd36c059388c27746d6bc45f6d to your computer and use it in GitHub Desktop.

Select an option

Save simonho288/e80d52bd36c059388c27746d6bc45f6d to your computer and use it in GitHub Desktop.
import subprocess
from flask import Flask
from flask import render_template
...
def cleos(args):
if isinstance(args, list):
command = ['cleos', '--wallet-url=http://localhost:8899']
command.extend(args)
command = ' '.join(command)
else:
command = 'cleos ' + args
results = subprocess.run(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, check=False)
return results
...
app = Flask(__name__)
...
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')
...
# RESTful API functions
@app.route('/api/getinfo', methods=['GET'])
def get_info():
result = cleos(['get', 'info'])
rstmsg = result.stderr.decode('ascii')
if not rstmsg.startswith('Fail'):
return result.stdout
else:
return 'nodeos connection failed', 500
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment