pre-allocate outbut buffer for typedtransaction JSON-RPC reading

This commit is contained in:
Dustin Brody 2021-12-13 11:51:22 +00:00
parent fe0674be9c
commit 0982a0a6e4
No known key found for this signature in database
GPG Key ID: 3D7A11A0156519DC
1 changed files with 9 additions and 0 deletions

View File

@ -46,6 +46,15 @@ proc fromJson*(n: JsonNode, argName: string, result: var Address) {.inline.} =
bytesFromJson(n, argName, array[20, byte](result))
proc fromJson*(n: JsonNode, argName: string, result: var TypedTransaction) {.inline.} =
let hexStrLen = n.getStr().len
if hexStrLen < 2:
# "0x" prefix
raise newException(ValueError, "Parameter \"" & argName & "\" value too short:" & $hexStrLen)
if hexStrLen mod 2 != 0:
# Spare nibble
raise newException(ValueError, "Parameter \"" & argName & "\" value not byte-aligned:" & $hexStrLen)
distinctBase(result).setLen((hexStrLen - 2) div 2)
bytesFromJson(n, argName, distinctBase(result))
proc fromJson*(n: JsonNode, argName: string, result: var Quantity) {.inline.} =