def __init__(self, vaccine, sender_pubkey, signature=None, **kwargs):
        super(VaccineTransaction, self).__init__(vaccine=vaccine,
                                                 signature=signature,
                                                 sender_pubkey=sender_pubkey,
                                                 **kwargs)

        self.vaccine = vaccine
        self.sender_pubkey = key_utils.cast_to_bytes(sender_pubkey)
        self.signature = signature
    def __init__(self,
                 doctor_pub_key,
                 patient_pub_key,
                 vaccine,
                 doctor_signature=None,
                 patient_signature=None,
                 **kwargs):
        super(VaccinationTransaction,
              self).__init__(vaccine=vaccine,
                             doctor_signature=doctor_signature,
                             patient_signature=patient_signature,
                             **kwargs)

        del self.signature  # remove the base classes single signature
        del self.sender_pubkey  # remove the base classes sender signature

        self.vaccine = vaccine
        self.doctor_signature = doctor_signature
        self.patient_signature = patient_signature
        self.doctor_pub_key = key_utils.cast_to_bytes(doctor_pub_key)
        self.patient_pub_key = key_utils.cast_to_bytes(patient_pub_key)
Exemplo n.º 3
0
    def __init__(self, requested_permission, sender_pubkey, approvals=None, **kwargs):
        logger.debug("Creating new permission transaction")
        super(PermissionTransaction, self).__init__(
                requested_permission=requested_permission, sender_pubkey=sender_pubkey,
                approvals=approvals, **kwargs
        )

        if not approvals:
            approvals = []

        self.requested_permission = requested_permission
        self.sender_pubkey = key_utils.cast_to_bytes(sender_pubkey)
        self.approvals = approvals
Exemplo n.º 4
0
def test_cast_to_bytes(public_key, public_key_hex, public_key_bytes,
                       private_key, private_key_hex, private_key_bytes):
    object = key_utils.cast_to_bytes(public_key)
    assert object == public_key_bytes
    object = key_utils.cast_to_bytes(public_key_bytes)
    assert object == public_key_bytes
    object = key_utils.cast_to_bytes(public_key_hex)
    assert object == public_key_bytes

    object = key_utils.cast_to_bytes(private_key)
    assert object == private_key_bytes
    object = key_utils.cast_to_bytes(private_key_bytes)
    assert object == private_key_bytes
    object = key_utils.cast_to_bytes(private_key_hex)
    assert object == private_key_bytes

    with pytest.raises(ValueError):
        key_utils.cast_to_bytes(1234)
    def __init__(self, data, public_key=None):
        """Create or Recreate a block object.

        This constructor supports both, recreating a block by its string
        representation and creating a successor block based on the header
        information (type(data): dict) of the latest block.
        To create the successor block, the passed dictionary has to have
        the following fields:
        {
            "index": 0,         [index of the previous block]
            "hash": "166AD84E"  [hash of the previous block]
        }
        """
        if type(data) == dict:
            self._from_dictionary(data)
            assert public_key
            self.public_key = key_utils.cast_to_bytes(public_key)
            self.signature = ""
        elif type(data) == str:
            self._from_string(data)
        else:
            raise ValueError("Given argument is neither string nor dict!")