Skip to content

Commit

Permalink
Merge branch 'main' into endorser-did-support
Browse files Browse the repository at this point in the history
  • Loading branch information
ianco authored Jan 20, 2022
2 parents 1b05b33 + fecb0a8 commit 010d674
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ async def receive_problem_report(
)
)

cred_ex_record.state = None
cred_ex_record.state = V10CredentialExchange.STATE_ABANDONED
code = message.description.get(
"code",
ProblemReportReason.ISSUANCE_ABANDONED.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Meta:
STATE_CREDENTIAL_RECEIVED = "credential_received"
STATE_ACKED = "credential_acked"
STATE_CREDENTIAL_REVOKED = "credential_revoked"
STATE_ABANDONED = "abandoned"

def __init__(
self,
Expand Down Expand Up @@ -188,6 +189,7 @@ async def save_error_state(
self,
session: ProfileSession,
*,
state: str = None,
reason: str = None,
log_params: Mapping[str, Any] = None,
log_override: bool = False,
Expand All @@ -202,10 +204,10 @@ async def save_error_state(
override: Override configured logging regimen, print to stderr instead
"""

if self._last_state is None: # already done
if self._last_state == state: # already done
return

self.state = None
self.state = state or V10CredentialExchange.STATE_ABANDONED
if reason:
self.error_msg = reason

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ async def test_receive_problem_report(self):
)
save_ex.assert_called_once()

assert ret_exchange.state is None
assert ret_exchange.state == V10CredentialExchange.STATE_ABANDONED

async def test_receive_problem_report_x(self):
connection_id = "connection-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ async def receive_problem_report(
)
)

cred_ex_record.state = None
cred_ex_record.state = V20CredExRecord.STATE_ABANDONED
code = message.description.get(
"code",
ProblemReportReason.ISSUANCE_ABANDONED.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Meta:
STATE_CREDENTIAL_RECEIVED = "credential-received"
STATE_DONE = "done"
STATE_CREDENTIAL_REVOKED = "credential-revoked"
STATE_ABANDONED = "abandoned"

def __init__(
self,
Expand Down Expand Up @@ -148,6 +149,7 @@ async def save_error_state(
self,
session: ProfileSession,
*,
state: str = None,
reason: str = None,
log_params: Mapping[str, Any] = None,
log_override: bool = False,
Expand All @@ -162,10 +164,10 @@ async def save_error_state(
override: Override configured logging regimen, print to stderr instead
"""

if self._last_state is None: # already done
if self._last_state == state: # already done
return

self.state = None
self.state = state or V20CredExRecord.STATE_ABANDONED
if reason:
self.error_msg = reason

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ async def test_receive_problem_report(self):
)
save_ex.assert_called_once()

assert ret_exchange.state is None
assert ret_exchange.state == V20CredExRecord.STATE_ABANDONED

async def test_receive_problem_report_x(self):
connection_id = "connection-id"
Expand Down
6 changes: 4 additions & 2 deletions aries_cloudagent/protocols/present_proof/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ async def receive_presentation(
name=name,
value=value,
):
presentation_exchange_record.state = None
presentation_exchange_record.state = (
V10PresentationExchange.STATE_ABANDONED
)
async with self._profile.session() as session:
await presentation_exchange_record.save(
session,
Expand Down Expand Up @@ -497,7 +499,7 @@ async def receive_problem_report(
)
)

pres_ex_record.state = None
pres_ex_record.state = V10PresentationExchange.STATE_ABANDONED
code = message.description.get("code", ProblemReportReason.ABANDONED.value)
pres_ex_record.error_msg = f"{code}: {message.description.get('en', code)}"
await pres_ex_record.save(session, reason="received problem report")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Meta:
STATE_PRESENTATION_RECEIVED = "presentation_received"
STATE_VERIFIED = "verified"
STATE_PRESENTATION_ACKED = "presentation_acked"
STATE_ABANDONED = "abandoned"

def __init__(
self,
Expand Down Expand Up @@ -158,6 +159,7 @@ async def save_error_state(
self,
session: ProfileSession,
*,
state: str = None,
reason: str = None,
log_params: Mapping[str, Any] = None,
log_override: bool = False,
Expand All @@ -172,10 +174,10 @@ async def save_error_state(
override: Override configured logging regimen, print to stderr instead
"""

if self._last_state is None: # already done
if self._last_state == state: # already done
return

self.state = None
self.state = state or V10PresentationExchange.STATE_ABANDONED
if reason:
self.error_msg = reason

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from asynctest import mock as async_mock, TestCase as AsyncTestCase

from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import (
V10CredentialExchange,
)

from .....core.in_memory import InMemoryProfile
from .....indy.holder import IndyHolder, IndyHolderError
from .....indy.issuer import IndyIssuer
Expand Down Expand Up @@ -1327,7 +1331,7 @@ async def test_receive_problem_report(self):
)
save_ex.assert_called_once()

assert ret_exchange.state is None
assert ret_exchange.state == V10CredentialExchange.STATE_ABANDONED

async def test_receive_problem_report_x(self):
connection_id = "connection-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async def save_error_state(
self,
session: ProfileSession,
*,
state: str = None,
reason: str = None,
log_params: Mapping[str, Any] = None,
log_override: bool = False,
Expand All @@ -159,10 +160,10 @@ async def save_error_state(
override: Override configured logging regimen, print to stderr instead
"""

if self._last_state == V20PresExRecord.STATE_ABANDONED: # already done
if self._last_state == state: # already done
return

self.state = V20PresExRecord.STATE_ABANDONED
self.state = state or V20PresExRecord.STATE_ABANDONED
if reason:
self.error_msg = reason

Expand Down
30 changes: 24 additions & 6 deletions demo/runners/agent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def handle_connections(self, message):
conn_id = message["connection_id"]

# inviter:
if message["state"] == "invitation":
if message.get("state") == "invitation":
self.connection_id = conn_id

# invitee:
Expand Down Expand Up @@ -158,7 +158,7 @@ async def handle_connections(self, message):
)

async def handle_issue_credential(self, message):
state = message["state"]
state = message.get("state")
credential_exchange_id = message["credential_exchange_id"]
prev_state = self.cred_state.get(credential_exchange_id)
if prev_state == state:
Expand Down Expand Up @@ -221,8 +221,12 @@ async def handle_issue_credential(self, message):
except ClientError:
pass

elif state == "abandoned":
log_status("Credential exchange abandoned")
self.log("Problem report message:", message.get("error_msg"))

async def handle_issue_credential_v2_0(self, message):
state = message["state"]
state = message.get("state")
cred_ex_id = message["cred_ex_id"]
prev_state = self.cred_state.get(cred_ex_id)
if prev_state == state:
Expand All @@ -238,6 +242,7 @@ async def handle_issue_credential_v2_0(self, message):
f"/issue-credential-2.0/records/{cred_ex_id}/issue",
{"comment": f"Issuing credential, exchange {cred_ex_id}"},
)

elif state == "offer-received":
log_status("#15 After receiving credential offer, send credential request")
if message["by_format"]["cred_offer"].get("indy"):
Expand All @@ -253,10 +258,15 @@ async def handle_issue_credential_v2_0(self, message):
await self.admin_POST(
f"/issue-credential-2.0/records/{cred_ex_id}/send-request", data
)

elif state == "done":
pass
# Logic moved to detail record specific handler

elif state == "abandoned":
log_status("Credential exchange abandoned")
self.log("Problem report message:", message.get("error_msg"))

async def handle_issue_credential_v2_0_indy(self, message):
rev_reg_id = message.get("rev_reg_id")
cred_rev_id = message.get("cred_rev_id")
Expand Down Expand Up @@ -284,7 +294,7 @@ async def handle_issuer_cred_rev(self, message):
pass

async def handle_present_proof(self, message):
state = message["state"]
state = message.get("state")

presentation_exchange_id = message["presentation_exchange_id"]
presentation_request = message["presentation_request"]
Expand Down Expand Up @@ -366,8 +376,12 @@ async def handle_present_proof(self, message):
)
self.log("Proof =", proof["verified"])

elif state == "abandoned":
log_status("Presentation exchange abandoned")
self.log("Problem report message:", message.get("error_msg"))

async def handle_present_proof_v2_0(self, message):
state = message["state"]
state = message.get("state")
pres_ex_id = message["pres_ex_id"]
self.log(f"Presentation: state = {state}, pres_ex_id = {pres_ex_id}")

Expand Down Expand Up @@ -507,11 +521,15 @@ async def handle_present_proof_v2_0(self, message):
self.log("Proof =", proof["verified"])
self.last_proof_received = proof

elif state == "abandoned":
log_status("Presentation exchange abandoned")
self.log("Problem report message:", message.get("error_msg"))

async def handle_basicmessages(self, message):
self.log("Received message:", message["content"])

async def handle_endorse_transaction(self, message):
self.log("Received transaction message:", message["state"])
self.log("Received transaction message:", message.get("state"))

async def handle_revocation_notification(self, message):
self.log("Received revocation notification message:", message)
Expand Down
2 changes: 1 addition & 1 deletion requirements.askar.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aries-askar~=0.2.2
aries-askar~=0.2.4
indy-credx~=0.3
indy-vdr~=0.3.3

0 comments on commit 010d674

Please sign in to comment.