Remove transport utils module as it's unused

This commit is contained in:
coffeepots 2018-05-15 18:49:27 +01:00 committed by zah
parent 8c7290c0fe
commit a9456bd22c
5 changed files with 4 additions and 56 deletions

View File

@ -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

View File

@ -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.} =

View File

@ -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)

View File

@ -1,3 +1,3 @@
import
testutils, testrpcmacro, testserverclient
testrpcmacro, testserverclient

View File

@ -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