Explicitly make the JSON output Bitcoin-flavoured (32-byte values reversed)

Also renames the 'json' output type to 'zcash' to make it more obvious.
This commit is contained in:
Jack Grigg 2018-06-13 11:48:17 +12:00
parent 145fe37af5
commit dd66ed8fec
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
1 changed files with 9 additions and 6 deletions

View File

@ -10,14 +10,17 @@ def chunk(h):
#
# JSON (with string comments)
# If bitcoin_flavoured == True, 32-byte values are reversed
#
def tv_value_json(value):
def tv_value_json(value, bitcoin_flavoured):
if type(value) == bytes:
if bitcoin_flavoured and len(value) == 32:
value = value[::-1]
value = hexlify(value).decode()
return value
def tv_json(filename, parts, vectors):
def tv_json(filename, parts, vectors, bitcoin_flavoured):
if type(vectors) == type({}):
vectors = [vectors]
@ -28,7 +31,7 @@ def tv_json(filename, parts, vectors):
', '.join([p[0] for p in parts])
))
print(' ' + ',\n '.join([
json.dumps([tv_value_json(v[p[0]]) for p in parts]) for v in vectors
json.dumps([tv_value_json(v[p[0]], bitcoin_flavoured) for p in parts]) for v in vectors
]))
print(']')
@ -89,11 +92,11 @@ def tv_rust(filename, parts, vectors):
def render_args():
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--target', choices=['json', 'rust'], default='rust')
parser.add_argument('-t', '--target', choices=['zcash', 'rust'], default='rust')
return parser.parse_args()
def render_tv(args, filename, parts, vectors):
if args.target == 'rust':
tv_rust(filename, parts, vectors)
elif args.target == 'json':
tv_json(filename, parts, vectors)
elif args.target == 'zcash':
tv_json(filename, parts, vectors, True)