Пример #1
0
    def call_server_statelessly_with_params(self, params, group_name):

        # if service is not initilized we will initialize it (unless we want skip registry check for update)
        if (not self.args.skip_update_check):
            self._init_or_update_registered_org_if_needed()
            self._init_or_update_registered_service_if_needed()

        org_metadata = self._read_metadata_for_org(self.args.org_id)
        service_metadata = self._get_service_metadata()
        endpoint = self._get_endpoint_from_metadata_or_args(service_metadata)
        grpc_channel = open_grpc_channel(endpoint)

        # if channel was not initilized we will try to initailize it (it will work only in simple case of signer == sender)
        channel = self._smart_get_initialized_channel_for_org(
            org_metadata, filter_by="signer")
        channel_id = channel["channelId"]
        price = self._get_price_from_metadata(service_metadata, group_name)
        server_state = self._get_channel_state_from_server(
            grpc_channel, channel_id)

        proceed = self.args.yes or input(
            "Price for this call will be %s AGI (use -y to remove this warning). Proceed? (y/n): "
            % (cogs2stragi(price))) == "y"
        if (not proceed):
            self._error("Cancelled")

        return self._call_server_via_grpc_channel(
            grpc_channel, channel_id, server_state["current_nonce"],
            server_state["current_signed_amount"] + price, params,
            service_metadata)
Пример #2
0
    def print_channel_state_statelessly(self):
        grpc_channel = open_grpc_channel(self.args.endpoint)

        current_nonce, current_amount, unspent_amount = self._get_channel_state_statelessly(
            grpc_channel, self.args.channel_id)
        self._printout("current_nonce                  = %i" % current_nonce)
        self._printout("current_signed_amount_in_cogs  = %i" % current_amount)
        self._printout("current_unspent_amount_in_cogs = %s" %
                       str(unspent_amount))
Пример #3
0
 def print_unclaimed(self):
     grpc_channel = open_grpc_channel(self.args.endpoint)
     payments = self._call_GetListUnclaimed(grpc_channel)
     self._printout("# channel_id  channel_nonce  signed_amount (AGI)")
     total = 0
     for p in payments:
         self._printout(
             "%i   %i   %s" %
             (p["channel_id"], p["nonce"], cogs2stragi(p["amount"])))
         total += p["amount"]
     self._printout("# total_unclaimed_in_AGI = %s" % cogs2stragi(total))
Пример #4
0
 def _service_status(self, url, secure=True):
     try:
         channel = open_grpc_channel(endpoint=url)
         stub = heartb_pb2_grpc.HealthStub(channel)
         response = stub.Check(
             heartb_pb2.HealthCheckRequest(service=""), timeout=10)
         if response != None and response.status == 1:
             return True
         return False
     except Exception as e:
         return False
Пример #5
0
    def claim_almost_expired_channels(self):
        grpc_channel = open_grpc_channel(self.args.endpoint)
        # we take list of all channels
        unclaimed_payments = self._call_GetListUnclaimed(grpc_channel)

        channels = []
        for p in unclaimed_payments:
            if (p["amount"] == 0):
                continue
            channel_id = p["channel_id"]
            blockchain = self._get_channel_state_from_blockchain(channel_id)
            if (blockchain["expiration"] < self.ident.w3.eth.blockNumber +
                    self.args.expiration_threshold):
                self._printout("We are going to claim channel %i" % channel_id)
                channels.append(channel_id)
        self._claim_in_progress_and_claim_channels(grpc_channel, channels)
Пример #6
0
    def call_server_lowlevel(self):

        self._init_or_update_registered_org_if_needed()
        self._init_or_update_registered_service_if_needed()

        params = self._get_call_params()
        service_metadata = self._get_service_metadata()
        endpoint = self._get_endpoint_from_metadata_or_args(service_metadata)
        grpc_channel = open_grpc_channel(endpoint)

        response = self._call_server_via_grpc_channel(grpc_channel,
                                                      self.args.channel_id,
                                                      self.args.nonce,
                                                      self.args.amount_in_cogs,
                                                      params, service_metadata)
        self._deal_with_call_response(response)
Пример #7
0
 def claim_all_channels(self):
     grpc_channel = open_grpc_channel(self.args.endpoint)
     # we take list of all channels
     unclaimed_payments = self._call_GetListUnclaimed(grpc_channel)
     channels = [p["channel_id"] for p in unclaimed_payments]
     self._claim_in_progress_and_claim_channels(grpc_channel, channels)
Пример #8
0
 def claim_channels(self):
     grpc_channel = open_grpc_channel(self.args.endpoint)
     self._claim_in_progress_and_claim_channels(grpc_channel,
                                                self.args.channels)