Skip to content

Commit

Permalink
🚧 in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Jun 3, 2024
1 parent 9ac2750 commit df69da0
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion aries_cloudagent/askar/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def handle(self) -> Session:
@property
def store(self) -> Store:
"""Accessor for the Store instance."""
return self._handle and self._handle.store
return self._handle and self._handle._store

@property
def is_transaction(self) -> bool:
Expand Down
12 changes: 11 additions & 1 deletion aries_cloudagent/protocols/connections/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
)
from marshmallow import fields, validate, validates_schema

from aries_cloudagent.storage.base import DEFAULT_PAGE_SIZE

from ....admin.decorators.auth import tenant_authentication
from ....admin.request_context import AdminRequestContext
from ....cache.base import BaseCache
Expand Down Expand Up @@ -468,11 +470,19 @@ async def connections_list(request: web.BaseRequest):
if request.query.get("connection_protocol"):
post_filter["connection_protocol"] = request.query["connection_protocol"]

limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE))
offset = int(request.query.get("offset", 0))

profile = context.profile
try:
async with profile.session() as session:
records = await ConnRecord.query(
session, tag_filter, post_filter_positive=post_filter, alt=True
session,
tag_filter,
limit=limit,
offset=offset,
post_filter_positive=post_filter,
alt=True,
)
results = [record.serialize() for record in records]
results.sort(key=connection_sort_key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ async def test_connections_list(self):
"their_public_did": "a_public_did",
"invitation_msg_id": "dummy_msg",
},
limit=100,
offset=0,
post_filter_positive={
"their_role": list(ConnRecord.Role.REQUESTER.value),
"connection_protocol": "connections/1.0",
Expand Down
12 changes: 11 additions & 1 deletion aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
)
from marshmallow import fields, validate

from aries_cloudagent.storage.base import DEFAULT_PAGE_SIZE

from ....admin.decorators.auth import tenant_authentication
from ....admin.request_context import AdminRequestContext
from ....connections.models.conn_record import ConnRecord
Expand Down Expand Up @@ -140,10 +142,18 @@ async def transactions_list(request: web.BaseRequest):
tag_filter = {}
post_filter = {}

limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE))
offset = int(request.query.get("offset", 0))

try:
async with context.profile.session() as session:
records = await TransactionRecord.query(
session, tag_filter, post_filter_positive=post_filter, alt=True
session,
tag_filter,
limit=limit,
offset=offset,
post_filter_positive=post_filter,
alt=True,
)
results = [record.serialize() for record in records]
except (StorageError, BaseModelError) as err:
Expand Down
7 changes: 7 additions & 0 deletions aries_cloudagent/protocols/issue_credential/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)
from marshmallow import ValidationError, fields, validate, validates_schema

from aries_cloudagent.storage.base import DEFAULT_PAGE_SIZE

from ....admin.decorators.auth import tenant_authentication
from ....admin.request_context import AdminRequestContext
from ....anoncreds.holder import AnonCredsHolderError
Expand Down Expand Up @@ -566,11 +568,16 @@ async def credential_exchange_list(request: web.BaseRequest):
if request.query.get(k, "") != ""
}

limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE))
offset = int(request.query.get("offset", 0))

try:
async with profile.session() as session:
cred_ex_records = await V20CredExRecord.query(
session=session,
tag_filter=tag_filter,
limit=limit,
offset=offset,
post_filter_positive=post_filter,
)

Expand Down
7 changes: 6 additions & 1 deletion aries_cloudagent/protocols/present_proof/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
UUID4_EXAMPLE,
UUID4_VALIDATE,
)
from ....storage.base import BaseStorage
from ....storage.base import DEFAULT_PAGE_SIZE, BaseStorage
from ....storage.error import StorageError, StorageNotFoundError
from ....storage.vc_holder.base import VCHolder
from ....storage.vc_holder.vc_record import VCRecord
Expand Down Expand Up @@ -448,11 +448,16 @@ async def present_proof_list(request: web.BaseRequest):
if request.query.get(k, "") != ""
}

limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE))
offset = int(request.query.get("offset", 0))

try:
async with profile.session() as session:
records = await V20PresExRecord.query(
session=session,
tag_filter=tag_filter,
limit=limit,
offset=offset,
post_filter_positive=post_filter,
)
results = [record.serialize() for record in records]
Expand Down
8 changes: 7 additions & 1 deletion aries_cloudagent/revocation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
get_endorser_connection_id,
is_author_role,
)
from ..storage.base import BaseStorage
from ..storage.base import DEFAULT_PAGE_SIZE, BaseStorage
from ..storage.error import StorageError, StorageNotFoundError
from ..utils.profiles import is_anoncreds_profile_raise_web_exception
from .error import RevocationError, RevocationNotSupportedError
Expand Down Expand Up @@ -827,10 +827,16 @@ async def rev_regs_created(request: web.BaseRequest):
tag_filter = {
tag: request.query[tag] for tag in search_tags if tag in request.query
}

limit = int(request.query.get("limit", DEFAULT_PAGE_SIZE))
offset = int(request.query.get("offset", 0))

async with context.profile.session() as session:
found = await IssuerRevRegRecord.query(
session,
tag_filter,
limit=limit,
offset=offset,
post_filter_negative={"state": IssuerRevRegRecord.STATE_INIT},
)

Expand Down
18 changes: 12 additions & 6 deletions aries_cloudagent/storage/askar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Aries-Askar implementation of BaseStorage interface."""

from typing import Mapping, Sequence
from typing import Mapping, Optional, Sequence

from aries_askar import AskarError, AskarErrorCode, Session
from aries_askar import AskarError, AskarErrorCode, Session, Store

from ..askar.profile import AskarProfile, AskarProfileSession
from .base import (
Expand Down Expand Up @@ -344,11 +344,14 @@ async def __anext__(self):
tags=row.tags,
)

async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]:
async def fetch(
self, max_count: Optional[int] = None, offset: Optional[int] = None
) -> Sequence[StorageRecord]:
"""Fetch the next list of results from the store.
Args:
max_count: Max number of records to return
offset: The offset to start retrieving records from
Returns:
A list of `StorageRecord` instances
Expand All @@ -359,11 +362,12 @@ async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]:
"""
if self._done:
raise StorageSearchError("Search query is complete")
await self._open()

limit = max_count or self.page_size
await self._open(limit=limit, offset=offset)

count = 0
ret = []
limit = max_count or self.page_size

while count < limit:
try:
Expand All @@ -389,14 +393,16 @@ async def fetch(self, max_count: int = None) -> Sequence[StorageRecord]:

return ret

async def _open(self):
async def _open(self, offset: Optional[int] = None, limit: Optional[int] = None):
"""Start the search query."""
if self._scan:
return
try:
self._scan = self._profile.store.scan(
category=self.type_filter,
tag_filter=self.tag_query,
offset=offset,
limit=limit,
profile=self._profile.settings.get("wallet.askar_profile"),
)
except AskarError as err:
Expand Down
2 changes: 1 addition & 1 deletion demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ async def register_or_switch_wallet(
"wallet_name": target_wallet_name,
"wallet_type": self.wallet_type,
"label": target_wallet_name,
"wallet_webhook_urls": self.webhook_url,
"wallet_webhook_urls": [self.webhook_url],
"wallet_dispatch_type": "both",
}
self.wallet_name = target_wallet_name
Expand Down

0 comments on commit df69da0

Please sign in to comment.