Ejemplo n.º 1
0
    def msg_deployed(self, message):
        self.contract.state = 'ACTIVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        self.next_check = timezone.now() + datetime.timedelta(
            seconds=self.check_interval)
        self.save()
        self.tron_contract.address = message['address']
        self.tron_contract.save()
        if self.contract.user.email:
            network = self.contract.network.name
            network_name = MAIL_NETWORK[network]
            send_mail(
                tron_deploy_subject,
                tron_deploy_text.format(
                    contract_type_name=self.contract.get_all_details_model()[
                        self.contract.contract_type]['name'],
                    network_name=network_name), DEFAULT_FROM_EMAIL,
                [self.contract.user.email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        take_off_blocking(self.contract.network.name)
        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
Ejemplo n.º 2
0
    def initialized(self, message):
        print("eos crowdsale initialized msg", flush=True)
        eos_contract_token = EOSContract()
        token_address = NETWORKS[self.contract.network.name]['token_address']
        eos_contract_token.address = token_address
        eos_contract_token.contract = self.contract
        eos_contract_token.save()
        self.eos_contract_token = eos_contract_token
        self.save()
        self.contract.state = 'ACTIVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        if self.contract.user.email:
            network_name = MAIL_NETWORK[self.contract.network.name]
            send_mail(eos_ico_subject,
                      eos_ico_message.format(network_name=network_name),
                      DEFAULT_FROM_EMAIL, [self.contract.user.email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
        take_off_blocking(self.contract.network.name, self.contract.id)
Ejemplo n.º 3
0
    def msg_deployed(self, message, eth_contract_attr_name='eth_contract'):
        self.contract.state = 'ACTIVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        self.tron_contract.address = message['address']
        self.tron_contract.save()
        take_off_blocking(self.contract.network.name)
        if self.contract.user.email:
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        if self.verification:
            send_verification_mail(
                network=self.contract.network.name,
                addresses=(hex2tronwif(self.tron_contract.address), ),
                compiler=self.tron_contract.compiler_version,
                files={'airdrop.sol': self.tron_contract.source_code},
            )
            self.verification_date_payment = datetime.datetime.now().date()
            self.verification_status = 'IN_PROCESS'
            self.save()
        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
Ejemplo n.º 4
0
    def initialized(self, message):
        if self.contract.state != 'WAITING_FOR_DEPLOYMENT':
            return
        take_off_blocking(self.contract.network.name)
        if message['contractId'] != self.eth_contract_crowdsale.id:
            print('ignored', flush=True)
            return
        self.contract.state = 'ACTIVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        if self.eth_contract_token.original_contract.contract_type == 5:
            self.eth_contract_token.original_contract.state = 'UNDER_CROWDSALE'
            self.eth_contract_token.original_contract.save()
        network_link = NETWORKS[self.contract.network.name]['link_address']
        network_name = MAIL_NETWORK[self.contract.network.name]
        if self.contract.user.email:
            send_mail(
                ico_subject,
                ico_text.format(
                    link1=network_link.format(
                        address=self.eth_contract_token.address, ),
                    link2=network_link.format(
                        address=self.eth_contract_crowdsale.address),
                    network_name=network_name), DEFAULT_FROM_EMAIL,
                [self.contract.user.email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        if self.verification:
            send_verification_mail(
                network=self.contract.network.name,
                addresses=(
                    self.eth_contract_token.address,
                    self.eth_contract_crowdsale.address,
                ),
                compiler=self.eth_contract_token.compiler_version,
                files={
                    'token.sol': self.eth_contract_token.source_code,
                    'ico.sol': self.eth_contract_crowdsale.source_code,
                },
            )
            self.verification_date_payment = datetime.datetime.now().date()
            self.verification_status = 'IN_PROCESS'
            self.save()
        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
Ejemplo n.º 5
0
    def tokenCreated(self, message):
        self.contract.state = 'ACTIVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        if self.contract.user.email:
            network_name = MAIL_NETWORK[self.contract.network.name]
            send_mail(
                eos_contract_subject,
                eos_contract_message.format(token_name=self.token_short_name,
                                            network_name=network_name),
                DEFAULT_FROM_EMAIL, [self.contract.user.email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
        take_off_blocking(self.contract.network.name, self.contract.id)
Ejemplo n.º 6
0
    def msg_deployed(self, message):
        take_off_blocking(self.contract.network.name)
        network = self.contract.network.name
        network_name = MAIL_NETWORK[network]
        self.contract.state = 'ACTIVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        if self.contract.user.email:
            send_mail(
                eos_airdrop_subject,
                eos_airdrop_message.format(network_name=network_name,
                                           hash=self.eos_contract.tx_hash),
                DEFAULT_FROM_EMAIL, [self.contract.user.email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
        self.save()
Ejemplo n.º 7
0
    def msg_deployed(self, message):
        take_off_blocking(self.contract.network.name)
        self.eth_contract.address = message['address']
        self.eth_contract.save()
        self.contract.state = 'WAITING_FOR_APPROVE'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        email = self.email if self.email else self.contract.user.email
        print('email', email, flush=True)
        try:
            send_mail(protector_deployed_subject, protector_deployed_text,
                      DEFAULT_FROM_EMAIL, [email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        except Exception as err:
            print('deployed mail failed', str(err), flush=True)
        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
Ejemplo n.º 8
0
    def initialized(self, message):
        if self.contract.state not in ('WAITING_FOR_DEPLOYMENT', 'ENDED'):
            return

        take_off_blocking(self.contract.network.name)

        self.contract.state = 'ACTIVE' if self.future_minting else 'ENDED'
        self.contract.deployed_at = datetime.datetime.now()
        self.contract.save()
        if self.contract.user.email:
            send_mail(
                common_subject,
                neo_token_text.format(addr=Crypto.ToAddress(
                    UInt160.ParseString(self.neo_contract.address)), ),
                DEFAULT_FROM_EMAIL, [self.contract.user.email])
            if not 'MAINNET' in self.contract.network.name:
                send_testnet_gift_emails.delay(self.contract.user.profile.id)
            else:
                send_promo_mainnet.delay(self.contract.user.email)

        msg = self.bot_message
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
Ejemplo n.º 9
0
 def wrapper(*args, **kwargs):
     contract = args[0].contract
     if contract.state == 'POSTPONED':
         print('message rejected because contract postponed', flush=True)
         send_mail(
             postponed_subject,
             postponed_message.format(
                 contract_id=contract.id
             ),
             DEFAULT_FROM_EMAIL,
             [EMAIL_FOR_POSTPONED_MESSAGE]
         )
         take_off_blocking(contract.network.name, contract_id=contract.id)
         raise AlreadyPostponed
     try:
         return f(*args, **kwargs)
     except Exception as e:
         contract.state = 'POSTPONED'
         contract.postponed_at = datetime.datetime.now()
         contract.save()
         postponed_type = contract.get_all_details_model()[contract.contract_type]['name']
         msg = f'<a><b>[POSTPONED CONTRACT]</b>\nid <b>{contract.id}</b>\n<b>{contract.network.name}</b>' \
               f'\n<b>{postponed_type}</b></a>'
         transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
         send_mail(
             postponed_subject,
             postponed_message.format(
                 contract_id=contract.id
             ),
             DEFAULT_FROM_EMAIL,
             [EMAIL_FOR_POSTPONED_MESSAGE]
         )
         print('contract postponed due to exception', flush=True)
         address = NETWORKS[contract.network.name]['address']
         take_off_blocking(
             contract.network.name, contract_id=contract.id, address=address
         )
         print('queue unlocked due to exception', flush=True)
         raise
Ejemplo n.º 10
0
    def msg_deployed(self, message):
        print('msg_deployed method of the ico contract')
        if self.contract.state != 'WAITING_FOR_DEPLOYMENT':
            take_off_blocking(self.contract.network.name)
            return
        if self.ride_contract.id == message['contractId']:
            self.contract.state = 'ACTIVE'
            self.contract.deployed_at = datetime.datetime.now()
            self.ride_contract.address = message['address']
            self.ride_contract.save()
            self.contract.save()
            take_off_blocking(self.contract.network.name)
            msg = self.bot_message
            transaction.on_commit(
                lambda: send_message_to_subs.delay(msg, True))
            if self.contract.user.email:
                network_link = NETWORKS[
                    self.contract.network.name]['link_address']
                network_asset = NETWORKS[
                    self.contract.network.name]['link_asset']
                network_name = MAIL_NETWORK[self.contract.network.name]
                send_mail(
                    waves_sto_subject,
                    waves_sto_text.format(
                        link1=network_asset.format(asset=self.asset_id, ),
                        link2=network_link.format(
                            address=self.ride_contract.address),
                        network_name=network_name), DEFAULT_FROM_EMAIL,
                    [self.contract.user.email])
                if not 'MAINNET' in self.contract.network.name:
                    send_testnet_gift_emails.delay(
                        self.contract.user.profile.id)
                else:
                    send_promo_mainnet.delay(self.contract.user.email)

            return
Ejemplo n.º 11
0
 def msg_deployed(self, message, eth_contract_attr_name='eth_contract'):
     network_link = NETWORKS[self.contract.network.name]['link_address']
     network = self.contract.network.name
     network_name = MAIL_NETWORK[network]
     take_off_blocking(self.contract.network.name)
     eth_contract = getattr(self, eth_contract_attr_name)
     eth_contract.address = message['address']
     eth_contract.save()
     self.contract.state = 'ACTIVE'
     self.contract.deployed_at = datetime.datetime.now()
     self.contract.save()
     msg = self.bot_message
     transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))
     if self.contract.user.email:
         if self.contract.contract_type == 11:
             send_mail(
                 eos_account_subject,
                 eos_account_message.format(
                     link=network_link.format(address=self.account_name),
                     network_name=network_name), DEFAULT_FROM_EMAIL,
                 [self.contract.user.email])
         elif self.contract.contract_type == 10:
             send_mail(
                 eos_contract_subject,
                 eos_contract_message.format(
                     token_name=self.token_short_name,
                     network_name=network_name), DEFAULT_FROM_EMAIL,
                 [self.contract.user.email])
         elif self.contract.contract_type == 20:
             pass
         else:
             network_id = self.contract.network.id
             types_info = AVAILABLE_CONTRACT_TYPES[network_id]
             for type_info in types_info:
                 if type_info['contract_type'] == self.contract.contract_type and \
                         type_info['contract_name'] == 'Token' and \
                         network_id in NETWORK_TYPES['mainnet']:
                     send_mail(
                         common_subject,
                         sale_message.format(
                             contract_type_name=self.contract.
                             get_all_details_model()[
                                 self.contract.contract_type]['name'],
                             link=network_link.format(
                                 address=eth_contract.address),
                             network_name=network_name,
                         ), DEFAULT_FROM_EMAIL, [self.contract.user.email])
                     break
             else:
                 send_mail(
                     common_subject,
                     common_text.format(
                         contract_type_name=self.contract.
                         get_all_details_model()[
                             self.contract.contract_type]['name'],
                         link=network_link.format(
                             address=eth_contract.address),
                         network_name=network_name,
                     ), DEFAULT_FROM_EMAIL, [self.contract.user.email])
         if not 'MAINNET' in self.contract.network.name:
             send_testnet_gift_emails.delay(self.contract.user.profile.id)
         else:
             send_promo_mainnet.delay(self.contract.user.email)
Ejemplo n.º 12
0
def create_payment(uid, tx, currency, amount, site_id, network=None):
    amount = float(amount)
    if amount == 0.0:
        return
    print('create payment')

    if tx and InternalPayment.objects.filter(
            tx_hash=tx).count():  # tx='' if payment received from frontend
        print(f'tx hash {tx} already processed')
        raise PaymentAlreadyRegistered

    if (SubSite.objects.get(id=site_id).site_name == MY_WISH_URL
            or SubSite.objects.get(id=site_id).site_name == TRON_URL):
        if currency in ['BWISH', 'BBNB', 'BSCWISH', 'WWISH']:
            amount = amount * 10**10
            if currency == 'BBNB':
                currency = 'BNB'
            else:
                amount *= 1.1

        value = amount if (currency in [
            'WISH', 'BWISH', 'BSCWISH', 'WWISH'
        ]) else amount * rate(currency, 'WISH').value
        if currency == 'BTC':
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['BTC']
        if currency in ['TRON', 'TRX', 'TRONISH']:
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['TRX']
        if currency in ['EOS', 'EOSISH']:
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['EOS']
        if currency == 'USDT':
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['USDT']
    elif SubSite.objects.get(id=site_id).site_name in [
            SWAPS_URL, RUBIC_EXC_URL, RUBIC_FIN_URL
    ]:
        value = amount if currency == 'USDT' else amount * float(
            rate(currency,
                 'USDT').value) / NET_DECIMALS[currency] * NET_DECIMALS['USDT']

    elif SubSite.objects.get(id=site_id).site_name == TOKEN_PROTECTOR_URL:
        value = amount if currency == 'USDT' else amount * float(
            rate(currency,
                 'USDT').value) / NET_DECIMALS[currency] * NET_DECIMALS['USDT']
    else:
        amount = calculate_decimals(currency, amount)
        value = amount if currency == 'EOSISH' else amount * rate(
            currency, 'EOSISH').value * NET_DECIMALS['EOSISH']
        amount = add_decimals(currency, amount)
    user = User.objects.get(id=uid)
    if amount < 0.0:
        if site_id == 4 or site_id == 5:
            try:
                negative_payment(user, -value, site_id, network)
            except:
                print('-5% payment', flush=True)
                value = value * 0.95
                negative_payment(user, -value, site_id, network)
        else:
            negative_payment(user, -value, site_id, network)
    else:
        positive_payment(user, value, site_id, currency, amount)

        link = NETWORKS.get(network, '').get('link_tx', '').format(tx=tx)
        text = tx if not link else 'hash'
        msg = '<a>[RECEIVED NEW PAYMENT]\n{amount} {curr}\n({wish_value} WISH)\nfrom user {email}, id {user_id}</a><a href="{url}">\n{text}</a>' \
            .format(amount=make_readable(amount, currency), wish_value=make_readable(value, 'WISH'),
                    curr=currency, email=user, user_id=uid, url=link, text=text)
        transaction.on_commit(lambda: send_message_to_subs.delay(msg, True))

    site = SubSite.objects.get(id=site_id)
    InternalPayment(user_id=uid,
                    delta=value,
                    tx_hash=tx,
                    original_currency=currency,
                    original_delta=str(amount),
                    site=site).save()
    print('PAYMENT: Created', flush=True)
    print(
        'PAYMENT: Received {amount} {curr} ({wish_value} WISH) from user {email}, id {user_id} with TXID: {txid} at site: {sitename}'
        .format(amount=amount,
                curr=currency,
                wish_value=value,
                email=user,
                user_id=uid,
                txid=tx,
                sitename=site_id),
        flush=True)