Further simplify parsing.
This also ensures that the encoding ends with a receiver value, not a type or length. Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
810c8bf275
commit
ce388d3783
|
@ -54,39 +54,32 @@ def decode_unified(addr_str):
|
||||||
assert suffix == padding(hrp)
|
assert suffix == padding(hrp)
|
||||||
rest = decoded[:-16]
|
rest = decoded[:-16]
|
||||||
|
|
||||||
s = 0
|
|
||||||
result = {}
|
result = {}
|
||||||
while len(rest) > 0:
|
while len(rest) > 0:
|
||||||
if s == 0:
|
(receiver_type, rest) = parse_compact_size(rest)
|
||||||
(receiver_type, rest) = parse_compact_size(rest)
|
(receiver_len, rest) = parse_compact_size(rest)
|
||||||
s = 1
|
|
||||||
elif s == 1:
|
|
||||||
(receiver_len, rest) = parse_compact_size(rest)
|
|
||||||
expected_len = {0: 20, 1: 20, 2: 43, 3: 43}.get(receiver_type)
|
|
||||||
if expected_len is not None:
|
|
||||||
assert receiver_len == expected_len, "incorrect receiver length"
|
|
||||||
s = 2
|
|
||||||
elif s == 2:
|
|
||||||
assert len(rest) >= receiver_len
|
|
||||||
(receiver, rest) = (rest[:receiver_len], rest[receiver_len:])
|
|
||||||
|
|
||||||
if receiver_type == 0 or receiver_type == 1:
|
expected_len = {0: 20, 1: 20, 2: 43, 3: 43}.get(receiver_type)
|
||||||
assert not ('transparent' in result), "duplicate transparent receiver detected"
|
if expected_len is not None:
|
||||||
assert len(receiver) == 20
|
assert receiver_len == expected_len, "incorrect receiver length"
|
||||||
result['transparent'] = receiver
|
|
||||||
s = 0
|
|
||||||
|
|
||||||
elif receiver_type == 2:
|
assert len(rest) >= receiver_len
|
||||||
assert not ('sapling' in result), "duplicate sapling receiver detected"
|
(receiver, rest) = (rest[:receiver_len], rest[receiver_len:])
|
||||||
assert len(receiver) == 43
|
|
||||||
result['sapling'] = receiver
|
|
||||||
s = 0
|
|
||||||
|
|
||||||
elif receiver_type == 3:
|
if receiver_type == 0 or receiver_type == 1:
|
||||||
assert not ('orchard' in result), "duplicate orchard receiver detected"
|
assert not ('transparent' in result), "duplicate transparent receiver detected"
|
||||||
assert len(receiver) == 43
|
assert len(receiver) == 20
|
||||||
result['orchard'] = receiver
|
result['transparent'] = receiver
|
||||||
s = 0
|
|
||||||
|
elif receiver_type == 2:
|
||||||
|
assert not ('sapling' in result), "duplicate sapling receiver detected"
|
||||||
|
assert len(receiver) == 43
|
||||||
|
result['sapling'] = receiver
|
||||||
|
|
||||||
|
elif receiver_type == 3:
|
||||||
|
assert not ('orchard' in result), "duplicate orchard receiver detected"
|
||||||
|
assert len(receiver) == 43
|
||||||
|
result['orchard'] = receiver
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue