tfchain/TFChainClient.py
def block_get(self, value):
        """
        Get a block from an available explorer Node.
        
        @param value: the identifier or height that points to the desired block
        """
        endpoint = "/explorer/?"
        resp = {}
        try:
            # get the explorer block
            if isinstance(value, int):
                endpoint = "/explorer/blocks/{}".format(int(value))
                resp = self.explorer_get(endpoint=endpoint)
                resp = json_loads(resp)
                resp = resp['block']
            else:
                blockid = self._normalize_id(value)
                endpoint = "/explorer/hashes/"+blockid
                resp = self.explorer_get(endpoint=endpoint)
                resp = json_loads(resp)
                if resp['hashtype'] != 'blockid':
                    raise tfchain.errors.ExplorerInvalidResponse("expected hash type 'blockid' not '{}'".format(resp['hashtype']), endpoint, resp)
                resp = resp['block']
                if resp['blockid'] != blockid:
                    raise tfchain.errors.ExplorerInvalidResponse("expected block ID '{}' not '{}'".format(blockid, resp['blockid']), endpoint, resp)
            # parse the transactions
            transactions = []
            for etxn in resp['transactions']:
                # parse the explorer transaction
                transaction = self._transaction_from_explorer_transaction(etxn, endpoint=endpoint, resp=resp)
                # append the transaction to the list of transactions
                transactions.append(transaction)
            rawblock = resp['rawblock']
            # parse the parent id
            parentid = Hash.from_json(obj=rawblock['parentid'])
            # parse the miner payouts
            miner_payouts = []
            minerpayoutids = resp.get('minerpayoutids', None) or []
            eminerpayouts = rawblock.get('minerpayouts', None) or []
            if len(eminerpayouts) != len(minerpayoutids):
                raise tfchain.errors.ExplorerInvalidResponse("amount of miner payouts and payout ids are not matching: {} != {}".format(len(eminerpayouts), len(minerpayoutids)), endpoint, resp)
            for idx, mp in enumerate(eminerpayouts):
                id = Hash.from_json(minerpayoutids[idx])
                value = Currency.from_json(mp['value'])
                unlockhash = UnlockHash.from_json(mp['unlockhash'])
                miner_payouts.append(ExplorerMinerPayout(id=id, value=value, unlockhash=unlockhash))
            # get the timestamp and height
            height = int(resp['height'])
            timestamp = int(rawblock['timestamp'])
            # get the block's identifier
            blockid = Hash.from_json(resp['blockid'])
            # return the block, as reported by the explorer
            return ExplorerBlock(
                id=blockid, parentid=parentid,
                height=height, timestamp=timestamp,
                transactions=transactions, miner_payouts=miner_payouts)
        except KeyError as exc:
            # return a KeyError as an invalid Explorer Response
            raise tfchain.errors.ExplorerInvalidResponse(str(exc), endpoint, resp) from exc

        Get a block from an available explorer Node.
        
        @param value: the identifier or height that points to the desired block
        
Get a block from an available explorer Node.
Get a block from an available explorer Node .
def block_get(self, value):
        endpoint = "/explorer/?"
        resp = {}
        try:
            if isinstance(value, int):
                endpoint = "/explorer/blocks/{}".format(int(value))
                resp = self.explorer_get(endpoint=endpoint)
                resp = json_loads(resp)
                resp = resp['block']
            else:
                blockid = self._normalize_id(value)
                endpoint = "/explorer/hashes/"+blockid
                resp = self.explorer_get(endpoint=endpoint)
                resp = json_loads(resp)
                if resp['hashtype'] != 'blockid':
                    raise tfchain.errors.ExplorerInvalidResponse("expected hash type 'blockid' not '{}'".format(resp['hashtype']), endpoint, resp)
                resp = resp['block']
                if resp['blockid'] != blockid:
                    raise tfchain.errors.ExplorerInvalidResponse("expected block ID '{}' not '{}'".format(blockid, resp['blockid']), endpoint, resp)
            transactions = []
            for etxn in resp['transactions']:
                transaction = self._transaction_from_explorer_transaction(etxn, endpoint=endpoint, resp=resp)
                transactions.append(transaction)
            rawblock = resp['rawblock']
            parentid = Hash.from_json(obj=rawblock['parentid'])
            miner_payouts = []
            minerpayoutids = resp.get('minerpayoutids', None) or []
            eminerpayouts = rawblock.get('minerpayouts', None) or []
            if len(eminerpayouts) != len(minerpayoutids):
                raise tfchain.errors.ExplorerInvalidResponse("amount of miner payouts and payout ids are not matching: {} != {}".format(len(eminerpayouts), len(minerpayoutids)), endpoint, resp)
            for idx, mp in enumerate(eminerpayouts):
                id = Hash.from_json(minerpayoutids[idx])
                value = Currency.from_json(mp['value'])
                unlockhash = UnlockHash.from_json(mp['unlockhash'])
                miner_payouts.append(ExplorerMinerPayout(id=id, value=value, unlockhash=unlockhash))
            height = int(resp['height'])
            timestamp = int(rawblock['timestamp'])
            blockid = Hash.from_json(resp['blockid'])
            return ExplorerBlock(
                id=blockid, parentid=parentid,
                height=height, timestamp=timestamp,
                transactions=transactions, miner_payouts=miner_payouts)
        except KeyError as exc:
            raise tfchain.errors.ExplorerInvalidResponse(str(exc), endpoint, resp) from exc
