From a9456bd22cde2a4ab4bbb7657d457cdae7bff880 Mon Sep 17 00:00:00 2001 From: coffeepots Date: Tue, 15 May 2018 18:49:27 +0100 Subject: [PATCH] Remove transport utils module as it's unused --- eth-rpc/server/private/transportutils.nim | 39 ----------------------- eth-rpc/server/serverdispatch.nim | 2 +- eth-rpc/server/servertypes.nim | 2 ++ tests/all.nim | 2 +- tests/testutils.nim | 15 --------- 5 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 eth-rpc/server/private/transportutils.nim delete mode 100644 tests/testutils.nim diff --git a/eth-rpc/server/private/transportutils.nim b/eth-rpc/server/private/transportutils.nim deleted file mode 100644 index e2c58e2..0000000 --- a/eth-rpc/server/private/transportutils.nim +++ /dev/null @@ -1,39 +0,0 @@ -from asyncdispatch import Port - -proc `$`*(port: Port): string = $int(port) - -iterator bytes*[T: SomeUnsignedInt](value: T): byte {.inline.} = - ## Traverse the bytes of a value in little endian - yield value.bytePairs[1] - -iterator bytePairs*[T: SomeUnsignedInt](value: T): tuple[key: int, val: byte] {.inline.} = - let argSize = sizeOf(T) - for bIdx in 0 ..< argSize: - let - shift = bIdx.uint * 8 - mask = 0xff'u64 shl shift - yield (bIdx, byte((value and mask) shr shift)) - -template stripLeadingZeros(value: string): string = - var cidx = 0 - # ignore the last character so we retain '0' on zero value - while cidx < value.len - 1 and value[cidx] == '0': - cidx.inc - value[cidx .. ^1] - -proc encodeQuantity*(value: SomeUnsignedInt): string = - var hValue = value.toHex.stripLeadingZeros - result = "0x" & hValue - -# REVIEW: I think Mamy has now introduced a similar proc in the `byteutils` package -proc encodeData*[T: SomeUnsignedInt](values: seq[T]): string = - ## Translates seq of values to hex string - let argSize = sizeOf(T) - result = newString((values.len * argSize) * 2 + 2) # reserve 2 bytes for "0x" - result[0..1] = "0x" - var cPos = 0 - for idx, value in values: - for bValue in values[idx].bytes: - result[cPos .. cPos + 1] = bValue.int.toHex(2) - cPos = cPos + 2 - diff --git a/eth-rpc/server/serverdispatch.nim b/eth-rpc/server/serverdispatch.nim index 692f1f3..637ac63 100644 --- a/eth-rpc/server/serverdispatch.nim +++ b/eth-rpc/server/serverdispatch.nim @@ -1,5 +1,5 @@ import asyncdispatch, asyncnet, json, tables, strutils, - servertypes, rpcconsts, private / [transportutils, debugutils], jsonutils, asyncutils, + servertypes, rpcconsts, private / debugutils, jsonutils, asyncutils, options proc processMessage(server: RpcServer, client: AsyncSocket, line: string) {.async.} = diff --git a/eth-rpc/server/servertypes.nim b/eth-rpc/server/servertypes.nim index d2e790b..c9fb6e0 100644 --- a/eth-rpc/server/servertypes.nim +++ b/eth-rpc/server/servertypes.nim @@ -32,6 +32,8 @@ var sharedServer: RpcServer proc sharedRpcServer*(): RpcServer = if sharedServer.isNil: sharedServer = newRpcServer("") result = sharedServer + +proc `$`*(port: Port): string = $int(port) template expect*(actual, expected: JsonNodeKind, argName: string) = if actual != expected: raise newException(ValueError, "Parameter \"" & argName & "\" expected " & $expected & " but got " & $actual) diff --git a/tests/all.nim b/tests/all.nim index 50cec98..c61d327 100644 --- a/tests/all.nim +++ b/tests/all.nim @@ -1,3 +1,3 @@ import - testutils, testrpcmacro, testserverclient + testrpcmacro, testserverclient diff --git a/tests/testutils.nim b/tests/testutils.nim deleted file mode 100644 index cb27129..0000000 --- a/tests/testutils.nim +++ /dev/null @@ -1,15 +0,0 @@ -import strutils, ../eth-rpc/server/private/transportutils, unittest - -suite "Encoding": - test "Encode quantity": - check 0.encodeQuantity == "0x0" - check 0x1000.encodeQuantity == "0x1000" - test "Encode data": - var i = 0 - for b in bytes(0x07_06_05_04_03_02_01_00'u64): - check b == i.byte - i.inc - test "Encode data pairs": - for i, b in bytePairs(0x07_06_05_04_03_02_01_00'u64): - check b == i.byte -