66from . import util
77import json
88
9- def get_block (block_id , api_code = None ):
9+
10+ def get_block (block_id , api_code = None ):
1011 """Get a single block based on a block index or hash.
1112
1213 :param str block_id: block hash or index to look up
@@ -21,7 +22,8 @@ def get_block(block_id, api_code = None):
2122 json_response = json .loads (response )
2223 return Block (json_response )
2324
24- def get_tx (tx_id , api_code = None ):
25+
26+ def get_tx (tx_id , api_code = None ):
2527 """Get a single transaction based on a transaction index or hash.
2628
2729 :param str block_id: transaction hash or index to look up
@@ -36,7 +38,8 @@ def get_tx(tx_id, api_code = None):
3638 json_response = json .loads (response )
3739 return Transaction (json_response )
3840
39- def get_block_height (height , api_code = None ):
41+
42+ def get_block_height (height , api_code = None ):
4043 """Get an array of blocks at the specified height.
4144
4245 :param int height: block height to look up
@@ -51,7 +54,8 @@ def get_block_height(height, api_code = None):
5154 json_response = json .loads (response )
5255 return [Block (b ) for b in json_response ['blocks' ]]
5356
54- def get_address (address , api_code = None ):
57+
58+ def get_address (address , api_code = None ):
5559 """Get data for a single address.
5660
5761 :param str address: address to look up
@@ -65,8 +69,9 @@ def get_address(address, api_code = None):
6569 response = util .call_api (resource )
6670 json_response = json .loads (response )
6771 return Address (json_response )
68-
69- def get_unspent_outputs (address , api_code = None ):
72+
73+
74+ def get_unspent_outputs (address , api_code = None ):
7075 """Get unspent outputs for a single address.
7176
7277 :param str address: address to look up
@@ -81,7 +86,8 @@ def get_unspent_outputs(address, api_code = None):
8186 json_response = json .loads (response )
8287 return [UnspentOutput (o ) for o in json_response ['unspent_outputs' ]]
8388
84- def get_latest_block (api_code = None ):
89+
90+ def get_latest_block (api_code = None ):
8591 """Get the latest block on the main chain.
8692
8793 :param str api_code: Blockchain.info API code (optional)
@@ -94,8 +100,9 @@ def get_latest_block(api_code = None):
94100 response = util .call_api (resource )
95101 json_response = json .loads (response )
96102 return LatestBlock (json_response )
97-
98- def get_unconfirmed_tx (api_code = None ):
103+
104+
105+ def get_unconfirmed_tx (api_code = None ):
99106 """Get a list of currently unconfirmed transactions.
100107
101108 :param str api_code: Blockchain.info API code (optional)
@@ -109,7 +116,8 @@ def get_unconfirmed_tx(api_code = None):
109116 json_response = json .loads (response )
110117 return [Transaction (t ) for t in json_response ['txs' ]]
111118
112- def get_blocks (time = None , pool_name = None , api_code = None ):
119+
120+ def get_blocks (time = None , pool_name = None , api_code = None ):
113121 """Get a list of blocks for a specific day or mining pool.
114122 Both parameters are optional but at least one is required.
115123
@@ -133,7 +141,8 @@ def get_blocks(time = None, pool_name = None, api_code = None):
133141 json_response = json .loads (response )
134142 return [SimpleBlock (b ) for b in json_response ['blocks' ]]
135143
136- def get_inventory_data (hash , api_code = None ):
144+
145+ def get_inventory_data (hash , api_code = None ):
137146 """Get inventory data.
138147
139148 :param str hash: tx or block hash
@@ -146,22 +155,25 @@ def get_inventory_data(hash, api_code = None):
146155 response = util .call_api (resource )
147156 json_response = json .loads (response )
148157 return InventoryData (json_response )
149-
158+
159+
150160class SimpleBlock :
151161 def __init__ (self , b ):
152162 self .height = b ['height' ]
153163 self .hash = b ['hash' ]
154164 self .time = b ['time' ]
155165 self .main_chain = b ['main_chain' ]
156-
166+
167+
157168class LatestBlock :
158169 def __init__ (self , b ):
159170 self .hash = b ['hash' ]
160171 self .time = b ['time' ]
161172 self .block_index = b ['block_index' ]
162173 self .height = b ['height' ]
163174 self .tx_indexes = [i for i in b ['txIndexes' ]]
164-
175+
176+
165177class UnspentOutput :
166178 def __init__ (self , o ):
167179 self .tx_hash = o ['tx_hash' ]
@@ -171,7 +183,8 @@ def __init__(self, o):
171183 self .value = o ['value' ]
172184 self .value_hex = o ['value_hex' ]
173185 self .confirmations = o ['confirmations' ]
174-
186+
187+
175188class Address :
176189 def __init__ (self , a ):
177190 self .hash160 = a ['hash160' ]
@@ -181,12 +194,13 @@ def __init__(self, a):
181194 self .total_sent = a ['total_sent' ]
182195 self .final_balance = a ['final_balance' ]
183196 self .transactions = [Transaction (tx ) for tx in a ['txs' ]]
184-
197+
198+
185199class Input :
186200 def __init__ (self , i ):
187201 obj = i .get ('prev_out' )
188202 if obj is not None :
189- # regular TX
203+ # regular TX
190204 self .n = obj ['n' ]
191205 self .value = obj ['value' ]
192206 self .address = obj ['addr' ]
@@ -196,10 +210,11 @@ def __init__(self, i):
196210 self .script_sig = i ['script' ]
197211 self .sequence = i ['sequence' ]
198212 else :
199- # coinbase TX
213+ # coinbase TX
200214 self .script_sig = i ['script' ]
201215 self .sequence = i ['sequence' ]
202216
217+
203218class Output :
204219 def __init__ (self , o ):
205220 self .n = o ['n' ]
@@ -209,6 +224,7 @@ def __init__(self, o):
209224 self .script = o ['script' ]
210225 self .spent = o ['spent' ]
211226
227+
212228class Transaction :
213229 def __init__ (self , t ):
214230 self .double_spend = t .get ('double_spend' , False )
@@ -224,7 +240,8 @@ def __init__(self, t):
224240
225241 if self .block_height is None :
226242 self .block_height = - 1
227-
243+
244+
228245class Block :
229246 def __init__ (self , b ):
230247 self .hash = b ['hash' ]
@@ -246,6 +263,7 @@ def __init__(self, b):
246263 for tx in self .transactions :
247264 tx .block_height = self .height
248265
266+
249267class InventoryData :
250268 def __init__ (self , i ):
251269 self .hash = i ['hash' ]
0 commit comments