Skip to content

Commit

Permalink
Add cyberway support to escrow
Browse files Browse the repository at this point in the history
Blockchain base class was changed to fit more blockchains. In
particular, part of it responsible for streaming new trasactions was
moved to another class, as it was decided to handle transaction check of
cyberway (which doesn't support streaming) by pressing on button instead
of starting check immediately to reduce node load.

As TellerBot uses node which is not public, node URLs were moved to
secrets.

Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed May 13, 2020
1 parent 7664d1a commit 150b22a
Show file tree
Hide file tree
Showing 16 changed files with 579 additions and 163 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ ORDER_DURATION_LIMIT=30
ESCROW_ENABLED=true
ESCROW_FEE_PERCENTS=5
CHECK_TIMEOUT_HOURS=24
WIF_FILENAME=/run/secrets/wif.json
ESCROW_FILENAME=/run/secrets/escrow.json
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
volumes:
- ${DATABASE_PASSWORD_FILENAME}:${DATABASE_PASSWORD_FILENAME}:ro
- ${TOKEN_FILENAME}:${TOKEN_FILENAME}:ro
- ${WIF_FILENAME}:${WIF_FILENAME}:ro
- ${ESCROW_FILENAME}:${ESCROW_FILENAME}:ro
ports:
- ${SERVER_PORT}:${SERVER_PORT}

Expand Down
14 changes: 13 additions & 1 deletion locale/en/LC_MESSAGES/bot.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: TellerBot\n"
"Report-Msgid-Bugs-To: rchrdsn@protonmail.ch\n"
"POT-Creation-Date: 2020-04-12 21:55+0300\n"
"POT-Creation-Date: 2020-05-13 15:08+0300\n"
"PO-Revision-Date: 2019-10-03 14:00+0300\n"
"Last-Translator: alfred richardsn <rchrdsn@protonmail.ch>\n"
"Language: en\n"
Expand Down Expand Up @@ -478,6 +478,18 @@ msgstr "Your escrow offer was declined."
msgid "offer_declined"
msgstr "Offer was declined."

#: src/handlers/escrow.py
msgid "transaction_check_starting"
msgstr "Starting transaction check..."

#: src/handlers/escrow.py
msgid "transaction_not_found"
msgstr "Transaction is not found."

#: src/handlers/escrow.py
msgid "check"
msgstr "Check transaction"

#: src/handlers/escrow.py
msgid "with_memo"
msgstr "with memo"
Expand Down
14 changes: 13 additions & 1 deletion locale/ru/LC_MESSAGES/bot.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: TellerBot\n"
"Report-Msgid-Bugs-To: rchrdsn@protonmail.ch\n"
"POT-Creation-Date: 2020-04-12 21:55+0300\n"
"POT-Creation-Date: 2020-05-13 15:08+0300\n"
"PO-Revision-Date: 2019-02-24 04:46+0300\n"
"Last-Translator: alfred richardsn <rchrdsn@protonmail.ch>\n"
"Language: ru\n"
Expand Down Expand Up @@ -479,6 +479,18 @@ msgstr "Ваше предложение эскроу отклонено."
msgid "offer_declined"
msgstr "Предложение отклонено."

#: src/handlers/escrow.py
msgid "transaction_check_starting"
msgstr "Начинаю проверку транзакции..."

#: src/handlers/escrow.py
msgid "transaction_not_found"
msgstr "Транзакция не найдена."

#: src/handlers/escrow.py
msgid "check"
msgstr "Проверить транзакцию"

#: src/handlers/escrow.py
msgid "with_memo"
msgstr "с мемо"
Expand Down
2 changes: 2 additions & 0 deletions requirements-escrow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git+https://github.com/eosnewyork/eospy.git@ed55d652f5dcc9e45917273e6bc14b37791e772d
golos-python==1.1.0
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
aiogram==2.8
emoji==0.5.4
golos-python==1.1.0
motor==2.1.0
pymongo==3.10.1
requests==2.23.0
17 changes: 17 additions & 0 deletions secrets/escrow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"golos": {
"wif": "abcdefghijklmopqrstuABCDEFGHIJKLMNOPQRSTU1234567890",
"nodes": [
"wss://api.golos.blckchnd.com/ws",
"wss://golosd.privex.io",
"wss://golos.solox.world/ws",
"wss://golos.lexa.host/ws"
]
},
"cyber": {
"wif": "abcdefghijklmopqrstuABCDEFGHIJKLMNOPQRSTU1234567890",
"nodes": [
"http://127.0.0.1:8888"
]
}
}
3 changes: 0 additions & 3 deletions secrets/wif.json

This file was deleted.

2 changes: 2 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from src.bot import dp
from src.bot import tg
from src.config import config
from src.escrow import close_blockchains
from src.escrow import connect_to_blockchains


Expand Down Expand Up @@ -52,6 +53,7 @@ def main():
dispatcher=dp,
webhook_path=webhook_path,
on_startup=lambda *args: on_startup(webhook_path, *args),
on_shutdown=lambda *args: close_blockchains(),
host=config.INTERNAL_HOST,
port=config.SERVER_PORT,
)
Expand Down
12 changes: 11 additions & 1 deletion src/escrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with TellerBot. If not, see <https://www.gnu.org/licenses/>.
from src.config import config
from src.escrow.blockchain import StreamBlockchain


if config.ESCROW_ENABLED:
from src.escrow.blockchain.golos_blockchain import GolosBlockchain
from src.escrow.blockchain.cyber_blockchain import CyberBlockchain

SUPPORTED_BLOCKCHAINS = [GolosBlockchain()]
SUPPORTED_BLOCKCHAINS = [GolosBlockchain(), CyberBlockchain()]
else:
SUPPORTED_BLOCKCHAINS = []

Expand All @@ -39,3 +41,11 @@ async def connect_to_blockchains():
"""Run ``connect()`` method on every blockchain instance."""
for bc in SUPPORTED_BLOCKCHAINS:
await bc.connect()
if isinstance(bc, StreamBlockchain) and bc._queue:
bc.start_streaming()


async def close_blockchains():
"""Run ``close()`` method on every blockchain instance."""
for bc in SUPPORTED_BLOCKCHAINS:
await bc.close()

0 comments on commit 150b22a

Please sign in to comment.