在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:fission-suite/ipfs-haskell开源软件地址:https://github.com/fission-suite/ipfs-haskell开源编程语言:Haskell 82.6%开源软件介绍:ipfs-haskellDocumentation: 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. QuickStartDefine instances for 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 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 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论