Bitcoin Forum
April 18, 2024, 09:11:54 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: python-bitcoinlib getblock , how to decode the hex string to human readable  (Read 1901 times)
kimitw (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
May 09, 2014, 08:42:33 AM
 #1

Dear All,

I use the  python-bitcoinlib getblock function

r = self._call('getblock', block_hash, False)

But i get the hex string format

020000003a42e1a730bd55a38c56d2f07a7094bb8d0e689............

how to decode the hex string to human readable for human readable format?

Thanks

Code:
def getblock(self, block_hash):
        """Get block <block_hash>

        Raises IndexError if block_hash is not valid.
        """
        try:
            block_hash = b2lx(block_hash)
        except TypeError:
            raise TypeError('%s.getblock(): block_hash must be bytes; got %r instance' %
                    (self.__class__.__name__, block_hash.__class__))
        try:
            r = self._call('getblock', block_hash, False)
        except JSONRPCException as ex:
            raise IndexError('%s.getblock(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        return CBlock.deserialize(unhexlify(r))
1713474714
Hero Member
*
Offline Offline

Posts: 1713474714

View Profile Personal Message (Offline)

Ignore
1713474714
Reply with quote  #2

1713474714
Report to moderator
Bitcoin mining is now a specialized and very risky industry, just like gold mining. Amateur miners are unlikely to make much money, and may even lose money. Bitcoin is much more than just mining, though!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713474714
Hero Member
*
Offline Offline

Posts: 1713474714

View Profile Personal Message (Offline)

Ignore
1713474714
Reply with quote  #2

1713474714
Report to moderator
1713474714
Hero Member
*
Offline Offline

Posts: 1713474714

View Profile Personal Message (Offline)

Ignore
1713474714
Reply with quote  #2

1713474714
Report to moderator
kimitw (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
May 09, 2014, 09:11:39 AM
 #2

Dear all,

sorry, i found how to do it.

from return CBlock.deserialize(unhexlify(r))
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!