nim-nitro/nitro/channel.nim
Mark Spanbroek 34072f4749 Fix ABI encoding of Nitro state to match javascript implementation
- rewrite ABI encoding to properly handle dynamic tuples
- surround Nitro types with extra tuples to match javascript
- test with examples of encoding extracted from javascript
2021-02-25 09:11:46 +01:00

21 lines
446 B
Nim

import pkg/nimcrypto
import ./abi
import ./types
export types
type
Channel* = object
nonce*: UInt48
participants*: seq[EthAddress]
chainId*: UInt256
proc getChannelId*(channel: Channel): array[32, byte] =
var encoder= AbiEncoder.init()
encoder.startTuple()
encoder.write(channel.chainId)
encoder.write(channel.participants)
encoder.write(channel.nonce)
encoder.finishTuple()
keccak256.digest(encoder.finish()).data