Decode strings

This commit is contained in:
Mark Spanbroek 2021-11-30 16:23:24 +01:00
parent 0f4c4d1465
commit 4126edf89f
2 changed files with 6 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import pkg/stint
import pkg/stew/endians2
import pkg/stew/byteutils
import pkg/upraises
import ./encoding
@ -108,6 +109,9 @@ func read*[I,T](decoder: var AbiDecoder, _: type array[I,T]): array[I,T] =
result[i] = decoder.read(T)
decoder.finishTuple()
func read*(decoder: var AbiDecoder, T: type string): T =
string.fromBytes(decoder.read(seq[byte]))
func decode*(_: type AbiDecoder, bytes: seq[byte], T: type): T =
var decoder = AbiDecoder.init(bytes)
result = decoder.read(T)

View File

@ -195,3 +195,5 @@ suite "ABI decoding":
test "decodes arrays with dynamic elements":
checkDecode([seq[byte].example, seq[byte].example])
test "decodes strings":
checkDecode("hello!☺")