def block_get ( self , value ) : endpoint = "/explorer/?" resp = { } try : if isinstance ( value , int ) : endpoint = "/explorer/blocks/{}" . format ( int ( value ) ) resp = self . explorer_get ( endpoint = endpoint ) resp = json_loads ( resp ) resp = resp [ 'block' ] else : blockid = self . _normalize_id ( value ) endpoint = "/explorer/hashes/" + blockid resp = self . explorer_get ( endpoint = endpoint ) resp = json_loads ( resp ) if resp [ 'hashtype' ] != 'blockid' : raise tfchain . errors . ExplorerInvalidResponse ( "expected hash type 'blockid' not '{}'" . format ( resp [ 'hashtype' ] ) , endpoint , resp ) resp = resp [ 'block' ] if resp [ 'blockid' ] != blockid : raise tfchain . errors . ExplorerInvalidResponse ( "expected block ID '{}' not '{}'" . format ( blockid , resp [ 'blockid' ] ) , endpoint , resp ) transactions = [ ] for etxn in resp [ 'transactions' ] : transaction = self . _transaction_from_explorer_transaction ( etxn , endpoint = endpoint , resp = resp ) transactions . append ( transaction ) rawblock = resp [ 'rawblock' ] parentid = Hash . from_json ( obj = rawblock [ 'parentid' ] ) miner_payouts = [ ] minerpayoutids = resp . get ( 'minerpayoutids' , None ) or [ ] eminerpayouts = rawblock . get ( 'minerpayouts' , None ) or [ ] if len ( eminerpayouts ) != len ( minerpayoutids ) : raise tfchain . errors . ExplorerInvalidResponse ( "amount of miner payouts and payout ids are not matching: {} != {}" . format ( len ( eminerpayouts ) , len ( minerpayoutids ) ) , endpoint , resp ) for idx , mp in enumerate ( eminerpayouts ) : id = Hash . from_json ( minerpayoutids [ idx ] ) value = Currency . from_json ( mp [ 'value' ] ) unlockhash = UnlockHash . from_json ( mp [ 'unlockhash' ] ) miner_payouts . append ( ExplorerMinerPayout ( id = id , value = value , unlockhash = unlockhash ) ) height = int ( resp [ 'height' ] ) timestamp = int ( rawblock [ 'timestamp' ] ) blockid = Hash . from_json ( resp [ 'blockid' ] ) return ExplorerBlock ( id = blockid , parentid = parentid , height = height , timestamp = timestamp , transactions = transactions , miner_payouts = miner_payouts ) except KeyError as exc : raise tfchain . errors . ExplorerInvalidResponse ( str ( exc ) , endpoint , resp ) from exc
Get a block from an available explorer Node.
Get a block from an available explorer Node .
"""
        Get a block from an available explorer Node.
        
        @param value: the identifier or height that points to the desired block
        """ # get the explorer block # parse the transactions # parse the explorer transaction # append the transaction to the list of transactions # parse the parent id # parse the miner payouts # get the timestamp and height # get the block's identifier # return the block, as reported by the explorer # return a KeyError as an invalid Explorer Response
self
value
the identifier or height that points to the desired block
the identifier or height that points to the desired block