-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreporting.py
More file actions
47 lines (41 loc) · 1.54 KB
/
reporting.py
File metadata and controls
47 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
This module creates a .csv file for viewing account totals and the whole block chain
'''
import ledger
import accounting
acts = accounting.acts
with open('report.csv','w') as f:
f.write('Accounts\n')
f.write('Display Name,Balance\n')
for act in acts:
disp = act['display-name']
bal = act['balance']
bal = str(bal)
line = disp + ',' + bal + '\n'
f.write(line)
f.write('\n\nLedger Blocks\n')
header = 'block ID,Miner ID, Miner PK,Previous Block Hash, Work,Posts\n'
f.write(header)
blocks = ledger.ledger['blocks'][1:] #ignore the first block
for block in blocks:
block_id = str(block.block_id).rstrip()
miner_id = str(block.miner_id).rstrip()
miner_pk = '' # str(block.miner_pk).rstrip()
previous_block_hash = str(block.previous_block_hash).rstrip()
try:
work_str = str(block.work).rstrip().replace(',','<comma>')
except AttributeError:
work_str = ''
post_str = ''
for post in block.posts:
p = post.post_payload
payer = p.poster_public_register['display-name']
try:
payee = p.transaction['payee']['display-name']
except TypeError:
payee=''
amount = str(p.transaction['amount'])
data = p.data
post_str += '%s | %s | %s | %s,'%(payer, payee, amount, data)
output = '%s,%s,%s,%s,%s,%s\n'%(block_id, miner_id, miner_pk, previous_block_hash, work_str, post_str)
f.write(output)