Skip to content
Snippets Groups Projects
Commit 23a9380b authored by Dylan Janssen's avatar Dylan Janssen
Browse files

Merge branch '4-create-general-functions-for-the-wallets' into 2-implement_all_user_flows

parents e0427c56 2d42c121
No related branches found
No related tags found
1 merge request!2Draft: initial user flow for creating a wallet
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env .env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
from peewee import MySQLDatabase, Model, CharField, BlobField, AutoField
from peewee import IntegerField, ForeignKeyField, DoubleField
import os
db = MySQLDatabase(None)
def connect(create_tables=False) -> None:
"""Initializes the database session and connects to the database
:param create_tables: Creates database tables [default: False]
"""
user = os.getenv("DB_USER")
pw = os.getenv("DB_PASSWORD")
host = os.getenv("DB_HOST")
port = os.getenv("DB_PORT")
name = os.getenv("DB_DATABASE")
db.init(name, host=host, port=int(port), user=user, password=pw)
db.connect()
if create_tables:
db.create_tables([State, User, Wallet,
WalletRequest, UserWallet, PendingTX])
class BaseModel(Model):
id = AutoField()
class Meta:
database = db
class State(BaseModel):
message = CharField()
menu = CharField()
prev_state = IntegerField()
class User(BaseModel):
telegram_id = IntegerField()
state_id = ForeignKeyField(State)
nickname = CharField()
variables = CharField()
class Wallet(BaseModel):
max_co_signers = IntegerField()
min_co_signers = IntegerField()
initiator_user_id = ForeignKeyField(User, backref='users')
name = CharField()
class WalletRequest(BaseModel):
token = CharField()
wallet_id = ForeignKeyField(User, backref='walletrequests')
class UserWallet(BaseModel):
user_id = ForeignKeyField(User, backref='wallets')
wallet_id = ForeignKeyField(Wallet, backref='wallets')
class PendingTX(BaseModel):
from_wallet_id = ForeignKeyField(Wallet, backref='pendingtx')
to_address = CharField()
amount = DoubleField()
fee_sat_per_byte = IntegerField()
status = IntegerField()
sign_count = IntegerField()
raw_data = BlobField()
txid = BlobField()
python-dotenv~=0.19.2 python-dotenv~=0.19.2
bitcoinlib~=0.6.4 bitcoinlib~=0.6.4
python-telegram-bot~=13.11 python-telegram-bot~=13.11
mysqlclient~=2.1.0 mysqlclient~=2.1.0
\ No newline at end of file peewee==3.14.10
#!/bin/env python3
from typing import Union
from bitcoinlib.wallets import Wallet, HDKey, WalletKey
import os
from util import DBManager
db = DBManager()
def new_multig_wallet(userId: Union[int, str],
sigs: int, klist: list[HDKey]) -> WalletKey:
"""
Creates a new multisig wallet.
userId: name of the wallet
sigs: number of signatures needed for the wallet
klist: list of (public master) keys inside the wallet
"""
return Wallet.create(name=userId,
sigs_required=sigs,
keys=klist,
network=os.getenv("BTC_NETWORK"),
db_uri=db.db_uri)
def new_HD_key() -> HDKey:
"""
Generates a new Hierarchical Deterministic key
"""
return HDKey(network=os.getenv("BTC_NETWORK"))
def main():
pass
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment