Skip to content

Commit

Permalink
Merge pull request #1785 from ianco/fix/tails_upload_multi2
Browse files Browse the repository at this point in the history
Fix tails server upload multi-ledger mode
  • Loading branch information
ianco authored May 26, 2022
2 parents ce11560 + 4cce473 commit a4013f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
28 changes: 28 additions & 0 deletions aries_cloudagent/ledger/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import tempfile
from datetime import date, datetime
from io import StringIO
from os import path
from time import time
from typing import Sequence, Tuple, Optional
Expand Down Expand Up @@ -42,6 +43,17 @@
GENESIS_TRANSACTION_FILE = "indy_genesis_transactions.txt"


def _normalize_txns(txns: str) -> str:
"""Normalize a set of genesis transactions."""
lines = StringIO()
for line in txns.splitlines():
line = line.strip()
if line:
lines.write(line)
lines.write("\n")
return lines.getvalue()


class IndySdkLedgerPoolProvider(BaseProvider):
"""Indy ledger pool provider which keys off the selected pool name."""

Expand Down Expand Up @@ -107,12 +119,28 @@ def __init__(
self.cache = cache
self.cache_duration = cache_duration
self.genesis_transactions = genesis_transactions
self.genesis_txns_cache = genesis_transactions
self.handle = None
self.name = name
self.taa_cache = None
self.read_only = read_only
self.socks_proxy = socks_proxy

@property
def genesis_txns(self) -> str:
"""Get the configured genesis transactions."""
if not self.genesis_txns_cache:
try:
txn_path = path.join(
tempfile.gettempdir(), f"{self.name}_{GENESIS_TRANSACTION_FILE}"
)
self.genesis_txns_cache = _normalize_txns(open(txn_path).read())
except FileNotFoundError:
raise LedgerConfigError(
"Pool config '%s' not found", self.name
) from None
return self.genesis_txns_cache

async def create_pool_config(
self, genesis_transactions: str, recreate: bool = False
):
Expand Down
16 changes: 12 additions & 4 deletions aries_cloudagent/tails/indy_tails_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Indy tails server interface class."""

from typing import Tuple
import logging

from ..config.injection_context import InjectionContext
from ..ledger.multiple_ledger.base_manager import BaseMultipleLedgerManager
Expand All @@ -10,6 +11,9 @@
from .error import TailsServerNotConfiguredError


LOGGER = logging.getLogger(__name__)


class IndyTailsServer(BaseTailsServer):
"""Indy tails server interface."""

Expand Down Expand Up @@ -38,12 +42,16 @@ async def upload_tails_file(
if not genesis_transactions:
ledger_manager = context.injector.inject(BaseMultipleLedgerManager)
write_ledgers = await ledger_manager.get_write_ledger()
LOGGER.debug(f"write_ledgers = {write_ledgers}")
pool = write_ledgers[1].pool
LOGGER.debug(f"write_ledger pool = {pool}")

genesis_transactions = pool.genesis_txns

try:
genesis_transactions = pool.genesis_transactions
except AttributeError:
genesis_transactions = pool.genesis_txns_cache
if not genesis_transactions:
raise TailsServerNotConfiguredError(
"no genesis_transactions for writable ledger"
)

if not tails_server_upload_url:
raise TailsServerNotConfiguredError(
Expand Down

0 comments on commit a4013f4

Please sign in to comment.