示例#1
0
    def on_new_block_event(cls, block_event: BlockEvent):
        if block_event.network.type not in cls.network_types:
            return

        addresses = block_event.transactions_by_address.keys()
        query_result = session \
            .query(DucatusUser) \
            .filter(cls.address_from(DucatusUser).in_(addresses)) \
            .all()
        for model in query_result:
            address = cls.address_from(model)
            transactions = block_event.transactions_by_address[address]

            for transaction in transactions:
                for output in transaction.outputs:
                    if address not in output.address:
                        print(
                            '{}: Found transaction out from internal address. Skip it.'
                            .format(block_event.network.type),
                            flush=True)
                        continue
                    print(block_event.__dict__)

                    message = {
                        'ducatus_user': model.id,
                        'confirmations': transaction.inputs,
                        'to_address': address,
                        'transactionHash': transaction.tx_hash,
                        'currency': cls.currency,
                        'amount': output.value,
                        'success': True,
                        'status': 'COMMITTED'
                    }

                    send_to_backend(cls.event_type, cls.queue, message)
示例#2
0
    def handle(cls, token_address: str, token_name, transactions, network):
        for tx in transactions:
            if token_address.lower() != tx.outputs[0].address.lower():
                continue

            processed_receipt = network.get_processed_tx_receipt(tx.tx_hash, token_name)
            if not processed_receipt:
                print('{}: WARNING! Can`t handle tx {}, probably we dont support this event'.format(
                    cls.network_types[0], tx.tx_hash), flush=True)
                return

            transfer_to = processed_receipt[0].args.to
            tokens_amount = processed_receipt[0].args.value

            model = session.query(AdvUser).\
                filter(AdvUser.eth_address == transfer_to.lower()).first()
            if not model:
                continue

            message = {
                'userID': model.id,
                "transactionHash": tx.tx_hash,
                "address": model.eth_address,
                "from_address": tx.inputs[0],
                "amount": tokens_amount,
                "currency": token_name,
                "status": "COMMITTED",
                "success": True
            }

            send_to_backend(cls.event_type, cls.queue, message)
示例#3
0
    def on_new_block_event(cls, block_event: BlockEvent):
        if block_event.network.type not in cls.network_type:
            return

        tx_hashes = set()
        for address_transactions in block_event.transactions_by_address.values(
        ):
            for transaction in address_transactions:
                tx_hashes.add(transaction.tx_hash)

        transfers = session \
            .query(Transfers) \
            .filter(Transfers.tx_hash.in_(tx_hashes), Transfers.currency == cls.currency) \
            .distinct(Transfers.tx_hash) \
            .all()
        for transfer in transfers:
            message = {
                'transactionHash': transfer.tx_hash,
                'transferId': transfer.id,
                'currency': cls.currency,
                'amount': int(transfer.amount),
                'success': True,
                'status': 'COMMITTED',
            }
            send_to_backend(cls.event_type,
                            NETWORKS[block_event.network.type]['queue'],
                            message)
示例#4
0
    def on_new_block_event(cls, block_event: BlockEvent):
        if block_event.network.type not in cls.network_types:
            return

        addresses = block_event.transactions_by_address.keys()
        query_result = session.query(AdvUser).filter(cls.address_from(AdvUser).in_(addresses)).all()
        for model in query_result:
            address = cls.address_from(model)
            transactions = block_event.transactions_by_address[address.lower()]

            if not transactions:
                print('{}: User {} received from DB, but was not found in transaction list (block {}).'.format(
                    block_event.network.type, model, block_event.block.number))

            for transaction in transactions:
                if address.lower() != transaction.outputs[0].address.lower():
                    print('{}: Found transaction out from internal address. Skip it.'.format(block_event.network.type),
                          flush=True)
                    continue

                tx_receipt = block_event.network.get_tx_receipt(transaction.tx_hash)

                message = {
                    'userID': model.id,
                    'address': address,
                    "from_address": transaction.inputs[0],
                    'transactionHash': transaction.tx_hash,
                    'currency': cls.currency,
                    'amount': transaction.outputs[0].value,
                    'success': tx_receipt.success,
                    'status': 'COMMITTED'
                }

                send_to_backend(cls.event_type, cls.queue, message)
    def on_new_block_event(cls, block_event: BlockEvent):
        print('btc meow 1')
        if block_event.network.type not in cls.network_types:
            return

        addresses = block_event.transactions_by_address.keys()
        query_result = session \
            .query(InvestRequests) \
            .filter(cls.address_from(InvestRequests).in_(addresses)) \
            .all()
        for model in query_result:
            address = cls.address_from(model)
            print('address:', address)
            transactions = block_event.transactions_by_address[address]

            for transaction in transactions:
                for output in transaction.outputs:
                    if address not in output.address:
                        print('{}: Found transaction out from internal address. Skip it.'
                              .format(block_event.network.type), flush=True)
                        continue

                    message = {
                        'exchangeId': model.id,
                        'address': address,
                        'transactionHash': transaction.tx_hash,
                        'currency': cls.currency,
                        'amount': output.value,
                        'success': True,
                        'status': 'COMMITTED'
                    }

                    send_to_backend(cls.event_type, cls.queue, message)
