# Path: deploy/utils.py
# def amount_format(web3, wei):
# def createWallet():
# def check_succesful_tx(web3, txid, timeout=180) -> dict:
#     def __init__(self,
#                  web3,
#                  abi,
#                  address,
#                  event_name,
#                  from_block=0,
#                  to_block='latest',
#                  filters=None,
#                  callback=None):
#     def get_logs(self):
#     def set_log_data(self, log):
#     def watch_logs(self, callback):
#         def log_callback(log):
#     def stop(self):
# def watch_logs(contract, event, callback, params={}):
# def print_logs(contract, event, name=''):
# def returnFundsToOwner(web3, owner, bidder):
# def sendFunds(web3, owner, bidder, max_bid):
# def assignFundsToBidders(web3, owner: str, bidders: list, distribution_limit: int=None):
# def set_connection_pool_size(web3, pool_connections, pool_size):
# def get_expected_tokens(amount, token_multiplier, final_price):
# class LogFilter:


import logging
import gevent
from deploy.utils import (
    check_succesful_tx,
    amount_format,
    passphrase,
    returnFundsToOwner,
    assignFundsToBidders
)
    from deploy.bidder import Bidder
    # come to daddy
    event_list = [gevent.spawn(returnFundsToOwner, web3, owner, bidder)
                  for bidder in bidder_addresses]
    gevent.joinall(event_list)

    log.info('Creating {0} bidder accounts: '.format(bidders - len(bidder_addresses)))
    for i in range(len(bidder_addresses), bidders):
        address = web3.personal.newAccount(passphrase)
        bidder_addresses.append(address)

    log.info('Simulating {0} bidders: {1}'.format(len(bidder_addresses), bidder_addresses))
    if bid_start_price:
        log.info('Bids will start at {0} WEI = {1} ETH  / TKN'.format(
            bid_start_price,
            web3.fromWei(bid_start_price, 'ether')))

    if fund_bidders:
        log.info('owner={owner} balance={balance}'
                 .format(owner=owner, balance=amount_format(web3, web3.eth.getBalance(owner))))
        assignFundsToBidders(web3, owner, bidder_addresses,
                             kwargs['distribution_limit'])
    return bidder_addresses


def successful_bid(web3, auction, bidder, amount):
    bid_successful = False

    while not bid_successful and amount > 0:
        try:
            txhash = auction.transact({'from': bidder, "value": amount}).bid()

# Path: deploy/utils.py
# def amount_format(web3, wei):
# def createWallet():
# def check_succesful_tx(web3, txid, timeout=180) -> dict:
#     def __init__(self,
#                  web3,
#                  abi,
#                  address,
#                  event_name,
#                  from_block=0,
#                  to_block='latest',
#                  filters=None,
#                  callback=None):
#     def get_logs(self):
#     def set_log_data(self, log):
#     def watch_logs(self, callback):
#         def log_callback(log):
#     def stop(self):
# def watch_logs(contract, event, callback, params={}):
# def print_logs(contract, event, name=''):
# def returnFundsToOwner(web3, owner, bidder):
# def sendFunds(web3, owner, bidder, max_bid):
# def assignFundsToBidders(web3, owner: str, bidders: list, distribution_limit: int=None):
# def set_connection_pool_size(web3, pool_connections, pool_size):
# def get_expected_tokens(amount, token_multiplier, final_price):
# class LogFilter:


# Path: deploy/simulation.py
import logging
import gevent
from deploy.utils import (
    check_succesful_tx,
    amount_format,
    passphrase,
    returnFundsToOwner,
    assignFundsToBidders
)
    from deploy.bidder import Bidder

    # come to daddy
    event_list = [gevent.spawn(returnFundsToOwner, web3, owner, bidder)
                  for bidder in bidder_addresses]
    gevent.joinall(event_list)

    log.info('Creating {0} bidder accounts: '.format(bidders - len(bidder_addresses)))
    for i in range(len(bidder_addresses), bidders):
        address = web3.personal.newAccount(passphrase)
        bidder_addresses.append(address)

    log.info('Simulating {0} bidders: {1}'.format(len(bidder_addresses), bidder_addresses))
    if bid_start_price:
        log.info('Bids will start at {0} WEI = {1} ETH  / TKN'.format(
            bid_start_price,
            web3.fromWei(bid_start_price, 'ether')))

    if fund_bidders:
        log.info('owner={owner} balance={balance}'
                 .format(owner=owner, balance=amount_format(web3, web3.eth.getBalance(owner))))
        assignFundsToBidders(web3, owner, bidder_addresses,
                             kwargs['distribution_limit'])
    return bidder_addresses


def successful_bid(web3, auction, bidder, amount):
    bid_successful = False

    while not bid_successful and amount > 0:
        try:
            txhash = auction.transact({'from': bidder, "value": amount}).bid()

            receipt = check_succesful_tx(web3, txhash)