Skip to content

Commit

Permalink
Merge branch 'main' into ryjones-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored Jun 27, 2022
2 parents 73c510d + 3c250c7 commit ae4d6b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 55 deletions.
67 changes: 16 additions & 51 deletions demo/bdd_support/agent_backchannel_client.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,16 @@
import asyncio
from aiohttp import (
web,
ClientSession,
ClientRequest,
ClientResponse,
ClientError,
ClientTimeout,
)
import json
import os
from time import sleep
import uuid

from runners.agent_container import AgentContainer, create_agent_with_args_list
from runners.support.agent import DemoAgent


######################################################################
# coroutine utilities
######################################################################


def run_coroutine(coroutine):
loop = asyncio.get_event_loop()
if not loop:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
return loop.run_until_complete(coroutine())
finally:
pass
# loop.close()


def run_coroutine_with_args(coroutine, *args):
loop = asyncio.get_event_loop()
if not loop:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
return loop.run_until_complete(coroutine(*args))
finally:
pass
# loop.close()


def run_coroutine_with_kwargs(coroutine, *args, **kwargs):
def run_coroutine(coroutine, *args, **kwargs):
loop = asyncio.get_event_loop()
if not loop:
loop = asyncio.new_event_loop()
Expand All @@ -58,22 +23,22 @@ def run_coroutine_with_kwargs(coroutine, *args, **kwargs):


def async_sleep(delay):
run_coroutine_with_args(asyncio.sleep, delay)
run_coroutine(asyncio.sleep, delay)


######################################################################
# high level aries agent interface
######################################################################
def create_agent_container_with_args(in_args: list):
return run_coroutine_with_args(create_agent_with_args_list, in_args)
return run_coroutine(create_agent_with_args_list, in_args)


def aries_container_initialize(
the_container: AgentContainer,
schema_name: str = None,
schema_attrs: list = None,
):
run_coroutine_with_kwargs(
run_coroutine(
the_container.initialize,
schema_name=schema_name,
schema_attrs=schema_attrs,
Expand All @@ -86,7 +51,7 @@ def agent_container_register_did(
verkey: str,
role: str,
):
run_coroutine_with_args(
run_coroutine(
the_container.register_did,
did,
verkey,
Expand All @@ -103,7 +68,7 @@ def aries_container_terminate(
def aries_container_generate_invitation(
the_container: AgentContainer,
):
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.generate_invitation,
)

Expand All @@ -112,7 +77,7 @@ def aries_container_receive_invitation(
the_container: AgentContainer,
invite_details: dict,
):
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.input_invitation,
invite_details,
)
Expand All @@ -130,7 +95,7 @@ def aries_container_create_schema_cred_def(
schema_attrs: list,
version: str = None,
):
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.create_schema_and_cred_def,
schema_name,
schema_attrs,
Expand All @@ -143,7 +108,7 @@ def aries_container_issue_credential(
cred_def_id: str,
cred_attrs: list,
):
return run_coroutine_with_args(
return run_coroutine(
the_container.issue_credential,
cred_def_id,
cred_attrs,
Expand All @@ -155,7 +120,7 @@ def aries_container_receive_credential(
cred_def_id: str,
cred_attrs: list,
):
return run_coroutine_with_args(
return run_coroutine(
the_container.receive_credential,
cred_def_id,
cred_attrs,
Expand All @@ -166,7 +131,7 @@ def aries_container_request_proof(
the_container: AgentContainer,
proof_request: dict,
):
return run_coroutine_with_args(
return run_coroutine(
the_container.request_proof,
proof_request,
)
Expand All @@ -176,7 +141,7 @@ def aries_container_verify_proof(
the_container: AgentContainer,
proof_request: dict,
):
return run_coroutine_with_args(
return run_coroutine(
the_container.verify_proof,
proof_request,
)
Expand Down Expand Up @@ -228,7 +193,7 @@ def agent_container_GET(
text: bool = False,
params: dict = None,
) -> dict:
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.admin_GET,
path,
text=text,
Expand All @@ -243,7 +208,7 @@ def agent_container_POST(
text: bool = False,
params: dict = None,
) -> dict:
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.admin_POST,
path,
data=data,
Expand All @@ -259,7 +224,7 @@ def agent_container_PATCH(
text: bool = False,
params: dict = None,
) -> dict:
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.admin_PATCH,
path,
data=data,
Expand All @@ -275,7 +240,7 @@ def agent_container_PUT(
text: bool = False,
params: dict = None,
) -> dict:
return run_coroutine_with_kwargs(
return run_coroutine(
the_container.admin_PUT,
path,
data=data,
Expand Down
7 changes: 3 additions & 4 deletions demo/runners/agent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
start_mediator_agent,
connect_wallet_to_mediator,
start_endorser_agent,
connect_wallet_to_endorser,
CRED_FORMAT_INDY,
CRED_FORMAT_JSON_LD,
DID_METHOD_SOV,
DID_METHOD_KEY,
KEY_TYPE_ED255,
KEY_TYPE_BLS,
SIG_TYPE_BLS,
)
from runners.support.utils import ( # noqa:E402
check_requires,
Expand Down Expand Up @@ -615,6 +611,7 @@ def __init__(
self,
ident: str,
start_port: int,
prefix: str = None,
no_auto: bool = False,
revocation: bool = False,
genesis_txns: str = None,
Expand All @@ -639,6 +636,7 @@ def __init__(
self.genesis_txn_list = genesis_txn_list
self.ident = ident
self.start_port = start_port
self.prefix = prefix or ident
self.no_auto = no_auto
self.revocation = revocation
self.tails_server_base_url = tails_server_base_url
Expand Down Expand Up @@ -685,6 +683,7 @@ async def initialize(
self.ident,
self.start_port,
self.start_port + 1,
prefix=self.prefix,
genesis_data=self.genesis_txns,
genesis_txn_list=self.genesis_txn_list,
no_auto=self.no_auto,
Expand Down

0 comments on commit ae4d6b4

Please sign in to comment.