tfchain/TFChainClient.py
def _output_get(self, id, expected_hash_type):
        """
        Get an output from an available explorer Node.

        Returns (output, creation_txn, spend_txn).

        @param id: the identifier (bytes, bytearray, hash or string) that points to the desired output
        @param expected_hash_type: one of ('coinoutputid', 'blockstakeoutputid')
        """
        if expected_hash_type not in ('coinoutputid', 'blockstakeoutputid'):
            raise ValueError("expected hash type should be one of ('coinoutputid', 'blockstakeoutputid'), not {}".format(expected_hash_type))
        id = self._normalize_id(id)
        endpoint = "/explorer/hashes/"+id
        resp = self.explorer_get(endpoint=endpoint)
        resp = json_loads(resp)
        try:
            hash_type = resp['hashtype']
            if hash_type != expected_hash_type:
                raise tfchain.errors.ExplorerInvalidResponse("expected hash type '{}', not '{}'".format(expected_hash_type, hash_type), endpoint, resp)
            tresp = resp['transactions']
            lresp = len(tresp)
            if lresp not in (1, 2):
                raise tfchain.errors.ExplorerInvalidResponse("expected one or two transactions to be returned, not {}".format(lresp), endpoint, resp)
            # parse the transaction(s)
            creation_txn = tresp[0]
            spend_txn = None
            if lresp == 2:
                if tresp[1]['height'] > creation_txn['height']:
                    spend_txn = tresp[1]
                else:
                    spend_txn = creation_txn
                    creation_txn = tresp[1]
            creation_txn = self._transaction_from_explorer_transaction(creation_txn, endpoint=endpoint, resp=resp)
            if spend_txn is not None:
                spend_txn = self._transaction_from_explorer_transaction(spend_txn, endpoint=endpoint, resp=resp)
            # collect the output
            output = None
            for out in (creation_txn.coin_outputs if hash_type == 'coinoutputid' else creation_txn.blockstake_outputs):
                if str(out.id) == id:
                    output = out
                    break
            if output is None:
                raise tfchain.errors.ExplorerInvalidResponse("expected output {} to be part of creation Tx, but it wasn't".format(id), endpoint, resp)
            # return the output and related transaction(s)
            return (output, creation_txn, spend_txn)
        except KeyError as exc:
            # return a KeyError as an invalid Explorer Response
            raise tfchain.errors.ExplorerInvalidResponse(str(exc), endpoint, resp) from exc

        Get an output from an available explorer Node.

        Returns (output, creation_txn, spend_txn).

        @param id: the identifier (bytes, bytearray, hash or string) that points to the desired output
        @param expected_hash_type: one of ('coinoutputid', 'blockstakeoutputid')
        
Get an output from an available explorer Node.
Get an output from an available explorer Node .
def _output_get(self, id, expected_hash_type):
        if expected_hash_type not in ('coinoutputid', 'blockstakeoutputid'):
            raise ValueError("expected hash type should be one of ('coinoutputid', 'blockstakeoutputid'), not {}".format(expected_hash_type))
        id = self._normalize_id(id)
        endpoint = "/explorer/hashes/"+id
        resp = self.explorer_get(endpoint=endpoint)
        resp = json_loads(resp)
        try:
            hash_type = resp['hashtype']
            if hash_type != expected_hash_type:
                raise tfchain.errors.ExplorerInvalidResponse("expected hash type '{}', not '{}'".format(expected_hash_type, hash_type), endpoint, resp)
            tresp = resp['transactions']
            lresp = len(tresp)
            if lresp not in (1, 2):
                raise tfchain.errors.ExplorerInvalidResponse("expected one or two transactions to be returned, not {}".format(lresp), endpoint, resp)
            creation_txn = tresp[0]
            spend_txn = None
            if lresp == 2:
                if tresp[1]['height'] > creation_txn['height']:
                    spend_txn = tresp[1]
                else:
                    spend_txn = creation_txn
                    creation_txn = tresp[1]
            creation_txn = self._transaction_from_explorer_transaction(creation_txn, endpoint=endpoint, resp=resp)
            if spend_txn is not None:
                spend_txn = self._transaction_from_explorer_transaction(spend_txn, endpoint=endpoint, resp=resp)
            output = None
            for out in (creation_txn.coin_outputs if hash_type == 'coinoutputid' else creation_txn.blockstake_outputs):
                if str(out.id) == id:
                    output = out
                    break
            if output is None:
                raise tfchain.errors.ExplorerInvalidResponse("expected output {} to be part of creation Tx, but it wasn't".format(id), endpoint, resp)
            return (output, creation_txn, spend_txn)
        except KeyError as exc:
            raise tfchain.errors.ExplorerInvalidResponse(str(exc), endpoint, resp) from exc
def _output_get ( self , id , expected_hash_type ) : if expected_hash_type not in ( 'coinoutputid' , 'blockstakeoutputid' ) : raise ValueError ( "expected hash type should be one of ('coinoutputid', 'blockstakeoutputid'), not {}" . format ( expected_hash_type ) ) id = self . _normalize_id ( id ) endpoint = "/explorer/hashes/" + id resp = self . explorer_get ( endpoint = endpoint ) resp = json_loads ( resp ) try : hash_type = resp [ 'hashtype' ] if hash_type != expected_hash_type : raise tfchain . errors . ExplorerInvalidResponse ( "expected hash type '{}', not '{}'" . format ( expected_hash_type , hash_type ) , endpoint , resp ) tresp = resp [ 'transactions' ] lresp = len ( tresp ) if lresp not in ( 1 , 2 ) : raise tfchain . errors . ExplorerInvalidResponse ( "expected one or two transactions to be returned, not {}" . format ( lresp ) , endpoint , resp ) creation_txn = tresp [ 0 ] spend_txn = None if lresp == 2 : if tresp [ 1 ] [ 'height' ] > creation_txn [ 'height' ] : spend_txn = tresp [ 1 ] else : spend_txn = creation_txn creation_txn = tresp [ 1 ] creation_txn = self . _transaction_from_explorer_transaction ( creation_txn , endpoint = endpoint , resp = resp ) if spend_txn is not None : spend_txn = self . _transaction_from_explorer_transaction ( spend_txn , endpoint = endpoint , resp = resp ) output = None for out in ( creation_txn . coin_outputs if hash_type == 'coinoutputid' else creation_txn . blockstake_outputs ) : if str ( out . id ) == id : output = out break if output is None : raise tfchain . errors . ExplorerInvalidResponse ( "expected output {} to be part of creation Tx, but it wasn't" . format ( id ) , endpoint , resp ) return ( output , creation_txn , spend_txn ) except KeyError as exc : raise tfchain . errors . ExplorerInvalidResponse ( str ( exc ) , endpoint , resp ) from exc
Get an output from an available explorer Node.
Get an output from an available explorer Node .
"""
        Get an output from an available explorer Node.

        Returns (output, creation_txn, spend_txn).

        @param id: the identifier (bytes, bytearray, hash or string) that points to the desired output
        @param expected_hash_type: one of ('coinoutputid', 'blockstakeoutputid')
        """ # parse the transaction(s) # collect the output # return the output and related transaction(s) # return a KeyError as an invalid Explorer Response
self
id
the identifier (bytes, bytearray, hash or string) that points to the desired output
the identifier ( bytes bytearray hash or string ) that points to the desired output
expected_hash_type
one of ('coinoutputid', 'blockstakeoutputid')
one of ( ' coinoutputid ' ' blockstakeoutputid ' )