Exemplo n.º 1
0
 def __init__(self, config):
     self.config = config
     os.makedirs(config.Worker.General.ListenerBlocksLogDir, exist_ok=True)
     web3 = Web3(Web3.WebsocketProvider(config.Worker.Blockchain.URI))
     contract = Contract(web3, config.Worker.Contract)
     receivers = Receiver.mapping_from_list(config.Receivers)
     self.listeners = Listener.from_config_list(
         contract,
         receivers,
         config.Listeners,
         config
     )
     self.logger = logging.getLogger(config.Worker.General.LoggerName)
Exemplo n.º 2
0
    def __init__(self,
                 contract=None,
                 receivers=None,
                 config=None,
                 global_config=None):
        self.__logger = logging.getLogger(config.Id)

        self.__contract = contract
        self.__config = config
        self.__global_config = global_config
        self.__receivers = tuple(receivers[id] for id in config.Receivers)
        self.__from_block_filename = os.path.join(
            global_config.Worker.General.ListenerBlocksLogDir, config.Id)
        self.__from_block = self.__load_from_block()
        self.__filter = None
        self.__update_filter()
Exemplo n.º 3
0
import json
import time
import urllib
import boto3
import requests
from web3 import Web3
from web3.exceptions import TimeExhausted
from web3.gas_strategies.time_based import fast_gas_price_strategy, medium_gas_price_strategy

from src.loggers import logging

logger = logging.getLogger('WORKER')

OPEN_ATTESTATION_VERSION_ID_V2_FRAMEWORK = 'https://schema.openattestation.com/2.0/schema.json'
OPEN_ATTESTATION_VERSION_ID_V3_FRAMEWORK = 'https://schema.openattestation.com/3.0/schema.json'
OPEN_ATTESTATION_VERSION_ID_V2_SHORT = 'open-attestation/2.0'
OPEN_ATTESTATION_VERSION_ID_V3_SHORT = 'open-attestation/3.0'

DOCUMENT_STORE_PROOF_TYPE = 'DOCUMENT_STORE'


class DocumentError(Exception):
    pass


class TransactionTimeoutException(Exception):
    pass


class UnderpricedReplacementTransactionException(Exception):
    pass
Exemplo n.º 4
0
import os
from collections import namedtuple
from contextlib import contextmanager
import time
import tempfile
import json
import yaml
import pytest
from src.config import Config
from src.worker import Worker
from src.contract import Contract
from src.loggers import logging
from tests.integration.conftest import CONFIG

logger = logging.getLogger('TEST')


def test_worker(empty_queue, MessageSent, MessageReceived, latest_block,
                worker_config_json):
    def queue_messages(queue):
        received_messages = []
        while new_messages := queue.receive_messages(
                WaitTimeSeconds=1, MaxNumberOfMessages=1):  # noqa
            received_messages.append(json.loads(new_messages[0].body))
        received_messages.sort(key=lambda e: e['Block'])
        return [m['Event'] for m in received_messages]

    @contextmanager
    def wait_for_blocks(number):
        logger.info('Waiting for %s blocks to be mined...', number)
        target = latest_block() + number
Exemplo n.º 5
0
 def __init__(self, config_obj):
     super().__init__(config_obj)
     self.__logger = logging.getLogger(self.config.Id)
Exemplo n.º 6
0
 def __init__(self, config_obj):
     super().__init__(config_obj)
     self.__logger = logging.getLogger(self.config.Id)
     self.__queue = aws.sqs(config_obj.Config.AWS).Queue(
         config_obj.QueueUrl)
Exemplo n.º 7
0
import random
import urllib
import requests
from libtrustbridge.websub.domain import Pattern
from src import repos
from src.loggers import logging

logger = logging.getLogger(__name__)


class PostNotificationUseCase:
    """
    Base use case to send message for notification
    """
    def __init__(self, notification_repo: repos.Notifications):
        self.notifications_repo = notification_repo

    def publish(self, message):
        topic = self.get_topic(message)
        job_payload = {'topic': topic, 'content': {'id': message['id']}}
        logger.debug('publish notification %r', job_payload)
        self.notifications_repo.post_job(job_payload)

    @staticmethod
    def get_topic(message):
        raise NotImplementedError


class PublishNewMessageUseCase(PostNotificationUseCase):
    """
    Given new message,