Skip to content

Commit 6d46159

Browse files
arnetheduckjmgomez
andauthored
json: adapt to array streaming API changes (#211)
Co-authored-by: Juan M Gómez <juamangomalv@gmail.com>
1 parent 440c628 commit 6d46159

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ jobs:
162162
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
163163
bash build_nim.sh nim csources dist/nimble NimBinaries
164164
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
165+
- name: Setup Nimble
166+
uses: nim-lang/setup-nimble-action@v1
167+
with:
168+
nimble-version: 'latest'
169+
repo-token: ${{ secrets.GITHUB_TOKEN }}
165170

166171
- name: Use gcc 14
167172
# Should be removed when ubuntu-latest is 26.04

ci-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -ex
44
npm install hardhat

web3/conversions.nim

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,17 @@ func valid(hex: string): bool =
170170
if x notin HexDigits: return false
171171
true
172172

173+
when not declared(json_serialization.streamElement): # json_serialization < 0.3.0
174+
template streamElement(w: var JsonWriter, s, body: untyped) =
175+
template s: untyped = w.stream
176+
body
177+
173178
proc writeHexValue(w: var JsonWriter, v: openArray[byte])
174179
{.gcsafe, raises: [IOError].} =
175-
w.stream.write "\"0x"
176-
w.stream.writeHex v
177-
w.stream.write "\""
180+
w.streamElement(s):
181+
s.write "\"0x"
182+
s.writeHex v
183+
s.write "\""
178184

179185
#------------------------------------------------------------------------------
180186
# Well, both rpc and chronicles share the same encoding of these types
@@ -209,9 +215,10 @@ proc writeValue*[F: CommonJsonFlavors](w: var JsonWriter[F], v: RlpEncodedBytes)
209215
proc writeValue*[F: CommonJsonFlavors](
210216
w: var JsonWriter[F], v: Quantity
211217
) {.gcsafe, raises: [IOError].} =
212-
w.stream.write "\"0x"
213-
w.stream.toHex(distinctBase v)
214-
w.stream.write "\""
218+
w.streamElement(s):
219+
s.write "\"0x"
220+
s.toHex(distinctBase v)
221+
s.write "\""
215222

216223
proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var DynamicBytes)
217224
{.gcsafe, raises: [IOError, JsonReaderError].} =
@@ -299,9 +306,10 @@ proc readValue*[F: CommonJsonFlavors](r: var JsonReader[F], val: var UInt256)
299306

300307
proc writeValue*(w: var JsonWriter[JrpcConv], v: uint64)
301308
{.gcsafe, raises: [IOError].} =
302-
w.stream.write "\"0x"
303-
w.stream.toHex(v)
304-
w.stream.write "\""
309+
w.streamElement(s):
310+
s.write "\"0x"
311+
s.toHex(v)
312+
s.write "\""
305313

306314
proc readValue*(r: var JsonReader[JrpcConv], val: var uint64)
307315
{.gcsafe, raises: [IOError, JsonReaderError].} =

0 commit comments

Comments
 (0)