# 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
    if auction.call().stage() >= AUCTION_ENDED:
        log.warning("requested finalizeAuction(), but auction has ended already. Skipping this.")
        return

    ret = auction.call({'from': owner}).missingFundsToEndAuction()
    assert ret == 0
    log.info('missing funds %s' % auction.call({'from': owner}).missingFundsToEndAuction())

    # Owner calls finalizeAuction
    txhash = auction.transact({'from': owner}).finalizeAuction()
    receipt, success = check_succesful_tx(web3, txhash)
    assert receipt is not None
    assert success is True
    assert auction.call().stage() == 3  # AuctionEnded


def get_balance(token, bidder):
    token_balance = token.call().balanceOf(bidder)
    log.info('{bidder} {tokens}'.format(bidder=bidder, tokens=token_balance))
    return token_balance


def auction_simulation(web3, token, auction, owner, kwargs):
    # Start the auction
    bidder_addresses = fund_bidders(web3, owner, kwargs)
    if kwargs['start_auction'] is True:
        start_auction(auction, owner, web3)

    # deploy bidders
    # this will return when auction ends

# 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

    if auction.call().stage() >= AUCTION_ENDED:
        log.warning("requested finalizeAuction(), but auction has ended already. Skipping this.")
        return

    ret = auction.call({'from': owner}).missingFundsToEndAuction()
    assert ret == 0
    log.info('missing funds %s' % auction.call({'from': owner}).missingFundsToEndAuction())

    # Owner calls finalizeAuction
    txhash = auction.transact({'from': owner}).finalizeAuction()
    receipt, success = check_succesful_tx(web3, txhash)
    assert receipt is not None
    assert success is True
    assert auction.call().stage() == 3  # AuctionEnded


def get_balance(token, bidder):
    token_balance = token.call().balanceOf(bidder)
    log.info('{bidder} {tokens}'.format(bidder=bidder, tokens=token_balance))
    return token_balance


def auction_simulation(web3, token, auction, owner, kwargs):
    # Start the auction
    bidder_addresses = fund_bidders(web3, owner, kwargs)
    if kwargs['start_auction'] is True:
        start_auction(auction, owner, web3)

    # deploy bidders
    # this will return when auction ends

    if kwargs['deploy_bidders']: