whitepaper.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. examples/whitepaper.py: extract the Bitcoin whitepaper from the blockchain
  12. """
  13. import asyncio
  14. from mmgen.cfg import Config
  15. from mmgen.rpc import rpc_init
  16. txid = '54e48e5f5c656b26c3bca14a8c95aa583d07ebe84dde3b7dd4a78f4e4186e713'
  17. fn = 'bitcoin.pdf'
  18. async def main():
  19. cfg = Config(process_opts=True)
  20. assert cfg.coin == 'BTC' and cfg.network == 'mainnet', 'This script works only on BTC mainnet!'
  21. c = await rpc_init( cfg, ignore_wallet=True )
  22. tx = await c.call('getrawtransaction',txid,True)
  23. chunks = [''.join( d['scriptPubKey']['asm'].split()[1:4] ) for d in tx['vout']]
  24. with open(fn,'wb') as f:
  25. f.write(bytes.fromhex( ''.join(chunks)[16:368600] ))
  26. print(f'Wrote {fn}')
  27. asyncio.run(main())