# 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
        bidder_objs[i].min_bid_price = 1
    bidder_gevents = [gevent.spawn(b.run) for b in bidder_objs]
    gevent.joinall(bidder_gevents)


def claim_tokens(auction, bidder, web3):
    unlocked = web3.personal.unlockAccount(bidder, passphrase)
    assert unlocked is True
    try:
        txhash = auction.transact({'from': bidder}).claimTokens()
    except ValueError as e:
        # method call failed: there are probably no tokens to claim
        if e.args[0]['code'] != -32015:
            raise e
        log.warn('claimTokens() failed for bidder ({0}). '
                 'Most likely this bidder owns no tokens or waiting perios hasn\'t expired. ({1})'
                 .format(bidder, str(e)))
        return
    receipt, success = check_succesful_tx(web3, txhash)
    if success is False:
        log.info('claimTokens(%s) failed for tx %s. This is either an error, '
                 'or funds have been claimed already' % (bidder, txhash))


def start_auction(auction, owner, web3):
    if auction.call().stage() >= AUCTION_STARTED:
        log.info('requested startAuction(), but auction has started already. skipping.')
        return

    log.info('Start auction owner balance %s' %

# 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

        bidder_objs[i].min_bid_price = 1
    bidder_gevents = [gevent.spawn(b.run) for b in bidder_objs]
    gevent.joinall(bidder_gevents)


def claim_tokens(auction, bidder, web3):
    unlocked = web3.personal.unlockAccount(bidder, passphrase)
    assert unlocked is True
    try:
        txhash = auction.transact({'from': bidder}).claimTokens()
    except ValueError as e:
        # method call failed: there are probably no tokens to claim
        if e.args[0]['code'] != -32015:
            raise e
        log.warn('claimTokens() failed for bidder ({0}). '
                 'Most likely this bidder owns no tokens or waiting perios hasn\'t expired. ({1})'
                 .format(bidder, str(e)))
        return
    receipt, success = check_succesful_tx(web3, txhash)
    if success is False:
        log.info('claimTokens(%s) failed for tx %s. This is either an error, '
                 'or funds have been claimed already' % (bidder, txhash))


def start_auction(auction, owner, web3):
    if auction.call().stage() >= AUCTION_STARTED:
        log.info('requested startAuction(), but auction has started already. skipping.')
        return

    log.info('Start auction owner balance %s' %

             amount_format(web3, web3.eth.getBalance(owner)))