Ejemplo n.º 1
0
    def bot_message(self):
        eth_contracts = self.contract.ethcontract_set.all()
        hashes = [eth_contract.tx_hash for eth_contract in eth_contracts]
        link = NETWORKS.get(self.contract.network.name, '').get('link_tx', '')
        links = [f'{link.format(tx=hsh)}' for hsh in hashes]

        contract_type = self.contract.get_all_details_model()[
            self.contract.contract_type]['name']
        user_id = self.contract.user.id
        contract_options = []
        for option in ['white_label', 'authio', 'verification']:
            try:
                if getattr(self, option):
                    contract_options.append(option)
            except AttributeError:
                pass

        contract_options = contract_options if any(
            contract_options) else 'NO OPTIONS'

        message = '<a>deployed contract\nid <b>{contract_id}</b>\n<b>{network}</b>\n<b>{contract_type}</b>\n<b>{contract_options}</b>\nuser id <b>{user_id}</b></a>'.format(
            contract_id=self.contract.id,
            network=self.contract.network.name,
            contract_type=contract_type,
            contract_options=contract_options,
            user_id=user_id)

        hyperlink = '<a href="{url}">\n{text}</a>'
        for idx, link in enumerate(links):
            if link:
                message += f'{hyperlink.format(url=link, text=f"hash{idx + 1}")}'
            else:
                message += f'\n{hashes[idx]}'

        return message
Ejemplo n.º 2
0
import time
import os
import datetime


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lastwill.settings')
import django

django.setup()

from lastwill.settings import TRX_FREEZE_TIMEOUT, TRX_FREEZE_AMOUNT, NETWORKS
from lastwill.contracts.submodels.tron import instantiate_tronapi


if __name__ == '__main__':
    while True:
        nets = [net for net in NETWORKS.keys() if 'TRON' in net]
        print('nets', nets, '\n', flush=True)
        time.sleep(TRX_FREEZE_TIMEOUT)
        for net in nets:
            tron = instantiate_tronapi(NETWORKS[net]['private_key'], net)
            unfreeze_tx = tron.trx.unfreeze_balance('ENERGY')
            print(net, 'unfreeze_tx at', datetime.datetime.now(), '\n', unfreeze_tx, '\n', flush=True)
            time.sleep(10)
            freeze_tx = tron.trx.freeze_balance(TRX_FREEZE_AMOUNT, 3, 'ENERGY')
            print(net, 'freeze_tx at', datetime.datetime.now(), '\n', freeze_tx, '\n', flush=True)
Ejemplo n.º 3
0
            'update_user',
            {'balance': str(instance.balance)},
        )
    except Exception as e:
        print('in save profile callback:', e)


def save_contract(sender, instance, **kwargs):
    try:
        contract_data = ContractSerializer().to_representation(instance)
        ws_interface.send(
            instance.user.id,
            'update_contract',
            contract_data,
        )
    except Exception as e:
        print('in save contract callback:', e)


post_save.connect(save_contract, sender=Contract)
post_save.connect(save_profile, sender=Profile)

nets = NETWORKS.keys()

ws_interface = WSInterface()
ws_interface.start()

for net in nets:
    rec = Receiver(net)
    rec.start()
Ejemplo n.º 4
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)