process stints to json strings rather than arrays

This commit is contained in:
coffeepots 2018-05-15 19:06:51 +01:00
parent 9c1944977e
commit 414c7dd1f2

View File

@ -1,21 +1,14 @@
import json, stint import json, stint, strutils
iterator bytes(i: UInt256|Int256): byte = template stintStr(n: UInt256|Int256): JsonNode =
let b = cast[ptr array[32, byte]](i.unsafeaddr) var s = n.toString
var pos = 0 if s.len mod 2 != 0: s = "0" & s
while pos < 32: s = "0x" & s
yield b[pos] %s
pos += 1
proc `%`*(n: UInt256): JsonNode = proc `%`*(n: UInt256): JsonNode = n.stintStr
result = newJArray()
for elem in n.bytes:
result.add(%int(elem))
proc `%`*(n: Int256): JsonNode = proc `%`*(n: Int256): JsonNode = n.stintStr
result = newJArray()
for elem in n.bytes:
result.add(%int(elem))
proc `%`*(n: byte{not lit}): JsonNode = proc `%`*(n: byte{not lit}): JsonNode =
result = newJInt(int(n)) result = newJInt(int(n))