Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEP] Add docker compose for easy setup #22

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
docker/data/**
wallets/wallet_*
debug.log*
__pycache__/
electrum/
secp256k1/
venv/
wallet_service_db
Electrum-**
config.ini
wallet_service_db
36 changes: 36 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"pylint.args": [
"--disable=C0103,C0114,C0115,C0116,C0121,C0209,C0410,C0411,W0201,W0611,W0612,W0613,W0621,W0707,W0718,W0719,W1202,W1514,E1101",
"--indent-string=' '",
"--max-line-length=120",
],
"yapf.args": [
"--style",
"{based_on_style: pep8, indent_width: 2, column_limit: 120}"
],
"[python]": {
"editor.formatOnSaveMode": "file",
"editor.formatOnSave": true,
"editor.defaultFormatter": "eeyore.yapf",
"editor.formatOnType": false
},
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/__pycache__": true,
"**/env": true,
"Electrum-**": true,
"**/__init__.py": true,
"venv": true,
"wallets": true,
"config.ini": true,
"config.ini.sample": true,
"wallet_service_supervisor.conf": true,
"debug.log*": true,
"wallet_service_db": true,
}
}
1 change: 1 addition & 0 deletions config.ini.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[SYSTEM]
wallet_dir = wallets
use_testnet = True
use_regtest = False
fee_level = 1

[USER]
Expand Down
29 changes: 14 additions & 15 deletions db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,39 @@
import uuid
import cryptocode


class DbManager:

def __init__(self, echo_mode=False):
Base = declarative_base()
engine = create_engine('sqlite:///wallet_service_db', echo=echo_mode)
Base.metadata.bind = engine
self.session = sessionmaker(bind=engine)()

def __del__(self):
self.session.close()

def __exit__(self, *err):
pass

def __enter__(self):
return self

def close_session(self):
self.session.close()
self.session.close()

def insert_transaction(self, address, amount, wallet_id, wallet_password):
# Only sent transactions have txid and fee
sr_id = str(uuid.uuid4().hex)
obj = Transactions(
sr_id = sr_id,
txid = None,
address = address,
amount = amount,
wallet_id = wallet_id,
fee = None,
sr_timestamp = int(time.time()),
tx_timestamp = None,
wallet_password = cryptocode.encrypt(wallet_password, sr_id)
)
obj = Transactions(sr_id=sr_id,
txid=None,
address=address,
amount=amount,
wallet_id=wallet_id,
fee=None,
sr_timestamp=int(time.time()),
tx_timestamp=None,
wallet_password=cryptocode.encrypt(wallet_password, sr_id))
self.session.add(obj)
self.session.commit()
return obj
Expand Down
24 changes: 13 additions & 11 deletions db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

Base = declarative_base()


class Transactions(Base):
__tablename__ = 'transactions'
sr_id = Column(String(250), primary_key = True)
txid = Column(String(250))
address = Column(String(250), primary_key = True)
amount = Column(Integer)
wallet_id = Column(Integer)
fee = Column(Integer)
sr_timestamp = Column(BigInteger)
tx_timestamp = Column(BigInteger)
wallet_password = Column(String(2000))
__tablename__ = 'transactions'
sr_id = Column(String(250), primary_key=True)
txid = Column(String(250))
address = Column(String(250), primary_key=True)
amount = Column(Integer)
wallet_id = Column(Integer)
fee = Column(Integer)
sr_timestamp = Column(BigInteger)
tx_timestamp = Column(BigInteger)
wallet_password = Column(String(2000))


Base.metadata.create_all(engine)
Base.metadata.create_all(engine)
32 changes: 32 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.10.6

RUN apt-get update && apt-get upgrade -y

# install commponly used debug tools and required libararies
RUN apt-get install git wget vim less nano curl -y
RUN apt-get install build-essential libsecp256k1-dev rustc -y

# install required python packages
RUN pip install cryptography pyqt5 sqlalchemy requests sanic cryptocode

# download and install electrum package
RUN wget https://download.electrum.org/4.2.1/Electrum-4.2.1.tar.gz
RUN tar -xvf Electrum-4.2.1.tar.gz
RUN pip install -e Electrum-4.2.1/.

