mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-02-16 03:23:12 +00:00
Signed-off-by: Chrysostomos Nanakos <chris@include.gr> Co-authored-by: Chrysostomos Nanakos <chris@include.gr> Co-authored-by: gmega <giuliano.mega@gmail.com>
36 lines
845 B
Nim
36 lines
845 B
Nim
{.push raises: [].}
|
|
|
|
import libp2p
|
|
import pkg/stint
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
import ./blockexc
|
|
|
|
import ../../blocktype
|
|
|
|
export questionable
|
|
export stint
|
|
export BlockPresenceType
|
|
|
|
type
|
|
PresenceMessage* = blockexc.BlockPresence
|
|
Presence* = object
|
|
address*: BlockAddress
|
|
have*: bool
|
|
|
|
func parse(_: type UInt256, bytes: seq[byte]): ?UInt256 =
|
|
if bytes.len > 32:
|
|
return UInt256.none
|
|
UInt256.fromBytesBE(bytes).some
|
|
|
|
func init*(_: type Presence, message: PresenceMessage): ?Presence =
|
|
some Presence(
|
|
address: message.address, have: message.`type` == BlockPresenceType.Have
|
|
)
|
|
|
|
func init*(_: type PresenceMessage, presence: Presence): PresenceMessage =
|
|
PresenceMessage(
|
|
address: presence.address,
|
|
`type`: if presence.have: BlockPresenceType.Have else: BlockPresenceType.DontHave,
|
|
)
|