Add converter from Json to UInt256

This commit is contained in:
coffeepots 2018-11-23 17:21:03 +00:00
parent dc5e62951a
commit a20a18f8e8

View File

@ -210,3 +210,10 @@ proc fromJson*(n: JsonNode, argName: string, result: var WhisperIdentityStr) =
raise newException(ValueError, "Parameter \"" & argName & "\" is not valid as a Whisper identity \"" & hexStr & "\"")
result = hexStr.WhisperIdentityStr
proc fromJson*(n: JsonNode, argName: string, result: var UInt256) =
n.kind.expect(JString, argName)
let hexStr = n.getStr()
if not hexStr.isValidEthHash: # Same format as hash
raise newException(ValueError, "Parameter \"" & argName & "\" is not valid as a UInt256 \"" & hexStr & "\"")
result = readUintBE[256](hexToPaddedByteArray[32](hexStr))