mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-02-18 07:46:42 +00:00
add hash proc to support using with containers (#516)
This commit is contained in:
parent
5aebf0990e
commit
5c234ddd37
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import tables
|
import tables, hashes
|
||||||
import multibase, multicodec, multihash, vbuffer, varint
|
import multibase, multicodec, multihash, vbuffer, varint
|
||||||
import stew/[base58, results]
|
import stew/[base58, results]
|
||||||
|
|
||||||
@ -268,6 +268,9 @@ proc encode*(mbtype: typedesc[MultiBase], encoding: string,
|
|||||||
## ``encoding``.
|
## ``encoding``.
|
||||||
result = MultiBase.encode(encoding, cid.data.buffer).tryGet()
|
result = MultiBase.encode(encoding, cid.data.buffer).tryGet()
|
||||||
|
|
||||||
|
proc hash*(cid: Cid): Hash {.inline.} =
|
||||||
|
hash(cid.data.buffer)
|
||||||
|
|
||||||
proc `$`*(cid: Cid): string =
|
proc `$`*(cid: Cid): string =
|
||||||
## Return official string representation of content identifier ``cid``.
|
## Return official string representation of content identifier ``cid``.
|
||||||
if cid.cidver == CIDv0:
|
if cid.cidver == CIDv0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user