|
5 | 5 | import logging |
6 | 6 | import tempfile |
7 | 7 | from datetime import date, datetime |
| 8 | +from io import StringIO |
8 | 9 | from os import path |
9 | 10 | from time import time |
10 | 11 | from typing import Sequence, Tuple, Optional |
|
42 | 43 | GENESIS_TRANSACTION_FILE = "indy_genesis_transactions.txt" |
43 | 44 |
|
44 | 45 |
|
| 46 | +def _normalize_txns(txns: str) -> str: |
| 47 | + """Normalize a set of genesis transactions.""" |
| 48 | + lines = StringIO() |
| 49 | + for line in txns.splitlines(): |
| 50 | + line = line.strip() |
| 51 | + if line: |
| 52 | + lines.write(line) |
| 53 | + lines.write("\n") |
| 54 | + return lines.getvalue() |
| 55 | + |
| 56 | + |
45 | 57 | class IndySdkLedgerPoolProvider(BaseProvider): |
46 | 58 | """Indy ledger pool provider which keys off the selected pool name.""" |
47 | 59 |
|
@@ -107,12 +119,28 @@ def __init__( |
107 | 119 | self.cache = cache |
108 | 120 | self.cache_duration = cache_duration |
109 | 121 | self.genesis_transactions = genesis_transactions |
| 122 | + self.genesis_txns_cache = genesis_transactions |
110 | 123 | self.handle = None |
111 | 124 | self.name = name |
112 | 125 | self.taa_cache = None |
113 | 126 | self.read_only = read_only |
114 | 127 | self.socks_proxy = socks_proxy |
115 | 128 |
|
| 129 | + @property |
| 130 | + def genesis_txns(self) -> str: |
| 131 | + """Get the configured genesis transactions.""" |
| 132 | + if not self.genesis_txns_cache: |
| 133 | + try: |
| 134 | + txn_path = path.join( |
| 135 | + tempfile.gettempdir(), f"{self.name}_{GENESIS_TRANSACTION_FILE}" |
| 136 | + ) |
| 137 | + self.genesis_txns_cache = _normalize_txns(open(txn_path).read()) |
| 138 | + except FileNotFoundError: |
| 139 | + raise LedgerConfigError( |
| 140 | + "Pool config '%s' not found", self.name |
| 141 | + ) from None |
| 142 | + return self.genesis_txns_cache |
| 143 | + |
116 | 144 | async def create_pool_config( |
117 | 145 | self, genesis_transactions: str, recreate: bool = False |
118 | 146 | ): |
|
0 commit comments