2021-04-08 10:09:59 +02:00
|
|
|
import pkg/stew/byteutils
|
2021-04-14 16:07:49 +02:00
|
|
|
import pkg/stint
|
2021-04-07 12:19:00 +02:00
|
|
|
import pkg/nitro
|
|
|
|
import pkg/questionable
|
2021-04-07 12:23:31 +02:00
|
|
|
import pkg/upraises
|
2021-08-30 13:25:20 -06:00
|
|
|
import ./blockexc
|
2021-04-07 12:19:00 +02:00
|
|
|
|
2021-05-10 16:21:47 +02:00
|
|
|
export AccountMessage
|
2021-04-07 14:30:33 +02:00
|
|
|
export StateChannelUpdate
|
2021-04-07 12:19:00 +02:00
|
|
|
|
2021-04-14 16:07:49 +02:00
|
|
|
export stint
|
2021-04-07 12:19:00 +02:00
|
|
|
export nitro
|
|
|
|
|
2025-01-21 21:54:46 +01:00
|
|
|
push:
|
|
|
|
{.upraises: [].}
|
2021-04-07 12:23:31 +02:00
|
|
|
|
2025-01-21 21:54:46 +01:00
|
|
|
type Account* = object
|
|
|
|
address*: EthAddress
|
2021-04-07 12:19:00 +02:00
|
|
|
|
2021-05-10 16:21:47 +02:00
|
|
|
func init*(_: type AccountMessage, account: Account): AccountMessage =
|
|
|
|
AccountMessage(address: @(account.address.toArray))
|
2021-04-07 12:19:00 +02:00
|
|
|
|
|
|
|
func parse(_: type EthAddress, bytes: seq[byte]): ?EthAddress =
|
|
|
|
var address: array[20, byte]
|
|
|
|
if bytes.len != address.len:
|
|
|
|
return EthAddress.none
|
2025-01-21 21:54:46 +01:00
|
|
|
for i in 0 ..< address.len:
|
2021-04-07 12:19:00 +02:00
|
|
|
address[i] = bytes[i]
|
|
|
|
EthAddress(address).some
|
|
|
|
|
2021-05-10 16:21:47 +02:00
|
|
|
func init*(_: type Account, message: AccountMessage): ?Account =
|
|
|
|
without address =? EthAddress.parse(message.address):
|
|
|
|
return none Account
|
|
|
|
some Account(address: address)
|
2021-04-07 14:30:33 +02:00
|
|
|
|
|
|
|
func init*(_: type StateChannelUpdate, state: SignedState): StateChannelUpdate =
|
|
|
|
StateChannelUpdate(update: state.toJson.toBytes)
|
|
|
|
|
|
|
|
proc init*(_: type SignedState, update: StateChannelUpdate): ?SignedState =
|
|
|
|
SignedState.fromJson(string.fromBytes(update.update))
|