本文整理汇总了Python中util.print_error函数的典型用法代码示例。如果您正苦于以下问题:Python print_error函数的具体用法?Python print_error怎么用?Python print_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: set_parameters
def set_parameters(self, host, port, protocol, proxy, auto_connect):
proxy_str = interface.serialize_proxy(proxy)
server_str = ':'.join([ host, port, protocol ])
self.config.set_key('auto_cycle', auto_connect, True)
self.config.set_key("proxy", proxy_str, True)
self.config.set_key("protocol", protocol, True)
self.config.set_key("server", server_str, True)
if self.proxy != proxy_str or self.protocol != protocol:
print_error('restarting network')
self.proxy = proxy_str
self.protocol = protocol
for i in self.interfaces.values(): i.stop()
if auto_connect:
#self.interface = None
return
if auto_connect:
if not self.interface.is_connected:
self.switch_to_random_interface()
else:
if self.server_is_lagging():
self.stop_interface()
else:
self.set_server(server_str)
开发者ID:WorldLeadCurrency,项目名称:electrum-wlc,代码行数:25,代码来源:network.py
示例2: verify_chunk
def verify_chunk(self, index, hexdata):
data = hexdata.decode('hex')
height = index*1920
num = len(data)/80
if index == 0:
previous_hash = ("0"*64)
else:
prev_header = self.read_header(index*1920-1)
if prev_header is None: raise
previous_hash = self.hash_header(prev_header)
if height < 43847:
bits, target = self.get_target(index)
for i in xrange(num):
height = index*1920 + i
raw_header = data[i*80:(i+1)*80]
header = self.header_from_string(raw_header)
_hash = self.pow_hash_header(header)
if height >= 43847:
bits, target = self.get_target(height, data=data)
assert previous_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert int('0x'+_hash,16) < target
print_error( 'verified height ', str(height))
previous_header = header
previous_hash = self.hash_header(header)
self.save_chunk(index, data)
print_error("validated chunk %d"%height)
开发者ID:Geopay,项目名称:electrum-exe,代码行数:32,代码来源:blockchain.py
示例3: get_chain
def get_chain(self, interface, final_header):
header = final_header
chain = [ final_header ]
requested_header = False
queue = Queue.Queue()
height = header.get('block_height')
while self.is_running():
if requested_header:
header = self.retrieve_header(interface, queue)
if not header: return
chain = [ header ] + chain
requested_header = False
height = header.get('block_height')
previous_header = self.read_header(height -1)
if not previous_header:
self.request_header(interface, height - 1, queue)
requested_header = True
continue
# verify that it connects to my chain
prev_hash = self.hash_header(previous_header)
if prev_hash != header.get('prev_block_hash'):
print_error("reorg")
self.request_header(interface, height - 1, queue)
requested_header = True
continue
else:
# the chain is complete
return chain
开发者ID:Geopay,项目名称:electrum-exe,代码行数:34,代码来源:blockchain.py
示例4: send
def send(self, messages, callback):
sub = []
for message in messages:
m, v = message
if m[-10:] == '.subscribe':
sub.append(message)
if sub:
with self.lock:
if self.subscriptions.get(callback) is None:
self.subscriptions[callback] = []
for message in sub:
if message not in self.subscriptions[callback]:
self.subscriptions[callback].append(message)
if not self.is_connected:
print_error("interface: trying to send while not connected")
return
if self.protocol in 'st':
with self.lock:
out = self.send_tcp(messages, callback)
else:
# do not use lock, http is synchronous
out = self.send_http(messages, callback)
return out
开发者ID:AdamISZ,项目名称:electrum,代码行数:28,代码来源:interface.py
示例5: run
def run(self):
self.network.start(self.network_queue)
while self.is_running():
try:
response = self.network_queue.get(timeout=0.1)
except Queue.Empty:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
m = response.get('method')
v = response.get('params')
for client in self.clients:
if repr((m, v)) in client.subscriptions:
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
开发者ID:abbylester1,项目名称:electrum,代码行数:25,代码来源:daemon.py
示例6: daemon_loop
def daemon_loop(server):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
daemon_port = server.config.get('daemon_port', DAEMON_PORT)
daemon_timeout = server.config.get('daemon_timeout', 5*60)
s.bind(('localhost', daemon_port))
s.listen(5)
s.settimeout(1)
t = time.time()
while server.running:
try:
connection, address = s.accept()
except socket.timeout:
if not server.clients:
if time.time() - t > daemon_timeout:
print_error("Daemon timeout")
break
else:
t = time.time()
continue
t = time.time()
client = ClientThread(server, connection)
client.start()
server.stop()
# sleep so that other threads can terminate cleanly
time.sleep(0.5)
print_error("Daemon exiting")
开发者ID:Henne123,项目名称:electrum-wlc,代码行数:27,代码来源:daemon.py
示例7: sign
def sign(self, keypairs):
for i, txin in enumerate(self.inputs()):
num = txin['num_sig']
for x_pubkey in txin['x_pubkeys']:
signatures = filter(None, txin['signatures'])
if len(signatures) == num:
# txin is complete
break
if x_pubkey in keypairs.keys():
print_error("adding signature for", x_pubkey)
# add pubkey to txin
txin = self._inputs[i]
x_pubkeys = txin['x_pubkeys']
ii = x_pubkeys.index(x_pubkey)
sec = keypairs[x_pubkey]
pubkey = public_key_from_private_key(sec)
txin['x_pubkeys'][ii] = pubkey
txin['pubkeys'][ii] = pubkey
self._inputs[i] = txin
# add signature
for_sig = Hash(self.tx_for_sig(i).decode('hex'))
pkey = regenerate_key(sec)
secexp = pkey.secret
private_key = bitcoin.MySigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
public_key = private_key.get_verifying_key()
sig = private_key.sign_digest_deterministic( for_sig, hashfunc=hashlib.sha256, sigencode = ecdsa.util.sigencode_der )
assert public_key.verify_digest( sig, for_sig, sigdecode = ecdsa.util.sigdecode_der)
txin['signatures'][ii] = sig.encode('hex')
self._inputs[i] = txin
print_error("is_complete", self.is_complete())
self.raw = self.serialize()
开发者ID:akshayaurora,项目名称:electrum,代码行数:31,代码来源:transaction.py
示例8: server_is_lagging
def server_is_lagging(self):
h = self.get_server_height()
if not h:
print_error('no height for main interface')
return False
lag = self.get_local_height() - self.get_server_height()
return lag > 1
开发者ID:ixcoin123,项目名称:electrum-ixc,代码行数:7,代码来源:network.py
示例9: new_blockchain_height
def new_blockchain_height(self, blockchain_height, i):
if self.is_connected():
if self.server_is_lagging():
print_error( "Server is lagging", blockchain_height, self.get_server_height())
if self.config.get('auto_cycle'):
self.set_server(i.server)
self.notify('updated')
开发者ID:ixcoin123,项目名称:electrum-ixc,代码行数:7,代码来源:network.py
示例10: run
def run(self):
self.blockchain.start()
with self.lock:
self.running = True
while self.is_running():
try:
i = self.queue.get(timeout = 30 if self.interfaces else 3)
except Queue.Empty:
if len(self.interfaces) < NUM_SERVERS:
self.start_random_interface()
continue
if i.is_connected:
self.add_recent_server(i)
i.send([ ('blockchain.headers.subscribe',[])], self.on_header)
if i == self.interface:
print_error('sending subscriptions to', self.interface.server)
self.send_subscriptions()
self.trigger_callback('connected')
else:
self.disconnected_servers.append(i.server)
self.interfaces.pop(i.server)
if i.server in self.heights:
self.heights.pop(i.server)
if i == self.interface:
self.interface = None
self.trigger_callback('disconnected')
if self.interface is None and self.config.get('auto_cycle'):
self.switch_to_random_interface()
开发者ID:genba,项目名称:electrum,代码行数:32,代码来源:network.py
示例11: __init__
def __init__(self, options={}):
# system conf, readonly
self.system_config = {}
if options.get('portable') == False:
self.read_system_config()
# user conf, writeable
self.user_dir = user_dir()
self.user_config = {}
if options.get('portable') == False:
self.read_user_config()
# command-line options
self.options_config = options
self.wallet_config = {}
self.wallet_file_exists = False
self.init_path(self.options_config.get('wallet_path'))
print_error( "path", self.path )
if self.path:
self.read_wallet_config(self.path)
# portable wallet: use the same directory for wallet and headers file
if options.get('portable'):
self.wallet_config['blockchain_headers_path'] = os.path.dirname(self.path)
开发者ID:AdvancedStyle,项目名称:electrum,代码行数:26,代码来源:simple_config.py
示例12: verify_chunk
def verify_chunk(self, index, hexdata):
data = hexdata.decode('hex')
height = index
num = len(data)/88
if index == 0:
previous_hash = ("0"*64)
else:
prev_header = self.read_header(index-1)
if prev_header is None: raise
previous_hash = self.hash_header(prev_header)
bits, target = self.get_target(index)
for i in range(num):
height = index + i
raw_header = data[i*88:(i+1)*88]
header = self.header_from_string(raw_header)
_hash = self.hash_header(header)
assert previous_hash == header.get('prev_block_hash')
#assert bits == header.get('bits')
#assert int('0x'+_hash,16) < target # Cant do bits for memorycoin yet
previous_header = header
previous_hash = _hash
self.save_chunk(index, data)
print_error("validated chunk %d"%height)
开发者ID:KillerByte,项目名称:electrum,代码行数:28,代码来源:blockchain.py
示例13: get_chunks
def get_chunks(self, i, header, height):
requested_chunks = []
min_index = (self.local_height + 1)/2016
max_index = (height + 1)/2016
for n in range(min_index, max_index + 1):
print_error( "requesting chunk", n )
i.send([ ('blockchain.block.get_chunk',[n])], 'get_header')
requested_chunks.append(n)
break
while requested_chunks:
try:
r = i.get_response('get_header',timeout=1)
except Queue.Empty:
continue
if not r: continue
if r.get('error'):
print_error('Verifier received an error:', r)
continue
# 3. handle response
method = r['method']
params = r['params']
result = r['result']
if method == 'blockchain.block.get_chunk':
index = params[0]
self.verify_chunk(index, result)
requested_chunks.remove(index)
开发者ID:nordcz,项目名称:electrum,代码行数:30,代码来源:blockchain.py
示例14: verify_header
def verify_header(self, header):
# add header to the blockchain file
# if there is a reorg, push it in a stack
height = header.get('block_height')
prev_header = self.read_header(height -1)
if not prev_header:
# return False to request previous header
return False
prev_hash = self.hash_header(prev_header)
bits, target = self.get_target(height/2016)
_hash = self.hash_header(header)
try:
assert prev_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert eval('0x'+_hash) < target
except:
# this can be caused by a reorg.
print_error("verify header failed"+ repr(header))
verifier.undo_verifications()
# return False to request previous header.
return False
self.save_header(header)
print_error("verify header:", _hash, height)
return True
开发者ID:nordcz,项目名称:electrum,代码行数:29,代码来源:blockchain.py
示例15: process_pending_sends
def process_pending_sends(self):
# Requests needs connectivity. If we don't have an interface,
# we cannot process them.
if not self.interface:
return
with self.lock:
sends = self.pending_sends
self.pending_sends = []
for messages, callback in sends:
for method, params in messages:
r = None
if method.endswith('.subscribe'):
k = self.get_index(method, params)
# add callback to list
l = self.subscriptions.get(k, [])
if callback not in l:
l.append(callback)
self.subscriptions[k] = l
# check cached response for subscriptions
r = self.sub_cache.get(k)
if r is not None:
util.print_error("cache hit", k)
callback(r)
else:
message_id = self.queue_request(method, params)
self.unanswered_requests[message_id] = method, params, callback
开发者ID:shadycarrot1258,项目名称:electrum,代码行数:28,代码来源:network.py
示例16: process_request
def process_request(self, request):
method = request['method']
params = request['params']
_id = request['id']
if method.startswith('network.'):
out = {'id':_id}
try:
f = getattr(self, method[8:])
except AttributeError:
out['error'] = "unknown method"
try:
out['result'] = f(*params)
except BaseException as e:
out['error'] = str(e)
print_error("network error", str(e))
self.response_queue.put(out)
return
if method == 'blockchain.address.subscribe':
addr = params[0]
if addr in self.addresses:
self.response_queue.put({'id':_id, 'result':self.addresses[addr]})
return
self.interface.send_request(request)
开发者ID:ixcoin123,项目名称:electrum-ixc,代码行数:27,代码来源:network.py
示例17: run
def run(self):
threading.Thread(target=self.reading_thread).start()
while self.is_running():
try:
r = self.response_queue.get(timeout=0.1)
except Queue.Empty:
continue
id = r.get('id')
if id is None:
method = r.get('method')
params = r.get('params')
else:
ws, amount, rr = self.sub_ws[id]
method = rr.get('method')
params = rr.get('params')
result = r.get('result')
if method == 'blockchain.address.subscribe':
util.print_error('response', r)
if result is not None:
request = {'method':'blockchain.address.get_balance', 'params':params, 'id':self.counter}
self.server.send_request(self, request)
self.sub_ws[self.counter] = ws, amount, request
self.counter += 1
if r.get('method') == 'blockchain.address.get_balance':
util.print_error('response', r)
if not ws.closed:
if sum(result.values()) >=amount:
ws.sendMessage(unicode('paid'))
self.server.remove_client(self)
开发者ID:huanghao2008,项目名称:electrum-grs,代码行数:33,代码来源:websockets.py
示例18: sign
def sign(self, keypairs):
print_error("tx.sign(), keypairs:", keypairs)
for i, txin in enumerate(self.inputs):
# if the input is multisig, parse redeem script
redeem_script = txin.get('redeemScript')
num, redeem_pubkeys = parse_redeemScript(redeem_script) if redeem_script else (1, [txin.get('redeemPubkey')])
# add pubkeys
txin["pubkeys"] = redeem_pubkeys
# get list of already existing signatures
signatures = txin.get("signatures",{})
# continue if this txin is complete
if len(signatures) == num:
continue
for_sig = Hash(self.tx_for_sig(i).decode('hex'))
for pubkey in redeem_pubkeys:
if pubkey in keypairs.keys():
# add signature
sec = keypairs[pubkey]
pkey = regenerate_key(sec)
secexp = pkey.secret
private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve = SECP256k1 )
public_key = private_key.get_verifying_key()
sig = private_key.sign_digest_deterministic( for_sig, hashfunc=hashlib.sha256, sigencode = ecdsa.util.sigencode_der )
assert public_key.verify_digest( sig, for_sig, sigdecode = ecdsa.util.sigdecode_der)
self.add_signature(i, pubkey, sig.encode('hex'))
print_error("is_complete", self.is_complete())
self.raw = self.serialize( self.inputs, self.outputs )
开发者ID:eehlers,项目名称:electrum,代码行数:33,代码来源:transaction.py
示例19: update_signatures
def update_signatures(self, raw):
"""Add new signatures to a transaction"""
d = deserialize(raw)
for i, txin in enumerate(self.inputs()):
sigs1 = txin.get('signatures')
sigs2 = d['inputs'][i].get('signatures')
for sig in sigs2:
if sig in sigs1:
continue
for_sig = Hash(self.tx_for_sig(i).decode('hex'))
# der to string
order = ecdsa.ecdsa.generator_secp256k1.order()
r, s = ecdsa.util.sigdecode_der(sig.decode('hex'), order)
sig_string = ecdsa.util.sigencode_string(r, s, order)
pubkeys = txin.get('pubkeys')
compressed = True
for recid in range(4):
public_key = MyVerifyingKey.from_signature(sig_string, recid, for_sig, curve = SECP256k1)
pubkey = point_to_ser(public_key.pubkey.point, compressed).encode('hex')
if pubkey in pubkeys:
public_key.verify_digest(sig_string, for_sig, sigdecode = ecdsa.util.sigdecode_string)
j = pubkeys.index(pubkey)
print_error("adding sig", i, j, pubkey, sig)
self._inputs[i]['signatures'][j] = sig
self._inputs[i]['x_pubkeys'][j] = pubkey
break
# redo raw
self.raw = self.serialize()
开发者ID:akshayaurora,项目名称:electrum,代码行数:28,代码来源:transaction.py
示例20: get_socket
def get_socket(self):
if self.use_ssl:
cert_path = os.path.join( self.config.path, 'certs', self.host)
if not os.path.exists(cert_path):
is_new = True
s = self.get_simple_socket()
if s is None:
return
# try with CA first
try:
s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv23, cert_reqs=ssl.CERT_REQUIRED, ca_certs=ca_path, do_handshake_on_connect=True)
except ssl.SSLError, e:
s = None
if s and self.check_host_name(s.getpeercert(), self.host):
print_error("SSL certificate signed by CA:", self.host)
return s
# get server certificate.
# Do not use ssl.get_server_certificate because it does not work with proxy
s = self.get_simple_socket()
try:
s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv23, cert_reqs=ssl.CERT_NONE, ca_certs=None)
except ssl.SSLError, e:
print_error("SSL error retrieving SSL certificate:", self.host, e)
return
dercert = s.getpeercert(True)
s.close()
cert = ssl.DER_cert_to_PEM_cert(dercert)
# workaround android bug
cert = re.sub("([^\n])-----END CERTIFICATE-----","\\1\n-----END CERTIFICATE-----",cert)
temporary_path = cert_path + '.temp'
with open(temporary_path,"w") as f:
f.write(cert)
开发者ID:1gabo,项目名称:electrum,代码行数:34,代码来源:interface.py
注:本文中的util.print_error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论