Exemple #1
0
 def on_balance_response_cell(self, source_address, data, _):
     _, payload = self._ez_unpack_noauth(BalanceResponsePayload, data)
     block = TriblerChainBlock.from_payload(payload, self.serializer)
     if not block.transaction:
         self.on_token_balance(payload.circuit_id, 0)
     else:
         self.on_token_balance(payload.circuit_id,
                               block.transaction["total_up"] - block.transaction["total_down"])
Exemple #2
0
    def on_relay_balance_response_cell(self, source_address, data, _):
        _, payload = self._ez_unpack_noauth(BalanceResponsePayload, data)
        block = TriblerChainBlock.from_payload(payload, self.serializer)

        # At this point, we don't have the circuit ID of the follow-up hop. We have to iterate over the items in the
        # request cache and find the link to the next hop.
        for cache in self.request_cache._identifiers.values():
            if isinstance(cache, ExtendRequestCache) and cache.from_circuit_id == payload.circuit_id:
                self.send_cell([cache.to_candidate_sock_addr],
                               u"balance-response",
                               BalanceResponsePayload.from_half_block(block, cache.to_circuit_id))