def transition_from_state(hex_message): channel_state = coder.get_channel_state(hex_message) message_transformations = CHANNEL_STATES[channel_state](hex_message) response_message = hex_message message_transformations += [coder.increment_state_turn_num] for transformation in message_transformations: response_message = transformation(response_message) return response_message
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
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)