1+ """This module corresponds to functionality documented
2+ at https://blockchain.info/api/blockchain_api
3+
4+ """
5+
16import util
27import json
38
49def get_block (block_id , api_code = None ):
10+ """Get a single block based on a block index or hash.
11+
12+ :param str block_id: block hash or index to look up
13+ :param str api_code: Blockchain.info API code (optional)
14+ :return: an instance of :class:`Block` class
15+ """
16+
517 resource = 'rawblock/' + block_id
618 if api_code is not None :
719 resource += '?api_code=' + api_code
@@ -10,6 +22,13 @@ def get_block(block_id, api_code = None):
1022 return Block (json_response )
1123
1224def get_tx (tx , api_code = None ):
25+ """Get a single transaction based on a transaction index or hash.
26+
27+ :param str block_id: transaction hash or index to look up
28+ :param str api_code: Blockchain.info API code (optional)
29+ :return: an instance of :class:`Transaction` class
30+ """
31+
1332 resource = 'rawtx/' + tx
1433 if api_code is not None :
1534 resource += '?api_code=' + api_code
@@ -18,6 +37,13 @@ def get_tx(tx, api_code = None):
1837 return Transaction (json_response )
1938
2039def get_block_height (height , api_code = None ):
40+ """Get an array of blocks at the specified height.
41+
42+ :param int height: block height to look up
43+ :param str api_code: Blockchain.info API code (optional)
44+ :return: an array of :class:`Block` objects
45+ """
46+
2147 resource = 'block-height/{0}?format=json' .format (height )
2248 if api_code is not None :
2349 resource += '&api_code=' + api_code
@@ -26,6 +52,13 @@ def get_block_height(height, api_code = None):
2652 return [Block (b ) for b in json_response ['blocks' ]]
2753
2854def get_address (address , api_code = None ):
55+ """Get data for a single address.
56+
57+ :param str address: address to look up
58+ :param str api_code: Blockchain.info API code (optional)
59+ :return: an instance of :class:`Address` class
60+ """
61+
2962 resource = 'rawaddr/' + address
3063 if api_code is not None :
3164 resource += '?api_code=' + api_code
@@ -34,6 +67,13 @@ def get_address(address, api_code = None):
3467 return Address (json_response )
3568
3669def get_unspent_outputs (address , api_code = None ):
70+ """Get unspent outputs for a single address.
71+
72+ :param str address: address to look up
73+ :param str api_code: Blockchain.info API code (optional)
74+ :return: an array of :class:`UnspentOutput` objects
75+ """
76+
3777 resource = 'unspent?active=' + address
3878 if api_code is not None :
3979 resource += '&api_code=' + api_code
@@ -42,6 +82,12 @@ def get_unspent_outputs(address, api_code = None):
4282 return [UnspentOutput (o ) for o in json_response ['unspent_outputs' ]]
4383
4484def get_latest_block (api_code = None ):
85+ """Get the latest block on the main chain.
86+
87+ :param str api_code: Blockchain.info API code (optional)
88+ :return: an instance of :class:`LatestBlock` class
89+ """
90+
4591 resource = 'latestblock'
4692 if api_code is not None :
4793 resource += '?api_code=' + api_code
@@ -50,6 +96,12 @@ def get_latest_block(api_code = None):
5096 return LatestBlock (json_response )
5197
5298def get_unconfirmed_tx (api_code = None ):
99+ """Get a list of currently unconfirmed transactions.
100+
101+ :param str api_code: Blockchain.info API code (optional)
102+ :return: an array of :class:`Transaction` objects
103+ """
104+
53105 resource = 'unconfirmed-transactions?format=json'
54106 if api_code is not None :
55107 resource += '&api_code=' + api_code
@@ -58,6 +110,15 @@ def get_unconfirmed_tx(api_code = None):
58110 return [Transaction (t ) for t in json_response ['txs' ]]
59111
60112def get_blocks (time = None , pool_name = None , api_code = None ):
113+ """Get a list of blocks for a specific day or mining pool.
114+ Both parameters are optional but at least one is required.
115+
116+ :param int time: time in milliseconds
117+ :param str pool_name: name of the mining pool
118+ :param str api_code: Blockchain.info API code (optional)
119+ :return: an array of :class:`SimpleBlock` objects
120+ """
121+
61122 resource = 'blocks/{0}?format=json'
62123 if api_code is not None :
63124 resource += '&api_code=' + api_code
@@ -73,6 +134,12 @@ def get_blocks(time = None, pool_name = None, api_code = None):
73134 return [SimpleBlock (b ) for b in json_response ['blocks' ]]
74135
75136def get_inventory_data (hash , api_code = None ):
137+ """Get inventory data.
138+
139+ :param str hash: tx or block hash
140+ :param str api_code: Blockchain.info API code (optional)
141+ :return: an instance of :class:`InventoryData` class
142+ """
76143 resource = 'inv/{0}?format=json' .format (hash )
77144 if api_code is not None :
78145 resource += '&api_code=' + api_code
0 commit comments