1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00
electrs/contrib/mempool.py

42 lines
1.1 KiB
Python
Raw Normal View History

2018-07-03 14:37:49 +02:00
#!/usr/bin/env python3
2019-08-03 13:46:39 +02:00
2018-08-14 09:08:11 +02:00
import argparse
2019-08-03 13:46:39 +02:00
from daemon import Daemon
2018-07-03 14:19:49 +02:00
import numpy as np
import matplotlib.pyplot as plt
2018-05-22 08:25:10 +02:00
def main():
2018-08-14 09:08:11 +02:00
parser = argparse.ArgumentParser()
parser.add_argument('--testnet', action='store_true')
args = parser.parse_args()
if args.testnet:
d = Daemon(port=18332, cookie_dir='~/.bitcoin/testnet3')
else:
d = Daemon(port=8332, cookie_dir='~/.bitcoin')
2018-07-17 09:11:28 +02:00
txids, = d.request('getrawmempool', [[False]])
2018-05-22 08:25:10 +02:00
txids = list(map(lambda a: [a], txids))
2018-07-03 14:19:49 +02:00
2018-07-17 09:11:28 +02:00
entries = d.request('getmempoolentry', txids)
entries = [{'fee': e['fee']*1e8, 'vsize': e['vsize']} for e in entries]
2018-07-03 14:19:49 +02:00
for e in entries:
e['rate'] = e['fee'] / e['vsize'] # sat/vbyte
entries.sort(key=lambda e: e['rate'], reverse=True)
vsize = np.array([e['vsize'] for e in entries]).cumsum()
rate = np.array([e['rate'] for e in entries])
plt.semilogy(vsize / 1e6, rate, '-')
plt.xlabel('Mempool size (MB)')
plt.ylabel('Fee rate (sat/vbyte)')
2018-07-03 14:37:49 +02:00
plt.title('{} transactions'.format(len(entries)))
2018-07-03 14:19:49 +02:00
plt.grid()
plt.show()
2018-05-22 08:25:10 +02:00
if __name__ == '__main__':
main()