def add_block(self, block_id, root='merkle_root'): txn_header = TransactionHeader(batcher_pubkey='pubkey', family_name='family', family_version='0.0', nonce=block_id, signer_pubkey='pubkey') txn = Transaction(header=txn_header.SerializeToString(), header_signature=block_id, payload=b'payload') batch_header = BatchHeader(signer_pubkey='pubkey', transaction_ids=[txn.header_signature]) batch = Batch(header=batch_header.SerializeToString(), header_signature=block_id, transactions=[txn]) blk_header = BlockHeader(block_num=len(self._store), previous_block_id=self._chain_head_id, signer_pubkey='pubkey', batch_ids=[batch.header_signature], consensus=b'consensus', state_root_hash=root) block = Block(header=blk_header.SerializeToString(), header_signature=block_id, batches=[batch]) self._store[block_id] = block self._chain_head_id = block_id
def create_batch(transactions, signer): transaction_signatures = [t.header_signature for t in transactions] header = BatchHeader(signer_public_key=signer.get_public_key().as_hex(), transaction_ids=transaction_signatures) header_bytes = header.SerializeToString() signature = signer.sign(header_bytes) batch = Batch(header=header_bytes, transactions=transactions, header_signature=signature) return batch
def _create_batch(self, transactions): """ Create batch for transactions """ transaction_signatures = [t.header_signature for t in transactions] header = BatchHeader( signer_public_key=self._signer.get_public_key().as_hex(), transaction_ids=transaction_signatures ).SerializeToString() signature = self._signer.sign(header) batch = Batch( header=header, transactions=transactions, header_signature=signature) return batch
def make_batches(cls, *batch_ids): """Returns Batch objects with the specified ids, and each with one Transaction with matching ids. """ batches = [] for batch_id in batch_ids: txns = cls.make_txns(batch_id) batch_header = BatchHeader( signer_public_key='public_key', transaction_ids=[t.header_signature for t in txns]) batch = Batch(header=batch_header.SerializeToString(), header_signature=batch_id, transactions=txns) batches.append(batch) return batches