def _create_batch_list(self, transactions): """ Create the list of batches that the client will send to the REST API Args: transactions (transaction): transaction(s) included in the batch Returns: BatchList: a list of batches to send to the REST API """ 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 BatchList(batches=[batch])
def submit_batch(transactions: []) -> dict: """ Submits a batch, returning the JSON return value from the Sawtooth API :param transactions: :return: """ transactions = as_list(transactions) batch_header_bytes = BatchHeader( signer_public_key=_signer.get_public_key().as_hex(), transaction_ids=[t.header_signature for t in transactions], ).SerializeToString() signature = _signer.sign(batch_header_bytes) batch = Batch(header=batch_header_bytes, header_signature=signature, transactions=transactions) batch_list_bytes = BatchList(batches=[batch]).SerializeToString() resp = _post("/batches", batch_list_bytes) resp_data = resp.json() print(json.dumps(resp_data, indent=4)) return resp_data
def make_BCMCS_transaction(signer, payload): payload_bytes = cbor.dumps(payload) # sha512('bcmcs'.encode('utf-8')).hexdigest()[0:6] == 'e92c0c' txn_header_bytes = TransactionHeader( family_name='bcmcs', family_version='1.0', inputs=['e92c0c'], outputs=['e92c0c'], signer_public_key=signer.get_public_key().as_hex(), batcher_public_key=signer.get_public_key().as_hex(), dependencies=[], payload_sha512=sha512(payload_bytes).hexdigest()).SerializeToString() signature = signer.sign(txn_header_bytes) txn = Transaction(header=txn_header_bytes, header_signature=signature, payload=payload_bytes) txns = [txn] batch_header_bytes = BatchHeader( signer_public_key=signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in txns], ).SerializeToString() signature = signer.sign(batch_header_bytes) batch = Batch(header=batch_header_bytes, header_signature=signature, transactions=txns) batch_list_bytes = BatchList(batches=[batch]).SerializeToString() return batch_list_bytes
def banktransfer(family, input, pubpos, signer): txn_header_bytes = TransactionHeader( family_name=family, family_version='1.0', inputs=[input, pubpos], outputs=[input, pubpos], signer_public_key=signer.get_public_key().as_hex(), batcher_public_key=signer.get_public_key().as_hex(), dependencies=[], payload_sha512=sha512(payload_bytes).hexdigest()).SerializeToString() signature = signer.sign(txn_header_bytes) txn = Transaction(header=txn_header_bytes, header_signature=signature, payload=payload_bytes) txns = [txn] batch_header_bytes = BatchHeader( signer_public_key=signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in txns], ).SerializeToString() signature = signer.sign(batch_header_bytes) batch = Batch(header=batch_header_bytes, header_signature=signature, transactions=txns) batch_list_bytes = BatchList(batches=[batch]).SerializeToString() return batch_list_bytes
def _wrap_and_send(self, action, kycCategoryAddress, *values): # Generate a csv utf-8 encoded string as payload rawPayload = action for val in values: rawPayload = "$".join([rawPayload, str(val), str(kycCategoryAddress)]) payload = rawPayload.encode() # Construct the address where we'll store our state address = self._address + _hash(KYC_CATEGORY.encode('utf-8'))[0:6] + _hash(kycCategoryAddress.encode('utf-8'))[0:58] inputAddressList = [address] outputAddressList = [address] # Create a TransactionHeader header = TransactionHeader( signer_public_key=self._publicKey, family_name=FAMILY_NAME, family_version="1.0", inputs=inputAddressList, outputs=outputAddressList, dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._publicKey, nonce=time.time().hex().encode() ).SerializeToString() # Create a Transaction from the header and payload above transaction = Transaction( header=header, payload=payload, header_signature=self._signer.sign(header) ) transactionList = [transaction] # Create a BatchHeader from transactionList above header = BatchHeader( signer_public_key=self._publicKey, transaction_ids=[txn.header_signature for txn in transactionList] ).SerializeToString() #Create Batch using the BatchHeader and transactionList above batch = Batch( header=header, transactions=transactionList, header_signature=self._signer.sign(header)) #Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) # Send batch_list to rest-api return self._send_to_restapi( "batches", batch_list.SerializeToString(), 'application/octet-stream')
def _create_batch_list(self, transactions): """ Helps create a batch list to be transmitted to the ledger. Args: transactions (list of Transaction): List containing transaction IDs Returns: type: BatchList BatchList object where each batch in the list are constructed in the function. """ transaction_signatures = [t.header_signature for t in transactions] header = BatchHeader( signer_public_key=self._public_key, transaction_ids=transaction_signatures).SerializeToString() signature = CryptoFactory(create_context("secp256k1")) \ .new_signer(Secp256k1PrivateKey.from_hex(self._private_key)) \ .sign(header) batch = Batch(header=header, transactions=transactions, header_signature=signature) return BatchList(batches=[batch])
def submit(self): batch_header_bytes = BatchHeader( signer_public_key=self.signer.get_public_key().as_hex(), transaction_ids=[t.header_signature for t in self._transactions], ).SerializeToString() signature = self.signer.sign(batch_header_bytes) batch = Batch( header=batch_header_bytes, header_signature=signature, transactions=self._transactions ) batch_list_bytes = BatchList(batches=[batch]).SerializeToString() resp = requests.post( url='http://localhost:8008/batches', data=batch_list_bytes, headers={ 'Content-Type': 'application/octet-stream' } ) resp_data = resp.json() print(json.dumps(resp_data, indent=4)) if 'link' in resp_data: self.poll_status(resp_data['link'])
def send(self, transactions): txn_signatures = [txn.header_signature for txn in transactions] header = BatchHeader( signer_public_key=self.identity_signer.get_public_key().as_hex(), transaction_ids=txn_signatures).SerializeToString() signature = self.identity_signer.sign(header) batch = Batch(header=header, transactions=transactions, header_signature=signature) future = self._stream.send( message_type=Message.CLIENT_BATCH_SUBMIT_REQUEST, content=ClientBatchSubmitRequest( batches=[batch]).SerializeToString()) LOGGER.debug('_BatchPublisherProxy: future.result ...') result = future.result() LOGGER.debug('_BatchPublisherProxy: future.result DONE') assert result.message_type == Message.CLIENT_BATCH_SUBMIT_RESPONSE response = ClientBatchSubmitResponse() response.ParseFromString(result.content) if response.status != ClientBatchSubmitResponse.OK: LOGGER.warning("Submitting batch failed with status %s", response)
def _wrap_and_send(self, action, *values): '''Erstellt eine Transaktion, verpackt sie in ein Batch ''' # Generate a csv utf-8 encoded string as payload rawPayload = action for val in values: rawPayload = ",".join([rawPayload, str(val)]) payload = rawPayload.encode() # Construct the address where we'll store our state address = self._address inputAddressList = [address] outputAddressList = [address] if "transfer" == action: toAddress = _hash(FAMILY_NAME.encode('utf-8'))[0:6] + \ _hash(values[1].encode('utf-8'))[0:64] inputAddressList.append(toAddress) outputAddressList.append(toAddress) # Create a TransactionHeader header = TransactionHeader( signer_public_key=self._publicKey, family_name=FAMILY_NAME, family_version="1.0", inputs=inputAddressList, outputs=outputAddressList, dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._publicKey, nonce=random.random().hex().encode()).SerializeToString() # Create a Transaction from the header and payload above transaction = Transaction(header=header, payload=payload, header_signature=self._signer.sign(header)) transactionList = [transaction] # Create a BatchHeader from transactionList above header = BatchHeader( signer_public_key=self._publicKey, transaction_ids=[txn.header_signature for txn in transactionList]).SerializeToString() #Create Batch using the BatchHeader and transactionList above batch = Batch(header=header, transactions=transactionList, header_signature=self._signer.sign(header)) #Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) # Send batch_list to rest-api return self._send_to_restapi("batches", batch_list.SerializeToString(), 'application/octet-stream')
def _wrap_and_send(self, buyer, seller, house, wait=None): """ Create a transaction, then wrap it in a batch. Even single transactions must be wrapped into a batch. """ # Generate a CSV UTF-8 encoded string as the payload. raw_payload = "{".join([buyer, seller, house]) payload = raw_payload.encode() # Convert Unicode to bytes # Construct the address where we'll store our state. # We just have one input and output address (the same one). input_and_output_address_list = [self._address] # Create a TransactionHeader. header = TransactionHeader( signer_public_key=self._public_key, family_name=FAMILY_NAME, family_version="1.0", inputs=input_and_output_address_list, outputs=input_and_output_address_list, dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._public_key, nonce=random.random().hex().encode() ).SerializeToString() # Create a Transaction from the header and payload above. transaction = Transaction( header=header, payload=payload, header_signature=self._signer.sign(header) ) transaction_list = [transaction] # Create a BatchHeader from transaction_list above. header = BatchHeader( signer_public_key=self._public_key, transaction_ids=[txn.header_signature for txn in transaction_list] ).SerializeToString() # Create Batch using the BatchHeader and transaction_list above. batch = Batch( header=header, transactions=transaction_list, header_signature=self._signer.sign(header)) # Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) batch_id = batch_list.batches[0].header_signature # Send batch_list to the REST API result = self._send_to_rest_api("batches", batch_list.SerializeToString(), 'application/octet-stream') # Wait until transaction status is COMMITTED, error, or timed out return self._wait_for_status(batch_id, wait, result)
def _batch_header(batch_signer, transactions): batch_header_bytes = BatchHeader( signer_public_key=batch_signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in transactions], ).SerializeToString() signature = batch_signer.sign(batch_header_bytes) return batch_header_bytes, signature
def _batch_header(self, batch_key, transactions): batch_header_bytes = BatchHeader( signer_public_key=batch_key, transaction_ids=[txn.header_signature for txn in transactions], ).SerializeToString() signature = self._signer.sign(batch_header_bytes) return batch_header_bytes, signature
def _wrap_and_send(self, action, data, input_and_output_address_list, wait=None): '''Create a transaction, then wrap it in a batch. Even single transactions must be wrapped into a batch. Called by all submission methods. ''' # Assemble an action and the actual payload in a dictionary transactionDictionary = {'Action': action, 'Payload': data} payload = cbor.dumps(transactionDictionary) # Create a TransactionHeader. header = TransactionHeader( signer_public_key=self._public_key, family_name=FAMILY_NAME, family_version="1.0", inputs=input_and_output_address_list, outputs=input_and_output_address_list, dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._public_key, nonce=random.random().hex().encode()).SerializeToString() # Create a Transaction from the header and payload above. transaction = Transaction(header=header, payload=payload, header_signature=self._signer.sign(header)) transaction_list = [transaction] # Create a BatchHeader from transaction_list above. header = BatchHeader( signer_public_key=self._public_key, transaction_ids=[txn.header_signature for txn in transaction_list]).SerializeToString() # Create Batch using the BatchHeader and transaction_list above. batch = Batch(header=header, transactions=transaction_list, header_signature=self._signer.sign(header)) # Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) batch_id = batch_list.batches[0].header_signature # Send batch_list to the REST API result = self._send_to_rest_api("batches", batch_list.SerializeToString(), 'application/octet-stream') # Wait until transaction status is COMMITTED, error, or timed out return self._wait_for_status(batch_id, wait, result)
def wrap_and_send(action, data='', wait=None): # Generate a CSV UTF-8 encoded string as the payload. raw_payload = ",".join([action,data]) payload = raw_payload # Convert Unicode to bytes # Construct the address where we'll store our state. # We just have one input and output address (the same one). input_and_output_address_list = [namespace] # Create a TransactionHeader. header = TransactionHeader( signer_public_key=public_key, family_name="bidding", family_version="1.0", inputs=input_and_output_address_list, outputs=input_and_output_address_list, dependencies=[], payload_sha512=hash(payload), batcher_public_key=public_key, nonce=random.random().hex().encode() ).SerializeToString() # Create a Transaction from the header and payload above. transaction = Transaction( header=header, payload=payload.encode(), header_signature=signer.sign(header) ) transaction_list = [transaction] # Create a BatchHeader from transaction_list above. header = BatchHeader( signer_public_key=public_key, transaction_ids=[txn.header_signature for txn in transaction_list] ).SerializeToString() # Create Batch using the BatchHeader and transaction_list above. batch = Batch( header=header, transactions=transaction_list, header_signature=signer.sign(header)) # Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) batch_id = batch_list.batches[0].header_signature # Send batch_list to the REST API result = send_to_rest_api("batches", batch_list.SerializeToString(), 'application/octet-stream') # Wait until transaction status is COMMITTED, error, or timed out return wait_for_status(batch_id, wait, result)
def _wrap_and_send(self, *values): payload = ",".join(values) print(" Payload ") print(payload) # Construct the address where we'll store our state address = self._address inputAddressList = [address] outputAddressList = [address] if "transfer" == values[0]: toAddress = get_wallet_address(values[2]) inputAddressList.append(toAddress) outputAddressList.append(toAddress) print("Inside the block") # Create a TransactionHeader header = TransactionHeader( signer_public_key=self._publicKey, family_name=FAMILY_NAME, family_version="1.0", inputs=inputAddressList, outputs=outputAddressList, dependencies=[], payload_sha512=hashlib.sha512(payload.encode()).hexdigest(), batcher_public_key=self._publicKey, nonce=random.random().hex().encode()).SerializeToString() # Create a Transaction from the header and payload above transaction = Transaction(header=header, payload=payload.encode(), header_signature=self._signer.sign(header)) transactionList = [transaction] # Create a BatchHeader from transactionList above header = BatchHeader( signer_public_key=self._publicKey, transaction_ids=[txn.header_signature for txn in transactionList]).SerializeToString() # Create Batch using the BatchHeader and transactionList above batch = Batch(header=header, transactions=transactionList, header_signature=self._signer.sign(header)) # Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) batch_id = batch_list.batches[0].header_signature print(batch_id) # Send batch_list to rest-api return self._send_to_restapi("batches", batch_list.SerializeToString(), 'application/octet-stream')
def gogogox(todo, amount, account_no): print('gogogo') context = create_context('secp256k1') # conn = sqlite3.connect('bank.db') # cursor = conn.execute("SELECT private_key from key") # for row in cursor: # privatek=row[0] # conn.close() # private_key = Secp256k1PrivateKey.from_hex(privatek) conn = sqlite3.connect('bank.db') cursor = conn.execute( "SELECT code from BANK WHERE account_no='{}'".format(account_no)) for row in cursor: code = row[0] conn.close() private_key = context.new_random_private_key() signer = CryptoFactory(context).new_signer(private_key) input = hash("bankregister".encode('utf-8'))[0:6] + hash( "overclockedbrain".encode('utf-8'))[0:58] + hash( code.encode('utf-8'))[0:6] payload = "{},{},{}".format(todo, amount, code) payload_bytes = cbor.dumps(payload) txn_header_bytes = TransactionHeader( family_name='bankregister', family_version='1.0', inputs=[input], outputs=[input], signer_public_key=signer.get_public_key().as_hex(), batcher_public_key=signer.get_public_key().as_hex(), dependencies=[], payload_sha512=sha512(payload_bytes).hexdigest()).SerializeToString() signature = signer.sign(txn_header_bytes) txn = Transaction(header=txn_header_bytes, header_signature=signature, payload=payload_bytes) txns = [txn] batch_header_bytes = BatchHeader( signer_public_key=signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in txns], ).SerializeToString() signature = signer.sign(batch_header_bytes) batch = Batch(header=batch_header_bytes, header_signature=signature, transactions=txns) batch_list_bytes = BatchList(batches=[batch]).SerializeToString() return batch_list_bytes
def create_batch_list(transactions, private_key_hex, public_key_hex): transaction_signatures = [t.header_signature for t in transactions] header = BatchHeader( signer_public_key=public_key_hex, transaction_ids=transaction_signatures).SerializeToString() signature = sign(header, private_key_hex) batch = Batch(header=header, transactions=transactions, header_signature=signature) return BatchList(batches=[batch])
def _create_batch_list(self, 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 BatchList(batches=[batch])
def create_batch(self): batch_header_bytes = BatchHeader( signer_public_key=self.signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in self.txns], ).SerializeToString() signature = self.signer.sign(batch_header_bytes) batch = Batch(header=batch_header_bytes, header_signature=signature, transactions=self.txns) self.batch_list_bytes = BatchList(batches=[batch]).SerializeToString()
def create_batch(self, transactions): batch_header = BatchHeader( signer_public_key=self.signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in transactions], ).SerializeToString() batch = Batch( header=batch_header, header_signature=self.signer.sign(batch_header), transactions=transactions, ) return BatchList(batches=[batch]).SerializeToString()
def wrap_and_send(action, data, input_address_list, output_address_list, wait=None): '''Create a transaction, then wrap it in a batch. ''' payload = ",".join([action, str(data)]) logging.info('payload: {}'.format(payload)) # Construct the address where we'll store our state. # Create a TransactionHeader. header = TransactionHeader( signer_public_key=public_key, family_name=family_name, family_version="1.0", inputs=input_address_list, # input_and_output_address_list, outputs=output_address_list, # input_and_output_address_list, dependencies=[], payload_sha512=hash(payload), batcher_public_key=public_key, nonce=random.random().hex().encode()).SerializeToString() # Create a Transaction from the header and payload above. transaction = Transaction( header=header, payload=payload.encode(), # encode the payload header_signature=signer.sign(header)) transaction_list = [transaction] # Create a BatchHeader from transaction_list above. header = BatchHeader(signer_public_key=public_key, transaction_ids=[ txn.header_signature for txn in transaction_list ]).SerializeToString() # Create Batch using the BatchHeader and transaction_list above. batch = Batch(header=header, transactions=transaction_list, header_signature=signer.sign(header)) # Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) batch_id = batch_list.batches[0].header_signature # Send batch_list to the REST API result = send_to_rest_api("batches", batch_list.SerializeToString(), 'application/octet-stream') # Wait until transaction status is COMMITTED, error, or timed out return wait_for_status(batch_id, result, wait=wait)
def _create_batch_list(self, transactions): transaction_signatures = [t.header_signature for t in transactions] header = BatchHeader( signer_public_key=self._public_key, transaction_ids=transaction_signatures).SerializeToString() signature = CryptoFactory(create_context('secp256k1')) \ .new_signer(Secp256k1PrivateKey.from_hex(self._private_key)).sign(header) batch = Batch(header=header, transactions=transactions, header_signature=signature) return BatchList(batches=[batch])
def _wrap_and_send(self,address,action, amount, wait=None,uaddress=''): ''' create and send transactions in batches ''' raw_payload = ",".join([action, str(amount)]) payload = raw_payload.encode() input_and_output_address_list=[] if uaddress=='': input_and_output_address_list = [address] else: input_and_output_address_list=[address,uaddress] header = TransactionHeader( signer_public_key=self._public_key, family_name=FAMILY_NAME, family_version="1.0", inputs=input_and_output_address_list, outputs=input_and_output_address_list, dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._public_key, nonce=random.random().hex().encode() ).SerializeToString() transaction = Transaction( header=header, payload=payload, header_signature=self._signer.sign(header) ) transaction_list = [transaction] header = BatchHeader( signer_public_key=self._public_key, transaction_ids=[txn.header_signature for txn in transaction_list] ).SerializeToString() batch = Batch( header=header, transactions=transaction_list, header_signature=self._signer.sign(header)) batch_list = BatchList(batches=[batch]) batch_id = batch_list.batches[0].header_signature result = self._send_to_rest_api("batches", batch_list.SerializeToString(), 'application/octet-stream') return self._wait_for_status(batch_id, wait, result)
def wrap_and_send(self, data_dict): payload = json.dumps(data_dict).encode() address = self._address inputAddressList = [address] outputAddresslist = [address] relate_address = data_dict.get('address', []) for re_address in relate_address: # if relate_address: inputAddressList.append(wrap_address(re_address)) outputAddresslist.append(wrap_address(re_address)) header = TransactionHeader( signer_public_key=self._public_key, family_name=FAMILY_NAME, family_version='1.0', inputs=inputAddressList, outputs=outputAddresslist, dependencies=[], payload_sha512=_hash(payload.decode()), batcher_public_key=self._public_key, nonce=time.time().hex().encode() ).SerializeToString() transaction = Transaction( header=header, payload=payload, header_signature=self._signer.sign(header) ) transactionList = [transaction] header = BatchHeader( signer_public_key=self._public_key, transaction_ids=[txn.header_signature for txn in transactionList] ).SerializeToString() batch = Batch( header=header, transactions=transactionList, header_signature=self._signer.sign(header) ) batch_list_serialize = BatchList(batches=[batch]).SerializeToString() return self._send_to_restapi('batches', batch_list_serialize, 'application/octet-stream')
def _wrap_and_send(self, action, value): # Generate a csv utf-8 encoded string as payload payload = ",".join([action, str(value)]).encode() # Construct the address where we'll store our state address = self._address # Create a TransactionHeader header = TransactionHeader( signer_public_key=self._publicKey, family_name=FAMILY_NAME, family_version="1.0", inputs=[address], outputs=[address], dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._publicKey, nonce=time.time().hex().encode()).SerializeToString() # Create a Transaction from the header and payload above transaction = Transaction(header=header, payload=payload, header_signature=self._signer.sign(header)) transactionList = [transaction] # Create a BatchHeader from TransactionList above header = BatchHeader( signer_public_key=self._publicKey, transaction_ids=[txn.header_signature for txn in transactionList]).SerializeToString() #Create Batch using the BatchHeader and transactionList above batch = Batch(header=header, transactions=transactionList, header_signature=self._signer.sign(header)) #Create a Batch List from Batch above batch_list = BatchList(batches=[batch]) # Create a batch id # batch_id = batch_list.batches[0].header_signature # Send batch_list to rest-api return self._send_to_restapi("batches", batch_list.SerializeToString(), 'application/octet-stream')
def make_batch(txn, signer): print('Creating Batch...', end='', flush=True) transactions = [txn] batch_header = BatchHeader( signer_public_key=signer.get_public_key().as_hex(), transaction_ids=[txn.header_signature for txn in transactions], ).SerializeToString() signature = signer.sign(batch_header) batch = Batch(header=batch_header, header_signature=signature, transactions=transactions) print('[OK]') return batch
def wrap_and_send(self, data_dict): # rawPayload = action # for val in values: # rawPayload = ",".join([rawPayload, str(val)]) payload = json.dumps(data_dict).encode() address = self._address inputAddressList = [address] outputAddressList = [address] header = TransactionHeader( signer_public_key=self._publicKey, family_name=FAMILY_NAME, family_version="1.0", inputs=inputAddressList, outputs=outputAddressList, dependencies=[], payload_sha512=_hash(payload), batcher_public_key=self._publicKey, nonce=time.time().hex().encode() ).SerializeToString() transaction = Transaction( header=header, payload=payload, header_signature=self._signer.sign(header) ) transactionList = [transaction] header = BatchHeader( signer_public_key=self._publicKey, transaction_ids=[txn.header_signature for txn in transactionList] ).SerializeToString() batch = Batch( header=header, transactions=transactionList, header_signature=self._signer.sign(header)) batch_list = BatchList(batches=[batch]) return self._send_to_restapi( "batches", batch_list.SerializeToString(), 'application/octet-stream')
def create_batch(self, signer, txn): '''Bundles together a batch that includes txn and is signed by given signer''' batch_header_bytes = BatchHeader( signer_public_key=signer.pubkey.serialize().hex(), transaction_ids=[txn.header_signature], ).SerializeToString() batch_signature = signer.ecdsa_sign(batch_header_bytes) batch_signature_bytes = signer.ecdsa_serialize_compact(batch_signature) signature = batch_signature_bytes.hex() batch = Batch(header=batch_header_bytes, header_signature=signature, transactions=[txn]) batch_list_bytes = BatchList(batches=[batch]).SerializeToString() return batch_list_bytes
def postAsBatch(self, url, Transactions = []): # Create a BatchHeader from transactionList above print("posting batches", flush=True) header = BatchHeader( signer_public_key=self.publicKey, transaction_ids=[txn.header_signature for txn in Transactions] ).SerializeToString() # Create Batch using the BatchHeader and transactionList above batch = Batch( header=header, transactions=Transactions, header_signature=self.signer.sign(header)) # Create a Batch List from Batch above batch_list_bytes = BatchList(batches=[batch]).SerializeToString() #sending the batch to the rest api response = postData(url,batch_list_bytes) print("Transaction addresses", Transactions) return response
def _create_batch_list(self, transactions): if len(transactions) < 1: self.log( "Attempting to create batch with no transactions, ignoring") return None 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 BatchList(batches=[batch])