# set electrum config parameters
RUN export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

WORKDIR /app

# Apply any changes to db
COPY ../db_model.py /app/
RUN python db_model.py

# Copy required files
COPY ../config.ini /app/
COPY ../db_manager.py /app/
COPY ../electrum_cmd_util.py /app/
COPY ../utils.py /app/
COPY ../wallet_service_api.py /app/
COPY ../wallet_service_cli.py /app/
38 changes: 38 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Setting up Docker Development Environment

## Run

1. Copy `cp config.ini.sample config.ini` and update values in config.ini file
2. run bitcoin-core in regtest mode all you have to do is:
- `docker compose -f .\docker\docker-compose.yml up --build`
- Make sure docker service/docker desktop is running.
3. Now you can interact with regtest's RPC server:
- `curl --user myuser:SomeDecentp4ssw0rd --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:18443/`
4. You can also interact with
- `curl localhost:8000/api/queue`
5. generate BTC and send to wallet 0 in wallet_service
- connect to wallet_service docker container:
- `docker exec -it wallet_service /bin/bash`
- [wallet_service] create a default wallet, if you have already created wallet 0 you can skip this
- `python wallet_service_cli.py createwallet test123`
- [wallet_service] generate a new address in this wallet 0
- `python wallet_service_cli.py getunusedaddress 0 test123`
- copy address generate here e.g: bcrt1qja5ss7segmmx845qtgjsg6hvfx4q28kdjk40yu
- connect to bitcoin node:
- `docker exec -it bitcoind /bin/sh`
- [bitcoind] create default wallet
- `bitcoin-cli createwallet default`
- [bitcoind] generate BTC
- `bitcoin-cli generate 101`
- [bitcoind] check balance of this wallet here
- `bitcoin-cli getwalletinfo`
- balance must be like 50 BTC
- [bitcoind] set tx fee
- `bitcoin-cli settxfee 0.00001`
- [bitcoind] send let's say 1 BTC to the wallet 0 address
- `bitcoin-cli sendtoaddress bcrt1qja5ss7segmmx845qtgjsg6hvfx4q28kdjk40yu 1`
- [bitcoind] Make the transaction confirm:
- `bitcoin-cli generatetoaddress 7 $(bitcoin-cli getnewaddress)`
- [wallet_service] confirm balance in wallet 0
- `python wallet_service_cli.py getbalance 0 test123`
- using these steps you can send any number of BTC to any addresses
15 changes: 15 additions & 0 deletions docker/bitcoin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server=1
rest=1
regtest=1
txindex=1

[regtest]
rpcuser=myuser
rpcpassword=SomeDecentp4ssw0rd
rpcport=18443
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
rpcallowip=::/0

printtoconsole=1
dbcache=512
45 changes: 45 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: "3"
services:
# run wallet service connecting to electrumx regtest server
app:
container_name: wallet_service
build:
context: ../
dockerfile: ./docker/Dockerfile
volumes:
- ./data/wallet_service/wallets:/app/wallets
ports:
- "8000:8000"
environment:
- PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- REGTEST_SERVER=host.docker.internal
depends_on:
- electrumx
command: "python wallet_service_api.py"
# run docker bitcoin node on regtest net
bitcoind:
container_name: bitcoind
user: 1000:1000
image: lncm/bitcoind:v27.0
ports:
- "18443:18443"
volumes:
- ./bitcoin.conf:/data/.bitcoin/bitcoin.conf
- ./data/bitcoind:/data/.bitcoin
restart: on-failure
stop_grace_period: 15m30s
# run electrumx server on regtest net
electrumx:
container_name: electrumx
image: lukechilds/electrumx
ports:
- "51002:50002"
- "51001:50001"
volumes:
- ./data/electrumx:/data
depends_on:
- bitcoind
environment:
- DAEMON_URL=http://myuser:SomeDecentp4ssw0rd@bitcoind:18443
- COIN=BitcoinSegwit
- NET=regtest
Loading