2021-04-07 10:19:00 +00:00
|
|
|
import pkg/protobuf_serialization
|
2021-04-08 08:09:59 +00:00
|
|
|
import pkg/stew/byteutils
|
2021-04-14 14:07:49 +00:00
|
|
|
import pkg/stint
|
2021-04-07 10:19:00 +00:00
|
|
|
import pkg/nitro
|
|
|
|
import pkg/questionable
|
2021-04-07 10:23:31 +00:00
|
|
|
import pkg/upraises
|
2021-04-08 07:22:41 +00:00
|
|
|
import ./bitswap
|
2021-04-07 10:19:00 +00:00
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
export AccountMessage
|
2021-04-07 12:30:33 +00:00
|
|
|
export StateChannelUpdate
|
2021-04-07 10:19:00 +00:00
|
|
|
|
2021-04-14 14:07:49 +00:00
|
|
|
export stint
|
2021-04-07 10:19:00 +00:00
|
|
|
export nitro
|
|
|
|
|
2021-04-07 10:23:31 +00:00
|
|
|
push: {.upraises: [].}
|
|
|
|
|
2021-04-07 10:19:00 +00:00
|
|
|
type
|
2021-05-10 14:21:47 +00:00
|
|
|
Account* = object
|
2021-04-07 10:19:00 +00:00
|
|
|
address*: EthAddress
|
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
func init*(_: type AccountMessage, account: Account): AccountMessage =
|
|
|
|
AccountMessage(address: @(account.address.toArray))
|
2021-04-07 10:19:00 +00:00
|
|
|
|
|
|
|
func parse(_: type EthAddress, bytes: seq[byte]): ?EthAddress =
|
|
|
|
var address: array[20, byte]
|
|
|
|
if bytes.len != address.len:
|
|
|
|
return EthAddress.none
|
|
|
|
for i in 0..<address.len:
|
|
|
|
address[i] = bytes[i]
|
|
|
|
EthAddress(address).some
|
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
func init*(_: type Account, message: AccountMessage): ?Account =
|
|
|
|
without address =? EthAddress.parse(message.address):
|
|
|
|
return none Account
|
|
|
|
some Account(address: address)
|
2021-04-07 12:30:33 +00: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))
|