def btc_notification(address, symbol, type_id):
    print("ashgajhghgggggggggggggggggggggggggggggggggggggggggggggggggggggggg")
    ret = BTC_balance.replace("{{address}}", '' + address + '')
    ret1 = ret.replace("{{symbol}}", '' + symbol + '')
    print(ret1)
    response_user_token = requests.get(url=ret1)
    transaction = response_user_token.json()
    total_current_tx = transaction['transaction_count']
    print('25')
    mycursor.execute(
        'SELECT total_tx_calculated FROM sws_address WHERE address="' +
        str(address) + '"')
    current_tx = mycursor.fetchone()
    tx_count = current_tx[0]
    print('29')
    print("tx_count")
    print(tx_count)
    print("total_current_tx")
    print(total_current_tx)
    if tx_count is None or total_current_tx > tx_count:
        mycursor.execute('UPDATE sws_address SET total_tx_calculated ="' +
                         str(total_current_tx) + '"  WHERE address = "' +
                         str(address) + '"')
        mycursor.execute(
            'SELECT u.email FROM db_safename.sws_address as a left join db_safename.sws_user as u on a.cms_login_name = u.username where a.address="'
            + str(address) + '"')
        email = mycursor.fetchone()
        email_id = email[0]
        print('35')
        if email_id is not None:
            message = Mail(
                from_email=Sendgrid_default_mail,
                to_emails=email_id,
                subject=
                'SafeName - New Transaction Notification In Your Account',
                html_content=
                '<h3> You got a new transaction on your BTC address</h3>')
            sg = SendGridAPIClient(SendGridAPIClient_key)
            response = sg.send(message)
            print(response.status_code, response.body, response.headers)
        else:
            print("email is none")
    else:
        print("no new transaction")
    '''
    transactions = transaction['txs']
    
    array=[]
    total_current_tx=len(transactions)s
    '''
    '''
def profile_risk_score():
    print("asdasndas,na")
    mycursor.execute('SELECT username FROM sws_user')
    sws_users = mycursor.fetchall()
    for user in sws_users:
        user_name=user[0]
        mycursor.execute('SELECT address_risk_score FROM sws_address WHERE cms_login_name="'+str(user_name)+'"')
        risk_scores = mycursor.fetchall()
        list_of_scores=[]
        for risk_score in risk_scores:
            score = risk_score[0]
            list_of_scores.append(score)
        if list_of_scores:
            avrage = np.mean(list_of_scores)
            mycursor.execute('SELECT profile_risk_score_by_kyc_options FROM sws_user WHERE username="******"')
            risk_scores = mycursor.fetchone()
            risk_score_kyc = risk_scores[0]
            final_profile_riskscore=risk_score_kyc+avrage
            mycursor.execute('UPDATE sws_user SET profile_risk_score="'+str(final_profile_riskscore)+'" WHERE username = "******"')
Пример #3
0
def auto_fetch():
    print("runing")
    response_user_token = requests.get(url=ETH_SCAM_URL)
    mycursor.execute("""CREATE TABLE IF NOT EXISTS `sws_heist_address` ( id INT,coin varchar(100),tag_name varchar(100),status varchar(100),address varchar(100),source varchar(1000),subcategory varchar(100),description varchar(1500),also_known_as varchar(1000))""")
    response = response_user_token.json()
    result = response['result']
    if result:
        for record in result:
            if "addresses" in record:
                coin = record['coin']
                category = record['category']
                status =  record['status']
                url = record['url']
                if "subcategory" in record:         
                    subcate = record['subcategory']
                else:
                    subcate = ""
                subcategory = subcate
                if "description" in record:         
                    description = record['description']
                else:
                    description = ""
                addr = record['addresses']
                for add in addr:
                    addresses = add
                    mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(addresses)+'"')
                    check = mycursor.fetchall()
                    if not check:
                        print("added")
                        mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''')
                        maxid = mycursor.fetchone()
                        check=maxid[0]
                        if check is None:
                            ids = 1
                        else:
                            ids=(maxid[0]+1)
                        print(ids)
                        conversion =description.replace('"','')
                        mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(addresses)+'","https://etherscamdb.info/api/scams","'+str(subcategory)+'","'+str(conversion)+'","'+str(url)+'")')
                        mydb.commit()
                    else:
                        print("already_exist")
