Run bitcoin-abe with parameters, from a script

published Sep 01, 2015 10:55   by admin ( last modified Sep 01, 2015 10:54 )

Bitcoin-abe takes its config values either from the command line or from a config file. What if you want to run it from inside of another script, how do you configure it? Please check the comments in the source code below:

 

from Abe import abe
# Your config settings
from myconfig import config

# A complex setting, a dictionary in a list, that
# we want bitcoin-abe to be configured with
datadir = [{
       "dirname": config.bitcoin_regtest_data_dir,
       "chain": "Regtest"
      }]


# It turns out that bitcoin-abe accepts JSON as values
# for its command-line arguments. It means we can pass
# in as complex data as we want

datadir_arg = '--datadir=' + json.dumps(datadir)
port_arg = '--port='+ str(config.abe_port)
config_arg = '--config='+ config.abe_config_location

# argv contains the command line arguments, so we just fake one
argv = [datadir_arg, port_arg, config_arg]

# Call the main function in abe with the command line arguments
def main():
    abe.main(argv)