stricter house conventions

This commit is contained in:
Alain Brenzikofer
2026-08-18 17:40:53 +02:00
parent 46a80c6c55
commit a445166fe2
3 changed files with 9 additions and 8 deletions
+5 -3
View File
@@ -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'
+3 -3
View File
@@ -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.
+1 -2
View File
@@ -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)