2018-11-03 23:50:34 +01:00
|
|
|
import logging
|
|
|
|
import argparse
|
|
|
|
import asyncio
|
|
|
|
import aiohttp
|
|
|
|
|
2020-01-03 04:50:27 +01:00
|
|
|
from lbry import wallet
|
2019-12-31 21:38:39 +01:00
|
|
|
from lbry.wallet.orchstr8.node import (
|
2021-11-08 20:18:22 +01:00
|
|
|
Conductor,
|
|
|
|
get_lbcd_node_from_ledger,
|
|
|
|
get_lbcwallet_node_from_ledger
|
2019-12-31 21:38:39 +01:00
|
|
|
)
|
|
|
|
from lbry.wallet.orchstr8.service import ConductorService
|
2018-11-03 23:50:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_argument_parser():
|
|
|
|
parser = argparse.ArgumentParser(
|
2019-12-31 22:33:08 +01:00
|
|
|
prog="orchstr8"
|
2018-11-03 23:50:34 +01:00
|
|
|
)
|
|
|
|
subparsers = parser.add_subparsers(dest='command', help='sub-command help')
|
|
|
|
|
2021-11-08 20:18:22 +01:00
|
|
|
subparsers.add_parser("download", help="Download lbcd and lbcwallet node binaries.")
|
2018-11-03 23:50:34 +01:00
|
|
|
|
|
|
|
start = subparsers.add_parser("start", help="Start orchstr8 service.")
|
2021-11-08 20:18:22 +01:00
|
|
|
start.add_argument("--lbcd", help="Hostname to start lbcd node.")
|
|
|
|
start.add_argument("--lbcwallet", help="Hostname to start lbcwallet node.")
|
2019-01-15 06:22:55 +01:00
|
|
|
start.add_argument("--spv", help="Hostname to start SPV server.")
|
|
|
|
start.add_argument("--wallet", help="Hostname to start wallet daemon.")
|
2018-11-03 23:50:34 +01:00
|
|
|
|
|
|
|
generate = subparsers.add_parser("generate", help="Call generate method on running orchstr8 instance.")
|
|
|
|
generate.add_argument("blocks", type=int, help="Number of blocks to generate")
|
|
|
|
|
2018-11-04 00:45:28 +01:00
|
|
|
subparsers.add_parser("transfer", help="Call transfer method on running orchstr8 instance.")
|
2018-11-03 23:50:34 +01:00
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
async def run_remote_command(command, **kwargs):
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.post('http://localhost:7954/'+command, data=kwargs) as resp:
|
|
|
|
print(resp.status)
|
|
|
|
print(await resp.text())
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = get_argument_parser()
|
|
|
|
args = parser.parse_args()
|
|
|
|
command = getattr(args, 'command', 'help')
|
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
2019-01-13 08:59:54 +01:00
|
|
|
asyncio.set_event_loop(loop)
|
2018-11-03 23:50:34 +01:00
|
|
|
|
|
|
|
if command == 'download':
|
|
|
|
logging.getLogger('blockchain').setLevel(logging.INFO)
|
2021-11-08 20:18:22 +01:00
|
|
|
get_lbcd_node_from_ledger(wallet).ensure()
|
|
|
|
get_lbcwallet_node_from_ledger(wallet).ensure()
|
2018-11-03 23:50:34 +01:00
|
|
|
|
|
|
|
elif command == 'generate':
|
|
|
|
loop.run_until_complete(run_remote_command(
|
|
|
|
'generate', blocks=args.blocks
|
|
|
|
))
|
|
|
|
|
|
|
|
elif command == 'start':
|
|
|
|
|
|
|
|
conductor = Conductor()
|
2021-11-08 20:18:22 +01:00
|
|
|
if getattr(args, 'lbcd', False):
|
|
|
|
conductor.lbcd_node.hostname = args.lbcd
|
|
|
|
loop.run_until_complete(conductor.start_lbcd())
|
|
|
|
if getattr(args, 'lbcwallet', False):
|
|
|
|
conductor.lbcwallet_node.hostname = args.lbcwallet
|
|
|
|
loop.run_until_complete(conductor.start_lbcwallet())
|
2018-11-03 23:50:34 +01:00
|
|
|
if getattr(args, 'spv', False):
|
2019-01-15 06:22:55 +01:00
|
|
|
conductor.spv_node.hostname = args.spv
|
2018-11-03 23:50:34 +01:00
|
|
|
loop.run_until_complete(conductor.start_spv())
|
|
|
|
if getattr(args, 'wallet', False):
|
2019-01-15 06:22:55 +01:00
|
|
|
conductor.wallet_node.hostname = args.wallet
|
2018-11-03 23:50:34 +01:00
|
|
|
loop.run_until_complete(conductor.start_wallet())
|
|
|
|
|
2018-11-04 06:55:50 +01:00
|
|
|
service = ConductorService(conductor, loop)
|
2018-11-03 23:50:34 +01:00
|
|
|
loop.run_until_complete(service.start())
|
|
|
|
|
|
|
|
try:
|
|
|
|
print('========== Orchstr8 API Service Started ========')
|
|
|
|
loop.run_forever()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
loop.run_until_complete(service.stop())
|
|
|
|
loop.run_until_complete(conductor.stop())
|
|
|
|
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
else:
|
|
|
|
parser.print_help()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|