<s> """<STR_LIT>""" <EOL> import json , requests , traceback <EOL> from . . hash import reverse_hash <EOL> BLOCKCHAIN_API_BASE_URL = "<STR_LIT>" <EOL> from . blockchain_client import BlockchainClient <EOL> class BlockchainInfoClient ( BlockchainClient ) : <EOL> def __init__ ( self , api_key = None ) : <EOL> self . type = '<STR_LIT>' <EOL> if api_key : <EOL> self . auth = ( api_key , '<STR_LIT>' ) <EOL> else : <EOL> self . auth = None <EOL> def format_unspents ( unspents ) : <EOL> return [ { <EOL> "<STR_LIT>" : reverse_hash ( s [ "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" : s [ "<STR_LIT>" ] , <EOL> "<STR_LIT:value>" : s [ "<STR_LIT:value>" ] , <EOL> "<STR_LIT>" : s [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : s [ "<STR_LIT>" ] <EOL> } <EOL> for s in unspents <EOL> ] <EOL> def get_unspents ( address , blockchain_client = BlockchainInfoClient ( ) ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( blockchain_client , BlockchainInfoClient ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> url = BLOCKCHAIN_API_BASE_URL + "<STR_LIT>" + address <EOL> auth = blockchain_client . auth <EOL> if auth and len ( auth ) == <NUM_LIT:2> and isinstance ( auth [ <NUM_LIT:0> ] , str ) : <EOL> url = url + "<STR_LIT>" + auth [ <NUM_LIT:0> ] <EOL> r = requests . get ( url , auth = auth ) <EOL> try : <EOL> unspents = r . json ( ) [ "<STR_LIT>" ] <EOL> except ValueError , e : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return format_unspents ( unspents ) <EOL> def broadcast_transaction ( hex_tx , blockchain_client = BlockchainInfoClient ( ) ) : <EOL> """<STR_LIT>""" <EOL> url = BLOCKCHAIN_API_BASE_URL + '<STR_LIT>' <EOL> payload = { '<STR_LIT>' : hex_tx } <EOL> r = requests . post ( url , data = payload , auth = blockchain_client . auth ) <EOL> if '<STR_LIT>' in r . text . lower ( ) : <EOL> return { '<STR_LIT:success>' : True } <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) </s>
