mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 12:35:51 +00:00
2396c4d76d
* Blockexchange uses merkle root and index to fetch blocks * Links the network store getTree to the local store. * Update codex/stores/repostore.nim Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> Signed-off-by: Tomasz Bekas <tomasz.bekas@gmail.com> * Rework erasure.nim to include recent cleanup * Revert accidential changes to lib versions * Addressing review comments * Storing proofs instead of trees * Fix a comment * Fix broken tests * Fix for broken testerasure.nim * Addressing PR comments --------- Signed-off-by: Tomasz Bekas <tomasz.bekas@gmail.com> Co-authored-by: benbierens <thatbenbierens@gmail.com> Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
47 lines
1.0 KiB
Nim
47 lines
1.0 KiB
Nim
import libp2p
|
|
import pkg/stint
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
import pkg/upraises
|
|
import ./blockexc
|
|
|
|
import ../../blocktype
|
|
|
|
export questionable
|
|
export stint
|
|
export BlockPresenceType
|
|
|
|
upraises.push: {.upraises: [].}
|
|
|
|
type
|
|
PresenceMessage* = blockexc.BlockPresence
|
|
Presence* = object
|
|
address*: BlockAddress
|
|
have*: bool
|
|
price*: UInt256
|
|
|
|
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 =
|
|
without price =? UInt256.parse(message.price):
|
|
return none Presence
|
|
|
|
some Presence(
|
|
address: message.address,
|
|
have: message.`type` == BlockPresenceType.Have,
|
|
price: price
|
|
)
|
|
|
|
func init*(_: type PresenceMessage, presence: Presence): PresenceMessage =
|
|
PresenceMessage(
|
|
address: presence.address,
|
|
`type`: if presence.have:
|
|
BlockPresenceType.Have
|
|
else:
|
|
BlockPresenceType.DontHave,
|
|
price: @(presence.price.toBytesBE)
|
|
)
|