We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c74d9fc commit 87fb8c1Copy full SHA for 87fb8c1
web3/encoding.nim
@@ -8,7 +8,7 @@
8
# those terms.
9
10
import
11
- std/macros,
+ std/[macros, math],
12
stint, ./eth_api_types, stew/[assign2, byteutils]
13
14
macro makeTypeEnum(): untyped =
@@ -71,7 +71,12 @@ macro makeTypeEnum(): untyped =
71
makeTypeEnum()
72
73
func encode*[bits: static[int]](x: StUint[bits]): seq[byte] =
74
- @(x.toByteArrayBE())
+ let numTargetBytes = bits div 8
75
+ let paddingBytes = 32 - numTargetBytes ## the Ethereum ABI imposes a 32 byte width for every type
76
+ let paddingZeros = newSeq[byte](paddingBytes)
77
+ let ret = paddingZeros & @(x.toByteArrayBE())
78
+ let retHex = ret.toHex()
79
+ ret
80
81
func encode*[bits: static[int]](x: StInt[bits]): seq[byte] =
82
@(x.toByteArrayBE())
0 commit comments