def submit_initialize_transaction(self, ledger_config, **extra_params): """submit the initialize transaction to the ledger """ if self.status is False: raise Exception( 'attempt to submit failed initialization transactions') global transaction_dependencies # an initialize operation has no previous state assert not self.old_state_hash initialize_submitter = Submitter(ledger_config['LedgerURL'], key_str=self.channel_keys.txn_private) b64_message_hash = crypto.byte_array_to_base64(self.message_hash) b64_new_state_hash = crypto.byte_array_to_base64(self.new_state_hash) b64_code_hash = crypto.byte_array_to_base64(self.code_hash) txnid = initialize_submitter.submit_ccl_initialize_from_data( self.originator_keys.signing_key, self.originator_keys.verifying_key, self.channel_keys.txn_public, self.enclave_service.enclave_id, self.signature, self.contract_id, b64_message_hash, b64_new_state_hash, self.encrypted_state, b64_code_hash, **extra_params) if txnid: transaction_dependencies.SaveDependency(self.contract_id, b64_new_state_hash, txnid) return txnid
def register_enclave(self, ledger_config): """ register the enclave with the sawtooth ledger :param ledger_config: dictionary of configuration information that must include LedgerURL """ try: logger.debug('submit enclave registration to %s', ledger_config['LedgerURL']) submitter = Submitter(ledger_config['LedgerURL'], key_str=self.txn_keys.txn_private) txnsignature = submitter.submit_enclave_registration_from_data( self.verifying_key, self.encryption_key, self.proof_data, self.nonce, ledger_config.get('Organization', "EMPTY"), wait=30.0) except TimeoutError as err: raise Exception('time out waiting for ledger commit') except Exception as e: logger.error('failed to register enclave; %s', str(e)) raise return txnsignature
def add_enclave_to_contract(ledger_config, creator_keys, contract_id, enclave_id, secrets, encrypted_state_encryption_key, signature, **extra_params): txn_keys = keys.TransactionKeys() enclave_secret_data_array = [] enclave_secret_data = dict() enclave_secret_data['contract_id'] = contract_id enclave_secret_data['contract_enclave_id'] = enclave_id enclave_secret_data[ 'encrypted_state_encryption_key'] = encrypted_state_encryption_key enclave_secret_data['signature'] = signature secret_list = [] for secret in secrets: secret_list.append(secret) enclave_secret_data['provisioning_key_state_secret_pairs'] = secret_list enclave_secret_data_array.append(enclave_secret_data) if 'wait' not in extra_params: extra_params['wait'] = 60 ss = Submitter(ledger_config['LedgerURL'], key_str=txn_keys.txn_private) txnsignature = ss.submit_add_enclave_from_data(creator_keys.signing_key, txn_keys.txn_public, contract_id, enclave_secret_data_array, **extra_params) return txnsignature
def submit_update_transaction(self, ledger_config, **extra_params): """submit the update transaction to the ledger """ global transaction_dependencies # there must be a previous state hash if this is # an update assert self.old_state_hash update_submitter = Submitter(ledger_config['LedgerURL'], key_str=self.channel_keys.txn_private) b64_message_hash = crypto.byte_array_to_base64(self.message_hash) b64_new_state_hash = crypto.byte_array_to_base64(self.new_state_hash) b64_old_state_hash = crypto.byte_array_to_base64(self.old_state_hash) # convert contract dependencies into transaction dependencies # to ensure that the sawtooth validator does not attempt to # re-order the transactions since it is unaware of the semantics # of the contract dependencies txn_dependencies = set() if extra_params.get('transaction_dependency_list'): txn_dependencies.update( extra_params['transaction_dependency_list']) txnid = transaction_dependencies.FindDependency( ledger_config, self.contract_id, b64_old_state_hash) if txnid: txn_dependencies.add(txnid) for dependency in self.dependencies: contract_id = dependency['contract_id'] state_hash = dependency['state_hash'] txnid = transaction_dependencies.FindDependency( ledger_config, contract_id, state_hash) if txnid: txn_dependencies.add(txnid) if txn_dependencies: extra_params['transaction_dependency_list'] = list( txn_dependencies) # now send off the transaction to the ledger txnid = update_submitter.submit_ccl_update_from_data( self.originator_keys.verifying_key, self.channel_keys.txn_public, self.enclave_service.enclave_id, self.signature, self.contract_id, b64_message_hash, b64_new_state_hash, b64_old_state_hash, self.encrypted_state, self.dependencies, **extra_params) if txnid: transaction_dependencies.SaveDependency(self.contract_id, b64_new_state_hash, txnid) return txnid
def register_contract(ledger_config, creator_keys, contract_code, provisioning_service_ids, **extra_params): txn_keys = keys.TransactionKeys() if 'wait' not in extra_params: extra_params['wait'] = 60 ss = Submitter(ledger_config['LedgerURL'], key_str=txn_keys.txn_private) txnsignature = ss.submit_contract_registration_from_data( creator_keys.signing_key, creator_keys.verifying_key, txn_keys.txn_public, crypto.byte_array_to_base64(contract_code.compute_hash()), provisioning_service_ids, **extra_params) contract_id = putils.from_transaction_signature_to_id(txnsignature) return contract_id
def __submit_update_transaction__(response, ledger_config, **extra_params): """submit the update transaction to the ledger """ if response.status is False: raise Exception('attempt to submit failed update transaction') # there must be a previous state hash if this is # an update assert response.old_state_hash update_submitter = Submitter(ledger_config['LedgerURL'], key_str=response.channel_keys.txn_private) b64_message_hash = crypto.byte_array_to_base64(response.message_hash) b64_new_state_hash = crypto.byte_array_to_base64(response.new_state_hash) b64_old_state_hash = crypto.byte_array_to_base64(response.old_state_hash) # get transaction dependency list from the input txn_dependencies = set() if extra_params.get('transaction_dependency_list'): txn_dependencies.update(extra_params['transaction_dependency_list']) raw_state = response.raw_state try: raw_state = raw_state.decode() except AttributeError: pass # now send off the transaction to the ledger txnid = update_submitter.submit_ccl_update_from_data( response.originator_keys.verifying_key, response.channel_keys.txn_public, response.enclave_service.enclave_id, response.signature, response.contract_id, b64_message_hash, b64_new_state_hash, b64_old_state_hash, raw_state, response.dependencies, **extra_params) if txnid: __lock_for_dependencies__.acquire() __dependencies__.SaveDependency(response.contract_id, b64_new_state_hash, txnid) __lock_for_dependencies__.release() return txnid
def __submit_initialize_transaction__(response, ledger_config, **extra_params): """submit the initialize transaction to the ledger """ if response.status is False: raise Exception('attempt to submit failed initialization transactions') # an initialize operation has no previous state assert not response.old_state_hash initialize_submitter = Submitter(ledger_config['LedgerURL'], key_str=response.channel_keys.txn_private) b64_message_hash = crypto.byte_array_to_base64(response.message_hash) b64_new_state_hash = crypto.byte_array_to_base64(response.new_state_hash) b64_code_hash = crypto.byte_array_to_base64(response.code_hash) raw_state = response.raw_state try: raw_state = raw_state.decode() except AttributeError: pass txnid = initialize_submitter.submit_ccl_initialize_from_data( response.originator_keys.signing_key, response.originator_keys.verifying_key, response.channel_keys.txn_public, response.enclave_service.enclave_id, response.signature, response.contract_id, b64_message_hash, b64_new_state_hash, raw_state, b64_code_hash, **extra_params) if txnid: __lock_for_dependencies__.acquire() __dependencies__.SaveDependency(response.contract_id, b64_new_state_hash, txnid) __lock_for_dependencies__.release() return txnid