forked from bitshares/python-bitshares
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.py
More file actions
58 lines (45 loc) · 1.95 KB
/
block.py
File metadata and controls
58 lines (45 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from .blockchainobject import BlockchainObject
from .exceptions import BlockDoesNotExistsException
from .utils import parse_time
class Block(BlockchainObject):
""" Read a single block from the chain
:param int block: block number
:param bitshares.bitshares.BitShares blockchain_instance: BitShares
instance
:param bool lazy: Use lazy loading
Instances of this class are dictionaries that come with additional
methods (see below) that allow dealing with a block and it's
corresponding functions.
.. code-block:: python
from bitshares.block import Block
block = Block(1)
print(block)
.. note:: This class comes with its own caching function to reduce the
load on the API server. Instances of this class can be
refreshed with ``Account.refresh()``.
"""
def refresh(self):
""" Even though blocks never change, you freshly obtain its contents
from an API with this method
"""
block = self.blockchain.rpc.get_block(self.identifier)
if not block:
raise BlockDoesNotExistsException
super(Block, self).__init__(block, blockchain_instance=self.blockchain)
def time(self):
""" Return a datatime instance for the timestamp of this block
"""
return parse_time(self["timestamp"])
class BlockHeader(BlockchainObject):
def refresh(self):
""" Even though blocks never change, you freshly obtain its contents
from an API with this method
"""
block = self.blockchain.rpc.get_block_header(self.identifier)
if not block:
raise BlockDoesNotExistsException
super(BlockHeader, self).__init__(block, blockchain_instance=self.blockchain)
def time(self):
""" Return a datatime instance for the timestamp of this block
"""
return parse_time(self["timestamp"])