Fixed gcsafety issues for newer nim

This commit is contained in:
Yuriy Glukhov 2019-09-09 23:51:24 +03:00 committed by zah
parent 817c819847
commit 08909f9972
2 changed files with 7 additions and 4 deletions

View File

@ -30,7 +30,7 @@ type
Subscription* = ref object Subscription* = ref object
id*: string id*: string
web3*: Web3 web3*: Web3
callback*: proc(j: JsonNode) callback*: proc(j: JsonNode) {.gcsafe.}
pendingEvents: seq[JsonNode] pendingEvents: seq[JsonNode]
historicalEventsProcessed: bool historicalEventsProcessed: bool
removed: bool removed: bool
@ -95,14 +95,14 @@ proc getHistoricalEvents(s: Subscription, options: JsonNode) {.async.} =
echo "Caught exception in getHistoricalEvents: ", e.msg echo "Caught exception in getHistoricalEvents: ", e.msg
echo e.getStackTrace() echo e.getStackTrace()
proc subscribe*(w: Web3, name: string, options: JsonNode, callback: proc(j: JsonNode)): Future[Subscription] {.async.} = proc subscribe*(w: Web3, name: string, options: JsonNode, callback: proc(j: JsonNode) {.gcsafe.}): Future[Subscription] {.async.} =
var options = options var options = options
if options.isNil: options = newJNull() if options.isNil: options = newJNull()
let id = await w.provider.eth_subscribe(name, options) let id = await w.provider.eth_subscribe(name, options)
result = Subscription(id: id, web3: w, callback: callback) result = Subscription(id: id, web3: w, callback: callback)
w.subscriptions[id] = result w.subscriptions[id] = result
proc subscribeToLogs*(w: Web3, options: JsonNode, callback: proc(j: JsonNode)): Future[Subscription] {.async.} = proc subscribeToLogs*(w: Web3, options: JsonNode, callback: proc(j: JsonNode) {.gcsafe.}): Future[Subscription] {.async.} =
result = await subscribe(w, "logs", options, callback) result = await subscribe(w, "logs", options, callback)
discard getHistoricalEvents(result, options) discard getHistoricalEvents(result, options)
@ -642,6 +642,8 @@ macro contract*(cname: untyped, body: untyped): untyped =
procTy = nnkProcTy.newTree(params, newEmptyNode()) procTy = nnkProcTy.newTree(params, newEmptyNode())
signature = getSignature(obj.eventObject) signature = getSignature(obj.eventObject)
procTy[1] = nnkPragma.newTree(ident"gcsafe") # TODO: use addPragma in nim 0.20.4 and later
callWithRawData.add jsonIdent callWithRawData.add jsonIdent
paramsWithRawData.add nnkIdentDefs.newTree( paramsWithRawData.add nnkIdentDefs.newTree(
jsonIdent, jsonIdent,
@ -650,6 +652,7 @@ macro contract*(cname: untyped, body: untyped): untyped =
) )
let procTyWithRawData = nnkProcTy.newTree(paramsWithRawData, newEmptyNode()) let procTyWithRawData = nnkProcTy.newTree(paramsWithRawData, newEmptyNode())
procTyWithRawData[1] = nnkPragma.newTree(ident"gcsafe") # TODO: use addPragma in nim 0.20.4 and later
result.add quote do: result.add quote do:
type `cbident` = object type `cbident` = object

View File

@ -41,7 +41,7 @@ proc addEthRpcs*(server: RpcServer) =
## Returns the SHA3 result of the given string. ## Returns the SHA3 result of the given string.
# TODO: Capture error on malformed input # TODO: Capture error on malformed input
var rawData: seq[byte] var rawData: seq[byte]
rawData = data.string.fromHex rawData = nimcrypto.fromHex(data.string)
# data will have 0x prefix # data will have 0x prefix
result = hexDataStr "0x" & $keccak_256.digest(rawData) result = hexDataStr "0x" & $keccak_256.digest(rawData)