def run(self): print('FileServer IS RUN') network = Network(None) network.start() self.server = ThreadedHTTPServer(('', 8008), CmFSHandler) self.server.serve_forever()
from electrum_ltc.network import filter_protocol, Network from electrum_ltc.util import create_and_start_event_loop, log_exceptions from electrum_ltc.simple_config import SimpleConfig try: txid = sys.argv[1] except: print("usage: txradar txid") sys.exit(1) config = SimpleConfig() loop, stopping_fut, loop_thread = create_and_start_event_loop() network = Network(config) network.start() @log_exceptions async def f(): try: peers = await network.get_peers() peers = filter_protocol(peers, 's') results = await network.send_multiple_requests( peers, 'blockchain.transaction.get', [txid]) r1, r2 = [], [] for k, v in results.items(): (r1 if not isinstance(v, Exception) else r2).append(k) print(f"Received {len(results)} answers") try: propagation = len(r1) * 100. / (len(r1) + len(r2))
#!/usr/bin/env python3 import asyncio from electrum_ltc.network import filter_protocol, Network from electrum_ltc.util import create_and_start_event_loop, log_exceptions from electrum_ltc.blockchain import hash_raw_header loop, stopping_fut, loop_thread = create_and_start_event_loop() network = Network() network.start() @log_exceptions async def f(): try: peers = await network.get_peers() peers = filter_protocol(peers, 's') results = await network.send_multiple_requests(peers, 'blockchain.headers.subscribe', []) for server, header in sorted(results.items(), key=lambda x: x[1].get('height')): height = header.get('height') blockhash = hash_raw_header(header.get('hex')) print(server, height, blockhash) finally: stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop)
class CmFSHandler(FSHandler): def Tx_test(self): global GRowTransaction global GFileID global ST4del global Tx_IOSave try: XTr = Transaction(GRowTransaction) except: return 0 #print('XTr = ',XTr) Flv , FLfee , TTime = FFS.FilePP[GFileID] if( Flv + FLfee == 0. ): return 1 try: amount,fee = Tx_IOSave[self.IDTran] except: if not XTr.is_complete(): return 0 try: #is_relevant, is_mine, v, fee = self.window.wallet.get_wallet_delta(XTr) self.netw = Network(None) self.netw.start() InputAdrs = {} for x in XTr.inputs(): InputAdrs[x['address']]=None for x in InputAdrs: InputAdrs[x]=self.netw.synchronous_get(('blockchain.address.listunspent', [x])) fee = 0 amount = 0 for x in XTr.inputs(): print(InputAdrs[x['address']] ) for y in InputAdrs[x['address']]: if y['tx_hash'] == x['prevout_hash']: fee += int( y['value']) for addr, value in XTr.get_outputs(): print('get_outputs=',addr, value , FFS.ReceivAddress ) fee -= value if addr == FFS.ReceivAddress: amount += value if len(ST4del) > 9: del Tx_IOSave[ST4del[0]] del ST4del[0] Tx_IOSave[self.IDTran] = amount,fee ST4del.append(self.IDTran) except: return 0 dFlv = abs (Flv * 1e8 - amount ) dFLfee = abs (FLfee * 1e8 - fee * 1000. / (len(GRowTransaction)/2) ) if dFLfee + dFlv < 1000 : msg = 'MemPoolLimit' if amount > MemPoolLimit * 1e8 : status, msg = None,None try: status, msg = self.window.network.broadcast(XTr) print('broadcast_try=',status, msg) except: pass print('broadcast=',status, msg) return 1 return 0 def TransactionTst(self): global quest_obj global GRowTransaction global GFileID GRowTransaction = self.RowTransaction GFileID = self.FileID #print('TransactionTst=', GRowTransaction ) self.netw = None Txres = self.Tx_test() if self.netw != None: self.netw.stop() return Txres