Skip to content

Instantly share code, notes, and snippets.

@burdettadam
Created August 23, 2018 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burdettadam/a31061aa256a50798379ddc4171fcfea to your computer and use it in GitHub Desktop.
Save burdettadam/a31061aa256a50798379ddc4171fcfea to your computer and use it in GitHub Desktop.
code that attempts to clean up a broken state from failed https://gist.github.com/burdettadam/136874a90362a58098cc2dcf82c97493#file-cred_defbytrustanchor-py code.
import time
from indy import anoncreds, crypto, did, ledger, pool, wallet
import json
import logging
from typing import Optional
from indy.error import ErrorCode, IndyError
from utils import get_pool_genesis_txn_path, run_coroutine, PROTOCOL_VERSION
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
async def run():
logger.info("Getting started -> started")
pool_name = 'pool1'
logger.info("Open Pool Ledger: {}".format(pool_name))
pool_genesis_txn_path = get_pool_genesis_txn_path(pool_name)
pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})
# Set protocol version 2 to work with Indy Node 1.4
await pool.set_protocol_version(PROTOCOL_VERSION)
try:
await pool.create_pool_ledger_config(pool_name, pool_config)
except IndyError as ex:
if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
pass
pool_handle = await pool.open_pool_ledger(pool_name, None)
steward_wallet_config = json.dumps({"id": "sovrin_steward_wallet"})
steward_wallet_credentials = json.dumps({"key": "steward_wallet_key"})
try:
await wallet.create_wallet(steward_wallet_config, steward_wallet_credentials)
except IndyError as ex:
if ex.error_code == ErrorCode.WalletAlreadyExistsError:
pass
steward_wallet = await wallet.open_wallet(steward_wallet_config, steward_wallet_credentials)
government_wallet_config = json.dumps({"id": "government_wallet"})
government_wallet_credentials = json.dumps({"key": "government_wallet_key"})
government_wallet = await wallet.open_wallet(government_wallet_config, government_wallet_credentials)
faber_wallet_config = json.dumps({"id": "faber_wallet"})
faber_wallet_credentials = json.dumps({"key": "faber_wallet_key"})
faber_wallet = await wallet.open_wallet(faber_wallet_config, faber_wallet_credentials)
acme_wallet_config = json.dumps({"id": "acme_wallet"})
acme_wallet_credentials = json.dumps({"key": "acme_wallet_key"})
acme_wallet = await wallet.open_wallet(acme_wallet_config, acme_wallet_credentials)
thrift_wallet_config = json.dumps({"id": " thrift_wallet"})
thrift_wallet_credentials = json.dumps({"key": "thrift_wallet_key"})
thrift_wallet = await wallet.open_wallet(thrift_wallet_config, thrift_wallet_credentials)
alice_wallet_config = json.dumps({"id": " alice_wallet"})
alice_wallet_credentials = json.dumps({"key": "alice_wallet_key"})
alice_wallet = await wallet.open_wallet(alice_wallet_config, alice_wallet_credentials)
logger.info("==============================")
logger.info(" \"Sovrin Steward\" -> Close and Delete wallet")
await wallet.close_wallet(steward_wallet)
await wallet.delete_wallet(steward_wallet_config, steward_wallet_credentials)
logger.info("\"Government\" -> Close and Delete wallet")
await wallet.close_wallet(government_wallet)
await wallet.delete_wallet(government_wallet_config, government_wallet_credentials)
logger.info("\"Faber\" -> Close and Delete wallet")
await wallet.close_wallet(faber_wallet)
await wallet.delete_wallet(faber_wallet_config, faber_wallet_credentials)
logger.info("\"Acme\" -> Close and Delete wallet")
await wallet.close_wallet(acme_wallet)
await wallet.delete_wallet(acme_wallet_config, acme_wallet_credentials)
logger.info("\"Thrift\" -> Close and Delete wallet")
await wallet.close_wallet(thrift_wallet)
await wallet.delete_wallet(thrift_wallet_config, thrift_wallet_credentials)
logger.info("\"Alice\" -> Close and Delete wallet")
await wallet.close_wallet(alice_wallet)
await wallet.delete_wallet(alice_wallet_config, alice_wallet_credentials)
logger.info("Close and Delete pool")
await pool.close_pool_ledger(pool_handle)
await pool.delete_pool_ledger_config(pool_name)
logger.info("Getting started -> done")
if __name__ == '__main__':
run_coroutine(run)
time.sleep(1) # FIXME waiting for libindy thread complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment