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_fill_ts_store_after_catchup(txnPoolNodeSet, looper, sdk_pool_handle, sdk_wallet_steward, tconf, tdir, allPluginsPath): sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 5) node_to_disconnect = txnPoolNodeSet[-1] disconnect_node_and_ensure_disconnected(looper, txnPoolNodeSet, node_to_disconnect) looper.removeProdable(name=node_to_disconnect.name) sdk_replies = sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 2) node_to_disconnect = start_stopped_node(node_to_disconnect, looper, tconf, tdir, allPluginsPath) txnPoolNodeSet[-1] = node_to_disconnect looper.run(checkNodesConnected(txnPoolNodeSet)) waitNodeDataEquality(looper, node_to_disconnect, *txnPoolNodeSet, exclude_from_check=['check_last_ordered_3pc_backup']) req_handler = node_to_disconnect.read_manager.request_handlers[GET_BUY] for reply in sdk_replies: key = BuyHandler.prepare_buy_key(get_from(reply[1]['result']), get_req_id(reply[1]['result'])) root_hash = req_handler.database_manager.ts_store.get_equal_or_prev( get_txn_time(reply[1]['result'])) assert root_hash from_state = req_handler.state.get_for_root_hash(root_hash=root_hash, key=key) assert domain_state_serializer.deserialize(from_state)['amount'] == \ get_payload_data(reply[1]['result'])['amount']
def test_state_proof_returned_for_get_nym(looper, nodeSetWithOneNodeResponding, sdk_user_wallet_a, sdk_pool_handle, sdk_wallet_client, sdk_wallet_endorser): """ Tests that state proof is returned in the reply for GET_NYM transactions. Use different submitter and reader! """ _, dest = sdk_user_wallet_a nym_operation = {TARGET_NYM: dest, TXN_TYPE: NYM} sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, nym_operation) get_nym_operation = {TARGET_NYM: dest, TXN_TYPE: GET_NYM} result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_client, get_nym_operation) assert DATA in result assert result[DATA] data = domain_state_serializer.deserialize(result[DATA]) assert ROLE in data assert VERKEY in data assert f.IDENTIFIER.nm in data assert result[TXN_TIME] check_valid_proof(result)
def test_state_proof_returned_for_get_nym(looper, trustAnchor, trustAnchorWallet, userWalletA, client1, wallet1): """ Tests that state proof is returned in the reply for GET_NYM transactions. Use different submitter and reader! """ dest = userWalletA.defaultId nym_operation = {TARGET_NYM: dest, TXN_TYPE: NYM} submit_operation_and_get_replies(looper, trustAnchorWallet, trustAnchor, nym_operation) get_nym_operation = {TARGET_NYM: dest, TXN_TYPE: GET_NYM} replies = submit_operation_and_get_replies(looper, wallet1, client1, get_nym_operation) for reply in replies: result = reply['result'] assert DATA in result assert result[DATA] data = domain_state_serializer.deserialize(result[DATA]) assert ROLE in data assert VERKEY in data assert f.IDENTIFIER.nm in data assert result[TXN_TIME] check_valid_proof(reply, client1)
def prepare_nym_for_state(txn): # TODO: this is semi-duplicated in plenum.DomainRequestHandler data = txn.get(DATA) parsed = domain_state_serializer.deserialize(data) parsed.pop(TARGET_NYM, None) value = domain_state_serializer.serialize(parsed) nym = txn[TARGET_NYM] key = make_state_path_for_nym(nym) return key, value
def prepare_get_nym_for_state(txn): data = txn.get(DATA) value = None if data is not None: parsed = domain_state_serializer.deserialize(data) parsed.pop(TARGET_NYM, None) value = domain_state_serializer.serialize(parsed) nym = txn[TARGET_NYM] key = make_state_path_for_nym(nym) return key, value
def prepare_get_nym_for_state(reply): data = reply.get(DATA) value = None if data is not None: parsed = domain_state_serializer.deserialize(data) parsed.pop(TARGET_NYM, None) value = domain_state_serializer.serialize(parsed) nym = reply[TARGET_NYM] key = make_state_path_for_nym(nym) return key, value
def test_state_proof_returned_for_get_nym(looper, trustAnchor, trustAnchorWallet, userWalletA): """ Tests that state proof is returned in the reply for GET_NYM transactions """ client = trustAnchor dest = userWalletA.defaultId nym = { TARGET_NYM: dest, TXN_TYPE: NYM } nym_request = trustAnchorWallet.signOp(nym) trustAnchorWallet.pendRequest(nym_request) pending = trustAnchorWallet.preparePending() client.submitReqs(*pending) get_nym_operation = { TARGET_NYM: dest, TXN_TYPE: GET_NYM } get_nym_request = trustAnchorWallet.signOp(get_nym_operation) trustAnchorWallet.pendRequest(get_nym_request) pending = trustAnchorWallet.preparePending() client.submitReqs(*pending) waitForSufficientRepliesForRequests(looper, trustAnchor, requests=pending) replies = getRepliesFromClientInbox(client.inBox, get_nym_request.reqId) for reply in replies: result = reply['result'] assert DATA in result assert result[DATA] data = domain_state_serializer.deserialize(result[DATA]) assert ROLE in data assert VERKEY in data assert f.IDENTIFIER.nm in data assert result[TXN_TIME] check_valid_proof(reply, client)
def get_nym_verify_proof(read_manager, db_manager, nym, data, multi_sig): request = Request(operation={ TARGET_NYM: nym, TXN_TYPE: GET_NYM, }, signatures={}, protocolVersion=CURRENT_PROTOCOL_VERSION) result = read_manager.get_result(request) proof = extract_proof(result, multi_sig) result_data = None assert proof if data: assert result[DATA] result_data = domain_state_serializer.deserialize(result[DATA]) data_from_req = copy.copy(result_data) data_from_req.pop(f.IDENTIFIER.nm, None) data_from_req.pop(f.SEQ_NO.nm, None) data_from_req.pop(TXN_TIME, None) assert data_from_req == data # Verifying signed state proof path = nym_to_state_key(nym) # If the value does not exist, serialization should be null and # verify_state_proof needs to be given null (None). This is done to # differentiate between absence of value and presence of empty string value if result_data: data.pop(TARGET_NYM, None) data.update({ f.IDENTIFIER.nm: result_data[f.IDENTIFIER.nm], f.SEQ_NO.nm: result_data[f.SEQ_NO.nm], TXN_TIME: result_data[TXN_TIME] }) serialized_value = domain_state_serializer.serialize( data) if data else None proof_nodes = base64.b64decode(proof[PROOF_NODES]) root_hash = base58.b58decode(proof[ROOT_HASH]) return db_manager.get_state(DOMAIN_LEDGER_ID).verify_state_proof( root_hash, path, serialized_value, proof_nodes, serialized=True)
def test_state_proof_returned_for_get_nym(looper, sdk_user_wallet_a, sdk_pool_handle, sdk_wallet_client, sdk_wallet_trust_anchor): """ Tests that state proof is returned in the reply for GET_NYM transactions. Use different submitter and reader! """ _, dest = sdk_user_wallet_a nym_operation = { TARGET_NYM: dest, TXN_TYPE: NYM } sdk_submit_operation_and_get_replies(looper, sdk_pool_handle, sdk_wallet_trust_anchor, nym_operation) get_nym_operation = { TARGET_NYM: dest, TXN_TYPE: GET_NYM } replies = sdk_submit_operation_and_get_replies(looper, sdk_pool_handle, sdk_wallet_client, get_nym_operation) for reply in replies: result = reply[1]['result'] assert DATA in result assert result[DATA] data = domain_state_serializer.deserialize(result[DATA]) assert ROLE in data assert VERKEY in data assert f.IDENTIFIER.nm in data assert result[TXN_TIME] check_valid_proof(reply[1])
def test_state_proof_returned_for_get_nym(looper, trustAnchor, trustAnchorWallet, userWalletA, client1, wallet1): """ Tests that state proof is returned in the reply for GET_NYM transactions. Use different submitter and reader! """ dest = userWalletA.defaultId nym_operation = { TARGET_NYM: dest, TXN_TYPE: NYM } submit_operation_and_get_replies(looper, trustAnchorWallet, trustAnchor, nym_operation) get_nym_operation = { TARGET_NYM: dest, TXN_TYPE: GET_NYM } replies = submit_operation_and_get_replies(looper, wallet1, client1, get_nym_operation) for reply in replies: result = reply['result'] assert DATA in result assert result[DATA] data = domain_state_serializer.deserialize(result[DATA]) assert ROLE in data assert VERKEY in data assert f.IDENTIFIER.nm in data assert result[TXN_TIME] check_valid_proof(reply, client1)
def _decode_state_value(self, encoded): if encoded: return domain_state_serializer.deserialize(encoded) return None, None, None
def decode_state_value(ecnoded_value): decoded = domain_state_serializer.deserialize(ecnoded_value) value = decoded.get(VALUE) last_seq_no = decoded.get(LAST_SEQ_NO) last_update_time = decoded.get(LAST_UPDATE_TIME) return value, last_seq_no, last_update_time
def get_nym_details(state, nym, is_committed: bool = False): key = nym_to_state_key(nym) data = state.get(key, is_committed) if not data: return {} return domain_state_serializer.deserialize(data)