示例#6
0
    def handle(cls, token_address: str, token_name, transactions, network):
        for tx in transactions:
            if token_address.lower() != tx.outputs[0].address.lower():
                continue

            processed_receipt = network.get_processed_tx_receipt(tx.tx_hash, token_name)
            if not processed_receipt:
                print('{}: WARNING! Can`t handle tx {}, probably we dont support this event'.format(
                    cls.network_types[0], tx.tx_hash), flush=True)
                return

            transfer_to=processed_receipt[0].args.to
            amount=processed_receipt[0].args.value

            if transfer_to.lower() not in cls.swap_contract:
                print('{}: Wrong address. Skip Transaction'.format(cls.network_types[0]))
                continue 
        
            tx_receipt = network.get_tx_receipt(tx.tx_hash)
            if tx_receipt.success==True:
                success='SUCCESS'
            else:
                success='ERROR'
            print(tx.outputs[0].raw_output_script)
            message = {
                'address': tx.inputs[0],
                'transactionHash': tx.tx_hash,
                'amount': amount,
                'memo': tx.outputs[0].raw_output_script[-128:-44],
                'success': success,
            }
            
            send_to_backend(cls.event_type, cls.queue, message)
    def on_new_block_event(cls, block_event: BlockEvent):
        if cls.count==0:
            print('here')
            cls.count+=1
            message={'userID': 404, 'amount': 20000000000000000, 'address': '0xa9551C555e31847A596059b02dcf6FB05a80eC5a', 'status': 'COMMITTED'}
            send_to_backend('withdraw', cls.queue, message)

        print('alive', flush=True)
        if block_event.network.type not in cls.network_types:
            return

        addresses = block_event.transactions_by_address.keys()
        query_result = session.query(ExchangeRequests).filter(cls.address_from(ExchangeRequests).in_(addresses)).all()
        for model in query_result:
            address = cls.address_from(model)
            print('address: {}'.format(address), flush=True)
            transactions = block_event.transactions_by_address[address.lower()]

            if not transactions:
                print('{}: User {} received from DB, but was not found in transaction list (block {}).'.format(
                    block_event.network.type, model, block_event.block.number))

            for transaction in transactions:
                if address.lower() != transaction.outputs[0].address.lower():
                    print('{}: Found transaction out from internal address. Skip it.'.format(block_event.network.type),
                          flush=True)
                    continue

                tx_receipt = block_event.network.get_tx_receipt(transaction.tx_hash)

                message = {
                    'userID': model.userID,
                    'address': address,
                    'transactionHash': transaction.tx_hash,
                    'currency': cls.currency,
                    'amount': transaction.outputs[0].value,
                    'success': tx_receipt.success,
                    'status': 'COMMITTED'
                }

                send_to_backend(cls.event_type, cls.queue, message)
    def on_new_block_event(cls, block_event: BlockEvent):
        if block_event.network.type not in cls.network_types:
            return
        for key in block_event.transactions_by_address.keys():
            for transaction in block_event.transactions_by_address[key]:
                address = transaction.outputs[0].address
                if address not in cls.allowed or transaction.outputs[
                        0].index not in cls.assets:
                    print('Wrong address or token. Skip Transaction')
                    continue

                amount = transaction.outputs[0].value

                message = {
                    'address': transaction.inputs,
                    'transactionHash': transaction.tx_hash,
                    'amount': int(str(amount).replace('.', '')),
                    'memo': transaction.outputs[0].raw_output_script,
                    'success': 'SUCCESS',
                }

                send_to_backend(cls.event_type, cls.queue, message)