def _make_batch(payload_bytes, inputs, outputs, transaction_signer, batch_signer): transaction_header = transaction_pb2.TransactionHeader( family_name=addresser.FAMILY_NAME, family_version=addresser.FAMILY_VERSION, inputs=inputs, outputs=outputs, signer_public_key=transaction_signer.get_public_key().as_hex(), batcher_public_key=batch_signer.get_public_key().as_hex(), dependencies=[], payload_sha512=hashlib.sha512(payload_bytes).hexdigest()) transaction_header_bytes = transaction_header.SerializeToString() transaction = transaction_pb2.Transaction( header=transaction_header_bytes, header_signature=transaction_signer.sign(transaction_header_bytes), payload=payload_bytes) batch_header = batch_pb2.BatchHeader( signer_public_key=batch_signer.get_public_key().as_hex(), transaction_ids=[transaction.header_signature]) batch_header_bytes = batch_header.SerializeToString() batch = batch_pb2.Batch( header=batch_header_bytes, header_signature=batch_signer.sign(batch_header_bytes), transactions=[transaction]) return batch
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 (sawtooth_signing.Signer): The txn signer's key pair. payload (bytes): The serialized RBACPayload. header (bytes): The serialized TransactionHeader. batch_key (sawtooth_signing.Signer): The batch signer's 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=txn_key.sign(header)) batch_header = batch_pb2.BatchHeader( signer_public_key=batch_key.get_public_key().as_hex(), transaction_ids=[transaction.header_signature]).SerializeToString() batch = batch_pb2.Batch(header=batch_header, header_signature=batch_key.sign(batch_header), transactions=[transaction]) return [batch], batch.header_signature
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 make_header_and_batch(payload, inputs, outputs, txn_key, batch_key): payload_sha512 = hashlib.sha512(payload.SerializeToString()).hexdigest() header = transaction_pb2.TransactionHeader( inputs=inputs, outputs=outputs, batcher_public_key=batch_key.get_public_key().as_hex(), dependencies=[], family_name=addresshandler.FAMILY_NAME, family_version='1.0', nonce=uuid4().hex, signer_public_key=txn_key.get_public_key().as_hex(), payload_sha512=payload_sha512) transaction = transaction_pb2.Transaction( payload=payload.SerializeToString(), header=header.SerializeToString(), header_signature=txn_key.sign(header.SerializeToString())) batch_header = batch_pb2.BatchHeader( signer_public_key=batch_key.get_public_key().as_hex(), transaction_ids=[transaction.header_signature]).SerializeToString() batch = batch_pb2.Batch( header=batch_header, header_signature=batch_key.sign(batch_header), transactions=[transaction]) return [batch], batch.header_signature
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'})
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