mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-24 00:48:12 +00:00
process stint
s to json strings rather than arrays
This commit is contained in:
parent
9c1944977e
commit
414c7dd1f2
@ -1,21 +1,14 @@
|
||||
import json, stint
|
||||
import json, stint, strutils
|
||||
|
||||
iterator bytes(i: UInt256|Int256): byte =
|
||||
let b = cast[ptr array[32, byte]](i.unsafeaddr)
|
||||
var pos = 0
|
||||
while pos < 32:
|
||||
yield b[pos]
|
||||
pos += 1
|
||||
template stintStr(n: UInt256|Int256): JsonNode =
|
||||
var s = n.toString
|
||||
if s.len mod 2 != 0: s = "0" & s
|
||||
s = "0x" & s
|
||||
%s
|
||||
|
||||
proc `%`*(n: UInt256): JsonNode =
|
||||
result = newJArray()
|
||||
for elem in n.bytes:
|
||||
result.add(%int(elem))
|
||||
proc `%`*(n: UInt256): JsonNode = n.stintStr
|
||||
|
||||
proc `%`*(n: Int256): JsonNode =
|
||||
result = newJArray()
|
||||
for elem in n.bytes:
|
||||
result.add(%int(elem))
|
||||
proc `%`*(n: Int256): JsonNode = n.stintStr
|
||||
|
||||
proc `%`*(n: byte{not lit}): JsonNode =
|
||||
result = newJInt(int(n))
|
||||
|
Loading…
x
Reference in New Issue
Block a user