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.hsindex 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 Ipfsimport Radicle.Internal.Parseimport Radicle.Internal.Prettyimport qualified Radicle.Internal.UUID as UUID-import Radicle.Ipfsimport qualified Radicle.Ipfs as IpfsjsonToValue :: Aeson.Value -> Aeson.Parser Value@@ -135,12 +134,15 @@ machineInputsFrom :: MachineId -> Maybe Ipfs.MachineEntryIndex -> IO (Ipfs.MachimachineInputsFrom = 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 MachineIdcreateMachine = 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.hsindex 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 whereimport Protolude hiding (catch, try)-import Control.Exception.Safeimport Control.Monad.Failimport Data.Aeson (FromJSON, ToJSON, (.:), (.=))import qualified Data.Aeson as Aeson@@ -30,18 +29,6 @@ import Radicle.Internal.Parseimport Radicle.Internal.Prettyimport 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 CIDderiving (Show, Eq)