From 17b0bc35d8d1b41ec2b26d9778735ec7e12635b2 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 30 Jun 2019 22:04:47 -0600 Subject: [PATCH] add json encoding for bitlist and vector --- test_libs/pyspec/eth2spec/debug/encode.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test_libs/pyspec/eth2spec/debug/encode.py b/test_libs/pyspec/eth2spec/debug/encode.py index 9080bb573..ac4bd9df2 100644 --- a/test_libs/pyspec/eth2spec/debug/encode.py +++ b/test_libs/pyspec/eth2spec/debug/encode.py @@ -1,6 +1,7 @@ -from eth2spec.utils.ssz.ssz_impl import hash_tree_root +from eth2spec.utils.ssz.ssz_impl import hash_tree_root, serialize from eth2spec.utils.ssz.ssz_typing import ( - uint, Container, boolean + uint, boolean, + Bitlist, Bitvector, Container ) @@ -12,6 +13,8 @@ def encode(value, include_hash_tree_roots=False): return int(value) elif isinstance(value, boolean): return value == 1 + elif isinstance(value, (Bitlist, Bitvector)): + return '0x' + serialize(value).hex() elif isinstance(value, list): # normal python lists, ssz-List, Vector return [encode(element, include_hash_tree_roots) for element in value] elif isinstance(value, bytes): # both bytes and BytesN