コード例 #1
0
    def on_deposit(self, address: CryptoAddress, opid, log_data, log_entry) -> CryptoAddressDeposit:
        """Handle Hosted Wallet Deposit event.

        Create incoming holding account holding the ETH assets until we receive enough confirmations.
        """

        op = CryptoAddressDeposit(address.network)

        # Get or create final account where we deposit the transaction
        asset = get_ether_asset(self.dbsession, network=address.network)
        crypto_account = address.get_or_create_account(asset)
        op.crypto_account = crypto_account

        op.external_address = eth_address_to_bin(log_data["from"])

        # Create holding account that keeps the value until we receive N amount of confirmations
        acc = Account(asset=asset)
        self.dbsession.add(acc)
        self.dbsession.flush()

        value = wei_to_eth(log_data["value"])
        acc.do_withdraw_or_deposit(value, "ETH deposit from {} in tx {}".format(log_data["from"], log_entry["transactionHash"]))

        op.holding_account = acc
        return op
コード例 #2
0
    def on_deposit(self, address: CryptoAddress, opid, log_data,
                   log_entry) -> CryptoAddressDeposit:
        """Handle Hosted Wallet Deposit event.

        Create incoming holding account holding the ETH assets until we receive enough confirmations.
        """

        op = CryptoAddressDeposit(address.network)

        # Get or create final account where we deposit the transaction
        asset = get_ether_asset(self.dbsession, network=address.network)
        crypto_account = address.get_or_create_account(asset)
        op.crypto_account = crypto_account

        op.external_address = eth_address_to_bin(log_data["from"])

        # Create holding account that keeps the value until we receive N amount of confirmations
        acc = Account(asset=asset)
        self.dbsession.add(acc)
        self.dbsession.flush()

        value = wei_to_eth(log_data["value"])
        acc.do_withdraw_or_deposit(
            value, "ETH deposit from {} in tx {}".format(
                log_data["from"], log_entry["transactionHash"]))

        op.holding_account = acc
        return op
コード例 #3
0
    def handle_event(self, event_name: str, contract_address: str,
                     log_data: dict, log_entry: dict):
        """Map incoming EVM log to database entry."""

        opid = self.get_unique_transaction_id(log_entry)

        existing_op = self.get_existing_op(opid, CryptoOperationType.deposit)
        if existing_op:
            # Already in the database, all we need to do is to call blocknumber updater now
            return False

        network = self.dbsession.query(AssetNetwork).get(self.network_id)
        asset = self.dbsession.query(Asset).filter_by(
            network=network,
            external_id=eth_address_to_bin(contract_address)).one()

        if event_name == "Transfer":

            to_address = eth_address_to_bin(log_data["to"])
            from_address = eth_address_to_bin(log_data["from"])
            value = Decimal(log_data["value"])

            self.logger.debug("Incoming transfer event %s %s %s", from_address,
                              to_address, value)

            # Get destination address entry
            address = self.dbsession.query(CryptoAddress).filter_by(
                address=to_address).one_or_none()
            if not address:
                # Address not in our system
                return False

            # Create operation
            op = CryptoAddressDeposit(network=network)
            op.opid = opid
            op.txid = txid_to_bin(log_entry["transactionHash"])
            op.external_address = from_address
            op.block = int(log_entry["blockNumber"], 16)
            op.required_confirmation_count = self.confirmation_count
            op.crypto_account = address.get_or_create_account(asset)

            # Create holding account that keeps the value until we receive N amount of confirmations
            acc = Account(asset=asset)
            self.dbsession.add(acc)
            self.dbsession.flush()

            acc.do_withdraw_or_deposit(
                value, "Token {} deposit from {} in tx {}".format(
                    asset.symbol, log_data["from"],
                    log_entry["transactionHash"]))
            op.holding_account = acc
            self.dbsession.add(op)

            self.notify_deposit(op)

            return True
        else:
            # Unmonitored event
            return False
コード例 #4
0
    def handle_event(self, event_name: str, contract_address: str, log_data: dict, log_entry: dict):
        """Map incoming EVM log to database entry."""

        with self._get_tm():

            opid = self.get_unique_transaction_id(log_entry)

            existing_op = self.get_existing_op(opid, CryptoOperationType.deposit)
            if existing_op:
                # Already in the database, all we need to do is to call blocknumber updater now
                return False

            network = self.dbsession.query(AssetNetwork).get(self.network_id)
            asset = self.dbsession.query(Asset).filter_by(network=network, external_id=eth_address_to_bin(contract_address)).one()

            if event_name == "Transfer":

                to_address = eth_address_to_bin(log_data["to"])
                from_address = eth_address_to_bin(log_data["from"])
                value = Decimal(log_data["value"])

                # Get destination address entry
                address = self.dbsession.query(CryptoAddress).filter_by(address=to_address).one_or_none()
                if not address:
                    # Address not in our system
                    return False

                # Create operation
                op = CryptoAddressDeposit(network=network)
                op.opid = opid
                op.txid = txid_to_bin(log_entry["transactionHash"])
                op.external_address = from_address
                op.block = int(log_entry["blockNumber"], 16)
                op.required_confirmation_count = self.confirmation_count
                op.crypto_account = address.get_or_create_account(asset)

                # Create holding account that keeps the value until we receive N amount of confirmations
                acc = Account(asset=asset)
                self.dbsession.add(acc)
                self.dbsession.flush()

                acc.do_withdraw_or_deposit(value, "Token {} deposit from {} in tx {}".format(asset.symbol, log_data["from"], log_entry["transactionHash"]))
                op.holding_account = acc
                self.dbsession.add(op)

                self.notify_deposit(op)

                return True
            else:
                # Unmonitored event
                return False