Skip to content

Commit

Permalink
feat(api): implement 'ipfs cat' (#48)
Browse files Browse the repository at this point in the history
* feat(ipfs): implement 'ipfs cat'

* feat(ipfs): implement 'ipfs cat' in pure

* feat(ipfs): express 'ipfs cat' in aqua

* chore: fix typos
  • Loading branch information
folex authored Jan 30, 2023
1 parent dfd03be commit d641e0e
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 199 deletions.
24 changes: 12 additions & 12 deletions aqua/ipfs-api.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ alias PeerId: string
alias CID: string
alias Path: string

-- Download file from remote IPFS node to Fluence node and then
-- Download file from remote IPFS node to Fluence node and then
-- put that file to local IPFS node, effectively caching it on the local IPFS node.
--
-- Arguments:
Expand All @@ -19,7 +19,7 @@ alias Path: string
-- Path on the node's local filesystem. It will be available only during single particle execution.
--
-- Errors:
-- If Ipfs.get_from or Ipfs.put fails, nil is returned.
-- If Ipfs.get_from or Ipfs.put fails, nil is returned.
-- Errors are reported to the `error` callback.
func get_and_cache(
node: PeerId,
Expand Down Expand Up @@ -49,14 +49,17 @@ func get_and_cache(
-- path should exist & be available to `aqua-ipfs`
func put(node: PeerId, path: string) -> IpfsPutResult:
on node:
result <- Ipfs.put(path)
<- result
<- Ipfs.put(path)

-- Download file `cid` from IPFS node `from` and save it to `node`
func get_from(node: PeerId, cid: CID, from: Multiaddr) -> IpfsGetResult:
on node:
result <- Ipfs.get_from(cid, from)
<- result
<- Ipfs.get_from(cid, from)

-- Return contents of the file `cid` from IPFS node `from`
func cat_from(node: PeerId, cid: CID, from: Multiaddr) -> IpfsCatResult:
on node:
<- Ipfs.cat_from(cid, from)

-- Set timeout for IPFS calls in `aqua-ipfs`
func set_timeout(node: PeerId, timeout_sec: u64):
Expand All @@ -66,17 +69,14 @@ func set_timeout(node: PeerId, timeout_sec: u64):
-- Get externally available multiaddress of IPFS's HTTP RPC endpoint (usually on port 5001)
func get_external_api_multiaddr(node: PeerId) -> IpfsMultiaddrResult:
on node:
result <- Ipfs.get_external_api_multiaddr()
<- result
<- Ipfs.get_external_api_multiaddr()

-- Get externally available multiaddress of IPFS's Swarm endpoint (usually on port 4001)
func get_external_swarm_multiaddr(node: PeerId) -> IpfsMultiaddrResult:
on node:
result <- Ipfs.get_external_swarm_multiaddr()
<- result
<- Ipfs.get_external_swarm_multiaddr()

-- Get local multiaddress of IPFS's HTTP RPC endpoint (usually on port 5001)
func get_local_api_multiaddr(node: PeerId) -> IpfsMultiaddrResult:
on node:
result <- Ipfs.get_local_api_multiaddr()
<- result
<- Ipfs.get_local_api_multiaddr()
9 changes: 8 additions & 1 deletion aqua/ipfs.aqua
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module Ipfs declares *

data IpfsCatResult:
success: bool
error: string
contents: string

data IpfsGetResult:
success: bool
error: string
Expand All @@ -20,6 +25,8 @@ data IpfsResult:
error: string

service Ipfs("aqua-ipfs"):
cat(hash: string) -> IpfsCatResult
cat_from(hash: string, external_multiaddr: string) -> IpfsCatResult
connect(multiaddr: string) -> IpfsResult
get(hash: string) -> IpfsGetResult
get_external_api_multiaddr() -> IpfsMultiaddrResult
Expand All @@ -30,4 +37,4 @@ service Ipfs("aqua-ipfs"):
set_external_api_multiaddr(multiaddr: string) -> IpfsResult
set_external_swarm_multiaddr(multiaddr: string) -> IpfsResult
set_local_api_multiaddr(multiaddr: string) -> IpfsResult
set_timeout(timeout_sec: u64)
set_timeout(timeout_sec: u64)
Loading

0 comments on commit d641e0e

Please sign in to comment.