Fix compilation with Nim 1.2.6

This commit is contained in:
Mark Spanbroek 2021-03-03 10:30:07 +01:00
parent 72ba624cdc
commit 415ab9d281
10 changed files with 25 additions and 16 deletions

View File

@ -1 +1 @@
nim 1.4.2
nim 1.4.4

1
nim.cfg Normal file
View File

@ -0,0 +1 @@
--warning[ObservableStores]:"off"

View File

@ -2,6 +2,8 @@ import pkg/stew/endians2
import pkg/stint
import ./types
include ./noerrors
type
AbiEncoder* = object
stack: seq[Tuple]
@ -13,8 +15,6 @@ type
head: Slice[int]
tail: seq[byte]
{.push raises:[].}
proc write*[T](encoder: var AbiEncoder, value: T)
proc encode*[T](_: type AbiEncoder, value: T): seq[byte]

View File

@ -2,6 +2,8 @@ import pkg/nimcrypto
import ./abi
import ./types
include ./noerrors
export types
type
@ -10,8 +12,6 @@ type
participants*: seq[EthAddress]
chainId*: UInt256
{.push raises:[].}
proc getChannelId*(channel: Channel): array[32, byte] =
var encoder= AbiEncoder.init()
encoder.startTuple()

View File

@ -1,13 +1,13 @@
import std/options
import pkg/stew/results
include ./noerrors
export options
export results
{.push raises:[].}
proc toOption*[T, E](res: Result[T, E]): Option[T] =
if res.isOk:
res.value.some
res.unsafeGet().some
else:
T.none

8
nitro/noerrors.nim Normal file
View File

@ -0,0 +1,8 @@
## Include this file to indicate that your module does not raise Errors.
## Disables compiler hints about unused declarations in Nim < 1.4.0
when (NimMajor, NimMinor, NimPatch) >= (1, 4, 0):
{.push raises:[].}
else:
{.push raises: [Defect].}
{.hint[XDeclaredButNotUsed]: off.}

View File

@ -2,6 +2,8 @@ import pkg/nimcrypto
import ./abi
import ./types
include ./noerrors
export types
export abi
@ -25,8 +27,6 @@ type
targetChannelId*: array[32, byte]
destinations*: seq[array[32, byte]]
{.push raises:[].}
proc encode*(encoder: var AbiEncoder, guarantee: Guarantee) =
encoder.startTuple()
encoder.startTuple()

View File

@ -5,6 +5,8 @@ import pkg/stew/byteutils
import ./state
import ./helpers
include ./noerrors
export options
export toPublicKey
@ -13,8 +15,6 @@ type
PublicKey* = SkPublicKey
Signature* = SkRecoverableSignature
{.push raises:[].}
proc rng(data: var openArray[byte]): bool =
randomBytes(data) == data.len

View File

@ -4,6 +4,8 @@ import ./channel
import ./outcome
import ./abi
include ./noerrors
export types
export channel
export outcome
@ -27,8 +29,6 @@ type
outcome*: seq[byte]
appdata*: seq[byte]
{.push raises:[].}
proc fixedPart*(state: State): FixedPart =
FixedPart(
chainId: state.channel.chainId,

View File

@ -3,6 +3,8 @@ import std/options
import pkg/stint
import pkg/stew/byteutils
include ./noerrors
export stint
export options
@ -10,8 +12,6 @@ type
UInt48* = range[0'u64..2'u64^48-1]
EthAddress* = distinct array[20, byte]
{.push raises:[].}
proc toArray*(address: EthAddress): array[20, byte] =
array[20, byte](address)