def _do_config_set(args): """Executes the 'set' subcommand. Given a key file, and a series of key/value pairs, it generates batches of sawtooth_config transactions in a BatchList instance, and stores it in a file. """ settings = [s.split('=', 1) for s in args.setting] with open(args.key, 'r') as key_file: wif_key = key_file.read().strip() signing_key = signing.encode_privkey( signing.decode_privkey(wif_key, 'wif'), 'hex') pubkey = signing.encode_pubkey(signing.generate_pubkey(signing_key), 'hex') txns = [ _create_config_txn(pubkey, signing_key, setting) for setting in settings ] txn_ids = [txn.header_signature for txn in txns] batch_header = BatchHeader(signer_pubkey=pubkey, transaction_ids=txn_ids).SerializeToString() batch = Batch(header=batch_header, header_signature=signing.sign(batch_header, signing_key), transactions=txns) batch_list = BatchList(batches=[batch]).SerializeToString() try: with open(args.output, 'wb') as batch_file: batch_file.write(batch_list) except: raise CliException('Unable to write to {}'.format(args.output))
def make_batch(self, batch_sig, *txns): txn_ids = [txn.header_signature for txn in txns] batch_header = BatchHeader( signer_pubkey='test_pubkey', transaction_ids=txn_ids).SerializeToString() batch = Batch(header=batch_header, header_signature=batch_sig, transactions=txns) batch_list = BatchList(batches=[batch]) target_path = os.path.join(self._temp_dir, batch_sig + ".batch") with open(target_path, "wb") as f: filename = f.name f.write(batch_list.SerializeToString()) return filename
def _create_batch(public_key, signing_key, transactions): """Creates a batch from a list of transactions and a public key, and signs the resulting batch with the given signing key. Args: public_key (str): The public key associated with the signing key. signing_key (str): The private key for signing the batch. transactions (list of `Transaction`): The transactions to add to the batch. Returns: `Batch`: The constructed and signed batch. """ txn_ids = [txn.header_signature for txn in transactions] batch_header = BatchHeader(signer_public_key=public_key, transaction_ids=txn_ids).SerializeToString() return Batch(header=batch_header, header_signature=signing.sign(batch_header, signing_key), transactions=transactions)
def _create_batch(signer, transactions): """Creates a batch from a list of transactions and a public key, and signs the resulting batch with the given signing key. Args: signer (:obj:`Signer`): The cryptographic signer transactions (list of `Transaction`): The transactions to add to the batch. Returns: `Batch`: The constructed and signed batch. """ txn_ids = [txn.header_signature for txn in transactions] batch_header = BatchHeader( signer_public_key=signer.get_public_key().as_hex(), transaction_ids=txn_ids).SerializeToString() return Batch(header=batch_header, header_signature=signer.sign(batch_header), transactions=transactions)