def wrap_payload_in_txn_batch(txn_key, payload, header, batch_key):
    """Takes the serialized RBACPayload and creates a batch_list, batch
    signature tuple.

    Args:
        txn_key (Key): The txn signer's public/private key pair.
        payload (bytes): The serialized RBACPayload.
        header (bytes): The serialized TransactionHeader.
        batch_key (Key): The batch signer's public/private key pair.

    Returns:
        tuple
            The zeroth element is a BatchList, and the first element is
            the batch header_signature.
    """

    transaction = transaction_pb2.Transaction(payload=payload,
                                              header=header,
                                              header_signature=signing.sign(
                                                  header, txn_key.private_key))

    batch_header = batch_pb2.BatchHeader(
        signer_pubkey=batch_key.public_key,
        transaction_ids=[transaction.header_signature]).SerializeToString()

    batch = batch_pb2.Batch(header=batch_header,
                            header_signature=signing.sign(
                                batch_header, batch_key.private_key),
                            transactions=[transaction])

    batch_list = batch_pb2.BatchList(batches=[batch])
    return batch_list, batch.header_signature
    def close_offer(self, key, identifier):
        batches, signature = transaction_creation.close_offer(
            txn_key=key, batch_key=BATCH_KEY, identifier=identifier)

        batch_list = batch_pb2.BatchList(batches=batches)
        self._client.send_batches(batch_list)
        return self._client.get_statuses([signature], wait=10)
Exemplo n.º 3
0
 def create_agent(self, key, name, timestamp):
     batch = transaction_creation.make_create_agent_transaction(
         transaction_signer=key,
         batch_signer=BATCH_KEY,
         name=name,
         timestamp=timestamp)
     batch_id = batch.header_signature
     batch_list = batch_pb2.BatchList(batches=[batch])
     self._client.send_batches(batch_list)
     return self._client.get_statuses([batch_id], wait=10)
 def create_asset(self, key, name, description, rules):
     batches, signature = transaction_creation.create_asset(
         txn_key=key,
         batch_key=BATCH_KEY,
         name=name,
         description=description,
         rules=rules)
     batch_list = batch_pb2.BatchList(batches=batches)
     self._client.send_batches(batch_list)
     return self._client.get_statuses([signature], wait=10)
    def create_account(self, key, label, description):
        batches, signature = transaction_creation.create_account(
            txn_key=key,
            batch_key=BATCH_KEY,
            label=label,
            description=description)
        batch_list = batch_pb2.BatchList(batches=batches)

        self._client.send_batches(batch_list)
        return self._client.get_statuses([signature], wait=10)
Exemplo n.º 6
0
    async def post_batch_ids(self, *batch_ids, wait=False):
        batches = [batch_pb2.Batch(
            header_signature=batch_id,
            header=b'header') for batch_id in batch_ids]
        batch_list = batch_pb2.BatchList(batches=batches)

        return await self.client.post(
            '/batches' + ('?wait' if wait else ''),
            data=batch_list.SerializeToString(),
            headers={'content-type': 'application/octet-stream'})
Exemplo n.º 7
0
 def transfer_record(self, key, receiving_agent, record_id, timestamp):
     batch = transaction_creation.make_transfer_record_transaction(
         transaction_signer=key,
         batch_signer=BATCH_KEY,
         receiving_agent=receiving_agent,
         record_id=record_id,
         timestamp=timestamp)
     batch_id = batch.header_signature
     batch_list = batch_pb2.BatchList(batches=[batch])
     self._client.send_batches(batch_list)
     return self._client.get_statuses([batch_id], wait=10)
 def accept_offer(self, key, identifier, receiver, offerer, count):
     batches, signature = transaction_creation.accept_offer(
         txn_key=key,
         batch_key=BATCH_KEY,
         identifier=identifier,
         offerer=offerer,
         receiver=receiver,
         count=count)
     batch_list = batch_pb2.BatchList(batches=batches)
     self._client.send_batches(batch_list)
     return self._client.get_statuses([signature], wait=10)
Exemplo n.º 9
0
 def update_record(self, key, latitude, longitude, record_id, timestamp):
     batch = transaction_creation.make_update_record_transaction(
         transaction_signer=key,
         batch_signer=BATCH_KEY,
         latitude=latitude,
         longitude=longitude,
         record_id=record_id,
         timestamp=timestamp)
     batch_id = batch.header_signature
     batch_list = batch_pb2.BatchList(batches=[batch])
     self._client.send_batches(batch_list)
     return self._client.get_statuses([batch_id], wait=10)
 def create_holding(self, key, identifier, label, description, asset,
                    quantity):
     batches, signature = transaction_creation.create_holding(
         txn_key=key,
         batch_key=BATCH_KEY,
         identifier=identifier,
         label=label,
         description=description,
         asset=asset,
         quantity=quantity)
     batch_list = batch_pb2.BatchList(batches=batches)
     self._client.send_batches(batch_list)
     return self._client.get_statuses([signature], wait=10)
 def create_offer(self, key, identifier, label, description, source, target,
                  rules):
     batches, signature = transaction_creation.create_offer(
         txn_key=key,
         batch_key=BATCH_KEY,
         identifier=identifier,
         label=label,
         description=description,
         source=source,
         target=target,
         rules=rules)
     batch_list = batch_pb2.BatchList(batches=batches)
     self._client.send_batches(batch_list)
     return self._client.get_statuses([signature], wait=10)
Exemplo n.º 12
0
def wrap_payload_in_txn_batch(txn_key, payload, header, batch_key):
    """Takes the serialized RBACPayload and creates a batch_list, batch
    signature tuple.

    Args:
        txn_key (Key): The txn signer's public/private key pair.
        payload (bytes): The serialized RBACPayload.
        header (bytes): The serialized TransactionHeader.
        batch_key (Key): The batch signer's public/private key pair.

    Returns:
        tuple
            The zeroth element is a BatchList, and the first element is
            the batch header_signature.
    """

    factory = CryptoFactory(sawtooth_signing.create_context("secp256k1"))

    txn_signer = factory.new_signer(
        Secp256k1PrivateKey.from_hex(txn_key.private_key))
    transaction = transaction_pb2.Transaction(
        payload=payload,
        header=header,
        header_signature=txn_signer.sign(header))

    batch_header = batch_pb2.BatchHeader(
        signer_public_key=batch_key.public_key,
        transaction_ids=[transaction.header_signature],
    ).SerializeToString()

    batch_signer = factory.new_signer(
        Secp256k1PrivateKey.from_hex(batch_key.private_key))
    batch = batch_pb2.Batch(
        header=batch_header,
        header_signature=batch_signer.sign(batch_header),
        transactions=[transaction],
    )

    batch_list = batch_pb2.BatchList(batches=[batch])
    return batch_list, batch.header_signature