示例#1
0
def alert_on_balance_drop(wallet, label, eth_threshold):

    print "Checking if the balance of %s (%s) is below %s" % (
        wallet,
        label,
        eth_threshold,
    )

    try:
        contact = fetch_wallet_balance(wallet)

        print(contact.eth_balance)

        if contact.eth_balance < eth_threshold:
            print "Low balance. Notifying."
            subject = "%s purse is running low. %s ETH remaining" % (
                label,
                contact.eth_balance,
            )
            body = "Please send more ETH to %s" % (wallet)
            print(body)
            print(subject)
            sgw.notify_founders(body, subject)

    except Exception as e:
        print e
def fetch_ogn_transactions():

    etherscan_url = 'http://api.etherscan.io/api?module=account&action=tokentx&contractaddress=%s&startblock=0&endblock=999999999&sort=desc&apikey=%s' % (
        ogn_contract, constants.ETHERSCAN_KEY)
    # print etherscan_url
    results = call_etherscan(etherscan_url)

    # loop through every transaction where Origin tokens were moved
    for result in results['result']:
        tx = db_common.get_or_create(db.session,
                                     db_models.TokenTransaction,
                                     tx_hash=result['hash'])
        tx.from_address = result['from'].lower()
        tx.to_address = result['to'].lower()
        # intentionally using ETH instead of WEI to be more human-friendly, despite being less precise
        tx.amount = float(result['value']) / math.pow(10, 18)
        tx.block_number = result['blockNumber']
        tx.timestamp = time_.fromtimestamp(result['timeStamp'])

        if tx.amount > 0:
            print "%g OGN moved in transaction %s" % (tx.amount,
                                                      result['hash'])

        # send an email alert every time OGN tokens are moved
        # only alert once & ignore marketplace transactions which show up as 0 OGN
        if (tx.amount > 0 and not tx.notification_sent):
            to_details = lookup_details(tx.to_address)
            from_details = lookup_details(tx.from_address)

            if from_details.name and to_details.name:
                subject = "%s moved %g OGN to %s" % (
                    from_details.name, tx.amount, to_details.name)
            elif from_details.name:
                subject = "%s moved %g OGN" % (from_details.name, tx.amount)
            elif to_details.name:
                subject = "%g OGN moved to %s" % (tx.amount, to_details.name)
            else:
                subject = "%g OGN moved" % (tx.amount)

            body = u"""
				{amount} OGN <a href='https://etherscan.io/tx/{tx_hash}'>moved</a>
				from <a href='https://etherscan.io/address/{from_address}'>{from_name}</a>
				to <a href='https://etherscan.io/address/{to_address}'>{to_name}</a>
			""".format(amount='{0:g}'.format(float(tx.amount)),
              tx_hash=tx.tx_hash,
              from_name=from_details.name
              if from_details.name else tx.from_address,
              from_address=tx.from_address,
              to_name=to_details.name if to_details.name else tx.to_address,
              to_address=tx.to_address)

            print subject

            sgw.notify_founders(body, subject)
            tx.notification_sent = True
            db.session.add(tx)
            db.session.commit()
def presale(full_name, email, accredited, entity_type, desired_allocation,
            desired_allocation_currency, citizenship, sending_addr, note,
            ip_addr):

    if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)",
                    email):
        return gettext('Please enter a valid email address')

    try:
        me = db_models.Presale()
        me.full_name = full_name
        me.email = email
        me.accredited = (accredited == '1')
        me.entity_type = entity_type
        me.desired_allocation = desired_allocation
        me.desired_allocation_currency = desired_allocation_currency
        me.citizenship = citizenship
        me.sending_addr = sending_addr
        me.note = note
        me.ip_addr = ip_addr
        db.session.add(me)
        db.session.commit()
    except Exception as e:
        print(e)
        return gettext('Ooops! Something went wrong.')

    if sending_addr:
        sending_addr = "<a href='https://etherscan.io/address/" + sending_addr + "'>" + sending_addr + "</a>" if sending_addr.startswith(
            '0x'
        ) else "<a href='https://blockchain.info/address/" + sending_addr + "'>" + sending_addr + "</a>"

    message = """Name: %s<br>
                 Email: %s<br>
                 Accredited: %s<br>
                 Entity: %s<br>
                 Desired allocation: %s %s<br>
                 Citizenship: %s<br>
                 Address: %s<br>
                 Note: %s<br>
                 IP: %s""" % (full_name, email,
                              ("Yes" if accredited == "1" else "No"),
                              entity_type, desired_allocation,
                              desired_allocation_currency, citizenship,
                              sending_addr, note, ip_addr)

    email_types.send_email_type('presale', DEFAULT_SENDER, email)

    sgw.notify_founders(message,
                        subject=full_name + " is interested in the presale")

    return gettext('Thanks! We\'ll be in touch soon.')
def fetch_meta_tx_balance():

    print "Fetching meta tx purse balance"

    try:

        url = "http://api.ethplorer.io/getAddressInfo/%s" % (meta_tx_purse)
        results = call_ethplorer(url)

        contact = db_common.get_or_create(db.session,
                                          db_models.EthContact,
                                          address=meta_tx_purse)
        contact.eth_balance = results['ETH']['balance']
        contact.transaction_count = results['countTxs']

        if 'tokens' in results:
            contact.tokens = results['tokens']
            # update the OGN & DAI balance
            for token in results['tokens']:
                if token['tokenInfo']['address'] == ogn_contract:
                    contact.ogn_balance = float(token['balance']) / math.pow(
                        10, 18)
                elif token['tokenInfo']['address'] == dai_contract:
                    contact.dai_balance = float(token['balance']) / math.pow(
                        10, 18)
            contact.token_count = len(results['tokens'])
        contact.last_updated = datetime.utcnow()

        print(contact.eth_balance)

        if contact.eth_balance < 1:
            print 'Low balance. Notifying.'
            subject = "Meta-transactions purse is running low. %s ETH remaining" % (
                contact.eth_balance)
            body = "Please send more ETH to %s" % (meta_tx_purse)
            print(body)
            print(subject)
            sgw.notify_founders(body, subject)

        db.session.add(contact)
        db.session.commit()
    except Exception as e:
        print e