コード例 #1
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)
コード例 #2
0
def _get_new_challenge(bot_addr):
    bot = get_bot(addr=bot_addr)
    return {
        'address': str_to_hex(bot[K_ADDRESS]),
        'name': bot[K_NAME],
        'isPublic': True,
        'stake': bot[K_STAKE],
        'createdAt': NOW
    }
コード例 #3
0
def _get_new_wallet(bot_addr):
    bot = get_bot(addr=bot_addr)
    return {
        'address': bot[K_ADDRESS],
        K_CHANNELS: None,
        'privateKey': bot[K_PK],
        K_UID: str_to_hex(bot[K_WALLET_UID]),
        K_NONCE: -1
    }
コード例 #4
0
def test_create_challenge(client, mocker):
    mocker.patch('firebase_admin.db.Reference', autospec=True)

    response = client.post('/create_challenge',
                           json={'address_key': get_bot0_addr()})
    assert response.status_code == 200
    firebase_admin.db.Reference().child('challenges').child(
        str_to_hex(get_bot0_addr())).set.assert_called_once_with(
            _get_new_challenge(0))
コード例 #5
0
def test_message_opponent_wallet(mocker):
    #pylint: disable=C0301
    message = '00000000000000000000000048BaCB9266a570d521063EF5dD96e61686DbE788000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000020000000000000000000000001599c26e9DcAB9A8f2410481c4329E8502C548a60000000000000000000000002d7d467f6622f1f5a1cFf4C3787b615ACca191660000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a7640000'
    signature = '0xd01e725ec776f6bb77b39b3d509eb3989f6eb5725dcc0b1a481b8b3b6725fa7b7b08dd1c080256e5cee725564e2f99cd87a9bef17fb98fe49d0d72d4d222f8791b'
    mocker.patch('firebase_admin.db.Reference.push')
    bot.fb_message.message_opponent(message, ADDRESSES[0])
    d_push = {'data': str_to_hex(
        message), 'signature': signature, 'queue': 'WALLET'}
    # pylint: disable=no-member
    firebase_admin.db.Reference.push.assert_called_once_with(
        d_push)
コード例 #6
0
def test_message_game_engine(mocker):
    #pylint: disable=C0301
    message = '000000000000000000000000c1912fee45d61c87cc5ea59dae31190fffff232d00000000000000000000000000000000000000000000000000000000000001c800000000000000000000000000000000000000000000000000000000000000020000000000000000000000005291fA3F70C8e3D21B58c831018E5a0D82Dc4ab900000000000000000000000055de2e479F3D0183D95f5A969bEEB3a147F60049000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000006a94d74f430000000000000000000000000000000000000000000000000000006a94d74f4300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000'
    signature = '0x708b8791d6054bda70f260a1f47a71ea47942f96bee5a2dfe232fa1d2c4ce3fc3806c6a87d8ecb889d019169b2710d3e833dabba8d6aa872fc49de420bb3a27d1c'
    mocker.patch('firebase_admin.db.Reference.push')
    bot.fb_message.message_opponent(message, ADDRESSES[0])
    d_push = {'data': str_to_hex(
        message), 'signature': signature, 'queue': 'GAME_ENGINE'}
    # pylint: disable=no-member
    firebase_admin.db.Reference.push.assert_called_once_with(
        d_push)
コード例 #7
0
def get_wallet(bot_addr):
    uid = get_bot(addr=bot_addr)[K_WALLET_UID]
    hex_uid = str_to_hex(uid)
    wallets_ref = get_wallets_ref()
    bot_wallet_query = wallets_ref.order_by_child(K_UID).equal_to(
        hex_uid).limit_to_first(1)
    wrapped_wallet = bot_wallet_query.get()
    if not wrapped_wallet:
        create_wallet(bot_addr)
        wrapped_wallet = bot_wallet_query.get()

    return (list(wrapped_wallet.values())[0], list(wrapped_wallet.keys())[0])
コード例 #8
0
def test_message_opponent_wallet(mocker):
    #pylint: disable=C0301
    message = '00000000000000000000000048BaCB9266a570d521063EF5dD96e61686DbE788000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000020000000000000000000000001599c26e9DcAB9A8f2410481c4329E8502C548a60000000000000000000000002d7d467f6622f1f5a1cFf4C3787b615ACca191660000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a7640000'
    signature = '0xb0ef6e5f02c931e81c40d93375292edf36f2a661b02da606709c11778aecd6512c23c74ca448575297a9b14d93bd1ae81f7731c80b765859b5e77aa789a943711b'
    mocker.patch('firebase_admin.db.Reference.push')
    bot.fb_message.message_opponent(message, ADDRESSES[0])
    d_push = {
        'data': str_to_hex(message),
        'signature': signature,
        'queue': 'WALLET'
    }
    # pylint: disable=no-member
    firebase_admin.db.Reference.push.assert_called_once_with(d_push)
コード例 #9
0
def test_message_game_engine(mocker):
    #pylint: disable=C0301
    message = '000000000000000000000000c1912fee45d61c87cc5ea59dae31190fffff232d00000000000000000000000000000000000000000000000000000000000001c800000000000000000000000000000000000000000000000000000000000000020000000000000000000000005291fA3F70C8e3D21B58c831018E5a0D82Dc4ab90000000000000000000000009552ceb4e6fa8c356c1a76a8bc8b1efa7b9fb205000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000006a94d74f430000000000000000000000000000000000000000000000000000006a94d74f4300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc10000'
    signature = '0x872695a7dd2591e95231bb91e7068baf927059e3d725cd8ddf547862498cbbff4703d2dca0878ceb3e86b06675b5c3f948ef83f4f0a9cd675c030fc36ea8f2861b'
    mocker.patch('firebase_admin.db.Reference.push')
    bot.fb_message.message_opponent(message, ADDRESSES[0])
    d_push = {
        'data': str_to_hex(message),
        'signature': signature,
        'queue': 'GAME_ENGINE'
    }
    # pylint: disable=no-member
    firebase_admin.db.Reference.push.assert_called_once_with(d_push)
コード例 #10
0
def _decode_move(hex_message):
    move_hash = get_game_precommit(hex_message)
    salt = "".join(['4' for i in range(0, 64)])
    hex_salt = str_to_hex(salt)

    for move in range(ROCK, NUM_MOVES):
        test_hash = Web3.soliditySha3(['uint256', 'bytes32'], [move, hex_salt])  #pylint: disable=E1120
        str_test_hash = hex_to_str(test_hash.hex())
        if str_test_hash == move_hash:
            return move

    reverse_hash_fail(hex_message)
    return -1
コード例 #11
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)
コード例 #12
0
def get_challenge_ref(bot_addr):
    return db.reference().child('challenges').child(str_to_hex(bot_addr))
コード例 #13
0
def get_bot0_addr():
    return str_to_hex(ADDRESSES[0])
コード例 #14
0
def _get_addr_ref(addr):
    return db.reference().child(K_MESSAGES).child(str_to_hex(addr))
コード例 #15
0
def set_last_message_for_channel(hex_message, bot_addr):
    message_ref = get_wallet_channel_ref(
        bot_addr, hex_message).child(K_RECEIVED).child(K_MESSAGE)
    message_ref.set(str_to_hex(hex_message))
コード例 #16
0
def _get_account(bot_addr):
    key = get_bot(addr=bot_addr)[K_PK]
    return Account.privateKeyToAccount(str_to_hex(key))  #pylint: disable=E1120