Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ActorForth/bch-toolkit into develop
Browse files Browse the repository at this point in the history
* 'develop' of github.com:ActorForth/bch-toolkit:
  removed unused self made docs
  randomly generate rpc password
  update docs
  fixed fulcrum config
  ignored the generated slpdb config
  removed generated slpdb-config
  fixed smartbch regtest rpc
  fixed slpdb not running
  BCH RPC configurable
  • Loading branch information
nach committed Jan 26, 2022
2 parents 623899a + 4593a1b commit 9388185
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ config.json
venv/
docker-compose.yml
.vscode/
/configs/slpdb-config.sh
48 changes: 40 additions & 8 deletions bch-devsuite
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import json
import os
import random
import shutil
import string
import subprocess
import sys
import time
from dataclasses import asdict, dataclass
from enum import Enum
from pathlib import Path
from typing import List, Optional
from urllib.parse import urlparse

import inquirer
import typer
Expand All @@ -25,6 +28,7 @@ BCH_GENERATE_ADDRESS = "bchreg:qzerfrqkvsclmrlx3hzl0j2ac2eh0k88wqa0efygtm"
BCH_WIF = "cUDjy47QLpAUyv1beivDPoYCHjCRVqwRMwCuSnkdF4teVFBDD1ip"



def subprocess_run(command):
typer.echo(f"DEBUG:subprocess_run:command: {command}")
output = subprocess.run(
Expand Down Expand Up @@ -63,9 +67,14 @@ class SLPMongoConf:

@dataclass
class RPCConf:
host: str
port: str
username: str
password: str

def host_without_protocol(self):
return urlparse(self.host).netloc


@dataclass
class LocalNode:
Expand All @@ -88,6 +97,7 @@ class InitConfig:
rest_service: Optional[RestService] = None
slp: Optional[SLPMongoConf] = None
smartbch: Optional[SmartBCHConf] = None
bch_rpc_conf: Optional[RPCConf] = None
exposed_ports: bool = True
docker_network: str = DEFAULT_DOCKER_NETWORK

Expand Down Expand Up @@ -155,12 +165,6 @@ def handle_local_node():
node = inquirer.list_input(
message="Local node?", choices=LOCAL_NODES, default=LOCAL_NODES[0]
)
username = inquirer.text(
message="Please enter a username for the node RPC connection"
)
password = inquirer.text(
message="Please enter a password for the node RPC connection"
)
regtest_blocks = None
if config.network == Network.REGTEST:
regtest_blocks = inquirer.text(
Expand All @@ -169,7 +173,6 @@ def handle_local_node():
)
config.local_node = LocalNode(
node=node,
rpc_conf=RPCConf(username=username, password=password),
regtest_blocks=regtest_blocks,
)

Expand Down Expand Up @@ -200,6 +203,17 @@ def handle_smartbch():
elif config.network in (Network.TESTNET, Network.MAINNET):
config.smartbch = SmartBCHConf(enabled=True)

def handle_bch_rpc_conf():
host = inquirer.text(message="BCH RPC host", default="http://bch-node")
port = inquirer.text(message="BCH RPC port", default=config.rpc_port())
username = inquirer.text(message="BCH RPC username", default="actorforth")
password = inquirer.text(message="BCH RPC password (randomly generated by default)", default=''.join(random.choices(string.ascii_letters + string.digits, k=32)))
config.bch_rpc_conf = RPCConf(
host=host,
port=port,
username=username,
password=password
)

component_handlers = {
"local_node": handle_local_node,
Expand All @@ -224,7 +238,7 @@ def build_config():
)
for component in components:
component_handlers[component]()

handle_bch_rpc_conf()
docker_network = inquirer.text(
message="docker network", default=DEFAULT_DOCKER_NETWORK
)
Expand Down Expand Up @@ -365,6 +379,22 @@ def setup_smartbch():
"""
pass

def make_executable(path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # copy R bits to X
os.chmod(path, mode)

def setup_slpdb():
if config.slp:
typer.echo(f"Setting up SLPDB...", nl=False)
with open("./configs/slpdb-config.sh", "w") as config_file:
config_file.write(
templates.get_template("slpdb-config.sh").render(
config=config, rpc_port=config.rpc_port()
)
)
make_executable('./configs/slpdb-config.sh')
typer.echo(success)

def pull_images():
"""
Expand Down Expand Up @@ -507,6 +537,7 @@ def init(
typer.echo("##############")
create_docker_network_if_not_exist()
setup_local_node()
setup_slpdb()
setup_rest_service()
setup_smartbch()
setup_docker_compose()
Expand Down Expand Up @@ -538,6 +569,7 @@ def clean():
remove("config file", "./config.json")
remove("config file", "./configs/bitcoin-unlimited.conf")
remove("config file", "./configs/bitcoincashnode.conf")
remove("config file", "./configs/slpdb-config.sh")
remove("config file", "./configs/temp-fulcrum-config.conf")
remove("docker-compose", "./docker-compose.yml")
remove("lock", "./.lock")
Expand Down
2 changes: 1 addition & 1 deletion docs/setup-option.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Local node (Bitcoin Unlimited node or Bitcoin Cash Node)
* REST service (A rest.bitcoin.com-compatible or Bch-API)
* SLP services (SLPDB, slpserve)
* SmartBCH (https://smartbch.org/ Currently only support regtest)
* SmartBCH (https://smartbch.org/)

### Local node

Expand Down
40 changes: 20 additions & 20 deletions templates/compose.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- {{ config.docker_network }}
{% if config.exposed_ports %}
ports:
- "{{ rpc_port }}:{{ rpc_port }}"
- "{{ config.bch_rpc_conf.port}}:{{ config.bch_rpc_conf.port}}"
- "28332:28332"
- "50001:50001"
{% endif %}
Expand All @@ -40,7 +40,7 @@ services:
- {{ config.docker_network }}
{% if config.exposed_ports %}
ports:
- "{{ rpc_port }}:{{ rpc_port }}"
- "{{ config.bch_rpc_conf.port}}:{{ config.bch_rpc_conf.port}}"
- "28332:28332"
{% endif %}
fulcrum:
Expand Down Expand Up @@ -78,9 +78,9 @@ services:
- NODE_TLS_REJECT_UNAUTHORIZED=0
- REDIS_HOST=6379
- REDIS_PORT=127.0.0.1
- RPC_BASEURL=http://bch-node:{{ rpc_port }}/
- RPC_PASSWORD={{ config.local_node.rpc_conf.password }}
- RPC_USERNAME={{ config.local_node.rpc_conf.username }}
- RPC_BASEURL={{ config.bch_rpc_conf.host }}:{{ config.bch_rpc_conf.port}}/
- RPC_PASSWORD={{ config.bch_rpc_conf.password }}
- RPC_USERNAME={{ config.bch_rpc_conf.username }}
- SECURITY=false
- SLPDB_URL=http://slpserve:4000/
- TOKENSECRET=somelongpassword
Expand Down Expand Up @@ -117,9 +117,9 @@ services:
- DO_NOT_USE_RATE_LIMITS=true
- NETWORK={{ config.network }}
- PORT=3000
- RPC_BASEURL=http://bch-node:{{ rpc_port }}/
- RPC_PASSWORD={{ config.local_node.rpc_conf.password }}
- RPC_USERNAME={{ config.local_node.rpc_conf.username }}
- RPC_BASEURL={{ config.bch_rpc_conf.host }}:{{ config.bch_rpc_conf.port}}/
- RPC_PASSWORD={{ config.bch_rpc_conf.password }}
- RPC_USERNAME={{ config.bch_rpc_conf.username }}
- SLPDB_URL=http://slpserve:4000/
- ZEROMQ_PORT=0
- ZEROMQ_URL=0
Expand All @@ -136,15 +136,15 @@ services:
container_name: opensight
environment:
{% if config.local_node.node == 'bu' %}
- ELECTRUM_HOST=bch-node
- ELECTRUM_HOST={{ config.bch_rpc_conf.host_without_protocol() }}
{% else %}
- ELECTRUM_HOST=fulcrum
{% endif %}
- ELECTRUM_PORT=50001
- NODE_RPC_HOST=bch-node
- NODE_RPC_PASS={{ config.local_node.rpc_conf.password }}
- NODE_RPC_PORT={{ rpc_port }}
- NODE_RPC_USER={{ config.local_node.rpc_conf.username }}
- NODE_RPC_HOST={{ config.bch_rpc_conf.host_without_protocol() }}
- NODE_RPC_PASS={{ config.bch_rpc_conf.password }}
- NODE_RPC_PORT={{ config.bch_rpc_conf.port}}
- NODE_RPC_USER={{ config.bch_rpc_conf.username }}
- OPENSIGHT_PORT=3001
restart: always
networks:
Expand Down Expand Up @@ -184,11 +184,11 @@ services:
- ./configs/slpdb-config.sh:/home/safeuser/start.sh
environment:
- db_url=mongodb://{{ config.slp.username }}:{{ config.slp.password }}@mongodb-slpdb:27017?connectTimeoutMS=90000&socketTimeoutMS=90000
- rpc_host=bch-node
- rpc_pass={{ config.local_node.rpc_conf.password }}
- rpc_port={{ rpc_port }}
- rpc_user={{ config.local_node.rpc_conf.username }}
- zmq_incoming_host=bch-node
- rpc_host={{ config.bch_rpc_conf.host_without_protocol() }}
- rpc_pass={{ config.bch_rpc_conf.password }}
- rpc_port={{ config.bch_rpc_conf.port}}
- rpc_user={{ config.bch_rpc_conf.username }}
- zmq_incoming_host={{ config.bch_rpc_conf.host_without_protocol() }}
- NODE_OPTIONS=--max-old-space-size=16384
restart: always
networks:
Expand Down Expand Up @@ -226,13 +226,13 @@ services:
container_name: smartbch
restart: always
{% if config.network == 'regtest' %}
command: start --home /opt/smartbchd --mainnet-rpc-url=http://bch-node:{{ rpc_port }} --mainnet-rpc-username {{ config.local_node.rpc_conf.username }} --mainnet-rpc-password {{ config.local_node.rpc_conf.password }} --unlock {{ ','.join(config.smartbch.test_keys) }}
command: start --home /opt/smartbchd --mainnet-rpc-url={{ config.bch_rpc_conf.host }}:{{ config.bch_rpc_conf.port}} --mainnet-rpc-username={{ config.bch_rpc_conf.username }} --mainnet-rpc-password={{ config.bch_rpc_conf.password }} --unlock {{ ','.join(config.smartbch.test_keys) }}
{% endif %}
{% if config.network == 'testnet' %}
command: start --home /opt/smartbchd --mainnet-genesis-height=602983
{% endif %}
{% if config.network == 'mainnet' %}
command: start --home /opt/smartbchd --mainnet-rpc-url=http://bch-node:{{ rpc_port }} --mainnet-rpc-username={{ config.local_node.rpc_conf.username }} --mainnet-rpc-password={{ config.local_node.rpc_conf.password }} --mainnet-genesis-height=698502
command: start --home /opt/smartbchd --mainnet-rpc-url={{ config.bch_rpc_conf.host }}:{{ config.bch_rpc_conf.port}} --mainnet-rpc-username={{ config.bch_rpc_conf.username }} --mainnet-rpc-password={{ config.bch_rpc_conf.password }} --mainnet-genesis-height=698502
{% endif %}
volumes:
- ./data/smartbchd:/opt/smartbchd/
Expand Down
8 changes: 4 additions & 4 deletions templates/default_bitcoincashnode.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ zmqpubhashblock=tcp://*:28332
zmqpubrawblock=tcp://*:28332
rpcallowip=0.0.0.0/0

rpcuser={{ config.local_node.rpc_conf.username }}
rpcpassword={{ config.local_node.rpc_conf.password }}
rpcuser={{ config.bch_rpc_conf.username }}
rpcpassword={{ config.bch_rpc_conf.password }}

{% if config.network == 'mainnet' or config.network == 'testnet' %}
maxconnections=10
Expand All @@ -28,5 +28,5 @@ regtest = 1
[regtest]
maxconnections=0
{% endif %}
rpcport={{ rpc_port }}
rpcbind=0.0.0.0:{{ rpc_port }}
rpcport={{ config.bch_rpc_conf.port}}
rpcbind=0.0.0.0:{{ config.bch_rpc_conf.port}}
8 changes: 4 additions & 4 deletions templates/default_bu.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ electrum.host=0.0.0.0

debug=electrum

rpcuser={{ config.local_node.rpc_conf.username }}
rpcpassword={{ config.local_node.rpc_conf.password }}
rpcuser={{ config.bch_rpc_conf.username }}
rpcpassword={{ config.bch_rpc_conf.password }}

{% if config.network == 'mainnet' %}
maxconnections=10
Expand All @@ -32,5 +32,5 @@ regtest=1
maxconnections=0
{% endif %}

rpcport={{ rpc_port }}
rpcbind=0.0.0.0:{{ rpc_port }}
rpcport={{ config.bch_rpc_conf.port}}
rpcbind=0.0.0.0:{{ config.bch_rpc_conf.port}}
6 changes: 3 additions & 3 deletions templates/fulcrum-config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ datadir = /data # Windows: datadir = D:\FulcrumData\mainnet
#bitcoind-tls = true
# *REQUIRED* This is the bitcoind RPC socket you configured usig rpcbind= and
# rpcport= in your bitcoind .conf file.
bitcoind = bch-node:{{ rpc_port }}
bitcoind = {{ config.bch_rpc_conf.host_without_protocol() }}:{{ config.bch_rpc_conf.port}}

# *REQUIRED* This is the bitcoind RPC username you specified in your bitciond
# .conf file. This corresponds to the rpcuser= from that file.
rpcuser = {{ config.local_node.rpc_conf.username }}
rpcuser = {{ config.bch_rpc_conf.username }}

# *REQUIRED* This is the bitcoind RPC password you specified in your bitciond
# .conf file. This corresponds to the rpcpassword= from that file.
rpcpassword = {{ config.local_node.rpc_conf.password }}
rpcpassword = {{ config.bch_rpc_conf.password }}



Expand Down
4 changes: 2 additions & 2 deletions configs/slpdb-config.sh → templates/slpdb-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ echo "Finished DB migrations."

# Set the full node IP address and port
export rpc_protocol='http'
export rpc_host=bch-node
export rpc_host={{ config.bch_rpc_conf.host_without_protocol() }}
export core_from=543375
export core_from_testnet=0
export zmq_incoming_host=bch-node
export zmq_incoming_host={{ config.bch_rpc_conf.host_without_protocol() }}
export zmq_incoming_port=28332

# Turn off graph search
Expand Down

0 comments on commit 9388185

Please sign in to comment.