Пример #4
0
def eth_notification(address, symbol, type_id):
    doc = ETH_transactions.replace("{{address}}", '' + address + '')
    response_user = requests.get(url=doc)
    res = response_user.json()
    transactions = res['result']
    if transactions:
        total_current_tx = len(transactions)
        transaction = transactions[-1]
        timestamp = transaction['timeStamp']
        first_date = int(timestamp)
        dt_object = datetime.fromtimestamp(first_date)
        fro = transaction['from']
        too = transaction['to']
        send_amount = (int(transaction['value']) / 1000000000000000000)
        tx_id = transaction['hash']
        print("87")
        mycursor.execute(
            'SELECT total_tx_calculated FROM sws_address WHERE address="' +
            str(address) + '"')
        current_tx = mycursor.fetchall()
        transactions_count = current_tx[0]
        tx_count = transactions_count[0]
        print("tx_count")
        print(tx_count)
        print("total_current_tx")
        print(total_current_tx)
        print("send_amount")
        print(send_amount)
        if tx_count is None or total_current_tx > tx_count:
            print("93")
            if send_amount != 0:
                print("105")
                mycursor.execute(
                    'UPDATE sws_address SET total_tx_calculated ="' +
                    str(total_current_tx) + '"  WHERE address = "' +
                    str(address) + '"')
                print(address)
                mycursor.execute(
                    'SELECT u.email FROM db_safename.sws_address as a left join db_safename.sws_user as u on a.cms_login_name = u.username where a.address="'
                    + str(address) + '"')
                email = mycursor.fetchone()
                email_id = email[0]
                print(email_id)

                if email_id is not None:
                    '''
                    print("sendinnnnnngggggggg")
                    mycursor.execute('SELECT address_safename FROM sws_address WHERE address="'+str(fro)+'"')
                    from_safename_tx = mycursor.fetchall()
                    if from_safename_tx:
                        frm_safenames=from_safename_tx[0]
                        frm = frm_safenames[0]
                        frm_safename=fro+'(safename:'+frm+')'
                    else:
                        frm_safename=fro
                    mycursor.execute('SELECT address_safename FROM sws_address WHERE address="'+str(too)+'"')
                    too_safenames_tx = mycursor.fetchall()
                    if too_safenames_tx:
                        too_safenames=too_safenames_tx[0]
                        to = too_safenames[0]
                        to_safename=too+'(safename:'+to+')'
                    else:
                        to_safename=too
                    '''
                    frm_safename = fro
                    to_safename = too
                    message = Mail(
                        from_email=Sendgrid_default_mail,
                        to_emails=email_id,
                        subject=
                        'SafeName - New Transaction Notification In Your Account',
                        html_content=
                        '<h3> You got a new transaction </h3><strong>Date:</strong> '
                        + str(dt_object) + ' <div><strong>From:</strong> ' +
                        str(frm_safename) + ' </div><strong>To:</strong> ' +
                        str(to_safename) +
                        ' </div><div><strong>Amount:</strong> ' +
                        str(send_amount) +
                        ' </div><div><strong>Tx_id:</strong> ' + str(tx_id) +
                        ' </div><div><strong>Coin Type:</strong> '
                        'ETH'
                        '  </div>')
                    sg = SendGridAPIClient(SendGridAPIClient_key)
                    response = sg.send(message)
                    print(response.status_code, response.body,
                          response.headers)
                else:
                    print("email is not none")
            else:
                print("amount is 0")
        else:
            print("no new transaction")
    else:
        print("no transcations")
