async def reduce_finish(self, action: redux.Action, changed_state: Dict[str, Any]): if action == "INCREASE_EQUITY": equity = self.get_state()["equity"] action = redux.Action("EQUITY_CHANGED", equity=equity) await self.send(action, redux.LocalMedium(self.store), UserService, self.node_id) if action == "NOT_ENOUGH_EQUITY": key = f"entry:user:{self.node_id}" action = redux.Action("NOT_ENOUGH_EQUITY") await self.send(action, redux.LocalMedium(self.store), UserService, self.node_id)
async def action_received(self, action: redux.Action): if action == "TRANSFER": from_user = action.arguments["from"] to_user = action.arguments["to"] change = action.arguments["change"] await self.send(redux.Action.no_op_command(), redux.LocalMedium(self.store), UserNode, from_user) result = await self.modify_database(from_user, to_user, change) medium = redux.LocalMedium(self.store) if result: await self.send(redux.Action("INCREASE_EQUITY", change=-change), medium, UserNode, from_user) await self.send(redux.Action("INCREASE_EQUITY", soft=True, change=change), medium, UserNode, to_user) else: await self.send(redux.Action("NOT_ENOUGH_EQUITY"), medium, UserNode, from_user)
async def action_received(self, action: redux.Action): if action == "__NO_OP": return print("PublicService received", self.key, action) if isinstance(action.medium, redux.EntryMedium): if action == "SUBSCRIBE": user = action.arguments["user"] await self.send(action, redux.LocalMedium(self.store), UserService, user) if action == "TRANSFER": user = action.arguments["user"] await self.send(action, redux.LocalMedium(self.store), UserService, user) if isinstance(action.medium, redux.LocalMedium): await self.response(action, self.entry_medium)
async def action_received(self, action: redux.Action): target = await redux.RemoteMedium.connect(self.store, "ws://127.0.0.1:9906") state = await self.get_remote_state(target.unwrap(), "user") assert state.unwrap() == dict(name="provider", age=1) state = await self.get_remote_state(redux.LocalMedium(self.store), "user") assert state.unwrap() == dict(name="provider", age=1) state = await self.get_remote_state(target.unwrap(), "user", ["name"]) assert state.unwrap() == dict(name="provider") state = await self.get_remote_state(redux.LocalMedium(self.store), "user", ["age"]) assert state.unwrap() == dict(age=1) await self.send(target.unwrap(), "user", redux.Action("CALL_ME"))
async def action_received(self, action: redux.Action): if action == "SUBSCRIBE": login_list = self.login_list login_list.append(action) self.login_list = login_list user = action.arguments["user"] if action == "TRANSFER": await self.send(action, redux.LocalMedium(self.store), TransactionNode) if action in ["EQUITY_CHANGED", "NOT_ENOUGH_EQUITY"]: for session in self.login_list: await self.response(action, session.medium, session.source_key)
async def action_received(self, action: redux.Action): if isinstance(action.medium, redux.EntryMedium): if action == "LOGIN": user_name = action.arguments["userName"] password = action.arguments["password"] action = redux.Action("VERIFY_LOGIN", user_name=user_name, password=password) await self.send(action, redux.LocalMedium(self.store), LoginVerify, user_name) if isinstance(action.medium, redux.LocalMedium): if action == "ACCESS_LOGIN": print(f"ACCESS_LOGIN {action.arguments['user_name']}") if action == "DENIED_LOGIN": print(f"DENIED_LOGIN {action.arguments['user_name']}")