def gen_txn_path(self, txn): """Return path to state as 'str' type or None""" txn_type = get_type(txn) if txn_type not in self.state_update_handlers: logger.error('Cannot generate id for txn of type {}'.format(txn_type)) return None if txn_type == NYM: nym = get_payload_data(txn).get(TARGET_NYM) binary_digest = domain.make_state_path_for_nym(nym) return hexlify(binary_digest).decode() elif txn_type == ATTRIB: path = domain.prepare_attr_for_state(txn, path_only=True) return path.decode() elif txn_type == SCHEMA: path = domain.prepare_schema_for_state(txn, path_only=True) return path.decode() elif txn_type == CLAIM_DEF: path = domain.prepare_claim_def_for_state(txn, path_only=True) return path.decode() elif txn_type == REVOC_REG_DEF: path = domain.prepare_revoc_def_for_state(txn, path_only=True) return path.decode() elif txn_type == REVOC_REG_ENTRY: path = domain.prepare_revoc_reg_entry_for_state(txn, path_only=True) return path.decode() raise NotImplementedError("path construction is not implemented for type {}".format(txn_type))
def handleGetNymReq(self, request: Request): nym = request.operation[TARGET_NYM] nymData = self.idrCache.getNym(nym, isCommitted=True) path = domain.make_state_path_for_nym(nym) if nymData: nymData[TARGET_NYM] = nym data = self.stateSerializer.serialize(nymData) seq_no = nymData[f.SEQ_NO.nm] update_time = nymData[TXN_TIME] proof = self.make_proof(path) else: data = None seq_no = None proof = self.make_proof(path) update_time = None # TODO: add update time here! result = self.make_result(request=request, data=data, last_seq_no=seq_no, update_time=update_time, proof=proof) result.update(request.operation) return result
def get_result(self, request: Request): self._validate_request_type(request) nym = request.operation[TARGET_NYM] path = domain.make_state_path_for_nym(nym) nym_data, proof = self._get_value_from_state(path, with_proof=True) if nym_data: nym_data = domain_state_serializer.deserialize(nym_data) nym_data[TARGET_NYM] = nym data = domain_state_serializer.serialize(nym_data) seq_no = nym_data[f.SEQ_NO.nm] update_time = nym_data[TXN_TIME] else: data = None seq_no = None update_time = None # TODO: add update time here! result = self.make_result(request=request, data=data, last_seq_no=seq_no, update_time=update_time, proof=proof) result.update(request.operation) return result
def test_idr_cache_update_after_catchup(txnPoolNodeSet, looper, sdk_pool_handle, sdk_wallet_steward, tconf, tdir, allPluginsPath): wallet_handle, identifier = sdk_wallet_steward node_to_disconnect = txnPoolNodeSet[-1] disconnect_node_and_ensure_disconnected(looper, txnPoolNodeSet, node_to_disconnect.name, stopNode=True) looper.removeProdable(node_to_disconnect) idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey() request = looper.loop.run_until_complete( build_nym_request(identifier, idr, verkey, None, None)) req_signed = looper.loop.run_until_complete( sign_request(wallet_handle, identifier, request)) result = json.loads( looper.loop.run_until_complete( submit_request(sdk_pool_handle, req_signed))) restarted_node = start_stopped_node(node_to_disconnect, looper, tconf, tdir, allPluginsPath) txnPoolNodeSet[-1] = restarted_node waitNodeDataEquality(looper, restarted_node, *txnPoolNodeSet[:-1]) req_handler = restarted_node.get_req_handler(DOMAIN_LEDGER_ID) root_hash = req_handler.ts_store.get_equal_or_prev( get_txn_time(result['result'])) key = domain.make_state_path_for_nym(idr) from_state = req_handler.state.get_for_root_hash(root_hash=root_hash, key=key) assert from_state deserialized = req_handler.stateSerializer.deserialize(from_state) assert deserialized items_after = req_handler.idrCache.get(idr) assert items_after
def gen_txn_path(txn, attr_store): txn_type = get_type(txn) if txn_type not in DomainReqHandler.write_types: return None if txn_type == NYM: nym = get_payload_data(txn).get(TARGET_NYM) binary_digest = domain.make_state_path_for_nym(nym) return hexlify(binary_digest).decode() elif txn_type == ATTRIB: attr_data = get_payload_data(txn) if RAW in attr_data or ENC in attr_data: attr_type = RAW if RAW in attr_data else ENC attr = attr_store.get(attr_data[attr_type]) copy_txn = copy.deepcopy(txn) copy_txn[TXN_PAYLOAD][TXN_PAYLOAD_DATA][attr_type] = attr path = domain.prepare_attr_for_state(copy_txn, path_only=True) return path.decode() if HASH in attr_data: path = domain.prepare_attr_for_state(txn, path_only=True) return path.decode() elif txn_type == SCHEMA: path = domain.prepare_schema_for_state(txn, path_only=True) return path.decode() elif txn_type == CLAIM_DEF: path = domain.prepare_claim_def_for_state(txn, path_only=True) return path.decode() elif txn_type == REVOC_REG_DEF: path = domain.prepare_revoc_def_for_state(txn, path_only=True) return path.decode() elif txn_type == REVOC_REG_ENTRY: path = domain.prepare_revoc_reg_entry_for_state(txn, path_only=True) return path.decode()
def test_idr_cache_update_after_catchup(txnPoolNodeSet, looper, sdk_pool_handle, sdk_wallet_steward): wallet_handle, identifier = sdk_wallet_steward node_to_disconnect = txnPoolNodeSet[-1] req_handler = node_to_disconnect.getDomainReqHandler() disconnect_node_and_ensure_disconnected(looper, txnPoolNodeSet, node_to_disconnect.name, stopNode=False) looper.runFor(2) idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey() request = looper.loop.run_until_complete(build_nym_request(identifier, idr, verkey, None, None)) req_signed = looper.loop.run_until_complete(sign_request(wallet_handle, identifier, request)) result = json.loads(looper.loop.run_until_complete(submit_request(sdk_pool_handle, req_signed))) reconnect_node_and_ensure_connected(looper, txnPoolNodeSet, node_to_disconnect.name) waitNodeDataEquality(looper, node_to_disconnect, *txnPoolNodeSet) key = domain.make_state_path_for_nym(idr) root_hash = req_handler.ts_store.get_equal_or_prev(result['result']['txnTime']) from_state = req_handler.state.get_for_root_hash(root_hash=root_hash, key=key) assert from_state deserialized = req_handler.stateSerializer.deserialize(from_state) assert deserialized items_after = req_handler.idrCache.get(idr) assert items_after
def test_idr_cache_update_after_catchup(txnPoolNodeSet, looper, sdk_pool_handle, sdk_wallet_steward, tconf, tdir, allPluginsPath): wallet_handle, identifier = sdk_wallet_steward node_to_disconnect = txnPoolNodeSet[-1] disconnect_node_and_ensure_disconnected(looper, txnPoolNodeSet, node_to_disconnect.name, stopNode=True) looper.removeProdable(node_to_disconnect) idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey() request = looper.loop.run_until_complete(build_nym_request(identifier, idr, verkey, None, None)) req_signed = looper.loop.run_until_complete(sign_request(wallet_handle, identifier, request)) result = json.loads(looper.loop.run_until_complete(submit_request(sdk_pool_handle, req_signed))) restarted_node = start_stopped_node(node_to_disconnect, looper, tconf, tdir, allPluginsPath) txnPoolNodeSet[-1] = restarted_node waitNodeDataEquality(looper, restarted_node, *txnPoolNodeSet[:-1]) req_handler = restarted_node.getDomainReqHandler() root_hash = req_handler.ts_store.get_equal_or_prev(get_txn_time(result['result'])) key = domain.make_state_path_for_nym(idr) from_state = req_handler.state.get_for_root_hash(root_hash=root_hash, key=key) assert from_state deserialized = req_handler.stateSerializer.deserialize(from_state) assert deserialized items_after = req_handler.idrCache.get(idr) assert items_after
def gen_txn_path(txn): txn_type = get_type(txn) if txn_type not in DomainReqHandler.write_types: return None if txn_type == NYM: nym = get_payload_data(txn).get(TARGET_NYM) binary_digest = domain.make_state_path_for_nym(nym) return hexlify(binary_digest).decode() elif txn_type == ATTRIB: _, path, _, _, _ = domain.prepare_attr_for_state(txn) return path.decode() elif txn_type == SCHEMA: path, _ = domain.prepare_schema_for_state(txn) return path.decode() elif txn_type == CLAIM_DEF: path, _ = domain.prepare_claim_def_for_state(txn) return path.decode() elif txn_type == REVOC_REG_DEF: path, _ = domain.prepare_revoc_def_for_state(txn) return path.decode() elif txn_type == REVOC_REG_ENTRY: path, _ = domain.prepare_revoc_reg_entry_for_state(txn) return path.decode()
def handleGetNymReq(self, request: Request): nym = request.operation[TARGET_NYM] path = domain.make_state_path_for_nym(nym) nym_data, proof = self.get_value_from_state(path, with_proof=True) if nym_data: nym_data = self.stateSerializer.deserialize(nym_data) nym_data[TARGET_NYM] = nym data = self.stateSerializer.serialize(nym_data) seq_no = nym_data[f.SEQ_NO.nm] update_time = nym_data[TXN_TIME] else: data = None seq_no = None update_time = None # TODO: add update time here! result = self.make_result(request=request, data=data, last_seq_no=seq_no, update_time=update_time, proof=proof) result.update(request.operation) return result
def gen_state_key(self, txn): self._validate_txn_type(txn) nym = get_payload_data(txn).get(TARGET_NYM) binary_digest = domain.make_state_path_for_nym(nym) return hexlify(binary_digest).decode()