adjust for vmcp
This commit is contained in:
parent
ff7455c914
commit
211a51553e
5
dump.py
5
dump.py
|
@ -16,7 +16,8 @@ parser.add_argument('--transform_segwit', type=bool, default=False)
|
|||
parser.add_argument('--reindex', type=bool, default=False)
|
||||
parser.add_argument('--bitcoind')
|
||||
parser.add_argument('--blockheight', type=int)
|
||||
parser.add_argument('--chainstate-version', type=int, default=15)
|
||||
parser.add_argument('--chainstate_version', type=int, default=15)
|
||||
parser.add_argument('--vmcp_file')
|
||||
|
||||
# debugging options
|
||||
parser.add_argument('--verbose', default=False)
|
||||
|
@ -35,4 +36,4 @@ if(args.reindex or args.bitcoind or args.blockheight):
|
|||
snap_utxos(args.bitcoind, args.bitcoind_datadir, args.blockheight)
|
||||
|
||||
dump_utxos(args.bitcoind_datadir, args.utxo_dir, args.nperfile,
|
||||
args.transform_segwit, args.maxutxos, debug=args.verbose)
|
||||
args.transform_segwit, args.maxutxos, debug=args.verbose, vmcp_file='vmcp.csv')
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import b128
|
||||
import binascii
|
||||
import itertools
|
||||
import os
|
||||
import plyvel
|
||||
|
|
45
utxo/dump.py
45
utxo/dump.py
|
@ -1,11 +1,15 @@
|
|||
import csv
|
||||
import os
|
||||
import struct
|
||||
|
||||
from binascii import hexlify
|
||||
|
||||
import pycoin.key.Key as Key
|
||||
from pycoin.encoding import a2b_hashed_base58
|
||||
|
||||
from utxo.chainstate import ldb_iter
|
||||
from utxo.script import unwitness
|
||||
from utxo.util import new_utxo_file
|
||||
from utxo.util import new_utxo_file, utxo_file_name
|
||||
|
||||
|
||||
def snap_utxos(bitcoind, bitcoind_datadir, stop_block):
|
||||
|
@ -16,7 +20,8 @@ def snap_utxos(bitcoind, bitcoind_datadir, stop_block):
|
|||
os.system(cmd)
|
||||
|
||||
|
||||
def dump_utxos(datadir, output_dir, n, convert_segwit, maxT=0, debug=True):
|
||||
def dump_utxos(datadir, output_dir, n, convert_segwit,
|
||||
maxT=0, debug=True, vmcp_file=None):
|
||||
|
||||
i = 0
|
||||
k = 1
|
||||
|
@ -49,3 +54,39 @@ def dump_utxos(datadir, output_dir, n, convert_segwit, maxT=0, debug=True):
|
|||
break
|
||||
|
||||
f.close()
|
||||
write_vmcp_data(output_dir, k + 1, vmcp_file)
|
||||
|
||||
|
||||
def write_vmcp_data(output_dir, k, vmcp_file):
|
||||
|
||||
def addr_to_script(addr):
|
||||
if addr[:2] == 't3':
|
||||
scr = 'a914' + a2b_hashed_base58(addr)[2:].encode('hex') + '87'
|
||||
return scr
|
||||
|
||||
assert addr[:2] == 't1'
|
||||
k = Key.from_text(addr)
|
||||
enc = '76a914'+k.hash160()[1:].encode('hex')+'88ac'
|
||||
return enc.decode('hex')
|
||||
|
||||
reader = csv.reader(open(vmcp_file, 'rb'), delimiter=",", quotechar='"')
|
||||
print 'writing vmcp data from {} to utxo-{}'.format(vmcp_file, utxo_file_name(output_dir, k))
|
||||
|
||||
balances = {}
|
||||
for i, line in enumerate(reader):
|
||||
if i == 0:
|
||||
continue
|
||||
|
||||
line[0] = addr_to_script(line[0])
|
||||
assert line[0] not in balances
|
||||
assert len(line) == 5
|
||||
balances[line[0]] = int(float(line[-1]) * 100E6)
|
||||
|
||||
f = new_utxo_file(output_dir, k)
|
||||
for script, amt in balances.iteritems():
|
||||
f.write(struct.pack('<QQ', amt, len(script)))
|
||||
f.write(script)
|
||||
f.write('\n')
|
||||
|
||||
f.close()
|
||||
print 'wrote {} records'.format(i)
|
||||
|
|
Loading…
Reference in New Issue