Ejemplo n.º 1
0
def close_wallet(wallet_handle):
    try:
        run_coroutine(wallet.close_wallet(wallet_handle))
    except IndyError as err:
        if err.error_code == ErrorCode.WalletInvalidHandle:
            return
        raise Exception(err.message)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def parse_payment_response(response):
    try:
        return json.loads(
            run_coroutine(
                payment.parse_payment_response(PAYMENT_METHOD, response)))
    except IndyError as err:
        handle_payment_error(err)
Ejemplo n.º 4
0
def get_payment_sources(pool_handle: int, payment_address: str):
    try:
        # wallet handle and submitter did can be omitted
        get_payment_sources_request, _ = run_coroutine(
            payment.build_get_payment_sources_request(-1, None,
                                                      payment_address))

        get_payment_sources_response = send_transaction(
            pool_handle, get_payment_sources_request)

        payment_sources = run_coroutine(
            payment.parse_get_payment_sources_response(
                PAYMENT_METHOD, get_payment_sources_response))
        return json.loads(payment_sources)
    except IndyError as err:
        handle_payment_error(err)
Ejemplo n.º 5
0
def build_payment_request(wallet_handle, inputs, outputs):
    try:
        payment_request, _ = run_coroutine(
            payment.build_payment_req(wallet_handle, None, json.dumps(inputs),
                                      json.dumps(outputs), None))
        return payment_request
    except IndyError as err:
        handle_payment_error(err)
Ejemplo n.º 6
0
def send_transaction(pool_handle: int, transaction: str) -> str:
    try:
        response = json.loads(
            run_coroutine(ledger.submit_request(pool_handle, transaction)))

        if response['op'] != 'REPLY':
            raise Exception(response['reason'])

        return json.dumps(response)
    except IndyError as err:
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid Transaction')
        if err.error_code == ErrorCode.PoolLedgerTimeout:
            raise Exception('Cannot get response from Ledger')
        raise Exception(err.message)
Ejemplo n.º 7
0
def open_pool() -> int:
    genesis_transactions = input(
        "Enter path to Pool Genesis Transactions file:     ")
    config = {'genesis_txn': genesis_transactions}

    try:
        return run_coroutine(create_and_open_pool(config))
    except IndyError as err:
        if err.error_code == ErrorCode.PoolLedgerNotCreatedError:
            raise Exception('Pool not found')
        if err.error_code == ErrorCode.CommonInvalidParam2:
            raise Exception('Invalid Pool name has been provided')
        if err.error_code == ErrorCode.PoolLedgerTimeout:
            raise Exception('Cannot connect to Pool')
        if err.error_code == ErrorCode.CommonIOError:
            raise Exception('Genesis Transactions file not found')
        raise Exception(err.message)
Ejemplo n.º 8
0
 def handle_reset_connection(self) -> str:
     run_coroutine(self.state['connection'].stop)
     return "OK"
Ejemplo n.º 9
0
 def handle_get_connection_state(self) -> str:
     return run_coroutine(self.state['connection'].get_state)
Ejemplo n.º 10
0
 def start_connection(self, actor):
     result = run_coroutine(actor.start)
     actor.thread = threading.Thread(target=actor.connect, args=())
     actor.thread.start()
     self.state['connection'] = actor
     return result
Ejemplo n.º 11
0
def close_pool(pool_handle):
    try:
        run_coroutine(close_and_delete_pool(pool_handle))
    except IndyError as err:
        raise Exception(err.message)