def _get_attempt_list(self) -> str:
        trigger_tx = flask_module.request.args.get(
            'trigger_tx')  # type: Optional[str]
        trigger_currency = flask_module.request.args.get(
            'trigger_currency')  # type: Optional[str]
        trigger_receiver = flask_module.request.args.get(
            'trigger_receiver')  # type: Optional[str]
        anything = flask_module.request.args.get(
            'anything')  # type: Optional[str]

        trigger_receiver_as_int = None  # type: Optional[int]

        if trigger_receiver is not None:
            trigger_receiver_as_int = int(trigger_receiver)

        if (trigger_tx is None) and (anything is None):
            return flask_module.abort(400)

        query = AttemptListQuery(trigger_currency=trigger_currency,
                                 trigger_tx=trigger_tx,
                                 trigger_receiver=trigger_receiver_as_int,
                                 anything=anything)

        attempt_lists = self._gateway_controller.query_attempt_lists(query)

        serialized_lists = map_array(
            lambda x: self._serializer.attempt_list_as_dict(x), attempt_lists)

        return flask_module.jsonify(serialized_lists)
    def _attempt_as_dict(self, attempt: TransactionAttempt) -> dict:
        res = dict()  # type: Any

        res[TransactionAttempt.DICT_CURRENCY] = attempt.currency
        res[TransactionAttempt.DICT_FEE] = str(attempt.fee)
        res[TransactionAttempt.DICT_SENDER] = attempt.sender
        res[TransactionAttempt.DICT_RECEIVERS] = map_array(self._receiver_as_dict, attempt.receivers)

        return res
    def _trigger_from_dict(self, data: dict) -> AttemptListTrigger:
        if AttemptListTrigger.DICT_SENDERS_KEY in data:
            senders = map_array(self._sender_from_dict, data[AttemptListTrigger.DICT_SENDERS_KEY])
        else:
            senders = None

        return AttemptListTrigger(
            tx=data[AttemptListTrigger.DICT_TX],
            receiver=data[AttemptListTrigger.DICT_RECEIVER],
            currency=data[AttemptListTrigger.DICT_CURRENCY],
            senders=senders)
    def _trigger_as_dict(self, trigger: AttemptListTrigger):
        res = dict()

        res[AttemptListTrigger.DICT_RECEIVER] = trigger.receiver
        res[AttemptListTrigger.DICT_TX] = trigger.tx
        res[AttemptListTrigger.DICT_CURRENCY] = trigger.currency

        if trigger.senders is not None:
            res[AttemptListTrigger.DICT_SENDERS_KEY] = map_array(self._sender_as_dict, trigger.senders)

        return res
    def attempt_list_as_dict(self, attempt_list: TransactionAttemptList):
        res = dict()

        res[TransactionAttemptList.DICT_ID] = attempt_list.attempt_list_id
        res[TransactionAttemptList.DICT_TRANSACTIONS] = attempt_list.transactions
        res[TransactionAttemptList.DICT_ATTEMPTS] = map_array(self._attempt_as_dict, attempt_list.attempts)
        res[TransactionAttemptList.DICT_TRIGGER] = self._trigger_as_dict(attempt_list.trigger)
        res[TransactionAttemptList.DICT_TRIES] = attempt_list.tries

        if attempt_list.last_modified is not None:
            res[TransactionAttemptList.DICT_LAST_MODIFIED] = attempt_list.last_modified

        if attempt_list.created_at is not None:
            res[TransactionAttemptList.DICT_CREATED_AT] = attempt_list.created_at

        return res
    def attempt_list_from_dict(self, data: dict) -> TransactionAttemptList:
        created_at = None
        last_modified = None
        tries = TransactionAttemptList.DEFAULT_TRIES

        if TransactionAttemptList.DICT_CREATED_AT in data:
            created_at = data[TransactionAttemptList.DICT_CREATED_AT]

        if TransactionAttemptList.DICT_LAST_MODIFIED in data:
            last_modified = data[TransactionAttemptList.DICT_LAST_MODIFIED]

        if TransactionAttemptList.DICT_TRIES in data:
            tries = data[TransactionAttemptList.DICT_TRIES]

        return TransactionAttemptList(
            trigger=self._trigger_from_dict(data[TransactionAttemptList.DICT_TRIGGER]),
            attempts=map_array(self._attempt_from_dict, data[TransactionAttemptList.DICT_ATTEMPTS]),
            transactions=data[TransactionAttemptList.DICT_TRANSACTIONS],
            last_modified=last_modified,
            created_at=created_at,
            tries=tries,
            attempt_list_id=data[TransactionAttemptList.DICT_ID])
 def query_attempt_lists(self, query: AttemptListQuery) -> List[TransactionAttemptList]:
     results = self._gateway_controller.query_attempt_lists(query)
     return map_array(lambda x: self._converter.revert_attempt_list_conversion(x), results)
Beispiel #8
0
 def get_transactions_of_block_at_height(self, height: int) -> List[Transaction]:
     transactions = self._chain_query_service.get_transactions_of_block_at_height(height)
     return map_array(lambda x: self._integer_converter_service.convert_transaction_to_int(x), transactions)
 def _attempt_from_dict(self, data: dict) -> TransactionAttempt:
     return TransactionAttempt(
         currency=data[TransactionAttempt.DICT_CURRENCY],
         fee=int(data[TransactionAttempt.DICT_FEE]),
         sender=data[TransactionAttempt.DICT_SENDER],
         receivers=map_array(self._receiver_from_dict, data[TransactionAttempt.DICT_RECEIVERS]))
Beispiel #10
0
 def get_transactions_of_block_at_height(self, height: int) -> List[Transaction]:
     transactions = self._get_response_from_node('/blocks/at/' + str(height))['transactions']
     waves_transactions = map_array(self._convert_node_response_to_transaction, transactions)
     return filter_array(lambda x: x is not None, waves_transactions)