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_intkey_transaction(verb, name, value, deps, signer): payload = IntKeyPayload(verb=verb, name=name, value=value) # The prefix should eventually be looked up from the # validator's namespace registry. addr = make_intkey_address(name) header = TransactionHeader( signer_public_key=signer.get_public_key().as_hex(), family_name='intkey', family_version='1.0', inputs=[addr], outputs=[addr], dependencies=deps, payload_sha512=payload.sha512(), batcher_public_key=signer.get_public_key().as_hex()) header_bytes = header.SerializeToString() signature = signer.sign(header_bytes) transaction = Transaction(header=header_bytes, payload=payload.to_cbor(), header_signature=signature) return transaction
def make_txns(*txn_ids): """Returns Transaction objects with the specified ids and a header nonce that matches its id. """ txns = [] for txn_id in txn_ids: txn_header = TransactionHeader(batcher_public_key='public_key', family_name='family', family_version='0.0', nonce=txn_id, signer_public_key='public_key') txn = Transaction(header=txn_header.SerializeToString(), header_signature=txn_id, payload=b'payload') txns.append(txn) return txns
def _create_transaction(self,payload,inputs,outputs,dependencies=[]): """ make transaction """ LOGGER.debug('BgxRouteHandler: _create_transaction make Transaction') txn_header = TransactionHeader( signer_public_key=self._signer.get_public_key().as_hex(), family_name=SMART_BGX_FAMILY, family_version=SMART_BGX_VER, inputs=inputs, outputs=outputs, dependencies=dependencies, payload_sha512=_sha512(payload), batcher_public_key=self._signer.get_public_key().as_hex(), nonce=hex(random.randint(0, 2**64)) ).SerializeToString() signature = self._signer.sign(txn_header) transaction = Transaction( header=txn_header, payload=payload, header_signature=signature ) return transaction