Skip to content

Commit

Permalink
Merge pull request #2676 from jamshale/feat/2668
Browse files Browse the repository at this point in the history
Cache TAA by wallet name
  • Loading branch information
swcurran authored Dec 18, 2023
2 parents c9d8dba + d7417c6 commit 94b1dde
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
28 changes: 13 additions & 15 deletions aries_cloudagent/ledger/indy_vdr.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
"""Indy-VDR ledger implementation."""

import asyncio
import json
import hashlib
import json
import logging
import os
import os.path
import tempfile

from datetime import datetime, date, timezone
from datetime import date, datetime, timezone
from io import StringIO
from pathlib import Path
from time import time
from typing import List, Tuple, Union, Optional
from typing import List, Optional, Tuple, Union

from indy_vdr import ledger, open_pool, Pool, Request, VdrError
from indy_vdr import Pool, Request, VdrError, ledger, open_pool

from ..cache.base import BaseCache
from ..core.profile import Profile
Expand All @@ -23,9 +22,8 @@
from ..utils import sentinel
from ..utils.env import storage_path
from ..wallet.base import BaseWallet, DIDInfo
from ..wallet.error import WalletNotFoundError
from ..wallet.did_posture import DIDPosture

from ..wallet.error import WalletNotFoundError
from .base import BaseLedger, Role
from .endpoint_type import EndpointType
from .error import (
Expand Down Expand Up @@ -947,19 +945,21 @@ async def accept_txn_author_agreement(
)
async with self.profile.session() as session:
storage = session.inject(BaseStorage)
cache = self.profile.inject_or(BaseCache)
await storage.add_record(record)
if self.pool.cache:
cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + self.pool_name
await self.pool.cache.set(cache_key, acceptance, self.pool.cache_duration)
if cache:
cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + self.profile.name
await cache.set(cache_key, acceptance, self.pool.cache_duration)

async def get_latest_txn_author_acceptance(self) -> dict:
"""Look up the latest TAA acceptance."""
cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + self.pool_name
cache_key = TAA_ACCEPTED_RECORD_TYPE + "::" + self.profile.name
acceptance = self.pool.cache and await self.pool.cache.get(cache_key)
if not acceptance:
tag_filter = {"pool_name": self.pool_name}
async with self.profile.session() as session:
storage = session.inject(BaseStorage)
cache = self.profile.inject_or(BaseCache)
found = await storage.find_all_records(
TAA_ACCEPTED_RECORD_TYPE, tag_filter
)
Expand All @@ -969,10 +969,8 @@ async def get_latest_txn_author_acceptance(self) -> dict:
acceptance = records[0]
else:
acceptance = {}
if self.pool.cache:
await self.pool.cache.set(
cache_key, acceptance, self.pool.cache_duration
)
if cache:
await cache.set(cache_key, acceptance, self.pool.cache_duration)
return acceptance

async def get_revoc_reg_def(self, revoc_reg_id: str) -> dict:
Expand Down
21 changes: 19 additions & 2 deletions aries_cloudagent/ledger/tests/test_indy_vdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import indy_vdr
import pytest
from aries_cloudagent.tests import mock

from aries_cloudagent.cache.base import BaseCache
from aries_cloudagent.cache.in_memory import InMemoryCache
from aries_cloudagent.tests import mock

from ...core.in_memory import InMemoryProfile
from ...indy.issuer import IndyIssuer
Expand Down Expand Up @@ -36,7 +38,12 @@
def ledger():
did_methods = DIDMethods()
did_methods.register(WEB)
profile = InMemoryProfile.test_profile(bind={DIDMethods: did_methods})
profile = InMemoryProfile.test_profile(
bind={
DIDMethods: did_methods,
BaseCache: InMemoryCache(),
}
)
ledger = IndyVdrLedger(IndyVdrLedgerPool("test-ledger"), profile)

async def open():
Expand Down Expand Up @@ -149,6 +156,16 @@ async def test_submit_signed_taa_accept(
assert result.get("signature")
assert result.get("taaAcceptance")

# no accept_time
await ledger.accept_txn_author_agreement(
{
"text": "txt",
"version": "ver",
"digest": ledger.taa_digest("ver", "txt"),
},
mechanism="manual",
)

@pytest.mark.asyncio
async def test_submit_unsigned(
self,
Expand Down

0 comments on commit 94b1dde

Please sign in to comment.