Пример #5
0
def invoice_notification():
    print("asdasndas,na")
    dab = mongo.db.sws_pending_txs_from_app.find({"type": "invoice"})
    dab = [serialize_doc(doc) for doc in dab]
    for data in dab:
        frm = data['from']
        to = data['to']
        symbol = data['symbol']
        amount = data['amt']
        notes = data['from_notes']
        to_username = data['to_username']
        print("from")
        print(frm)
        print("to")
        print(to)
        print(amount)
        dabb = mongo.db.sws_history.find(
            {
                "transactions": {
                    '$elemMatch': {
                        "from": {
                            '$elemMatch': {
                                "from": to,
                                "send_amount": amount
                            }
                        },
                        "to": {
                            '$elemMatch': {
                                "to": frm
                            }
                        }
                    }
                }
            }, {"transactions.$": 1})
        dabb = [serialize_doc(doc) for doc in dabb]
        print(dabb)
        if dabb:
            for data in dabb:
                trans = data['transactions']
                for tx_id in trans:
                    transaction_id = tx_id['Tx_id']

            docs = mongo.db.sws_pending_txs_from_app.remove({
                "from": frm,
                "to": to,
                "amt": amount,
                "type": "invoice"
            })

            report = mongo.db.sws_notes.insert_one({
                "tx_id":
                transaction_id,
                "notes":
                notes,
                "from":
                frm,
                "to":
                to,
                "type":
                "invoice",
                "username":
                to_username,
                "update_at":
                datetime.datetime.now(),
                "created_at":
                datetime.datetime.now()
            }).inserted_id
        else:
            mycursor.execute(
                'SELECT u.email FROM db_safename.sws_address as a left join db_safename.sws_user as u on a.cms_login_name = u.username where a.address="'
                + str(to) + '"')
            email = mycursor.fetchone()
            print(email)
            if email is not None:
                email_id = email[0]
                print(email_id)
                message = Mail(
                    from_email=Sendgrid_default_mail,
                    to_emails='*****@*****.**',
                    subject='SafeName - Invoice Notification In Your Account',
                    html_content=
                    '<h3> Your invoice is not clear please accept the request</h3>'
                )
                sg = SendGridAPIClient(SendGridAPIClient_key)
                response = sg.send(message)
                print(response.status_code, response.body, response.headers)
Пример #6
0
def heist_associated_fetch():
    print("runningggggg")
    mycursor.execute('select coin, address from `sws_heist_address`')
    result = mycursor.fetchall()
    for res in result:
        coin = res[0]
        address= res[1]
        if coin == 'ETH':
            print("eth")
            url1=ETH_TRANSACTION_URL
            doc=url1.replace("{{address}}",''+address+'')
            response_user = requests.get(url=doc)
            res = response_user.json()       
            if 'status' in res:
                status_code = res['status']
            else:
                status_code = "1"
            if status_code != "0":
                transactions=res['result']
                frm=[]
                to=[]
                for transaction in transactions:
                    fro =transaction['from']
                    too=transaction['to']
                    to.append({"to":too})
                    frm.append({"from":fro})
                for fund_trans in frm:
                    address=fund_trans['from']
                    mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(address)+'"')
                    check = mycursor.fetchall()
                    if not check:
                        print("added")
                        mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''')
                        maxid = mycursor.fetchone()
                        check=maxid[0]
                        if check is None:
                            ids = 1
                        else:
                            ids=(maxid[0]+1)
                        print(ids)
                        category = "heist_associated"
                        status = "Active"
                        url = ""
                        subcategory = ""
                        conversion = ""
                        mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(address)+'","'+str(url)+'","'+str(subcategory)+'","'+str(conversion)+'","related to heist_address")')
                        mydb.commit()
                    else:
                        print("already_exist")
                for fund_reci in to:
                    address=fund_reci['to']
                    mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(address)+'"')
                    check = mycursor.fetchall()
                    if not check:
                        print("to_added")
                        mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''')
                        maxid = mycursor.fetchone()
                        check=maxid[0]
                        if check is None:
                            ids = 1
                        else:
                            ids=(maxid[0]+1)
                        print(ids)
                        name = ""
                        category = "heist_associated"
                        status = "Active"
                        url = ""
                        subcategory = ""
                        conversion = ""
                        mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(address)+'","'+str(url)+'","'+str(subcategory)+'","'+str(conversion)+'","related to heist_address")')
                        mydb.commit()
                    else:
                        print("already_exist")
        if coin == 'BTC':
            print("btc")
            url1=BTC_TRANSACTION
            doc=url1.replace("{{address}}",''+address+'')
            response_user = requests.get(url=doc)
            res = response_user.json()       
            transactions = res['txs']
            frm=[]
            for transaction in transactions:
                frmm=transaction['inputs']
                for trans in frmm:
                    fro=trans['address']
                    frm.append({"from":fro})
            for fund_trans in frm:
                address=fund_trans['from']
                mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(address)+'"')
                check = mycursor.fetchall()
                if not check:
                    print("added")
                    mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''')
                    maxid = mycursor.fetchone()
                    check=maxid[0]
                    if check is None:
                        ids = 1
                    else:
                        ids=(maxid[0]+1)
                    print(ids)
                    category = "heist_associated"
                    status = "Active"
                    url = ""
                    subcategory = ""
                    conversion = ""
                    mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(address)+'","'+str(url)+'","'+str(subcategory)+'","'+str(conversion)+'","related to heist_address")')
                    mydb.commit()
                else:
                    print("already_exist")