ipfs: Access IPFS locally and remotely

[ agpl, library, network ] [ Propose Tags ]

Interact with the IPFS network by shelling out to a local IPFS node or communicating via the HTTP interface of a remote IPFS node.


[Skip to Readme]
Versions [faq] 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.3.1, 1.1.4.0, 1.1.5.0
Dependencies aeson, base (<5), bytestring, envy, flow, Glob, http-media, ip, lens, monad-logger, regex-compat, rio, servant, servant-client, servant-server, swagger2, text, vector [details]
License AGPL-3.0-or-later
Copyright © 2020 Fission Internet Software Services for Open Networks Inc.
Author Brooklyn Zelenka, Daniel Holmgren, Steven Vandevelde
Maintainer brooklyn@fission.codes, daniel@fission.codes, steven@fission.codes
Category Network
Home page https://github.com/fission-suite/ipfs-haskell#readme
Bug tracker https://github.com/fission-suite/ipfs-haskell/issues
Source repo head: git clone https://github.com/fission-suite/ipfs-haskell
Uploaded by expede at 2020-09-16T01:35:16Z
Distributions NixOS:1.1.3
Downloads 994 total (158 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2020-09-16 [all 3 reports]

Modules

  • Network
    • Network.IPFS
      • Network.IPFS.Add
        • Network.IPFS.Add.Error
      • BinPath
        • Network.IPFS.BinPath.Types
      • Bytes
        • Network.IPFS.Bytes.Types
      • CID
        • Network.IPFS.CID.Types
      • Network.IPFS.Client
        • Network.IPFS.Client.Add
        • Network.IPFS.Client.Cat
        • Error
          • Network.IPFS.Client.Error.Types
        • Network.IPFS.Client.Param
        • Network.IPFS.Client.Pin
        • Network.IPFS.Client.Stat
      • Network.IPFS.DAG
        • Network.IPFS.DAG.Link
          • Network.IPFS.DAG.Link.Types
        • Node
          • Network.IPFS.DAG.Node.Types
      • Network.IPFS.Error
      • File
        • Network.IPFS.File.Types
      • Gateway
        • Network.IPFS.Gateway.Types
      • Network.IPFS.Get
        • Network.IPFS.Get.Error
      • Ignored
        • Network.IPFS.Ignored.Types
      • Info
        • Network.IPFS.Info.Types
      • Internal
        • Orphanage
          • ByteString
            • Network.IPFS.Internal.Orphanage.ByteString.Lazy
          • Network.IPFS.Internal.Orphanage.Natural
          • Network.IPFS.Internal.Orphanage.Utf8Builder
        • Network.IPFS.Internal.UTF8
      • Local
        • Network.IPFS.Local.Class
      • MIME
        • RawPlainText
          • Network.IPFS.MIME.RawPlainText.Types
      • Name
        • Network.IPFS.Name.Types
      • Path
        • Network.IPFS.Path.Types
      • Network.IPFS.Peer
        • Network.IPFS.Peer.Error
        • Network.IPFS.Peer.Types
      • Network.IPFS.Pin
      • Network.IPFS.Prelude
      • Network.IPFS.Process
        • Network.IPFS.Process.Error
        • Network.IPFS.Process.Types
      • Remote
        • Network.IPFS.Remote.Class
      • Network.IPFS.SparseTree
        • Network.IPFS.SparseTree.Types
      • Network.IPFS.Stat
        • Network.IPFS.Stat.Types
      • Timeout
        • Network.IPFS.Timeout.Types
      • Network.IPFS.Types
      • URL
        • Network.IPFS.URL.Types
  • Paths_ipfs

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for ipfs-1.1.4.0

[back to package description]

ipfs-haskell

Build Status License Maintainability Built by FISSION Discord Discourse

Documentation: ipfs on hackage

A library for integrating IPFS into your haskell applications. Interact with the IPFS network by shelling out to a local IPFS node or communicating via the HTTP interface of a remote node.

QuickStart

Define instances for MonadLocalIPFS and/or MonadRemoteIPFS. Each requires only one function:

class Monad m => MonadRemoteIPFS m where
  runRemote :: Servant.ClientM a -> m (Either Servant.ClientError a)

class Monad m => MonadLocalIPFS m where
  runLocal ::
       [IPFS.Opt]
    -> Lazy.ByteString
    -> m (Either Process.Error Process.RawMessage)

We use RIO processes to shell out to a local IPFS node and Servant for HTTP requests to a remote node.

After that, simply add MonadLocalIPFS m as a constraint to a function and you'll be able to call IPFS within it. For instance:

import           Network.IPFS
import qualified Network.IPFS.Add        as IPFS
import           Network.IPFS.File.Types as File

add ::
  MonadLocalIPFS  m
  => File.Serialzed
  -> m ()
add (Serialized rawData) = IPFS.addRaw rawData >>= \case
  Right newCID -> 
    -- ...
  Left err ->
    -- ...

You can see example instances below:

instance
  ( HasProcessContext cfg
  , HasLogFunc cfg
  , Has IPFS.BinPath cfg
  , Has IPFS.Timeout cfg
  )
  => MonadLocalIPFS (RIO cfg) where
    runLocal opts arg = do
      IPFS.BinPath ipfs <- view hasLens
      IPFS.Timeout secs <- view hasLens
      let opts' = ("--timeout=" <> show secs <> "s") : opts

      runProc readProcess ipfs (byteStringInput arg) byteStringOutput opts' >>= \case
        (ExitSuccess, contents, _) ->
          return $ Right contents
        (ExitFailure _, _, stdErr)
          | Lazy.isSuffixOf "context deadline exceeded" stdErr ->
              return . Left $ Process.Timeout secs
          | otherwise ->
            return . Left $ Process.UnknownErr stdErr

instance
  ( Has IPFS.URL     cfg
  , Has HTTP.Manager cfg
  )
  => MonadRemoteIPFS (RIO cfg) where
    runRemote query = do
      IPFS.URL url <- view hasLens
      manager      <- view hasLens

      url
        & mkClientEnv manager
        & runClientM query
        & liftIO