示例#1
0
    def on_payout_block(self, source_address, data):
        if not self.bandwidth_wallet:
            self.logger.warning(
                "Got payout while not having a TrustChain community running!")
            return

        payload = self._ez_unpack_noauth(PayoutPayload,
                                         data,
                                         global_time=False)
        peer = Peer(payload.public_key, source_address)

        def on_transaction_completed(blocks):
            # Send the next payout
            if blocks and payload.circuit_id in self.relay_from_to and block.transaction[
                    'down'] > payload.base_amount:
                relay = self.relay_from_to[payload.circuit_id]
                self._logger.info("Sending next payout to peer %s", relay.peer)
                self.do_payout(
                    relay.peer, relay.circuit_id,
                    block.transaction['down'] - payload.base_amount * 2,
                    payload.base_amount)

        block = TriblerBandwidthBlock.from_payload(payload, self.serializer)
        self.bandwidth_wallet.trustchain.process_half_block(block, peer)\
            .addCallbacks(on_transaction_completed, lambda _: None)

        # Check whether the block has been added to the database and has been verified
        if not self.bandwidth_wallet.trustchain.persistence.contains(block):
            self.logger.warning(
                "Not proceeding with payout - received payout block is not valid"
            )
            return
示例#2
0
    def on_payout_block(self, source_address, data):
        if not self.bandwidth_wallet:
            self.logger.warning(
                "Got payout while not having a TrustChain community running!")
            return

        payload = self._ez_unpack_noauth(PayoutPayload,
                                         data,
                                         global_time=False)
        peer = Peer(payload.public_key, source_address)
        block = TriblerBandwidthBlock.from_payload(payload, self.serializer)
        self.bandwidth_wallet.trustchain.process_half_block(block, peer)

        # Send the next payout
        if payload.circuit_id in self.relay_from_to and block.transaction[
                'down'] > payload.base_amount:
            relay = self.relay_from_to[payload.circuit_id]
            circuit_peer = self.get_peer_from_address(relay.peer.address)
            if not circuit_peer:
                self.logger.warning(
                    "%s Unable to find next peer %s for payout!", self.my_peer,
                    relay.peer)
                return

            self.do_payout(circuit_peer, relay.circuit_id,
                           block.transaction['down'] - payload.base_amount * 2,
                           payload.base_amount)
示例#3
0
 def on_balance_response_cell(self, source_address, data, _):
     payload = self._ez_unpack_noauth(BalanceResponsePayload, data, global_time=False)
     block = TriblerBandwidthBlock.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"])
示例#4
0
 def on_balance_response_cell(self, source_address, data, _):
     payload = self._ez_unpack_noauth(BalanceResponsePayload, data, global_time=False)
     block = TriblerBandwidthBlock.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"])
示例#5
0
    def on_relay_balance_response_cell(self, source_address, data, _):
        payload = self._ez_unpack_noauth(BalanceResponsePayload, data, global_time=False)
        block = TriblerBandwidthBlock.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_peer.address],
                               u"balance-response",
                               BalanceResponsePayload.from_half_block(block, cache.to_circuit_id))
示例#6
0
    def on_relay_balance_response_cell(self, source_address, data, _):
        payload = self._ez_unpack_noauth(BalanceResponsePayload, data, global_time=False)
        block = TriblerBandwidthBlock.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, CreateRequestCache) and cache.from_circuit_id == payload.circuit_id:
                self.send_cell([cache.to_peer.address],
                               u"balance-response",
                               BalanceResponsePayload.from_half_block(block, cache.to_circuit_id))
示例#7
0
    def on_payout_block(self, source_address, data):
        if not self.bandwidth_wallet:
            self.logger.warning("Got payout while not having a TrustChain community running!")
            return

        payload = self._ez_unpack_noauth(PayoutPayload, data, global_time=False)
        peer = Peer(payload.public_key, source_address)

        def on_transaction_completed(blocks):
            # Send the next payout
            if blocks and payload.circuit_id in self.relay_from_to and block.transaction['down'] > payload.base_amount:
                relay = self.relay_from_to[payload.circuit_id]
                self._logger.info("Sending next payout to peer %s", relay.peer)
                self.do_payout(relay.peer, relay.circuit_id, block.transaction['down'] - payload.base_amount * 2,
                               payload.base_amount)

        block = TriblerBandwidthBlock.from_payload(payload, self.serializer)
        self.bandwidth_wallet.trustchain.process_half_block(block, peer)\
            .addCallbacks(on_transaction_completed, lambda _: None)

        # Check whether the block has been added to the database and has been verified
        if not self.bandwidth_wallet.trustchain.persistence.contains(block):
            self.logger.warning("Not proceeding with payout - received payout block is not valid")
            return