Fix SingleOrList parser

This commit is contained in:
jangko 2024-01-13 22:21:54 +07:00
parent 744b4e2dc3
commit 4ab592bddb
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 20 additions and 0 deletions

View File

@ -194,3 +194,18 @@ suite "JSON-RPC Quantity":
let c = JrpcConv.decode(x, RtBlockIdentifier) let c = JrpcConv.decode(x, RtBlockIdentifier)
check c.kind == bidNumber check c.kind == bidNumber
check c.number == 77 check c.number == 77
let d = JrpcConv.decode("\"10\"", RtBlockIdentifier)
check d.kind == bidAlias
check d.alias == "10"
expect JsonReaderError:
let d = JrpcConv.decode("10", RtBlockIdentifier)
discard d
test "check address or list":
let a = AddressOrList(kind: slkNull)
let x = JrpcConv.encode(a)
let c = JrpcConv.decode(x, AddressOrList)
check c.kind == slkNull

View File

@ -154,6 +154,10 @@ func valid(hex: string): bool =
if hex.len >= 2: if hex.len >= 2:
if hex[0] == '0' and hex[1] in {'x', 'X'}: if hex[0] == '0' and hex[1] in {'x', 'X'}:
start = 2 start = 2
else:
return false
else:
return false
for i in start..<hex.len: for i in start..<hex.len:
let x = hex[i] let x = hex[i]
@ -329,6 +333,7 @@ proc readValue*[T](r: var JsonReader[JrpcConv], val: var SingleOrList[T])
r.readValue(val.list) r.readValue(val.list)
of JsonValueKind.Null: of JsonValueKind.Null:
val = SingleOrList[T](kind: slkNull) val = SingleOrList[T](kind: slkNull)
r.parseNull()
else: else:
r.raiseUnexpectedValue("TopicOrList unexpected token kind =" & $tok) r.raiseUnexpectedValue("TopicOrList unexpected token kind =" & $tok)