Skip to content

Commit 0047f81

Browse files
author
swapper-phoenix
committed
Add services to docker-composes and basic connector methods
1 parent e8062ef commit 0047f81

File tree

11 files changed

+168
-9
lines changed

11 files changed

+168
-9
lines changed

Connector/xmr/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import apirpc

Connector/xmr/apirpc.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from .constants import *
2+
from .connector import RPC_ENDPOINT
3+
from rpcutils import rpcutils, errorhandler as rpcerrorhandler
4+
from rpcutils.rpcconnector import RPCConnector
5+
from . import utils
6+
from logger import logger
7+
8+
9+
@rpcutils.rpcMethod
10+
def syncing(id, params):
11+
12+
logger.printInfo(f"Executing RPC method syncing with id {id} and params {params}")
13+
14+
requestSchema, responseSchema = utils.getMethodSchemas(SYNCING)
15+
16+
err = rpcutils.validateJSONRPCSchema(params, requestSchema)
17+
if err is not None:
18+
raise rpcerrorhandler.BadRequestError(err.message)
19+
20+
blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id,
21+
GET_SYNC_INFO, None)
22+
23+
if blockchainInfo is None:
24+
logger.printWarning("Could not get blockchain info from node")
25+
raise rpcerrorhandler.BadRequestError(
26+
"Could not get blockchain info from node")
27+
28+
# if blockchainInfo[BLOCKS] != blockchainInfo[HEADERS]:
29+
# response = {
30+
# SYNCING: True,
31+
# SYNC_PERCENTAGE:
32+
# f'{str(blockchainInfo[VERIFICATION_PROGRESS]*100)}%',
33+
# CURRENT_BLOCK_INDEX: blockchainInfo[BLOCKS],
34+
# LATEST_BLOCK_INDEX: blockchainInfo[HEADERS],
35+
# }
36+
# else:
37+
# response = {SYNCING: False}
38+
39+
response = {SYNCING: blockchainInfo}
40+
41+
err = rpcutils.validateJSONRPCSchema(response, responseSchema)
42+
if err is not None:
43+
raise rpcerrorhandler.BadRequestError(err.message)
44+
45+
return response

Connector/xmr/connector.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RPC_MONEROD_PORT = 38081
2+
RPC_MONEROD_HOST = "monerod"
3+
RPC_MONEROD_ENDPOINT = "json_rpc"
4+
5+
RPC_ENDPOINT = "http://{}:{}/{}".format(RPC_MONEROD_HOST, RPC_MONEROD_PORT, RPC_MONEROD_ENDPOINT)

Connector/xmr/constants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SYNCING = "syncing"
2+
3+
RPC_JSON_SCHEMA_FOLDER = "xmr/rpcschemas/"
4+
WS_JSON_SCHEMA_FOLDER = "xmr/wsschemas/"
5+
SCHEMA_CHAR_SEPARATOR = "_"
6+
REQUEST = "request"
7+
RESPONSE = "response"
8+
SCHEMA_EXTENSION = ".json"
9+
10+
GET_SYNC_INFO = "sync_info"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "object",
6+
"properties": {}
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "object",
6+
"properties": {
7+
"syncing": {
8+
"type": "boolean"
9+
},
10+
"syncPercentage":{
11+
"type": "string"
12+
},
13+
"currentBlock":{
14+
"type": "string"
15+
},
16+
"latestBlock":{
17+
"type": "string"
18+
}
19+
},
20+
"required": [
21+
"syncing"
22+
]
23+
}

Connector/xmr/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/python3
2+
from .constants import *
3+
4+
5+
def getMethodSchemas(name):
6+
return getRequestMethodSchema(name), getResponseMethodSchema(name)
7+
8+
9+
def getRequestMethodSchema(name):
10+
return RPC_JSON_SCHEMA_FOLDER + name + SCHEMA_CHAR_SEPARATOR + REQUEST + SCHEMA_EXTENSION
11+
12+
13+
def getResponseMethodSchema(name):
14+
return RPC_JSON_SCHEMA_FOLDER + name + SCHEMA_CHAR_SEPARATOR + RESPONSE + SCHEMA_EXTENSION

