async def _state_changed(self, *args): change = args[0] if self.websocket is None: return payloads: List[Dict] = await self.rpc_api._state_changed(*args) if change == "add_connection" or change == "close_connection": data = await self.get_connections({}) if data is not None: payload = create_payload_dict( "get_connections", data, self.service_name, "wallet_ui", ) payloads.append(payload) for payload in payloads: if "success" not in payload["data"]: payload["data"]["success"] = True try: await self.websocket.send_str(dict_to_json_str(payload)) except Exception: tb = traceback.format_exc() self.log.warning(f"Sending data failed. Exception {tb}.")
async def _state_changed(self, change: str) -> List[WsRpcMessage]: if change == "plots": data = await self.get_plots({}) payload = create_payload_dict("get_plots", data, self.service_name, "wallet_ui") return [payload] return []
async def _state_changed(self, change: str) -> List[WsRpcMessage]: payloads = [] if change == "new_peak" or change == "sync_mode": data = await self.get_blockchain_state({}) assert data is not None payloads.append( create_payload_dict( "get_blockchain_state", data, self.service_name, "wallet_ui", )) return payloads return []
async def _state_changed(self, change: str, change_data: Dict) -> List[WsRpcMessage]: if change == "new_signage_point": sp_hash = change_data["sp_hash"] data = await self.get_signage_point({"sp_hash": sp_hash.hex()}) return [ create_payload_dict( "new_signage_point", data, self.service_name, "wallet_ui", ) ] elif change == "new_farming_info": return [ create_payload_dict( "new_farming_info", change_data, self.service_name, "wallet_ui", ) ] return []
async def _state_changed(self, *args) -> List[WsRpcMessage]: """ Called by the WalletNode or WalletStateManager when something has changed in the wallet. This gives us an opportunity to send notifications to all connected clients via WebSocket. """ if len(args) < 2: return [] data = { "state": args[0], } if args[1] is not None: data["wallet_id"] = args[1] if args[2] is not None: data["additional_data"] = args[2] return [ create_payload_dict("state_changed", data, "chia_wallet", "wallet_ui") ]
def format_request(self, command: str, data: Dict[str, Any]) -> WsRpcMessage: request = create_payload_dict(command, data, "client", "daemon") return request