mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-24 08:58:18 +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 =
|
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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user