def do_show(args): name = args.name url = _get_url(args) auth_user, auth_password = _get_auth_info(args) client = XoClient(base_url=url, keyfile=None) data = client.show(name, auth_user=auth_user, auth_password=auth_password) if data is not None: board_str, game_state, player1, player2 = { name: (board, state, player_1, player_2) for name, board, state, player_1, player_2 in [ game.split(',') for game in data.decode().split('|') ] }[name] board = list(board_str.replace("-", " ")) print("GAME: : {}".format(name)) print("PLAYER 1 : {}".format(player1[:6])) print("PLAYER 2 : {}".format(player2[:6])) print("STATE : {}".format(game_state)) print("") print(" {} | {} | {}".format(board[0], board[1], board[2])) print(" ---|---|---") print(" {} | {} | {}".format(board[3], board[4], board[5])) print(" ---|---|---") print(" {} | {} | {}".format(board[6], board[7], board[8])) print("") else: raise XoException("Game not found: {}".format(name))
def _get_merkle_root(self): result = self._send_request("state") try: return yaml.load(result)['merkleRoot'] except BaseException: raise XoException("Could not retrieve merkle root.")
def check_valid(self, store): """Determines if the transaction is valid. Args: store (dict): Transaction store mapping. """ if not super(XoTransaction, self).is_valid(store): raise XoException("invalid transaction") LOGGER.debug('checking %s', str(self)) if self._name is None or self._name == '': raise XoException('name not set') if self._action is None or self._action == '': raise XoException('action not set') if self._action == 'CREATE': if self._name in store: raise XoException('game already exists') elif self._action == 'TAKE': if self._space is None: raise XoException('TAKE requires space') if self._space < 1 or self._space > 9: raise XoException('invalid space') if self._name not in store: raise XoException('no such game') state = store[self._name]['State'] if state in ['P1-WIN', 'P2-WIN', 'TIE']: raise XoException('game complete') if state == 'P1-NEXT' and 'Player1' in store[self._name]: player1 = store[self._name]['Player1'] if player1 != self.OriginatorID: raise XoException('invalid player 1') if state == 'P2-NEXT' and 'Player2' in store[self._name]: player1 = store[self._name]['Player2'] if player1 != self.OriginatorID: raise XoException('invalid player 2') if store[self._name]['Board'][self._space - 1] != '-': raise XoException('space already taken') else: raise XoException('invalid action')