Move common imports into a "basics" module

This commit is contained in:
Mark Spanbroek 2021-03-09 11:07:35 +01:00
parent 4afe88965c
commit f7dda63c04
14 changed files with 41 additions and 43 deletions

11
nitro/basics.nim Normal file
View File

@ -0,0 +1,11 @@
import pkg/questionable
import pkg/questionable/results
import pkg/stint
import ./uint48
import ./ethaddress
export questionable
export results
export stint
export uint48
export ethaddress

View File

@ -1,24 +1,14 @@
import std/math
import pkg/questionable
import pkg/stint
import pkg/stew/byteutils
include questionable/errorban
export stint
export questionable
type
UInt48* = range[0'u64..2'u64^48-1]
EthAddress* = distinct array[20, byte]
type EthAddress* = distinct array[20, byte]
proc toArray*(address: EthAddress): array[20, byte] =
array[20, byte](address)
proc fromHex*(_: type EthAddress, hex: string): ?EthAddress =
try:
EthAddress(array[20, byte].fromHex(hex)).some
except ValueError:
EthAddress.none
EthAddress(array[20, byte].fromHex(hex)).catch.toOption
proc `==`*(a, b: EthAddress): bool {.borrow.}

View File

@ -1,10 +1,9 @@
import pkg/stew/endians2
import pkg/stint
import ../types
import ../basics
include questionable/errorban
export types
export basics
type
AbiEncoder* = object

View File

@ -1,10 +1,10 @@
import pkg/nimcrypto
import ../types
import ../basics
import ./abi
include questionable/errorban
export types
export basics
type
Channel* = object

View File

@ -1,10 +1,10 @@
import pkg/nimcrypto
import ../types
import ../basics
import ./abi
include questionable/errorban
export types
export basics
type
Outcome* = distinct seq[AssetOutcome]

View File

@ -1,13 +1,12 @@
import pkg/questionable
import pkg/questionable/results
import pkg/nimcrypto
import pkg/secp256k1
import pkg/nimcrypto
import pkg/stew/byteutils
import ../basics
import ./state
include questionable/errorban
export questionable
export basics
export toPublicKey
type

View File

@ -1,12 +1,12 @@
import pkg/nimcrypto
import ../types
import ../basics
import ./channel
import ./outcome
import ./abi
include questionable/errorban
export types
export basics
export channel
export outcome

3
nitro/uint48.nim Normal file
View File

@ -0,0 +1,3 @@
import std/math
type UInt48* = range[0'u64..2'u64^48-1]

View File

@ -0,0 +1,7 @@
import std/unittest
import pkg/nitro
import ./examples
export unittest
export nitro
export examples

View File

@ -1,7 +1,5 @@
import std/unittest
import ./basics
import pkg/nitro/protocol/abi
import pkg/stint
import ./examples
suite "ABI encoding":

View File

@ -1,9 +1,7 @@
import std/unittest
import pkg/nitro/protocol/channel
import ./basics
import pkg/nitro/protocol/abi
import pkg/nimcrypto
import pkg/stew/byteutils
import ./examples
suite "channel":

View File

@ -1,9 +1,7 @@
import std/unittest
import ./basics
import pkg/nitro/protocol/abi
import pkg/nimcrypto
import pkg/stew/byteutils
import pkg/nitro/protocol/abi
import pkg/nitro/protocol/outcome
import ./examples
suite "outcome":

View File

@ -1,10 +1,7 @@
import std/unittest
import ./basics
import pkg/nimcrypto
import pkg/secp256k1
import pkg/stew/byteutils
import pkg/nitro/protocol/state
import pkg/nitro/protocol/signature
import ./examples
suite "signature":

View File

@ -1,9 +1,7 @@
import std/unittest
import ./basics
import pkg/nitro/protocol/abi
import pkg/nimcrypto
import pkg/stew/byteutils
import pkg/nitro/protocol/state
import pkg/nitro/protocol/abi
import ./examples
suite "state":