0

Is it possible to listen to each users contract events from the database at once? I've tried but it only works for one user.

Web3 python telebot

from web3 import Web3

import json,os,sys

import datetime

import requests

from db import *

import telebot

bot = telebot.TeleBot("Telegram bot api will be here")



 
bsc = "https://bsc-dataseed.binance.org/"

web3 = Web3(Web3.HTTPProvider(bsc))

class BuyBot():

    def __init__(self,token,group):
        self.token = token
        self.group = group
        
    
    def main(self):
        print(f"EVENTS RUNNING FOR {self.token}")
        event_filter = web3.eth.filter({"address": web3.toChecksumAddress((self.token).upper()), "block_identifier": 'pending', })
        
        
        self.log_loop(event_filter, 2)
               
        
           
    def log_loop(self,event_filter, poll_interval):
        try:
            while True:
                for event in event_filter.get_new_entries():
                    self.handle_event(event)
                    break
                time.sleep(poll_interval)
        except Exception as p:
            print(p)
            self.main()
            
    def handle_event(self,event):
        txn = json.loads(Web3.toJSON(event))
        hash = txn['transactionHash']
    
        if len(hash) > 0:
            transaction_recipt = web3.eth.wait_for_transaction_receipt(hash)
            trs = web3.toHex(transaction_recipt['transactionHash'])
            usl_hash = f"https://bscscan.com/tx/{trs}"
            bot.send_message(self.group,url_hash)


def main():

    while True:
        print("am here")
        con = bot_db()
        mc= con.cursor()
        mc.execute('SELECT * FROM Contracts')
        rows = mc.fetchall()
        for all in rows:
            group = all[1]
            ca = all[0]
            
            check_ = BuyBot(ca,group)
            check_.main()

bot.polling(none_stop=True)

if __name__ == "__main__":

    try:
        print("Started")
        main()
    except Exception:
        print("rebooted")
        main()
CallMeStag
  • 5,467
  • 1
  • 7
  • 22
Bigo Calls
  • 25
  • 3

1 Answers1

-1

Maybe use concurrent.futures module with ThreadPoolExecutor

Devyl
  • 565
  • 3
  • 8