mirror of
https://github.com/status-im/nim-contract-abi.git
synced 2025-02-22 07:28:06 +00:00
Decode strings
This commit is contained in:
parent
0f4c4d1465
commit
4126edf89f
@ -1,5 +1,6 @@
|
|||||||
import pkg/stint
|
import pkg/stint
|
||||||
import pkg/stew/endians2
|
import pkg/stew/endians2
|
||||||
|
import pkg/stew/byteutils
|
||||||
import pkg/upraises
|
import pkg/upraises
|
||||||
import ./encoding
|
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)
|
result[i] = decoder.read(T)
|
||||||
decoder.finishTuple()
|
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 =
|
func decode*(_: type AbiDecoder, bytes: seq[byte], T: type): T =
|
||||||
var decoder = AbiDecoder.init(bytes)
|
var decoder = AbiDecoder.init(bytes)
|
||||||
result = decoder.read(T)
|
result = decoder.read(T)
|
||||||
|
@ -195,3 +195,5 @@ suite "ABI decoding":
|
|||||||
test "decodes arrays with dynamic elements":
|
test "decodes arrays with dynamic elements":
|
||||||
checkDecode([seq[byte].example, seq[byte].example])
|
checkDecode([seq[byte].example, seq[byte].example])
|
||||||
|
|
||||||
|
test "decodes strings":
|
||||||
|
checkDecode("hello!☺")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user