def scan_transactions(net):
    games = Game.get_enabled_by_net(net)
    for game in games:
        transactions = Transaction.get_pending_queue(game)
        for tx in transactions:
            receipt = get_transaction_receipt(tx.hash, net)
            if receipt is not None:
                if receipt.status == 0:
                    tx.scan(receipt.blockNumber, receipt.gasUsed,
                            receipt.status)
                    continue
                if tx.action == '':
                    data = get_transaction(tx.hash, net)
                    function = GameAbiFunction.get_by_hash(
                        data['input'][0:10], game)
                    tx.action = function.name
                    tx.save()
                else:
                    function = GameAbiFunction.get_by_name(tx.action, game)
                for abi_event in function.events.all():
                    event_created = create_update_event(
                        tx, net, abi_event, receipt)
                    #if not event_created:
                    #    return
                tx.scan(receipt.blockNumber, receipt.gasUsed, receipt.status)
            else:
                return
def get_points(net):
    games = Game.get_enabled_by_net(net)
    for game in games:
        ranking = Ranking.list(game)
        for r in ranking[0]:
            points = get_ship_points(game, r.ship.ship_id)
            if points is not None:
                logging.info("get_points(): update points for ship %s in game %s" % (r.ship.ship_id, game))
                r.update(points)
def get_ships_owner(net):
    css  = CryptoSpaceShip.get_by_network(net)
    games = Game.get_enabled_by_net(net)
    for game in games:
        ranking = Ranking.list(game)
        for r in ranking[0]:
            ship = get_ship(css, int(r.ship.ship_id))
            if ship is not None:
                player = Player.get_by_address(ship['owner'].lower())
                logging.info("get_ships_owner(): update owner for ship %s: %s" % (r.ship.ship_id, player.user.username))
                r.ship.set_player(player)
def get_games_addresses(net):
    ret = {}
    games = Game.get_enabled_by_net(net)
    for game in games:
       ret[str(game.address).lower()] = game
    return ret
def post_discord_events(net):
    games = Game.get_enabled_by_net(net)
    for game in games:
        events = DiscordEvent.get_pending_queue(game)
        for event in events:
            post_to_discord(event)