diff --git a/Browser.py b/Browser.py
index ed8cf7f..b31aa64 100644
--- a/Browser.py
+++ b/Browser.py
@@ -5,11 +5,14 @@
###########
# Imports #
###########
-from time import sleep
import re
import sys
-from multiprocessing import Process
+import os
import traceback
+import json
+
+from time import sleep
+from multiprocessing import Process
from rpc_client import get_acct_raw, get_acct_info, start_rpc_client_instance
from client import start_client_instance, do_cmd
@@ -28,8 +31,6 @@
# Definitions #
###############
ctr = 0 # counter of requests since last init
-DB_PATH = './tx_cache.db' # path to the db we should load
-CLIENT_PATH = '~/libra/' # root directory of Libra client
c2 = None # placeholder for connection object
header = '''
Libra Testnet Experimental Browser
@@ -109,7 +110,7 @@ def add_br_every64(s):
@app.route('/')
def index():
update_counters()
- c2, conn = connect_to_db(DB_PATH)
+ c2, conn = connect_to_db(config['DB_PATH'])
bver = str(get_latest_version(c2))
@@ -120,7 +121,7 @@ def index():
@app.route('/version/')
def version(ver):
update_counters()
- c2, conn = connect_to_db(DB_PATH)
+ c2, conn = connect_to_db(config['DB_PATH'])
bver = str(get_latest_version(c2))
@@ -158,7 +159,7 @@ def acct_details(acct):
if not is_valid_account(acct):
return invalid_account_template
- c2, conn = connect_to_db(DB_PATH)
+ c2, conn = connect_to_db(config['DB_PATH'])
bver = str(get_latest_version(c2))
acct_state_raw = get_acct_raw(acct)
@@ -195,7 +196,7 @@ def search_redir():
@app.route('/stats')
def stats():
update_counters()
- c2, conn = connect_to_db(DB_PATH)
+ c2, conn = connect_to_db(config['DB_PATH'])
try:
# get stats
stats_all_time = calc_stats(c2)
@@ -217,7 +218,7 @@ def stats():
def faucet():
update_counters()
- c2, conn = connect_to_db(DB_PATH)
+ c2, conn = connect_to_db(config['DB_PATH'])
bver = str(get_latest_version(c2))
message = ''
@@ -255,13 +256,25 @@ def send_asset(path):
# Main #
########
if __name__ == '__main__':
- tx_p = Process(target=tx_db_worker, args=(DB_PATH, ))
+ with open('config.json', 'r') as f:
+ config = json.load(f)
+
+ try:
+ config = config[os.getenv("BROWSER")]
+ except:
+ config = config["PRODUCTION"]
+
+ print("system configuration:")
+ print(json.dumps(config, indent=4))
+
+ tx_p = Process(target=tx_db_worker, args=(config['DB_PATH'], config['RPC_SERVER'], config['MINT_ACCOUNT']))
tx_p.start()
- start_rpc_client_instance()
+ start_rpc_client_instance(config['RPC_SERVER'], config['MINT_ACCOUNT'])
- p = start_client_instance(CLIENT_PATH)
+ p = start_client_instance(config['CLIENT_PATH'], config['ACCOUNT_FILE'])
sleep(1)
- app.run(port=5000, threaded=False, host='0.0.0.0', debug=False)
+ app.run(port=config['FLASK_PORT'], threaded=config['FLASK_THREADED'],
+ host=config['FLASK_HOST'], debug=config['FLASK_DEBUG'])
diff --git a/README.md b/README.md
index eac5f99..3213406 100644
--- a/README.md
+++ b/README.md
@@ -13,12 +13,19 @@ A browser for the Libra Blockchain TestNet. See: https://librabrowser.io
## Installation
1. Install Libra per official instructions
-2. make sure the CLIENT_PATH variable is correct
-3. pip3 install grpcio grpcio-tools hexdump
+2. Run: pip3 install grpcio grpcio-tools hexdump
+3. Open the official client, create an account and save the account to disk (should be set in ACCOUNT_FILE setting)
+4. Edit config.json and make sure that settings match your environment (in particular CLIENT_PATH)
## Running the project
At the root project folder execute the command:
> python3 Browser.py
+Or to execute and leave it to run with output redirected to a file execute:
+> nohup python3 Browser.py &> browser.log < /dev/null &
+> tail -f browser.log #if you want to see the logs
+
+To use "DEVELOPMENT" mode settings set the environment variable "BROWSER=DEVELOPMENT"
+
## Credits
rpc support is based on: https://github.com/egorsmkv/libra-grpc-py
diff --git a/client.py b/client.py
index 0d3a0d2..0514f71 100644
--- a/client.py
+++ b/client.py
@@ -15,7 +15,7 @@
#########
# Funcs #
#########
-def start_client_instance(client_path = ''):
+def start_client_instance(client_path = '', account_file = ''):
c_path = os.path.expanduser(client_path + "target/debug/client")
p = Popen([c_path, "--host", "ac.testnet.libra.org", "--port", "80",
"-s", "./scripts/cli/trusted_peers.config.toml"], cwd=os.path.expanduser(client_path),
@@ -25,7 +25,7 @@ def start_client_instance(client_path = ''):
print(os.read(p.stdout.fileno(), 10000))
print('loading account')
- print(do_cmd("a r ./test_acct", p = p))
+ print(do_cmd("a r " + account_file, p = p))
sys.stdout.flush()
return p
diff --git a/db_funcs.py b/db_funcs.py
index 8f9bedd..6dbad8b 100644
--- a/db_funcs.py
+++ b/db_funcs.py
@@ -94,17 +94,17 @@ def init_db(c):
sys.exit()
-def tx_db_worker(db_path='./tx_cache.db'):
+def tx_db_worker(db_path, rpc_server, mint_addr):
while True:
try:
print('transactions db worker starting')
# create rpc connection
try:
- start_rpc_client_instance()
+ start_rpc_client_instance(rpc_server, mint_addr)
except:
sleep(10)
- start_rpc_client_instance()
+ start_rpc_client_instance(rpc_server, mint_addr)
# connect to DB
c, conn = connect_to_db(db_path) # returns cursor object
diff --git a/rpc_client.py b/rpc_client.py
index fb6a4d6..d4a5971 100644
--- a/rpc_client.py
+++ b/rpc_client.py
@@ -22,8 +22,8 @@
###########
# Globals #
###########
-SERVER_ADDRESS = 'ac.testnet.libra.org:8000'
-MINT_ACCOUNT = '0000000000000000000000000000000000000000000000000000000000000000'
+SERVER_ADDRESS = ''
+MINT_ACCOUNT = ''
stub = None
last_version_seen = 0
@@ -31,11 +31,16 @@
#########
# Funcs #
#########
-def start_rpc_client_instance(server_address = SERVER_ADDRESS):
+def start_rpc_client_instance(rpc_server, mint_addr):
global last_version_seen
global stub
+ global SERVER_ADDRESS
+ global MINT_ACCOUNT
- channel = grpc.insecure_channel(server_address)
+ SERVER_ADDRESS = rpc_server
+ MINT_ACCOUNT = mint_addr
+
+ channel = grpc.insecure_channel(SERVER_ADDRESS)
stub = AdmissionControlStub(channel)
last_version_seen = get_latest_version_from_ledger()