Exemple #1
0
def make_payload(message, message_type, inputs, outputs, signer_user_id,
                 signer_public_key):
    """ Turn a message into a payload
    """
    return rbac_payload.make_payload(
        message=message,
        message_type=message_type,
        inputs=inputs,
        outputs=outputs,
        signer=Signer(user_id=signer_user_id, public_key=signer_public_key),
    )
    def make_payload(self, message, signer_user_id, signer_keypair):
        """Make a payload for the given message type"""
        if not signer_keypair:
            raise ValueError(
                "{} signer_keypair is required".format(self.message_type_name)
            )
        if not signer_user_id:
            raise ValueError(
                "{} signer_user_id is required".format(self.message_type_name)
            )
        self.validate(
            message=message,
            signer=Signer(user_id=signer_user_id, public_key=signer_keypair.public_key),
        )

        message_type = self.message_type
        inputs, outputs = self.make_addresses(
            message=message, signer_user_id=signer_user_id
        )
        inputs = set(inputs)
        outputs = set(outputs)

        inputs.add(addresser.key.address(object_id=signer_keypair.public_key))
        inputs.add(addresser.user.address(object_id=signer_user_id))
        inputs.add(
            addresser.user.key.address(
                object_id=signer_user_id, related_id=signer_keypair.public_key
            )
        )

        if not outputs.issubset(inputs):
            raise ValueError(
                "{} output addresses {} not contained in inputs".format(
                    self.message_type_name,
                    addresser.parse_addresses(outputs.difference(inputs)),
                )
            )

        return batcher.make_payload(
            message=message,
            message_type=message_type,
            inputs=inputs,
            outputs=outputs,
            signer_user_id=signer_user_id,
            signer_public_key=signer_keypair.public_key,
        )
 def new(self, signer_keypair, signer_user_id, **kwargs):
     """Creates and send a message to the blockchain"""
     message = kwargs.get("message")
     if not message:
         message = self.make(**kwargs)
     else:
         self.validate(
             message=message,
             signer=Signer(
                 user_id=signer_user_id, public_key=signer_keypair.public_key
             ),
         )
     return self.send(
         signer_keypair=signer_keypair,
         payload=self.make_payload(
             message=message,
             signer_keypair=signer_keypair,
             signer_user_id=signer_user_id,
         ),
     )
 def batch_list(self, signer_user_id, signer_keypair, batch_list=None, **kwargs):
     """Adds a new message to an existing or new batch list"""
     message = kwargs.get("message")
     if not message:
         message = self.make(**kwargs)
     else:
         self.validate(
             message=message,
             signer=Signer(
                 user_id=signer_user_id, public_key=signer_keypair.public_key
             ),
         )
     payload = self.make_payload(
         message=message,
         signer_user_id=signer_user_id,
         signer_keypair=signer_keypair,
     )
     _, new_batch, new_batch_list, _ = batcher.make(
         payload=payload, signer_keypair=signer_keypair
     )
     if batch_list:
         batch_list.batches.extend([new_batch])
         return batch_list
     return new_batch_list
 def batch(self, signer_user_id, signer_keypair, batch=None, **kwargs):
     """Adds a new message to an existing or new batch"""
     message = kwargs.get("message")
     if not message:
         message = self.make(**kwargs)
     else:
         self.validate(
             message=message,
             signer=Signer(
                 user_id=signer_user_id, public_key=signer_keypair.public_key
             ),
         )
     payload = self.make_payload(
         message=message,
         signer_keypair=signer_keypair,
         signer_user_id=signer_user_id,
     )
     transaction, new_batch, _, _ = batcher.make(
         payload=payload, signer_keypair=signer_keypair
     )
     if batch:
         batch.transactions.extend([transaction])
         return batch
     return new_batch
def make_signer(user_id, public_key):
    """Make a signer object
    """
    return Signer(user_id=user_id, public_key=public_key)
Exemple #7
0
def make_signer(next_id, public_key):
    """Make a signer object
    """
    return Signer(next_id=next_id, public_key=public_key)