From a445166fe23cb2bcd426fff1a876a60d965ebb07 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 18 Aug 2026 17:40:53 +0200 Subject: [PATCH] stricter house conventions --- src/Simplex/Chat/Library/Commands.hs | 8 +++++--- src/Simplex/Chat/Names/Protocol.hs | 6 +++--- tests/Bots/NamesServiceTests.hs | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index b72dd58e15..20909a44b2 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -1471,15 +1471,18 @@ processChatCommand cxt nm = \case secret <- NameSecret <$> atomically (C.randomBytes 32 g) let ttl = defaultNameTtl commitment = mkCommitment nm' owner secret ttl + -- a service error ends the registration, so it is raised here rather + -- than repeated at each step sendNames c = do let req = NamesRequest currentNamesVersion c respData <- withAgent $ \a -> sendServiceRequestAsync a (aUserId user) cReq Nothing Nothing (LB.toStrict $ J.encode req) - either (const $ throwCmdError "invalid names response") pure $ J.eitherDecodeStrict' respData + either (const $ throwCmdError "invalid names response") pure (J.eitherDecodeStrict' respData) >>= \case + NRPError {nrCode, nrMessage} -> throwChatError $ CENameRegistrationFailed (textEncode nrCode) nrMessage + r -> pure r progress phase waitMs = toView $ CEvtNameRegistrationProgress user nm' phase waitMs progress NRPhaseCommitting Nothing sendNames (NRCommit commitment) >>= \case NRPCommitted {} -> pure () - NRPError {nrCode, nrMessage} -> throwChatError $ CENameRegistrationFailed (textEncode nrCode) nrMessage _ -> throwCmdError "unexpected commit response" progress NRPhaseCommitted (Just commitWaitMs) liftIO $ threadDelay $ fromIntegral commitWaitMs * 1000 @@ -1487,7 +1490,6 @@ processChatCommand cxt nm = \case (expiry', txHash') <- sendNames (NRReveal nm' owner secret ttl sLink) >>= \case NRPRegistered {nrExpiry, nrTxHash} -> pure (nrExpiry, nrTxHash) - NRPError {nrCode, nrMessage} -> throwChatError $ CENameRegistrationFailed (textEncode nrCode) nrMessage _ -> throwCmdError "unexpected reveal response" progress NRPhaseRegistered Nothing pure $ CRNameRegistered user nm' (tshow owner) expiry' txHash' diff --git a/src/Simplex/Chat/Names/Protocol.hs b/src/Simplex/Chat/Names/Protocol.hs index f0028b6e31..2c129e3e86 100644 --- a/src/Simplex/Chat/Names/Protocol.hs +++ b/src/Simplex/Chat/Names/Protocol.hs @@ -32,10 +32,11 @@ module Simplex.Chat.Names.Protocol ) where +import Control.Applicative (optional) import Data.Aeson (FromJSON (..), ToJSON (..), (.:), (.:?), (.=)) import qualified Data.Aeson as J +import qualified Data.Aeson.TH as JQ import qualified Data.Aeson.Types as JT -import Control.Applicative (optional) import Data.Attoparsec.ByteString.Char8 (Parser) import qualified Data.Attoparsec.ByteString.Char8 as A import qualified Data.ByteArray.Encoding as BAE @@ -47,12 +48,11 @@ import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) import Data.Time.Clock (UTCTime) import Data.Word (Word16, Word32) -import qualified Data.Aeson.TH as JQ import Simplex.Messaging.Encoding (smpEncode) import Simplex.Messaging.Encoding.String -import Simplex.Messaging.Parsers (enumJSON) import Simplex.Messaging.Eth.Address (Address, checksumAddress, parseAddress, unAddress) import Simplex.Messaging.Eth.Keccak (keccak256) +import Simplex.Messaging.Parsers (enumJSON) import Simplex.Messaging.Util (safeDecodeUtf8) -- | Protocol version, negotiated the way the badge service version is. diff --git a/tests/Bots/NamesServiceTests.hs b/tests/Bots/NamesServiceTests.hs index ff3fc07491..a72ffabf96 100644 --- a/tests/Bots/NamesServiceTests.hs +++ b/tests/Bots/NamesServiceTests.hs @@ -1,5 +1,4 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PostfixOperators #-} module Bots.NamesServiceTests where @@ -7,11 +6,11 @@ import Bots.BadgeServiceTests (badgeProfile, mkBadgeServiceOpts, runBadgeService import ChatClient import ChatTests.DBUtils import ChatTests.Utils -import Data.List (isPrefixOf) import qualified Data.Aeson as J import qualified Data.ByteString as B import qualified Data.ByteString.Lazy.Char8 as LB import Data.Char (isHexDigit) +import Data.List (isPrefixOf) import Simplex.Chat.Names.Protocol import Simplex.Messaging.Encoding.String (strEncode) import Simplex.Messaging.Eth.Address (parseAddress)