Beispiel #1
0
def test_channel_attributes():
    nonce = coder.get_channel_nonce(SAMPLE_MESSAGE)
    assert nonce == SAMPLE_NONCE

    players = coder.get_channel_players(SAMPLE_MESSAGE)
    assert players[0] == SAMPLE_PLAYER_A
    assert players[1] == SAMPLE_PLAYER_B

    channel_type = coder.get_channel_type(SAMPLE_MESSAGE)
    assert channel_type == SAMPLE_TYPE

    state = coder.get_channel_state(SAMPLE_MESSAGE)
    assert state == 0
Beispiel #2
0
def message_opponent(message, bot_addr):
    state_type = coder.get_channel_state(message)
    queue = 'GAME_ENGINE'
    # Postfund and conclusion messages are sent to the wallet
    if state_type == 1 or state_type == 3:
        queue = 'WALLET'
    hex_message = str_to_hex(message)
    signature = str_to_hex(sign_message(hex_message, bot_addr))

    d_message = {'data': hex_message, 'signature': signature, 'queue': queue}

    players = coder.get_channel_players(message)
    opponents = list(filter(lambda player: player != bot_addr, players))
    opponent_address = opponents[0]
    ref = _get_addr_ref(opponent_address)
    ref.push(d_message)
Beispiel #3
0
def game_engine_message(message, bot_addr):
    d_response = {}

    last_message = wallet.get_last_message_for_channel(message, bot_addr)
    if last_message == message:
        warning = f'Duplicate message received {last_message}'
        current_app.logger.warning(warning)
        # Turning off duplicate message safeguard for now
        # return set_response_message(warning, d_response)
    wallet.set_last_message_for_channel(message, bot_addr)

    coder.assert_channel_num_players(message)
    players = coder.get_channel_players(message)
    if bot_addr not in players:
        warning = 'The message players do not include a bot'
        current_app.logger.warning(warning)
        return set_response_message(warning, d_response)

    new_state = transition_from_state(message)

    current_app.logger.info(f'Sending opponent: {new_state}')
    fb_message.message_opponent(new_state, bot_addr)
    return set_response_message(str_to_hex(new_state), d_response)
Beispiel #4
0
def track_ge_event(hex_message, action):
    opponent = get_channel_players(hex_message)[0]
    track_event(opponent, "game_engine", action)
Beispiel #5
0
def reverse_hash_fail(hex_message):
    players = get_channel_players(hex_message)
    move_hash = get_game_precommit(hex_message)
    message = f'Stumped by player {players[0]}. Cannot decrypt move hash {move_hash}'
    requests.post(SLACK_HOOK, json={'text': message})