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)
async def f(): try: peers = await network.get_peers() peers = filter_protocol(peers) results = await network.send_multiple_requests( peers, 'blockchain.estimatefee', [2]) print(json.dumps(results, indent=4)) feerate_estimates = filter(lambda x: isinstance(x, Number), results.values()) print(f"median feerate: {median(feerate_estimates)}") finally: stopping_fut.set_result(1)
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)) except ZeroDivisionError: propagation = 0 print(f"Propagation rate: {propagation:.1f} percent") finally: stopping_fut.set_result(1)