wip, auto increment seqno for lwwref in cli

This commit is contained in:
Dmitry Zuikov 2024-03-17 04:45:07 +03:00
parent 18ed7137b9
commit 00a4cac055
1 changed files with 13 additions and 1 deletions

View File

@ -51,12 +51,24 @@ pLwwRefUpdate :: Parser (IO ())
pLwwRefUpdate = do pLwwRefUpdate = do
rpc <- pRpcCommon rpc <- pRpcCommon
puk <- argument pPubKey (metavar "LWWREF") puk <- argument pPubKey (metavar "LWWREF")
seq <- option @Word64 auto (short 's' <> long "seq" <> help "seqno" <>metavar "SEQ") seq' <- optional $ option @Word64 auto (short 's' <> long "seq" <> help "seqno" <>metavar "SEQ")
val <- option (maybeReader fromStringMay) (short 'v' <> long "value" <> help "value" <> metavar "VALUE") val <- option (maybeReader fromStringMay) (short 'v' <> long "value" <> help "value" <> metavar "VALUE")
pure $ withMyRPC @LWWRefAPI rpc $ \caller -> do pure $ withMyRPC @LWWRefAPI rpc $ \caller -> do
(sk,pk) <- liftIO $ runKeymanClient do (sk,pk) <- liftIO $ runKeymanClient do
creds <- loadCredentials puk >>= orThrowUser "can't load credentials" creds <- loadCredentials puk >>= orThrowUser "can't load credentials"
pure ( view peerSignSk creds, view peerSignPk creds ) pure ( view peerSignSk creds, view peerSignPk creds )
seq <- case seq' of
Just v -> pure v
Nothing -> do
let ref = LWWRefKey puk
callService @RpcLWWRefGet caller ref >>= \case
Left e -> err (viaShow e) >> exitFailure
Right Nothing -> err ("not found value for" <+> pretty ref) >> exitFailure
Right (Just r) -> pure $ succ (lwwSeq r)
let box = makeSignedBox @L4Proto pk sk (LWWRef @L4Proto seq val Nothing) let box = makeSignedBox @L4Proto pk sk (LWWRef @L4Proto seq val Nothing)
callService @RpcLWWRefUpdate caller box >>= \case callService @RpcLWWRefUpdate caller box >>= \case
Left e -> err (viaShow e) >> exitFailure Left e -> err (viaShow e) >> exitFailure