2021-01-12 12:58:57 +00:00
|
|
|
import std/tables
|
|
|
|
import std/hashes
|
2021-01-14 12:41:54 +00:00
|
|
|
import pkg/libp2p
|
2021-01-14 13:21:07 +00:00
|
|
|
import ./ipfsobject
|
2021-01-12 12:58:57 +00:00
|
|
|
|
2021-01-14 13:21:07 +00:00
|
|
|
export ipfsobject
|
2021-01-12 12:58:57 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
Repo* = ref object
|
2021-01-14 13:21:07 +00:00
|
|
|
storage: Table[Cid, IpfsObject]
|
2021-01-12 12:58:57 +00:00
|
|
|
|
2021-01-14 12:41:54 +00:00
|
|
|
proc hash(id: Cid): Hash =
|
|
|
|
hash($id)
|
2021-01-12 12:58:57 +00:00
|
|
|
|
2021-01-14 13:21:07 +00:00
|
|
|
proc store*(repo: Repo, obj: IpfsObject) =
|
|
|
|
repo.storage[obj.cid] = obj
|
2021-01-12 12:58:57 +00:00
|
|
|
|
2021-01-14 12:41:54 +00:00
|
|
|
proc contains*(repo: Repo, id: Cid): bool =
|
|
|
|
repo.storage.hasKey(id)
|
2021-01-12 12:58:57 +00:00
|
|
|
|
2021-01-14 13:21:07 +00:00
|
|
|
proc retrieve*(repo: Repo, id: Cid): IpfsObject =
|
2021-01-14 12:41:54 +00:00
|
|
|
repo.storage[id]
|