def _get_channel_state_from_server(self, grpc_channel, channel_id): # Compile protobuf if needed codegen_dir = Path.home().joinpath(".snet", "mpe_client", "state_service") proto_dir = Path(__file__).absolute().parent.joinpath("resources", "proto") if (not codegen_dir.joinpath("state_service_pb2.py").is_file()): compile_proto(proto_dir, codegen_dir, proto_file = "state_service.proto") # make PaymentChannelStateService.GetChannelState call to the daemon stub_class, request_class, _ = import_protobuf_from_dir(codegen_dir, "GetChannelState") message = self.w3.soliditySha3(["uint256"], [channel_id]) signature = self.ident.sign_message_after_soliditySha3(message) request = request_class(channel_id = self.w3.toBytes(channel_id), signature = bytes(signature)) stub = stub_class(grpc_channel) response = getattr(stub, "GetChannelState")(request) # convert bytes to int state = dict() state["current_nonce"] = int.from_bytes(response.current_nonce, byteorder='big') state["current_signed_amount"] = int.from_bytes(response.current_signed_amount, byteorder='big') if (state["current_signed_amount"] > 0): good = self._verify_my_signature(bytes(response.current_signature), self.get_mpe_address(), channel_id, state["current_nonce"], state["current_signed_amount"]) if (not good): raise Exception("Error in _get_channel_state_from_server. My own signature from the server is not valid.") return state
def _get_channel_state_from_server(self, grpc_channel, channel_id): # Compile protobuf if needed codegen_dir = Path.home().joinpath(".snet", "mpe_client", "state_service") proto_dir = Path(__file__).absolute().parent.joinpath("resources", "proto") if (not codegen_dir.joinpath("state_service_pb2.py").is_file()): compile_proto(proto_dir, codegen_dir, proto_file = "state_service.proto") # make PaymentChannelStateService.GetChannelState call to the daemon stub_class, request_class, _ = import_protobuf_from_dir(codegen_dir, "GetChannelState") message = self.w3.soliditySha3(["uint256"], [channel_id]) signature = self.ident.sign_message_after_soliditySha3(message) request = request_class(channel_id = self.w3.toBytes(channel_id), signature = bytes(signature)) stub = stub_class(grpc_channel) response = getattr(stub, "GetChannelState")(request) # convert bytes to int state = dict() state["current_nonce"] = int.from_bytes(response.current_nonce, byteorder='big') state["current_signed_amount"] = int.from_bytes(response.current_signed_amount, byteorder='big') if (state["current_signed_amount"] > 0): good = self._verify_my_signature(bytes(response.current_signature), self.get_mpe_address(), channel_id, state["current_nonce"], state["current_signed_amount"]) if (not good): raise Exception("Error in _get_channel_state_from_server. My own signature from the server is not valid.") return state
def get_request_class(org_id, service_id, method_name, service_name=""): conf = Config() client = MPEClientCommand(conf, {}) _, request_class, _ = import_protobuf_from_dir(client.get_service_spec_dir( org_id, service_id), method_name, service_name=service_name) return request_class
def _get_stub_and_request_classes(self, service_name): """ import protobuf and return stub and request class """ # Compile protobuf if needed codegen_dir = Path.home().joinpath(".snet", "mpe_client", "control_service") proto_dir = Path(__file__).absolute().parent.joinpath("resources", "proto") if (not codegen_dir.joinpath("control_service_pb2.py").is_file()): compile_proto(proto_dir, codegen_dir, proto_file = "control_service.proto") stub_class, request_class, _ = import_protobuf_from_dir(codegen_dir, service_name) return stub_class, request_class
def _get_stub_and_request_classes(self, service_name): """ import protobuf and return stub and request class """ # Compile protobuf if needed codegen_dir = Path.home().joinpath(".snet", "mpe_client", "control_service") proto_dir = Path(__file__).absolute().parent.joinpath( "resources", "proto") if (not codegen_dir.joinpath("control_service_pb2.py").is_file()): compile_proto(proto_dir, codegen_dir, proto_file="control_service.proto") stub_class, request_class, _ = import_protobuf_from_dir( codegen_dir, service_name) return stub_class, request_class
def _import_protobuf_for_service(self): spec_dir = self.get_service_spec_dir(self.args.org_id, self.args.service_id) return import_protobuf_from_dir(spec_dir, self.args.method, self.args.service)
def _import_protobuf_for_channel(self): channel_dir = self.get_channel_dir() return import_protobuf_from_dir(channel_dir, self.args.method, self.args.service)
def _import_protobuf_for_service(self): spec_dir = self.get_service_spec_dir(self.args.org_id, self.args.service_id) return import_protobuf_from_dir(spec_dir, self.args.method, self.args.service)
def _import_protobuf_for_channel(self, service_name, method_name): channel_dir = self.get_channel_dir() return import_protobuf_from_dir(channel_dir, method_name, service_name)