Created
July 4, 2020 02:32
-
-
Save simonho288/e80d52bd36c059388c27746d6bc45f6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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