Skip to content
Merged
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ exclude =
Connector/tests/docker-compose,
# This contains nginx configuration files
nginx,
max-complexity = 10
max-complexity = 11
22 changes: 11 additions & 11 deletions Connector/bch/apirpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def getBlockByHash(id, params, config):
raise error.RpcBadRequestError(err.message)

block = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_BLOCK_METHOD,
params=[
Expand Down Expand Up @@ -288,7 +288,7 @@ def getBlockByNumber(id, params, config):
raise error.RpcBadRequestError(err.message)

blockHash = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_BLOCK_HASH_METHOD,
params=[params["blockNumber"]])
Expand Down Expand Up @@ -316,7 +316,7 @@ def getFeePerByte(id, params, config):
)

feePerByte = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=ESTIMATE_SMART_FEE_METHOD,
params=[params["confirmations"]])
Expand Down Expand Up @@ -355,14 +355,14 @@ def getHeight(id, params, config):

latestBlockHeight = int(
RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_BLOCK_COUNT_METHOD,
params=[]
)
)
latestBlockHash = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_BLOCK_HASH_METHOD,
params=[latestBlockHeight]
Expand Down Expand Up @@ -402,7 +402,7 @@ def getTransactionHex(id, params, config):
)

rawTransaction = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_TRANSACTION_METHOD,
params=[params["txHash"]]
Expand Down Expand Up @@ -438,7 +438,7 @@ def getTransaction(id, params, config):
try:
# Parameters: TransactionId, include_watchonly, verbose
transaction = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_TRANSACTION_METHOD,
params=[
Expand All @@ -455,7 +455,7 @@ def getTransaction(id, params, config):

for vin in transaction["decoded"]["vin"]:
inputTransaction = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_TRANSACTION_METHOD,
params=[
Expand Down Expand Up @@ -594,7 +594,7 @@ def broadcastTransaction(id, params, config):
)

hash = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=SEND_RAW_TRANSACTION_METHOD,
params=[params["rawTransaction"]])
Expand Down Expand Up @@ -662,7 +662,7 @@ def syncing(id, params, config):
raise error.RpcBadRequestError(err.message)

