From 1802c5bc9ed14f4bf67c680df9625061296b0ee9 Mon Sep 17 00:00:00 2001 From: Sergey Ivanov Date: Thu, 16 Mar 2023 02:42:28 +0400 Subject: [PATCH] wip lref-list, lref-update --- docs/devlog.md | 2 +- hbs2-peer/app/PeerMain.hs | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/devlog.md b/docs/devlog.md index ab549b54..a268e951 100644 --- a/docs/devlog.md +++ b/docs/devlog.md @@ -844,7 +844,7 @@ FIXME: Обработка ошибок в асинхронном приложе FIXME: RPC, cli для линейных ссылок * [x] lref-get через rpc пира get -* [ ] lref-new через rpc пира new +* [x] lref-new через rpc пира new * [ ] lref-update через rpc пира update * [ ] lref-list через rpc пира list diff --git a/hbs2-peer/app/PeerMain.hs b/hbs2-peer/app/PeerMain.hs index ca180cfb..f81a57af 100644 --- a/hbs2-peer/app/PeerMain.hs +++ b/hbs2-peer/app/PeerMain.hs @@ -179,7 +179,9 @@ data RPCCommand = | SETLOG SetLogging | LREFANN (Hash HbSync) | LREFNEW (PubKey 'Sign UDP) Text + | LREFLIST | LREFGET (Hash HbSync) + | LREFUPDATE (PrivKey 'Sign UDP) (PubKey 'Sign UDP) (Hash HbSync) (Hash HbSync) data PeerOpts = PeerOpts @@ -244,9 +246,9 @@ runCLI = join . customExecParser (prefs showHelpOnError) $ <> command "log" (info pLog (progDesc "set logging level")) <> command "lref-ann" (info pLRefAnn (progDesc "announce linear ref")) <> command "lref-new" (info pLRefNew (progDesc "generates a new linear ref")) - -- <> command "lref-list" (info pLRefList (progDesc "list node linear refs")) + <> command "lref-list" (info pLRefList (progDesc "list node linear refs")) <> command "lref-get" (info pLRefGet (progDesc "get a linear ref")) - -- <> command "lref-update" (info pLRefUpdate (progDesc "updates a linear ref")) + <> command "lref-update" (info pLRefUpdate (progDesc "updates a linear ref")) ) confOpt = strOption ( long "config" <> short 'c' <> help "config" ) @@ -331,11 +333,28 @@ runCLI = join . customExecParser (prefs showHelpOnError) $ <&> parseCredentials @UDP . AsCredFile . LBS.toStrict . LBS.take 4096) `orDie` "can't parse credential file" runRpcCommand rpc (LREFNEW (_peerSignPk cred) t) + + pLRefList = do + rpc <- pRpcCommon + pure $ do + runRpcCommand rpc (LREFLIST) + pLRefGet = do rpc <- pRpcCommon h <- strArgument ( metavar "REF-ID" ) pure $ runRpcCommand rpc (LREFGET h) + pLRefUpdate = do + rpc <- pRpcCommon + credFile <- strOption ( short 'k' <> long "key" <> help "author keys file" ) + lrefId <- strArgument ( metavar "REF-ID" ) + hval <- strArgument ( metavar "HASH" ) + pure $ do + cred <- (LBS.readFile credFile + <&> parseCredentials @UDP . AsCredFile . LBS.toStrict . LBS.take 4096) + `orDie` "can't parse credential file" + runRpcCommand rpc (LREFUPDATE (_peerSignSk cred) (_peerSignPk cred) lrefId hval) + myException :: SomeException -> IO () myException e = die ( show e ) >> exitFailure