forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ArtObr <[email protected]>
- Loading branch information
Showing
19 changed files
with
516 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 72 additions & 1 deletion
73
indy_node/server/request_handlers/read_req_handlers/get_attribute_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,76 @@ | ||
from indy_common.state import domain | ||
|
||
from indy_common.constants import ATTRIB, GET_ATTR | ||
|
||
from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler | ||
from indy_node.server.request_handlers.utils import validate_attrib_keys | ||
from plenum.common.constants import RAW, ENC, HASH, TARGET_NYM, DOMAIN_LEDGER_ID | ||
from plenum.common.exceptions import InvalidClientRequest | ||
from plenum.common.request import Request | ||
from plenum.common.txn_util import get_request_data | ||
from plenum.server.database_manager import DatabaseManager | ||
from stp_core.common.log import getlogger | ||
|
||
logger = getlogger() | ||
|
||
|
||
class GetAttributeHandler(ReadRequestHandler): | ||
pass | ||
|
||
def __init__(self, database_manager: DatabaseManager): | ||
super().__init__(database_manager, GET_ATTR, DOMAIN_LEDGER_ID) | ||
|
||
def get_result(self, request: Request): | ||
self._validate_request_type(request) | ||
identifier, req_id, operation = get_request_data(request) | ||
if not validate_attrib_keys(operation): | ||
raise InvalidClientRequest(identifier, req_id, | ||
'{} should have one and only one of ' | ||
'{}, {}, {}' | ||
.format(ATTRIB, RAW, ENC, HASH)) | ||
nym = operation[TARGET_NYM] | ||
if RAW in operation: | ||
attr_type = RAW | ||
elif ENC in operation: | ||
# If attribute is encrypted, it will be queried by its hash | ||
attr_type = ENC | ||
else: | ||
attr_type = HASH | ||
attr_key = operation[attr_type] | ||
value, last_seq_no, last_update_time, proof = \ | ||
self.get_attr(did=nym, key=attr_key, attr_type=attr_type) | ||
attr = None | ||
if value is not None: | ||
if HASH in operation: | ||
attr = attr_key | ||
else: | ||
attr = value | ||
return self.make_result(request=request, | ||
data=attr, | ||
last_seq_no=last_seq_no, | ||
update_time=last_update_time, | ||
proof=proof) | ||
|
||
def get_attr(self, | ||
did: str, | ||
key: str, | ||
attr_type, | ||
is_committed=True) -> (str, int, int, list): | ||
assert did is not None | ||
assert key is not None | ||
path = domain.make_state_path_for_attr(did, key, attr_type == HASH) | ||
try: | ||
hashed_val, last_seq_no, last_update_time, proof = \ | ||
self.lookup(path, is_committed, with_proof=True) | ||
except KeyError: | ||
return None, None, None, None | ||
if not hashed_val or hashed_val == '': | ||
# Its a HASH attribute | ||
return hashed_val, last_seq_no, last_update_time, proof | ||
else: | ||
try: | ||
value = self.database_manager.attribute_store.get(hashed_val) | ||
except KeyError: | ||
logger.error('Could not get value from attribute store for {}' | ||
.format(hashed_val)) | ||
return None, None, None, None | ||
return value, last_seq_no, last_update_time, proof |
48 changes: 47 additions & 1 deletion
48
indy_node/server/request_handlers/read_req_handlers/get_claim_def_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
from indy_common.state import domain | ||
|
||
from indy_common.constants import CLAIM_DEF_SIGNATURE_TYPE, GET_CLAIM_DEF | ||
from indy_common.req_utils import get_read_claim_def_from, get_read_claim_def_signature_type, \ | ||
get_read_claim_def_schema_ref, get_read_claim_def_tag | ||
|
||
from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler | ||
from plenum.common.constants import DOMAIN_LEDGER_ID | ||
from plenum.common.request import Request | ||
from plenum.server.database_manager import DatabaseManager | ||
|
||
|
||
class GetClaimDefHandler(ReadRequestHandler): | ||
pass | ||
|
||
def __init__(self, database_manager: DatabaseManager): | ||
super().__init__(database_manager, GET_CLAIM_DEF, DOMAIN_LEDGER_ID) | ||
|
||
def get_result(self, request: Request): | ||
self._validate_request_type(request) | ||
frm = get_read_claim_def_from(request) | ||
signature_type = get_read_claim_def_signature_type(request) | ||
schema_ref = get_read_claim_def_schema_ref(request) | ||
tag = get_read_claim_def_tag(request) | ||
keys, last_seq_no, last_update_time, proof = self.get_claim_def( | ||
author=frm, | ||
schema_seq_no=schema_ref, | ||
signature_type=signature_type, | ||
tag=tag | ||
) | ||
result = self.make_result(request=request, | ||
data=keys, | ||
last_seq_no=last_seq_no, | ||
update_time=last_update_time, | ||
proof=proof) | ||
result[CLAIM_DEF_SIGNATURE_TYPE] = signature_type | ||
return result | ||
|
||
def get_claim_def(self, | ||
author: str, | ||
schema_seq_no: str, | ||
signature_type, | ||
tag, | ||
is_committed=True) -> (str, int, int, list): | ||
assert author is not None | ||
assert schema_seq_no is not None | ||
path = domain.make_state_path_for_claim_def(author, schema_seq_no, signature_type, tag) | ||
try: | ||
keys, seq_no, last_update_time, proof = self.lookup(path, is_committed, with_proof=True) | ||
return keys, seq_no, last_update_time, proof | ||
except KeyError: | ||
return None, None, None, None |
39 changes: 38 additions & 1 deletion
39
indy_node/server/request_handlers/read_req_handlers/get_nym_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
from indy_common.constants import GET_NYM | ||
|
||
from common.serializers.serialization import domain_state_serializer | ||
from indy_common.state import domain | ||
from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler | ||
|
||
from plenum.common.constants import TARGET_NYM, TXN_TIME, DOMAIN_LEDGER_ID | ||
from plenum.common.request import Request | ||
from plenum.common.types import f | ||
from plenum.server.database_manager import DatabaseManager | ||
|
||
|
||
class GetNymHandler(ReadRequestHandler): | ||
pass | ||
|
||
def __init__(self, database_manager: DatabaseManager): | ||
super().__init__(database_manager, GET_NYM, DOMAIN_LEDGER_ID) | ||
|
||
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 |
24 changes: 23 additions & 1 deletion
24
indy_node/server/request_handlers/read_req_handlers/get_revoc_reg_def_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
from indy_common.constants import ID, GET_REVOC_REG_DEF | ||
|
||
from indy_node.server.request_handlers.read_request_handler import ReadRequestHandler | ||
from plenum.common.constants import DOMAIN_LEDGER_ID | ||
from plenum.common.request import Request | ||
from plenum.server.database_manager import DatabaseManager | ||
|
||
|
||
class GetRevocRegDefHandler(ReadRequestHandler): | ||
pass | ||
|
||
def __init__(self, database_manager: DatabaseManager): | ||
super().__init__(database_manager, GET_REVOC_REG_DEF, DOMAIN_LEDGER_ID) | ||
|
||
def get_result(self, request: Request): | ||
self._validate_request_type(request) | ||
state_path = request.operation.get(ID, None) | ||
assert state_path | ||
try: | ||
keys, last_seq_no, last_update_time, proof = self.lookup(state_path, isCommitted=True, with_proof=True) | ||
except KeyError: | ||
keys, last_seq_no, last_update_time, proof = None, None, None, None | ||
result = self.make_result(request=request, | ||
data=keys, | ||
last_seq_no=last_seq_no, | ||
update_time=last_update_time, | ||
proof=proof) | ||
return result |
Oops, something went wrong.