Example #1
0
def open_wallet(wallet_info) -> int:
    wallet_config = {
        'id': wallet_info['walletId'],
        'storage_config': {
            'path': wallet_info['walletPath']
        }
    }

    key = getpass("Enter Key for Wallet \"{}\":   ".format(
        wallet_config['id']))

    wallet_credentials = {'key': key}

    try:
        return run_coroutine(
            wallet.open_wallet(json.dumps(wallet_config),
                               json.dumps(wallet_credentials)))
    except IndyError as err:
        if err.error_code == ErrorCode.WalletNotFoundError:
            raise Exception('Wallet not found')
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid Wallet name has been provided')
        if err.error_code == ErrorCode.WalletAccessFailed:
            raise Exception('Invalid key has been provided')
        raise Exception(err.message)
class indy_pep:

    def __init__(self):
        with open('conf/indy.conf') as f:
            self.conf = json.load(f)
                loop = asyncio.get_event_loop()
        self.wallet_handle = loop.run_until_complete(wallet.open_wallet(json.dumps(self.conf['wallet_config']), json.dumps(self.conf['wallet_credentials'])))
        self.pool_handle = None
Example #3
0
 def __init__(self, wallet_handle = None):
     with open('conf/pds.conf') as f:
         self.conf = json.load(f)
     loop = asyncio.get_event_loop()
     if (wallet_handle == None):
         self.wallet_handle = loop.run_until_complete(wallet.open_wallet(json.dumps(self.conf['wallet_config']), json.dumps(self.conf['wallet_credentials'])))
     else:
         self.wallet_handle = wallet_handle
     self.pool_handle = None
Example #4
0
def open_wallet(name: str, key: str) -> int:
    wallet_config = {'id': name}
    wallet_credential = {'key': key}
    try:
        return run_coroutine(wallet.open_wallet(json.dumps(wallet_config), json.dumps(wallet_credential)))
    except IndyError as err:
        if err.error_code == ErrorCode.WalletNotFoundError:
            raise Exception('Wallet not found')
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid Wallet name has been provided')
        if err.error_code == ErrorCode.WalletAccessFailed:
            raise Exception('Invalid key has been provided')
        raise Exception(err.message)
Example #5
0
def wallet(looper):
    wallet_name = randomString()

    create_wallet_future = create_wallet(json.dumps({"id": wallet_name}),
                                         json.dumps({"key": "1"}))
    looper.loop.run_until_complete(create_wallet_future)

    open_wallet_future = open_wallet(json.dumps({"id": wallet_name}),
                                     json.dumps({"key": "1"}))
    wallet_handle = looper.loop.run_until_complete(open_wallet_future)

    yield wallet_handle

    close_wallet_future = close_wallet(wallet_handle)
    looper.loop.run_until_complete(close_wallet_future)

    delete_wallet_future = delete_wallet(json.dumps({"id": wallet_name}),
                                         json.dumps({"key": "1"}))
    looper.loop.run_until_complete(delete_wallet_future)
Example #6
0
def wallet_handle(event_loop, xwallet, wallet_config, credentials,
                  wallet_handle_cleanup):
    logger = logging.getLogger(__name__)
    logger.debug(
        "wallet_handle: >>> xwallet: %r, wallet_config: %r, credentials: %r, wallet_handle_cleanup: %r",
        xwallet, wallet_config, credentials, wallet_handle_cleanup)

    logger.debug("wallet_handle: Opening wallet")
    wallet_handle = event_loop.run_until_complete(
        wallet.open_wallet(wallet_config, credentials))
    assert type(wallet_handle) is int

    logger.debug("wallet_handle: yield %r", wallet_handle)
    yield wallet_handle

    logger.debug("wallet_handle: Closing wallet")
    event_loop.run_until_complete(
        wallet.close_wallet(wallet_handle)) if wallet_handle_cleanup else None

    logger.debug("wallet_handle: <<<")
Example #7
0
def main():
    global conf
    global wallet_handle
    global pool_handle
    if len(sys.argv) != 2:
        print("Usage pds.py <configuration file>")
        sys.exit()
    with open(sys.argv[1]) as f:
        conf = json.load(f)
    httpd = HTTPServer(('', conf["port"]), PDSHandler)
    loop = asyncio.get_event_loop()
    wallet_handle = loop.run_until_complete(
        wallet.open_wallet(json.dumps(conf['wallet_config']),
                           json.dumps(conf['wallet_credentials'])))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    loop.run_until_complete(wallet.close_wallet(wallet_handle))
Example #8
0
def wallet_handle(event_loop, xwallet, wallet_config, credentials, wallet_handle_cleanup):
    logger = logging.getLogger(__name__)
    logger.debug(
        "wallet_handle: >>> xwallet: %r, wallet_config: %r, credentials: %r, wallet_handle_cleanup: %r",
        xwallet,
        wallet_config,
        credentials,
        wallet_handle_cleanup)

    logger.debug("wallet_handle: Opening wallet")
    wallet_handle = event_loop.run_until_complete(wallet.open_wallet(wallet_config, credentials))
    assert type(wallet_handle) is int

    logger.debug("wallet_handle: yield %r", wallet_handle)
    yield wallet_handle

    logger.debug("wallet_handle: Closing wallet")
    event_loop.run_until_complete(wallet.close_wallet(wallet_handle)) if wallet_handle_cleanup else None

    logger.debug("wallet_handle: <<<")
 def __init__(self):
     with open('conf/pds.conf') as f:
         self.conf = json.load(f)
     loop = asyncio.get_event_loop()
     self.wallet_handle = loop.run_until_complete(
         wallet.open_wallet(json.dumps(self.conf['wallet_config']),
                            json.dumps(self.conf['wallet_credentials'])))
     self.pool_handle = None
     try:
         self.pds = PDS(self.wallet_handle, self.pool_handle)
         self.web3_provider = Web3(
             Web3.HTTPProvider(self.conf['web3provider']))
         self.eth_account = self.web3_provider.eth.accounts[0]
         with open('conf/contract/PDS.abi', 'r') as myfile:
             self.abi = myfile.read()
         self.PDSContract_instance = self.web3_provider.eth.contract(
             abi=self.abi,
             address=Web3.toChecksumAddress(self.conf['pds_sc_address']))
     except:
         print("Couldn't connect to Ethereum blockchain")
         pass
Example #10
0
def wallet_handle(wallet_created, wallet_name, event_loop):
    wallet_handle = event_loop.run_until_complete(
        wallet.open_wallet(wallet_name, None, None))
    yield wallet_handle
    event_loop.run_until_complete(wallet.close_wallet(wallet_handle))
Example #11
0
def wallet_handle(wallet_created, wallet_name, event_loop):
    wallet_handle = event_loop.run_until_complete(
        wallet.open_wallet(wallet_name, None, None))
    yield wallet_handle
    event_loop.run_until_complete(wallet.close_wallet(wallet_handle))