本文整理汇总了Python中indy.error.IndyError方法的典型用法代码示例。如果您正苦于以下问题:Python error.IndyError方法的具体用法?Python error.IndyError怎么用?Python error.IndyError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indy.error
的用法示例。
在下文中一共展示了error.IndyError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sdk_get_reply
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def sdk_get_reply(looper, sdk_req_resp, timeout=None):
req_json, resp_task = sdk_req_resp
# TODO: change timeout evaluating logic, when sdk will can tuning timeout from outside
if timeout is None:
timeout = waits.expectedTransactionExecutionTime(7)
try:
resp = looper.run(asyncio.wait_for(resp_task, timeout=timeout))
resp = json.loads(resp)
except IndyError as e:
resp = e.error_code
except TimeoutError as e:
resp = ErrorCode.PoolLedgerTimeout
return req_json, resp
# TODO: Check places where sdk_get_replies used without sdk_check_reply
# We need to be sure that test behaviour don't need to check response
# validity
示例2: sdk_get_replies
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def sdk_get_replies(looper, sdk_req_resp: Sequence, timeout=None):
resp_tasks = [resp for _, resp in sdk_req_resp]
# TODO: change timeout evaluating logic, when sdk will can tuning timeout from outside
if timeout is None:
timeout = waits.expectedTransactionExecutionTime(7)
def get_res(task, done_list):
if task in done_list:
try:
resp = json.loads(task.result())
except IndyError as e:
resp = e.error_code
else:
resp = ErrorCode.PoolLedgerTimeout
return resp
done, pending = looper.run(asyncio.wait(resp_tasks, timeout=timeout))
if pending:
for task in pending:
task.cancel()
ret = [(req, get_res(resp, done)) for req, resp in sdk_req_resp]
return ret
示例3: close
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def close(self):
"""Close the pool ledger."""
if self.opened:
exc = None
for attempt in range(3):
try:
await indy.pool.close_pool_ledger(self.pool_handle)
except IndyError as err:
await asyncio.sleep(0.01)
exc = err
continue
self.pool_handle = None
self.opened = False
exc = None
break
if exc:
self.logger.error("Exception when closing pool ledger")
self.ref_count += 1 # if we are here, we should have self.ref_lock
self.close_task = None
raise IndyErrorHandler.wrap_error(
exc, "Exception when closing pool ledger", LedgerError
)
示例4: get_revoc_reg_def
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def get_revoc_reg_def(self, revoc_reg_id: str) -> dict:
"""Get revocation registry definition by ID."""
public_info = await self.wallet.get_public_did()
try:
fetch_req = await indy.ledger.build_get_revoc_reg_def_request(
public_info and public_info.did, revoc_reg_id
)
response_json = await self._submit(fetch_req, sign_did=public_info)
(
found_id,
found_def_json,
) = await indy.ledger.parse_get_revoc_reg_def_response(response_json)
except IndyError as e:
logging.error(
f"get_revoc_reg_def failed with revoc_reg_id={revoc_reg_id}. "
f"{e.error_code}: {e.message}"
)
raise e
assert found_id == revoc_reg_id
return json.loads(found_def_json)
示例5: get_credential
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def get_credential(self, credential_id: str) -> str:
"""
Get a credential stored in the wallet.
Args:
credential_id: Credential id to retrieve
"""
try:
credential_json = await indy.anoncreds.prover_get_credential(
self.wallet.handle, credential_id
)
except IndyError as err:
if err.error_code == ErrorCode.WalletItemNotFound:
raise WalletNotFoundError(
"Credential {} not found in wallet {}".format(
credential_id, self.wallet.name
)
)
else:
raise IndyErrorHandler.wrap_error(
err, f"Error when fetching credential {credential_id}", HolderError
) from err
return credential_json
示例6: remove
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def remove(self):
"""
Remove an existing wallet.
Raises:
WalletNotFoundError: If the wallet could not be found
WalletError: If there was an libindy error
"""
try:
await indy.wallet.delete_wallet(
config=json.dumps(self._wallet_config),
credentials=json.dumps(self._wallet_access),
)
except IndyError as x_indy:
if x_indy.error_code == ErrorCode.WalletNotFoundError:
raise IndyErrorHandler.wrap_error(
x_indy, "Wallet {} not found".format(self.name), WalletNotFoundError
) from x_indy
raise IndyErrorHandler.wrap_error(
x_indy, "Wallet error", WalletError
) from x_indy
示例7: get_signing_key
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def get_signing_key(self, verkey: str) -> KeyInfo:
"""
Fetch info for a signing keypair.
Args:
verkey: The verification key of the keypair
Returns:
A `KeyInfo` representing the keypair
Raises:
WalletNotFoundError: If no keypair is associated with the verification key
WalletError: If there is a libindy error
"""
try:
metadata = await indy.crypto.get_key_metadata(self.handle, verkey)
except IndyError as x_indy:
if x_indy.error_code == ErrorCode.WalletItemNotFound:
raise WalletNotFoundError("Unknown key: {}".format(verkey))
else:
raise IndyErrorHandler.wrap_error(
x_indy, "Wallet {} error".format(self.name), WalletError
) from x_indy
return KeyInfo(verkey, json.loads(metadata) if metadata else {})
示例8: add_record
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def add_record(self, record: StorageRecord):
"""
Add a new record to the store.
Args:
record: `StorageRecord` to be stored
"""
_validate_record(record)
tags_json = json.dumps(record.tags) if record.tags else None
try:
await non_secrets.add_wallet_record(
self._wallet.handle, record.type, record.id, record.value, tags_json
)
except IndyError as x_indy:
if x_indy.error_code == ErrorCode.WalletItemAlreadyExists:
raise StorageDuplicateError(
"Duplicate record ID: {}".format(record.id)
) from x_indy
raise StorageError(str(x_indy)) from x_indy
示例9: update_record_value
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def update_record_value(self, record: StorageRecord, value: str):
"""
Update an existing stored record's value.
Args:
record: `StorageRecord` to update
value: The new value
Raises:
StorageNotFoundError: If record not found
StorageError: If a libindy error occurs
"""
_validate_record(record)
try:
await non_secrets.update_wallet_record_value(
self._wallet.handle, record.type, record.id, value
)
except IndyError as x_indy:
if x_indy.error_code == ErrorCode.WalletItemNotFound:
raise StorageNotFoundError(f"Record not found: {record.id}")
raise StorageError(str(x_indy))
示例10: delete_record
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def delete_record(self, record: StorageRecord):
"""
Delete a record.
Args:
record: `StorageRecord` to delete
Raises:
StorageNotFoundError: If record not found
StorageError: If a libindy error occurs
"""
_validate_record(record)
try:
await non_secrets.delete_wallet_record(
self._wallet.handle, record.type, record.id
)
except IndyError as x_indy:
if x_indy.error_code == ErrorCode.WalletItemNotFound:
raise StorageNotFoundError(f"Record not found: {record.id}")
raise StorageError(str(x_indy))
示例11: open
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def open(self):
"""Start the search query."""
query_json = json.dumps(self.tag_query or {})
options_json = json.dumps(
{
"retrieveRecords": True,
"retrieveTotalCount": False,
"retrieveType": False,
"retrieveValue": True,
"retrieveTags": self.option("retrieveTags", True),
}
)
try:
self._handle = await non_secrets.open_wallet_search(
self.store.wallet.handle, self.type_filter, query_json, options_json
)
except IndyError as x_indy:
raise StorageSearchError(str(x_indy)) from x_indy
示例12: issue_credential_v1_0_issuer_create_credential_schema
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def issue_credential_v1_0_issuer_create_credential_schema(self, name: str, version: str, attrs: [str]) -> str:
(schema_id, schema) = await anoncreds.issuer_create_schema(
self.did, name, version, json.dumps(attrs))
try:
# Check to see if the schema is already on the ledger
request = await ledger.build_get_schema_request(self.did, schema_id)
response = await ledger.submit_request(self.pool, request)
resp = json.loads(response)
if resp["result"]["seqNo"]:
(_, schema) = await ledger.parse_get_schema_response(response)
return schema_id
except IndyError as e:
pass
# Try to write the schema to the ledger
schema_request = await ledger.build_schema_request(self.did, schema)
schema_request = await self._append_taa(schema_request)
await ledger.sign_and_submit_request(self.pool, self.wallet, self.did, schema_request)
return schema_id
示例13: did_for_key
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def did_for_key(wallet_handle, key):
""" Retrieve DID for a given key from the non_secrets verkey to DID map.
"""
_did = None
try:
_did = json.loads(
await non_secrets.get_wallet_record(
wallet_handle,
'key-to-did',
key,
'{}'
)
)['value']
except error.IndyError as e:
if e.error_code is error.ErrorCode.WalletItemNotFound:
pass
else:
raise e
return _did
示例14: set_did_metadata
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def set_did_metadata():
try:
print_log('\nOpening wallet ...\n')
print(wallet_config)
print(wallet_credentials)
wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials)
print_log('\nGenerating seed hash ...')
seed_hash = sha256(did_seed.encode()).hexdigest()
did_metadata = {**(metadata or {}), 'public': True, 'seed_hash': seed_hash}
print_log('\nWriting metadata for DID ...')
print_log('DID: ' + wallet_did)
print_log('Metadata: ' + json.dumps(did_metadata))
await did.set_did_metadata(wallet_handle, wallet_did, json.dumps(did_metadata))
except IndyError as e:
print('Error occurred: %s' % e)
示例15: submit_request
# 需要导入模块: from indy import error [as 别名]
# 或者: from indy.error import IndyError [as 别名]
def submit_request(
self, req_json: str, signed: bool = False, apply_taa=False
):
try:
if signed:
if not self._did:
raise AnchorException("Cannot sign request: no DID")
req = json.loads(req_json)
if apply_taa and self._taa_accept:
req["taaAcceptance"] = self._taa_accept
signer = SimpleSigner(self._did, self._seed)
req["signature"] = signer.sign(req)
req_json = json.dumps(req)
rv_json = await ledger.submit_request(self._pool, req_json)
await asyncio.sleep(0)
except IndyError as e:
raise AnchorException("Error submitting ledger transaction request") from e
resp = json.loads(rv_json)
if resp.get("op", "") in ("REQNACK", "REJECT"):
raise AnchorException(
"Ledger rejected transaction request: {}".format(resp["reason"])
)
return resp