diff --git a/nitro/channelupdate.nim b/nitro/channelupdate.nim index 249f67c..539421a 100644 --- a/nitro/channelupdate.nim +++ b/nitro/channelupdate.nim @@ -8,10 +8,10 @@ type state*: State signatures*: seq[(EthAddress, Signature)] -proc participants*(update: ChannelUpdate): seq[EthAddress] = +func participants*(update: ChannelUpdate): seq[EthAddress] = update.state.channel.participants -proc verifySignatures*(update: ChannelUpdate): bool = +func verifySignatures*(update: ChannelUpdate): bool = for (participant, signature) in update.signatures: if not update.participants.contains(participant): return false diff --git a/nitro/destination.nim b/nitro/destination.nim index b6c664b..44ee379 100644 --- a/nitro/destination.nim +++ b/nitro/destination.nim @@ -7,18 +7,18 @@ include questionable/errorban type Destination* = distinct array[32, byte] -proc toArray*(destination: Destination): array[32, byte] = +func toArray*(destination: Destination): array[32, byte] = array[32, byte](destination) -proc `$`*(destination: Destination): string = +func `$`*(destination: Destination): string = destination.toArray().toHex() -proc parse*(_: type Destination, s: string): ?Destination = +func parse*(_: type Destination, s: string): ?Destination = Destination(array[32, byte].fromHex(s)).catch.option -proc `==`*(a, b: Destination): bool {.borrow.} +func `==`*(a, b: Destination): bool {.borrow.} -proc toDestination*(address: EthAddress): Destination = +func toDestination*(address: EthAddress): Destination = var bytes: array[32, byte] for i in 0..<20: bytes[12 + i] = array[20, byte](address)[i] diff --git a/nitro/ethaddress.nim b/nitro/ethaddress.nim index 9f68fcb..15423f2 100644 --- a/nitro/ethaddress.nim +++ b/nitro/ethaddress.nim @@ -6,16 +6,16 @@ export questionable type EthAddress* = distinct array[20, byte] -proc zero*(_: type EthAddress): EthAddress = +func zero*(_: type EthAddress): EthAddress = EthAddress.default -proc toArray*(address: EthAddress): array[20, byte] = +func toArray*(address: EthAddress): array[20, byte] = array[20, byte](address) -proc `$`*(a: EthAddress): string = +func `$`*(a: EthAddress): string = a.toArray().toHex() -proc parse*(_: type EthAddress, hex: string): ?EthAddress = +func parse*(_: type EthAddress, hex: string): ?EthAddress = EthAddress(array[20, byte].fromHex(hex)).catch.option -proc `==`*(a, b: EthAddress): bool {.borrow.} +func `==`*(a, b: EthAddress): bool {.borrow.} diff --git a/nitro/keys.nim b/nitro/keys.nim index 8158f6c..5beed84 100644 --- a/nitro/keys.nim +++ b/nitro/keys.nim @@ -17,13 +17,13 @@ proc rng(data: var openArray[byte]): bool = proc random*(_: type PrivateKey): PrivateKey = PrivateKey.random(rng).get() -proc `$`*(key: PrivateKey): string = +func `$`*(key: PrivateKey): string = key.toHex() -proc parse*(_: type PrivateKey, s: string): ?PrivateKey = +func parse*(_: type PrivateKey, s: string): ?PrivateKey = SkSecretKey.fromHex(s).option -proc toAddress*(key: PublicKey): EthAddress = +func toAddress*(key: PublicKey): EthAddress = let hash = keccak256.digest(key.toRaw()) var bytes: array[20, byte] for i in 0..<20: diff --git a/nitro/ledger.nim b/nitro/ledger.nim index 7131442..a7b053b 100644 --- a/nitro/ledger.nim +++ b/nitro/ledger.nim @@ -2,7 +2,7 @@ import ./basics import ./channelupdate import ./protocol -proc startLedger*(me: EthAddress, +func startLedger*(me: EthAddress, hub: EthAddress, chainId: UInt256, nonce: UInt48, diff --git a/nitro/protocol/abi.nim b/nitro/protocol/abi.nim index 15d384f..b09681e 100644 --- a/nitro/protocol/abi.nim +++ b/nitro/protocol/abi.nim @@ -16,16 +16,16 @@ type head: Slice[int] tail: seq[byte] -proc write*[T](encoder: var AbiEncoder, value: T) -proc encode*[T](_: type AbiEncoder, value: T): seq[byte] +func write*[T](encoder: var AbiEncoder, value: T) +func encode*[T](_: type AbiEncoder, value: T): seq[byte] -proc init*(_: type AbiEncoder): AbiEncoder = +func init*(_: type AbiEncoder): AbiEncoder = AbiEncoder(stack: @[Tuple()]) -proc append(tupl: var Tuple, bytes: openArray[byte]) = +func append(tupl: var Tuple, bytes: openArray[byte]) = tupl.bytes.add(bytes) -proc postpone(tupl: var Tuple, bytes: seq[byte]) = +func postpone(tupl: var Tuple, bytes: seq[byte]) = var split: Split split.head.a = tupl.bytes.len tupl.append(AbiEncoder.encode(0'u64)) @@ -33,7 +33,7 @@ proc postpone(tupl: var Tuple, bytes: seq[byte]) = split.tail = bytes tupl.postponed.add(split) -proc finish(tupl: Tuple): seq[byte] = +func finish(tupl: Tuple): seq[byte] = var bytes = tupl.bytes for split in tupl.postponed: let offset = bytes.len @@ -41,74 +41,74 @@ proc finish(tupl: Tuple): seq[byte] = bytes.add(split.tail) bytes -proc append(encoder: var AbiEncoder, bytes: openArray[byte]) = +func append(encoder: var AbiEncoder, bytes: openArray[byte]) = encoder.stack[^1].append(bytes) -proc postpone(encoder: var AbiEncoder, bytes: seq[byte]) = +func postpone(encoder: var AbiEncoder, bytes: seq[byte]) = if encoder.stack.len > 1: encoder.stack[^1].postpone(bytes) else: encoder.stack[0].append(bytes) -proc setDynamic(encoder: var AbiEncoder) = +func setDynamic(encoder: var AbiEncoder) = encoder.stack[^1].dynamic = true -proc startTuple*(encoder: var AbiEncoder) = +func startTuple*(encoder: var AbiEncoder) = encoder.stack.add(Tuple()) -proc encode(encoder: var AbiEncoder, tupl: Tuple) = +func encode(encoder: var AbiEncoder, tupl: Tuple) = if tupl.dynamic: encoder.postpone(tupl.finish()) encoder.setDynamic() else: encoder.append(tupl.finish()) -proc finishTuple*(encoder: var AbiEncoder) = +func finishTuple*(encoder: var AbiEncoder) = encoder.encode(encoder.stack.pop()) -proc pad(encoder: var AbiEncoder, len: int) = +func pad(encoder: var AbiEncoder, len: int) = let padlen = (32 - len mod 32) mod 32 for _ in 0..