示例#1
0
def findAllFolders(folder):
    folders = []
    folders.append(folder)
    spinner = Spinner()
    if os.path.isdir(folder):
        for root, dirs, _ in os.walk(folder):
            for folder in dirs:
                fullpath = os.path.join(root, folder)
                folders.append(fullpath)
                spinner.message = "Analysing folders: "
                spinner.next()
    click.echo("\nFound {} folders.".format(len(folders)))
    return folders
示例#2
0
 def wait_desired_conditions(self):
     spinner = Spinner()
     rcv_current = None
     while True:
         prev_rcv = rcv_current
         rcv_current = self.router.functions.getAmountsOut(
             amountIn=self.spend_amount, path=self.path
         ).call()[1]
         if rcv_current != prev_rcv:
             print("")
             spinner.message=f"Expected: {self.rcv_amount} {self.rcv_token_symbol}, Current: {rcv_current} "
         spinner.next()
         if rcv_current >= self.rcv_amount:
             print("\nConditions are met!")
             return True
         time.sleep(0.5)
示例#3
0
def getFilesFromFolder(folder, types=[".mp3"]):
    fileList = []
    iterations = 0
    spinner = Spinner()
    if os.path.isdir(folder):
        for root, _, files in os.walk(folder):
            if len(files) == 0:
                break
            for file in files:
                iterations += 1
                spinner.message = "Analysing folder: '{}' - Files: {} - Duplicates: {} - ".format(
                    folder, iterations, DUPLICATES.total)
                spinner.next()
                path = os.path.join(root, file)
                size = os.path.getsize(path)
                extension = os.path.splitext(file)[-1]
                filter_duplicates(extension, types, path, fileList, size)
            spinner.clearln()
    return fileList
示例#4
0
with open("erc20.abi", "r") as abi_file:
    erc20_abi = json.load(abi_file)

token0 = w3.eth.contract(abi=erc20_abi, address=t0)
token1 = w3.eth.contract(abi=erc20_abi, address=t1)
token0_symbol = token0.functions.symbol().call()
token1_symbol = token1.functions.symbol().call()
print(f"Looking for pair: {t0}({token0_symbol}), {t1}({token1_symbol})")

factory = w3.eth.contract(abi=uniswap_factory_abi, address=UNI_FACTORY)
num = factory.functions.allPairsLength().call()
sp = Spinner(f"Scanning 0 of {num} pairs ")
search_pair = [t0, t1]
for i in range(num):
    sp.message = f"Scanning {i} of {num} pairs "
    sp.next()
    pair_addr = Web3.toChecksumAddress(factory.functions.allPairs(i).call())
    pair = w3.eth.contract(abi=uniswap_pair_abi, address=pair_addr)
    token0_addr = Web3.toChecksumAddress(pair.functions.token0().call())
    token1_addr = Web3.toChecksumAddress(pair.functions.token1().call())
    token0 = w3.eth.contract(abi=erc20_abi, address=token0_addr)
    token1 = w3.eth.contract(abi=erc20_abi, address=token1_addr)
    if token0_addr in search_pair and token1_addr in search_pair:
        try:
            token0_symbol = token0.functions.symbol().call()
            token1_symbol = token1.functions.symbol().call()
            token0_decimals = int(token0.functions.decimals().call())
            token1_decimals = int(token1.functions.decimals().call())
            print(
                f"\nPair found:{pair_addr} ({token0_symbol} {token1_symbol})")
示例#5
0
print("Connect to Web3 Ethereum provider... ", end="")
w3 = Web3(Web3.HTTPProvider(WEB3_ENDPOINT))
print(f"{GREEN}DONE{ENDC}")

print(f"Target block: {GREEN}{BLOCK_HEIGHT}{ENDC} ")
print(f"Confirmations: {GREEN}{CONFIRMATIONS}{ENDC} ")
print("")

block_hash = None
spinner = Spinner()
while True:
    current_block = w3.eth.block_number
    got_confirmations = current_block - BLOCK_HEIGHT
    if current_block < BLOCK_HEIGHT:
        spinner.message = f"Waiting for target block. {current_block} of {BLOCK_HEIGHT} "
        spinner.update()
        for i in range(10):
            time.sleep(0.1)
            spinner.next()
        continue
    if block_hash is None:
        spinner.clearln()
        print(f'Target block {current_block} mined!')
        block_hash = w3.eth.get_block(BLOCK_HEIGHT).hash
        print(
            f"Hash of the block {BLOCK_HEIGHT} is {GREEN}{block_hash.hex()}{ENDC}"
        )
        print(f"See it on Etherscan https://etherscan.io/block/{BLOCK_HEIGHT}")
    if got_confirmations <= CONFIRMATIONS:
        spinner.message = f'Waiting confirmations {got_confirmations} of {CONFIRMATIONS} '