blockchainInfo = RPCConnector.request(
endpoint=config.bitcoincoreRpcEndpoint,
endpoint=config.bitcoinabcRpcEndpoint,
id=id,
method=GET_BLOCKCHAIN_INFO,
params=None
Expand All @@ -675,7 +675,7 @@ def syncing(id, params, config):
if blockchainInfo["blocks"] != blockchainInfo["headers"]:
response = {
"syncing": True,
"syncPercentage": f"{str(blockchainInfo['verificationprogess']*100)}%",
"syncPercentage": f"{str(blockchainInfo['verificationprogress']*100)}%",
"currentBlockIndex": str(blockchainInfo["blocks"]),
"latestBlockIndex": str(blockchainInfo["headers"]),
}
Expand Down
109 changes: 56 additions & 53 deletions Connector/bch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,47 @@ def __init__(self, coin, networkName):

self._networkName = networkName
self._coin = coin
self._bitcoincoreProtocol = ""
self._bitcoincoreHost = ""
self._bitcoincorePort = ""
self._bitcoincoreUser = ""
self._bitcoincorePassword = ""
self._bitcoinabcProtocol = ""
self._bitcoinabcHost = ""
self._bitcoinabcPort = ""
self._bitcoinabcUser = ""
self._bitcoinabcPassword = ""
self._electrumCashProtocol = ""
self._electrumCashHost = ""
self._electrumCashPort = ""
self._electrumCashUser = ""
self._electrumCashPassword = ""

def __attachNetworkToHost(self, host):
return f"{host}-{self.networkName}"

def loadConfig(self, config):

defaultConfig, err = utils.loadDefaultPackageConf(self.coin)
if err is not None:
return False, err

self.bitcoincoreProtocol = config["bitcoincoreProtocol"] if "bitcoincoreProtocol" in config \
else defaultConfig["bitcoincoreProtocol"]
self.bitcoincoreHost = config["bitcoincoreHost"] if "bitcoincoreHost" in config \
else defaultConfig["bitcoincoreHost"]
self.bitcoinabcProtocol = config["bitcoinabcProtocol"] if "bitcoinabcProtocol" in config \
else defaultConfig["bitcoinabcProtocol"]
self.bitcoinabcHost = config["bitcoinabcHost"] if "bitcoinabcHost" in config \
else self.__attachNetworkToHost(defaultConfig["bitcoinabcHost"])

if "bitcoincorePort" in config:
if config["bitcoincorePort"].isdigit():
self.bitcoincorePort = config["bitcoincorePort"]
if "bitcoinabcPort" in config:
if config["bitcoinabcPort"].isdigit():
self.bitcoinabcPort = config["bitcoinabcPort"]
else:
return False, f"Value {config['bitcoincorePort']} for bitcoincorePort is not digit"
return False, f"Value {config['bitcoinabcPort']} for bitcoinabcPort is not digit"
else:
self.bitcoincorePort = defaultConfig["bitcoincorePort"]
self.bitcoinabcPort = defaultConfig["bitcoinabcPort"]

self.bitcoincoreUser = config["bitcoincoreUser"] if "bitcoincoreUser" in config \
else defaultConfig["bitcoincoreUser"]
self.bitcoincorePassword = config["bitcoincorePassword"] if "bitcoincorePassword" in config \
else defaultConfig["bitcoincorePassword"]
self.bitcoinabcUser = config["bitcoinabcUser"] if "bitcoinabcUser" in config \
else defaultConfig["bitcoinabcUser"]
self.bitcoinabcPassword = config["bitcoinabcPassword"] if "bitcoinabcPassword" in config \
else defaultConfig["bitcoinabcPassword"]
self.electrumCashProtocol = config["electrumCashProtocol"] if "electrumCashProtocol" in config \
else defaultConfig["electrumCashProtocol"]
self.electrumCashHost = config["electrumCashHost"] if "electrumCashHost" in config \
else defaultConfig["electrumCashHost"]
else self.__attachNetworkToHost(defaultConfig["electrumCashHost"])

if "electrumCashPort" in config:
if config["electrumCashPort"].isdigit():
Expand Down Expand Up @@ -76,44 +79,44 @@ def networkName(self, value):
self._networkName = value

@property
def bitcoincoreProtocol(self):
return self._bitcoincoreProtocol
def bitcoinabcProtocol(self):
return self._bitcoinabcProtocol

@bitcoincoreProtocol.setter
def bitcoincoreProtocol(self, value):
self._bitcoincoreProtocol = value
@bitcoinabcProtocol.setter
def bitcoinabcProtocol(self, value):
self._bitcoinabcProtocol = value

@property
def bitcoincoreHost(self):
return self._bitcoincoreHost
def bitcoinabcHost(self):
return self._bitcoinabcHost

@bitcoincoreHost.setter
def bitcoincoreHost(self, value):
self._bitcoincoreHost = value
@bitcoinabcHost.setter
def bitcoinabcHost(self, value):
self._bitcoinabcHost = value

@property
def bitcoincorePort(self):
return self._bitcoincorePort
def bitcoinabcPort(self):
return self._bitcoinabcPort

@bitcoincorePort.setter
def bitcoincorePort(self, value):
self._bitcoincorePort = value
@bitcoinabcPort.setter
def bitcoinabcPort(self, value):
self._bitcoinabcPort = value

@property
def bitcoincoreUser(self):
return self._bitcoincoreUser
def bitcoinabcUser(self):
return self._bitcoinabcUser

@bitcoincoreUser.setter
def bitcoincoreUser(self, value):
self._bitcoincoreUser = value
@bitcoinabcUser.setter
def bitcoinabcUser(self, value):
self._bitcoinabcUser = value

@property
def bitcoincorePassword(self):
return self._bitcoincorePassword
def bitcoinabcPassword(self):
return self._bitcoinabcPassword

@bitcoincorePassword.setter
def bitcoincorePassword(self, value):
self._bitcoincorePassword = value
@bitcoinabcPassword.setter
def bitcoinabcPassword(self, value):
self._bitcoinabcPassword = value

@property
def electrumCashProtocol(self):
Expand Down Expand Up @@ -156,10 +159,10 @@ def electrumCashPassword(self, value):
self._electrumCashPassword = value

@property
def bitcoincoreRpcEndpoint(self):
return f"{self.bitcoincoreProtocol}://" \
f"{self.bitcoincoreUser}:{self.bitcoincorePassword}@" \
f"{self.bitcoincoreHost}:{self.bitcoincorePort}"
def bitcoinabcRpcEndpoint(self):
return f"{self.bitcoinabcProtocol}://" \
f"{self.bitcoinabcUser}:{self.bitcoinabcPassword}@" \
f"{self.bitcoinabcHost}:{self.bitcoinabcPort}"

@property
def electrumCashRpcEndpoint(self):
Expand All @@ -174,11 +177,11 @@ def jsonEncode(self):
class ConfigEncoder(JSONEncoder):
def encode(self, o):
return {
"bitcoincoreProtocol": o.bitcoincoreProtocol,
"bitcoincoreHost": o.bitcoincoreHost,
"bitcoincorePort": o.bitcoincorePort,
"bitcoincoreUser": o.bitcoincoreUser,
"bitcoincorePassword": o.bitcoincorePassword,
"bitcoinabcProtocol": o.bitcoinabcProtocol,
"bitcoinabcHost": o.bitcoinabcHost,
"bitcoinabcPort": o.bitcoinabcPort,
"bitcoinabcUser": o.bitcoinabcUser,
"bitcoinabcPassword": o.bitcoinabcPassword,
"electrumCashProtocol": o.electrumCashProtocol,
"electrumCashHost": o.electrumCashHost,
"electrumCashPort": o.electrumCashPort,
Expand Down
10 changes: 5 additions & 5 deletions Connector/bch/defaultConf.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"bitcoincoreProtocol": "http",
"bitcoincoreHost": "bitcoincore",
"bitcoincorePort": "8332",
"bitcoincoreUser": "swapper",
"bitcoincorePassword": "swapper",
"bitcoinabcProtocol": "http",
"bitcoinabcHost": "bitcoinabc",
"bitcoinabcPort": "8332",
"bitcoinabcUser": "swapper",
"bitcoinabcPassword": "swapper",
"electrumCashProtocol": "http",
"electrumCashHost": "electrum",
"electrumCashPort": "30000",
Expand Down
4 changes: 0 additions & 4 deletions Connector/bch/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def addConfig(self, network, config):
logger.printError(f"Configuration {network} already added for {self.coin}")
return False, f"Configuration {network} already added for {self.coin}"

defaultConf, err = utils.loadDefaultPackageConf(self.coin)
if err is not None:
return False, err

pkgConfig = Config(
coin=self.coin,
networkName=network
Expand Down
2 changes: 1 addition & 1 deletion Connector/btc/apirpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def syncing(id, params, config):
if blockchainInfo["blocks"] != blockchainInfo["headers"]:
response = {
"syncing": True,
"syncPercentage": f"{str(blockchainInfo['verificationprogess']*100)}%",
"syncPercentage": f"{str(blockchainInfo['verificationprogress']*100)}%",
"currentBlockIndex": str(blockchainInfo["blocks"]),
"latestBlockIndex": str(blockchainInfo["headers"]),
}
Expand Down
11 changes: 8 additions & 3 deletions Connector/btc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(self, coin, networkName):
self._electrumxHost = ""
self._electrumxPort = ""

def __attachNetworkToHost(self, host):
return f"{host}-{self.networkName}"

def loadConfig(self, config):

defaultConfig, err = utils.loadDefaultPackageConf(self.coin)
Expand All @@ -36,7 +39,7 @@ def loadConfig(self, config):
self.bitcoincoreProtocol = config["bitcoincoreProtocol"] if "bitcoincoreProtocol" in config \
else defaultConfig["bitcoincoreProtocol"]
self.bitcoincoreHost = config["bitcoincoreHost"] if "bitcoincoreHost" in config \
else defaultConfig["bitcoincoreHost"]
else self.__attachNetworkToHost(defaultConfig["bitcoincoreHost"])

if "bitcoincorePort" in config:
if config["bitcoincorePort"].isdigit():
Expand All @@ -63,7 +66,8 @@ def loadConfig(self, config):

self.electrumProtocol = config["electrumProtocol"] if "electrumProtocol" in config \
else defaultConfig["electrumProtocol"]
self.electrumHost = config["electrumHost"] if "electrumHost" in config else defaultConfig["electrumHost"]
self.electrumHost = config["electrumHost"] if "electrumHost" in config \
else self.__attachNetworkToHost(defaultConfig["electrumHost"])

if "electrumPort" in config:
if config["electrumPort"].isdigit():
Expand All @@ -81,7 +85,8 @@ def loadConfig(self, config):
else defaultConfig["bitcoincoreCallbackProtocol"]
self.bitcoincoreCallbackHost = config["bitcoincoreCallbackHost"] if "bitcoincoreCallbackHost" in config \
else defaultConfig["bitcoincoreCallbackHost"]
self.electrumxHost = config["electrumxHost"] if "electrumxHost" in config else defaultConfig["electrumxHost"]
self.electrumxHost = config["electrumxHost"] if "electrumxHost" in config \
else self.__attachNetworkToHost(defaultConfig["electrumxHost"])

if "electrumxPort" in config:
if config["electrumxPort"].isdigit():
Expand Down
5 changes: 4 additions & 1 deletion Connector/eth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ def __init__(self, coin, networkName):
self._rpcPort = ""
self._wsPort = ""

def __attachNetworkToHost(self, host):
return f"{host}-{self.networkName}"

def loadConfig(self, config):

defaultConfig, err = utils.loadDefaultPackageConf(self.coin)
if err is not None:
return False, err

self.protocol = config["protocol"] if "protocol" in config else defaultConfig["protocol"]
self.host = config["host"] if "host" in config else defaultConfig["host"]
self.host = config["host"] if "host" in config else self.__attachNetworkToHost(defaultConfig["host"])

if "rpcPort" in config:
if config["rpcPort"].isdigit():
Expand Down
Loading