def bootstrap_new_identity(self, amount):
        """
        One-way payment channel.
        Create a new temporary identity, and transfer funds to the new identity.
        A different party can then take the result and do a transfer from the temporary identity to itself
        """

        # Create new identity for the temporary identity
        tmp_member = self.dispersy.get_new_member(u"curve25519")

        # Create the transaction specification
        transaction = {
            'up': 0, 'down': amount
        }

        # Create the two half blocks that form the transaction
        local_half_block = TriblerChainBlock.create(transaction, self.persistence, self.my_member.public_key,
                                                    link_pk=tmp_member.public_key)
        local_half_block.sign(self.my_member.private_key)
        tmp_half_block = TriblerChainBlock.create(transaction, self.persistence, tmp_member.public_key,
                                                  link=local_half_block, link_pk=self.my_member.public_key)
        tmp_half_block.sign(tmp_member.private_key)

        self.persistence.add_block(local_half_block)
        self.persistence.add_block(tmp_half_block)

        # Create the bootstrapped identity format
        block = {'block_hash': tmp_half_block.hash.encode('base64'),
                 'sequence_number': tmp_half_block.sequence_number}

        result = {'private_key': tmp_member.private_key.key_to_bin().encode('base64'),
                  'transaction': {'up': amount, 'down': 0}, 'block': block}
        return result
Exemple #2
0
 def test_validate_linked_down(self):
     db = MockDatabase()
     (block1, block2, _, _) = TestBlocks.setup_validate()
     db.add_block(block2)
     # Act
     db.add_block(TriblerChainBlock.create(block1.transaction, db, block1.link_public_key, block1))
     block1.transaction["down"] -= 5
     result = block1.validate(db)
     self.assertEqual(result[0], ValidationResult.invalid)
     self.assertIn("Down/up mismatch on linked block", result[1])
Exemple #3
0
    def test_crawl_request(self):
        """
        Test whether a crawl request is sent when receiving an introduction response
        """
        his_pk = self.nodes[1].overlay.my_peer.public_key.key_to_bin()
        block = TriblerChainBlock.create(
            {
                'up': 20,
                'down': 40
            },
            self.nodes[0].overlay.persistence,
            self.nodes[0].overlay.my_peer.public_key.key_to_bin(),
            link=None,
            link_pk=his_pk)
        block.sign(self.nodes[0].overlay.my_peer.key)
        self.nodes[0].overlay.persistence.add_block(block)

        yield self.introduce_nodes()

        # The block should be available in the databases of both involved parties.
        for node_nr in [0, 1]:
            self.assertIsNotNone(self.nodes[node_nr].overlay.persistence.get(
                self.nodes[0].overlay.my_peer.public_key.key_to_bin(), 1))