Browse Source

whitespace: examples

The MMGen Project 4 months ago
parent
commit
747279c106
4 changed files with 26 additions and 17 deletions
  1. 1 1
      examples/bip_hd.py
  2. 15 6
      examples/coin-daemon-info.py
  3. 5 5
      examples/halving-calculator.py
  4. 5 5
      examples/whitepaper.py

+ 1 - 1
examples/bip_hd.py

@@ -15,7 +15,7 @@ examples/bip_hd.py: Usage examples for the MMGen BIP-32/-44 hierarchical/determi
 from mmgen.cfg import Config
 from mmgen.util import fmt
 from mmgen.bip39 import bip39
-from mmgen.bip_hd import MasterNode,BipHDNode
+from mmgen.bip_hd import MasterNode, BipHDNode
 
 cfg = Config()
 

+ 15 - 6
examples/coin-daemon-info.py

@@ -36,7 +36,7 @@ examples/coin-daemon-info.py:
 #
 #       PYTHONPATH=. examples/coin-daemon-info.py btc ltc eth
 
-import sys,os,asyncio
+import sys, os, asyncio
 
 from mmgen.exception import SocketError
 from mmgen.cfg import Config
@@ -45,7 +45,7 @@ from mmgen.util import make_timestr
 
 async def get_rpc(cfg):
 	try:
-		return await rpc_init( cfg, ignore_wallet=True )
+		return await rpc_init(cfg, ignore_wallet=True)
 	except SocketError:
 		return False
 
@@ -68,9 +68,18 @@ async def main(coins):
 
 	def gen_output():
 		fs = '{:4} {:7} {:6} {:<5} {:<8} {:30} {:13} {:23} {}'
-		yield fs.format('Coin','Network','Status','Port','Chain','Latest Block','Daemon','Version','Datadir')
-		for coin,rpc in rpcs.items():
-			info = ('Down','-','-','-','-','-','-') if rpc is False else (
+		yield fs.format(
+			'Coin',
+			'Network',
+			'Status',
+			'Port',
+			'Chain',
+			'Latest Block',
+			'Daemon',
+			'Version',
+			'Datadir')
+		for coin, rpc in rpcs.items():
+			info = ('Down', '-', '-', '-', '-', '-', '-') if rpc is False else (
 				'Up',
 				rpc.port,
 				rpc.chain,
@@ -79,7 +88,7 @@ async def main(coins):
 				rpc.daemon_version_str,
 				rpc.daemon.datadir
 			)
-			yield fs.format( coin.upper(), cfgs[coin].network, *info )
+			yield fs.format(coin.upper(), cfgs[coin].network, *info)
 
 	base_cfg._util.stdout_or_pager('\n'.join(gen_output()))
 

+ 5 - 5
examples/halving-calculator.py

@@ -45,29 +45,29 @@ def date(t):
 	return '{}-{:02}-{:02} {:02}:{:02}:{:02}'.format(*time.gmtime(t)[:6])
 
 def dhms(t):
-	t,neg = (-t,'-') if t < 0 else (t,' ')
+	t, neg = (-t, '-') if t < 0 else (t, ' ')
 	return f'{neg}{t//60//60//24} days, {t//60//60%24:02}:{t//60%60:02}:{t%60:02} h/m/s'
 
 def time_diff_warning(t_diff):
 	if abs(t_diff) > 60*60:
 		print('Warning: block tip time is {} {} clock time!'.format(
 			dhms(abs(t_diff)),
-			('behind','ahead of')[t_diff<0]))
+			('behind', 'ahead of')[t_diff<0]))
 
 async def main():
 
 	proto = cfg._proto
 
 	from mmgen.rpc import rpc_init
-	c = await rpc_init( cfg, proto, ignore_wallet=True )
+	c = await rpc_init(cfg, proto, ignore_wallet=True)
 
 	tip = await c.call('getblockcount')
 	assert tip > 1, 'block tip must be > 1'
 	remaining = proto.halving_interval - tip % proto.halving_interval
-	sample_size = int(cfg.sample_size) if cfg.sample_size else min(tip-1,max(remaining,144))
+	sample_size = int(cfg.sample_size) if cfg.sample_size else min(tip-1, max(remaining, 144))
 
 	# aiohttp backend will perform these two calls concurrently:
-	cur,old = await c.gathered_call('getblockstats',((tip,),(tip - sample_size,)))
+	cur, old = await c.gathered_call('getblockstats', ((tip,), (tip - sample_size,)))
 
 	clock_time = int(time.time())
 	time_diff_warning(clock_time - cur['time'])

+ 5 - 5
examples/whitepaper.py

@@ -25,14 +25,14 @@ async def main():
 
 	assert cfg.coin == 'BTC' and cfg.network == 'mainnet', 'This script works only on BTC mainnet!'
 
-	c = await rpc_init( cfg, ignore_wallet=True )
+	c = await rpc_init(cfg, ignore_wallet=True)
 
-	tx = await c.call('getrawtransaction',txid,True)
+	tx = await c.call('getrawtransaction', txid, True)
 
-	chunks = [''.join( d['scriptPubKey']['asm'].split()[1:4] ) for d in tx['vout']]
+	chunks = [''.join(d['scriptPubKey']['asm'].split()[1:4]) for d in tx['vout']]
 
-	with open(fn,'wb') as f:
-		f.write(bytes.fromhex( ''.join(chunks)[16:368600] ))
+	with open(fn, 'wb') as f:
+		f.write(bytes.fromhex(''.join(chunks)[16:368600]))
 
 	print(f'Wrote {fn}')