docker-compose/mainnet/xmr.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "3"
2+
services:
3+
monerod:
4+
build: ../../packages/swapper-monerod
5+
image: monerod
6+
command: --p2p-bind-ip=0.0.0.0 --p2p-bind-port=18080 --rpc-bind-ip=0.0.0.0 --rpc-bind-port=18081 --non-interactive --confirm-external-bind
7+
volumes:
8+
- ${BLOCKCHAIN_PATH}/bitmonero:/home/monero/.bitmonero
9+
user: "${UID}:${GID}"
10+
11+
connector:
12+
build: ../../Connector
13+
environment:
14+
COIN: XMR
15+
STAGE: ${STAGE}
16+
PORT: ${PORT}
17+
image: connector
18+
depends_on:
19+
- monerod
20+
21+
nginx:
22+
image: nginx
23+
volumes:
24+
- ${NGINX_CONFIG_PATH}:/etc/nginx/nginx.conf
25+
- ${CERT_PATH}:/etc/nginx/certs
26+
ports:
27+
- ${PORT}:80
28+
- ${SSL_PORT}:443
29+
depends_on:
30+
- connector

docker-compose/testnet/xmr.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "3"
2+
services:
3+
monerod:
4+
build: ../../packages/swapper-monerod
5+
image: monerod
6+
command: --stagenet --p2p-bind-ip=0.0.0.0 --p2p-bind-port=38080 --rpc-bind-ip=0.0.0.0 --rpc-bind-port=38081 --non-interactive --confirm-external-bind
7+
volumes:
8+
- ${BLOCKCHAIN_PATH}/bitmonero:/home/monero/.bitmonero
9+
user: "${UID}:${GID}"
10+
11+
connector:
12+
build: ../../Connector
13+
environment:
14+
COIN: XMR
15+
STAGE: ${STAGE}
16+
PORT: ${PORT}
17+
image: connector
18+
depends_on:
19+
- monerod
20+
21+
nginx:
22+
image: nginx
23+
volumes:
24+
- ${NGINX_CONFIG_PATH}:/etc/nginx/nginx.conf
25+
- ${CERT_PATH}:/etc/nginx/certs
26+
ports:
27+
- ${PORT}:80
28+
- ${SSL_PORT}:443
29+
depends_on:
30+
- connector
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM debian:bullseye-slim AS build
33

44
ENV MONERO_VERSION=0.17.2.3 MONERO_SHA256=8069012ad5e7b35f79e35e6ca71c2424efc54b61f6f93238b182981ba83f2311
55

6-
RUN apt-get update && apt-get install -y curl bzip2
6+
RUN apt-get update && apt-get install -y curl bzip2 gosu
77

88
WORKDIR /root
99

@@ -24,17 +24,11 @@ COPY --chown=monero:monero --from=build /root/monerod /home/monero/monerod
2424

2525
VOLUME /home/monero/.bitmonero
2626

27-
EXPOSE 18080 18081
27+
EXPOSE 18080 18081 38080 38081
2828

2929

3030
COPY --chown=monero:monero entrypoint.sh ./entrypoint.sh
3131
RUN chmod +x entrypoint.sh
3232
ENTRYPOINT ["/home/monero/entrypoint.sh"]
3333

34-
ENTRYPOINT ["./monerod"]
35-
CMD ["--p2p-bind-ip=0.0.0.0", \
36-
"--p2p-bind-port=18080", \
37-
"--rpc-bind-ip=0.0.0.0", \
38-
"--rpc-bind-port=18081", \
39-
"--non-interactive", \
40-
"--confirm-external-bind" ]
34+
ENTRYPOINT ["./monerod"]

0 commit comments

Comments
 (0)