2022-05-19 19:56:03 +00:00
|
|
|
## Nim-Codex
|
2021-02-26 00:23:22 +00:00
|
|
|
## Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
## Licensed under either of
|
|
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
## at your option.
|
|
|
|
## This file may not be copied, modified, or distributed except according to
|
|
|
|
## those terms.
|
|
|
|
|
|
|
|
import std/hashes
|
|
|
|
import std/sequtils
|
2023-11-14 12:02:17 +00:00
|
|
|
import pkg/stew/endians2
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-10-13 23:58:57 +00:00
|
|
|
import message
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
import ../../blocktype
|
|
|
|
|
2023-03-10 07:02:54 +00:00
|
|
|
export Message, protobufEncode, protobufDecode
|
2023-11-14 12:02:17 +00:00
|
|
|
export Wantlist, WantType, WantListEntry
|
|
|
|
export BlockDelivery, BlockPresenceType, BlockPresence
|
2021-05-10 14:21:47 +00:00
|
|
|
export AccountMessage, StateChannelUpdate
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc hash*(a: BlockAddress): Hash =
|
|
|
|
if a.leaf:
|
|
|
|
let data = a.treeCid.data.buffer & @(a.index.uint64.toBytesBE)
|
|
|
|
hash(data)
|
|
|
|
else:
|
|
|
|
hash(a.cid.data.buffer)
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc hash*(e: WantListEntry): Hash =
|
|
|
|
hash(e.address)
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc contains*(a: openArray[WantListEntry], b: BlockAddress): bool =
|
2021-02-26 00:23:22 +00:00
|
|
|
## Convenience method to check for peer precense
|
|
|
|
##
|
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
a.anyIt(it.address == b)
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc `==`*(a: WantListEntry, b: BlockAddress): bool =
|
|
|
|
return a.address == b
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc `<`*(a, b: WantListEntry): bool =
|
2021-02-26 00:23:22 +00:00
|
|
|
a.priority < b.priority
|
|
|
|
|
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc `==`*(a: BlockPresence, b: BlockAddress): bool =
|
|
|
|
return a.address == b
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
proc contains*(a: openArray[BlockPresence], b: BlockAddress): bool =
|
2021-02-26 00:23:22 +00:00
|
|
|
## Convenience method to check for peer precense
|
|
|
|
##
|
|
|
|
|
2023-11-14 12:02:17 +00:00
|
|
|
a.anyIt(it.address == b)
|