Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ double-env:

# run all e2e tests
e2e-test:
./scripts/wait_for_server_ready.sh 12 # 12 services should have log, 2 gateways has no log
./scripts/wait_for_server_ready.sh 6 # 12 services should have log, 2 gateways has no log
cat double.vars
source double.vars && PIPENV_PIPFILE=backend/Pipfile pipenv run pytest \
backend/tests/e2e_tests -k "$(T)" -W ignore::DeprecationWarning
Expand Down
4 changes: 0 additions & 4 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
fakeredis = "*"
black = "*"
pyre-check = "*"
pyre-extensions = "*"
Expand All @@ -17,9 +16,6 @@ ipython = "*"

[packages]
diem-sample-wallet = {editable = true,path = "."}
dramatiq = {extras = ["redis", "watch"],version = "*"}
flask-redis = "*"
redis = "*"
Flask = ">=1.1.1"
Flask-WTF = "*"
WTForms = "*"
Expand Down
228 changes: 29 additions & 199 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Then run the following to build the images from source and stand up a local depl

The default gateway port is 8080, so you can visit http://localhost:8080. Develop mode also exposes the other ports from the backend services onto the host. The main backend webserver is on 5000. Swagger API docs can be found at http://localhost:5000/apidocs.

Getting started in the code, we've provided detailed logs through each of the [workflows](wallet/background_tasks), which can be found at http://localhost:5000/execution_logs.
Getting started in the code, we've provided detailed logs through each of the [workflows](wallet), which can be found at http://localhost:5000/execution_logs.

### Docker Compose

Expand All @@ -55,15 +55,6 @@ If you want to go the extra mile, you can also use helm to install the Diem Refe

The Python backend relies on pipenv. To set up, run `pipenv install --dev` in /backend directory.

The workflows use [dramatiq](https://dramatiq.io/) with the Redis broker. Install Redis and run it as a daemon:

$ redis-server --daemonize yes

After ensuring you have Redis running:

$ ./run_web.sh # runs main webserver
$ ./run_worker.sh # runs dramatiq workers

To test:

$ ./format.sh # runs black
Expand Down
34 changes: 0 additions & 34 deletions backend/pubsub/__main__.py
Original file line number Diff line number Diff line change
@@ -1,34 +0,0 @@
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

import argparse
import json
import sys

from pubsub import DEFL_CONFIG, VASP_ADDR
from pubsub.client import LRWPubSubClient


parser = argparse.ArgumentParser(
description="Pubsub CLI tool. Takes in pubsub config file or VASP_ADDR environment variable"
)
parser.add_argument("-f", "--file", type=str, help="LRW pubsub config file path")
args = parser.parse_args()

if args.file:
try:
with open(args.file) as f:
conf = json.load(f)
except:
print("Missing or invalid config file, exiting...")
sys.exit(1)
else: # load in by env var
if not VASP_ADDR:
print("Missing VASP_ADDR environment variable, exiting...")
sys.exit(1)
conf = DEFL_CONFIG

print(conf)

client = LRWPubSubClient(conf)
client.start()
30 changes: 26 additions & 4 deletions backend/pubsub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import logging
import json

from wallet.background_tasks.background import process_incoming_txn
from .types import LRWPubSubEvent
from wallet.services.transaction import process_incoming_transaction
from diem_utils.types.currencies import DiemCurrency
from diem import jsonrpc
from . import DEFL_CONFIG


class FileProgressStorage:
Expand All @@ -31,14 +33,14 @@ def save_state(self, state: Dict[str, int]) -> None:


class LRWPubSubClient:
def __init__(self, config: Dict[str, Any]) -> None:
def __init__(self, config: Dict[str, Any] = DEFL_CONFIG) -> None:
self.sync_interval_ms = config["sync_interval_ms"]
self.accounts = config["accounts"]

self.diem_node_uri = config["diem_node_uri"]
self.progress_file_path = config["progress_file_path"]
self.fetch_batch_size = 10
self.processor = config.get("processor", process_incoming_txn)
self.processor = config.get("processor", LRWPubSubClient.process_incoming_txn)

logging.info(f"Loaded LRWPubSubClient with config: {config}")

Expand All @@ -63,7 +65,7 @@ def sync(
)
for event in events:
lrw_event = LRWPubSubEvent.from_jsonrpc_event(event)
self.processor.send(lrw_event)
self.processor(lrw_event)
logging.info(f"SUCCESS: sent to wallet onchain {lrw_event}")

after_sync_state[key] = sequence_num + len(events)
Expand All @@ -87,3 +89,23 @@ def init_progress_state(self) -> Dict[str, int]:
if account.received_events_key not in state:
state[account.received_events_key] = 0
return state

@staticmethod
def process_incoming_txn(txn: LRWPubSubEvent) -> None:
metadata = txn.metadata
blockchain_version = txn.version
sender_address = txn.sender
receiver_address = txn.receiver
sequence = txn.sequence
amount = txn.amount
currency = DiemCurrency[txn.currency]
process_incoming_transaction(
blockchain_version=blockchain_version,
sender_address=sender_address,
receiver_address=receiver_address,
sequence=sequence,
amount=amount,
currency=currency,
metadata=metadata,
)

6 changes: 0 additions & 6 deletions backend/run_pubsub.sh

This file was deleted.

14 changes: 0 additions & 14 deletions backend/run_worker.sh

This file was deleted.

2 changes: 1 addition & 1 deletion backend/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -euo pipefail

# NOTE:
# each of these test modules need to be run independently due to how they
# instantiate dramatiq and other test dependencies in conftest.py
# instantiate test dependencies in conftest.py
pipenv run python3 $DIR/setup.py pytest --addopts="$DIR/tests/wallet_tests $@"
pipenv run python3 $DIR/setup.py pytest --addopts="$DIR/tests/webapp_tests $@"
pipenv run python3 $DIR/setup.py pytest --addopts="$DIR/tests/pubsub_tests $@"
Expand Down
8 changes: 0 additions & 8 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ def wait_for_transaction(*args):
yield network


@pytest.fixture(autouse=True)
def no_background_tasks(monkeypatch) -> None:
def mocked() -> bool:
return False

monkeypatch.setattr(services, "run_bg_tasks", mocked)


class LpClientMock:
QUOTES: Dict[QuoteId, QuoteData] = {}
TRADES: Dict[TradeId, TradeData] = {}
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/wallet_tests/services/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_send_transaction() -> None:
assert tx.destination_subaddress == "receiver_subaddress"


def test_transaction_direction(no_background_tasks) -> None:
def test_transaction_direction() -> None:
account_id, send_tx = send_fake_tx()
assert get_transaction_direction(account_id, send_tx) == TransactionDirection.SENT

Expand Down
5 changes: 0 additions & 5 deletions backend/wallet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

# keep config import first, because we MUST configure dramatiq broker prior to background_tasks import
# once @actor is being used (e.g. in background_tasks) and no global dramatiq broker configured -
# dramatiq will try to use default RabbitMQ one (this is hardcoded and can't be changed) - which will fail

from . import config
from . import background_tasks
4 changes: 0 additions & 4 deletions backend/wallet/background_tasks/__init__.py

This file was deleted.

74 changes: 0 additions & 74 deletions backend/wallet/background_tasks/background.py

This file was deleted.

51 changes: 0 additions & 51 deletions backend/wallet/background_tasks/utils.py

This file was deleted.

Loading