async def _submit(self, req_json: str) -> str: """ Submit (json) request to ledger; return (json) result. Raise AbsentPool for no pool, ClosedPool if pool is not yet open, or BadLedgerTxn on failure. :param req_json: json of request to sign and submit :return: json response """ LOGGER.debug('BaseAnchor._submit >>> req_json: %s', req_json) if not self.pool: LOGGER.debug('BaseAnchor._submit <!< absent pool') raise AbsentPool('Cannot submit request: absent pool') if not self.pool.handle: LOGGER.debug('BaseAnchor._submit <!< closed pool %s', self.pool.name) raise ClosedPool('Cannot submit request to closed pool {}'.format( self.pool.name)) rv_json = await ledger.submit_request(self.pool.handle, req_json) await asyncio.sleep(0) resp = json.loads(rv_json) if resp.get('op', '') in ('REQNACK', 'REJECT'): LOGGER.debug('BaseAnchor._submit <!< ledger rejected request: %s', resp['reason']) raise BadLedgerTxn( 'Ledger rejected transaction request: {}'.format( resp['reason'])) LOGGER.debug('BaseAnchor._submit <<< %s', rv_json) return rv_json
async def _sign_submit(self, req_json: str) -> str: """ Sign and submit (json) request to ledger; return (json) result. Raise ClosedPool if pool is not yet open, CorruptWallet if existing wallet's pool is no longer extant, or BadLedgerTxn on any other failure. :param req_json: json of request to sign and submit :param wait: whether to wait for the transaction to appear on the ledger before proceeding :return: json response """ LOGGER.debug('_BaseAnchor._sign_submit >>> json: %s', req_json) if not self.pool.handle: LOGGER.debug('_BaseAnchor._submit <!< closed pool %s', self.pool.name) raise ClosedPool('Cannot submit request to closed pool {}'.format( self.pool.name)) try: rv_json = await ledger.sign_and_submit_request( self.pool.handle, self.wallet.handle, self.did, req_json) await asyncio.sleep(0) except IndyError as x_indy: if x_indy.error_code == ErrorCode.WalletIncompatiblePoolError: LOGGER.debug( '_BaseAnchor._sign_submit: <!< Corrupt wallet %s is not compatible with pool %s', self.wallet.name, self.pool.name) raise CorruptWallet( 'Corrupt wallet {} is not compatible with pool {}'.format( self.wallet.name, self.pool.name)) else: LOGGER.debug( '_BaseAnchor._sign_submit: <!< cannot sign/submit request for ledger: indy error code %s', self.wallet.name) raise BadLedgerTxn( 'Cannot sign/submit request for ledger: indy error code {}' .format(x_indy.error_code)) resp = json.loads(rv_json) if ('op' in resp) and (resp['op'] in ('REQNACK', 'REJECT')): LOGGER.debug( '_BaseAnchor._sign_submit: ledger rejected request: %s', resp['reason']) raise BadLedgerTxn( 'Ledger rejected transaction request: {}'.format( resp['reason'])) seq_no = resp.get('result', {}).get('seqNo', None) if 'reason' in resp and seq_no is None: LOGGER.debug( '_BaseAnchor._sign_submit: <!< response indicates no transaction: %s', resp['reason']) raise BadLedgerTxn('Response indicates no transaction: {}'.format( resp['reason'])) LOGGER.debug('_BaseAnchor._sign_submit <<< %s', rv_json) return rv_json
async def _sign_submit(self, req_json: str) -> str: """ Sign and submit (json) request to ledger; return (json) result. Raise: * AbsentPool for no pool * ClosedPool if pool is not yet open * CorruptWallet if existing wallet appears not to pertain to the anchor's pool * WalletState if wallet is closed * BadLedgerTxn on ledger rejection of transaction. :param req_json: json of request to sign and submit :return: json response """ LOGGER.debug('BaseAnchor._sign_submit >>> req_json: %s', req_json) if not self.pool: LOGGER.debug('BaseAnchor._sign_submit <!< absent pool') raise AbsentPool('Cannot sign and submit request: absent pool') if not self.pool.handle: LOGGER.debug('BaseAnchor._submit <!< closed pool %s', self.pool.name) raise ClosedPool('Cannot sign and submit request to closed pool {}'.format(self.pool.name)) if not self.wallet.handle: LOGGER.debug('BaseAnchor._sign_submit <!< Wallet %s is closed', self.name) raise WalletState('Wallet {} is closed'.format(self.name)) try: rv_json = await ledger.sign_and_submit_request(self.pool.handle, self.wallet.handle, self.did, req_json) await asyncio.sleep(0) except IndyError as x_indy: if x_indy.error_code == ErrorCode.WalletIncompatiblePoolError: LOGGER.debug( 'BaseAnchor._sign_submit <!< Corrupt wallet %s is not compatible with pool %s', self.name, self.pool.name) raise CorruptWallet('Corrupt wallet {} is not compatible with pool {}'.format( self.name, self.pool.name)) LOGGER.debug( 'BaseAnchor._sign_submit <!< cannot sign/submit request for ledger: indy error code %s', x_indy.error_code) raise BadLedgerTxn('Cannot sign/submit request for ledger: indy error code {}'.format( x_indy.error_code)) resp = json.loads(rv_json) if resp.get('op', '') in ('REQNACK', 'REJECT'): LOGGER.debug('BaseAnchor._sign_submit: ledger rejected request: %s', resp['reason']) raise BadLedgerTxn('Ledger rejected transaction request: {}'.format(resp['reason'])) LOGGER.debug('BaseAnchor._sign_submit <<< %s', rv_json) return rv_json
async def _submit(self, req_json: str) -> str: """ Submit (json) request to ledger; return (json) result. Raise ClosedPool if pool is not yet open, or BadLedgerTxn on failure. :param req_json: json of request to sign and submit :param wait: whether to wait for the transaction to appear on the ledger before proceeding :return: json response """ LOGGER.debug('_BaseAnchor._submit >>> json: %s', req_json) if not self.pool.handle: LOGGER.debug('_BaseAnchor._submit <!< closed pool %s', self.pool.name) raise ClosedPool('Cannot submit request to closed pool {}'.format( self.pool.name)) rv_json = await ledger.submit_request(self.pool.handle, req_json) await asyncio.sleep(0) resp = json.loads(rv_json) if ('op' in resp) and (resp['op'] in ('REQNACK', 'REJECT')): LOGGER.debug( '_BaseAnchor._submit: <!< ledger rejected request: %s', resp['reason']) raise BadLedgerTxn( 'Ledger rejected transaction request: {}'.format( resp['reason'])) seq_no = resp.get('result', {}).get('seqNo', None) if 'reason' in resp and seq_no is None: LOGGER.debug( '_BaseAnchor._submit: <!< response indicates no transaction: %s', resp['reason']) raise BadLedgerTxn('Response indicates no transaction: {}'.format( resp['reason'])) LOGGER.debug('_BaseAnchor._submit <<< %s', rv_json) return rv_json