Skip to content

A peer-to-peer stack for code collaboration

Simplify 'Radicle.Daemon.Ipfs.createMachine'

Thomas Scholtesdf7d1961bc69
diff --git a/src/Radicle/Daemon/Ipfs.hs b/src/Radicle/Daemon/Ipfs.hs
index 3fd724b..f6a2be6 100644
--- a/src/Radicle/Daemon/Ipfs.hs
+++ b/src/Radicle/Daemon/Ipfs.hs
@@ -35,7 +35,6 @@ import qualified Radicle.Internal.MachineBackend.Ipfs as Ipfs
import Radicle.Internal.Parse
import Radicle.Internal.Pretty
import qualified Radicle.Internal.UUID as UUID
-import Radicle.Ipfs
import qualified Radicle.Ipfs as Ipfs
jsonToValue :: Aeson.Value -> Aeson.Parser Value
@@ -135,12 +134,15 @@ machineInputsFrom :: MachineId -> Maybe Ipfs.MachineEntryIndex -> IO (Ipfs.Machi
machineInputsFrom = Ipfs.receiveIpfs . getMachineId
-- | Create an IPFS machine and return its ID.
+--
+-- Generates a new IPNS key and sets the IPNS record to the empty
+-- machine DAG node.
createMachine :: IO MachineId
createMachine = do
- id_ <- Ipfs.ipfsMachineCreate =<< UUID.uuid
- case id_ of
- Left e -> throw (IpfsException e)
- Right id -> pure (MachineId id)
+ uuid <- UUID.uuid
+ Ipfs.KeyGenResponse ipnsId <- Ipfs.keyGen uuid
+ Ipfs.namePublish ipnsId $ Ipfs.AddressIpfs Ipfs.emptyMachineCid
+ pure $ MachineId ipnsId
-- | Publish to IPNS a machine entry index for a machine. Should only be issued
-- by the writer.
diff --git a/src/Radicle/Internal/MachineBackend/Ipfs.hs b/src/Radicle/Internal/MachineBackend/Ipfs.hs
index 9fd4697..69d614b 100644
--- a/src/Radicle/Internal/MachineBackend/Ipfs.hs
+++ b/src/Radicle/Internal/MachineBackend/Ipfs.hs
@@ -19,7 +19,6 @@ module Radicle.Internal.MachineBackend.Ipfs where
import Protolude hiding (catch, try)
-import Control.Exception.Safe
import Control.Monad.Fail
import Data.Aeson (FromJSON, ToJSON, (.:), (.=))
import qualified Data.Aeson as Aeson
@@ -30,18 +29,6 @@ import Radicle.Internal.Parse
import Radicle.Internal.Pretty
import qualified Radicle.Ipfs as Ipfs
--- | Create a Radicle machine and return its identifier. The argument
--- is the name to store with the returned key on the local. It is not
--- portable. To avoid conflicts it is recommended to use a UUID.
-ipfsMachineCreate :: Text -> IO (Either Text Ipfs.IpnsId)
-ipfsMachineCreate name = do
- res <- liftIO $ tryAny $ do
- Ipfs.KeyGenResponse machineId <- Ipfs.keyGen name
- Ipfs.namePublish machineId $ Ipfs.AddressIpfs emptyMachineCid
- pure machineId
- pure $ first (toS . displayException) res
-
-
newtype MachineEntryIndex = MachineEntryIndex CID
deriving (Show, Eq)