store: rename badge service to store service (#7987)

Co-authored-by: sh-agents <350651734+sh-agents@users.noreply.github.com>
This commit is contained in:
shandsh-agents authored and GitHub committed 2026-11-03 13:24:17 +00:00
1 parent 6f8ebda2c5
commit 2c09d06793
191 files changed
+1341 -1309

No files matched your search

+1 -1
View File
@@ -71,7 +71,7 @@ defaultChatConfig =
chatVRange = supportedChatVRange,
callVRange = supportedCallVRange,
badgePublicKeys = M.mapKeys fromIntegral entitlementIssuerKeys,
badgeServiceAddress = Just $ either error id $ strDecode "https://smp5.simplex.im/a#ooSNWlEZTO2RPE0Ff5ZoybAs5zEhWLMlQrXesnhaZHM",
storeServiceAddress = Just $ either error id $ strDecode "https://smp5.simplex.im/a#ooSNWlEZTO2RPE0Ff5ZoybAs5zEhWLMlQrXesnhaZHM",
badgeCurrentTime = getCurrentTime,
badgeRetryInterval = RetryInterval {initialInterval = 30_000000, increaseAfter = 0, maxInterval = 3600_000000},
badgeConsecutiveRetries = 3,
+1 -1
View File
@@ -189,7 +189,7 @@ mkBadgeStatus now verified BadgeInfo {badgeExpiry = e} = case verified of
-- A badge credential (own, secret) and a proof (a presentation) are independent records.
-- badgeKeyIdx is the issuer key index: it tells verifiers which configured key to use.
-- Only proofs ride the wire (in a profile); credentials come from the badge service. Neither is
-- Only proofs ride the wire (in a profile); credentials come from the store service. Neither is
-- ever serialized as a sum - each travels as its own record, so the JSON carries no credential/proof tag.
data BadgeCredential = BadgeCredential
+1 -1
View File
@@ -1,7 +1,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Badge redemption codes, shared by the client, the badge service and the checkout site.
-- | Badge redemption codes, shared by the client, the store service and the checkout site.
--
-- A code is "SB-" and 20 Crockford base32 characters in four groups of five:
-- 19 payload characters and a final check character.
+1 -1
View File
@@ -29,7 +29,7 @@ import Data.Time.Calendar (addDays, addGregorianMonthsClip, toGregorian)
import Data.Time.Calendar.WeekDate (toWeekDate)
import Data.Time.Clock (NominalDiffTime, UTCTime (..), addUTCTime)
import Simplex.Chat.Badges (BadgeType)
import Simplex.Chat.Badges.Service (StatementCreditType (..), StatementDebitType (..), StatementEntry (..), StatementEntryType (..))
import Simplex.Chat.StoreService (StatementCreditType (..), StatementDebitType (..), StatementEntry (..), StatementEntryType (..))
import Simplex.Chat.PaymentService.Types (InvoiceId)
import qualified Simplex.Messaging.Crypto as C
+71 -71
View File
@@ -19,7 +19,7 @@ module Simplex.Chat.Badges.Types
LedgerCreditType (..),
LedgerDebitType (..),
BadgeAlertKind (..),
BadgeServiceErrorCode (..),
StoreServiceErrorCode (..),
SubscriptionState (..),
BadgeIssueFailure (..),
BadgeIssueError (..),
@@ -231,28 +231,28 @@ data BadgeAlertPrice = BadgeAlertPrice
}
deriving (Show)
data BadgeServiceErrorCode
= BSEBadRequest
| BSEUnsupportedVersion
| BSEUnknownPurchaseKey
| BSEUnknownOfferId
| BSEOfferDisabled
| BSEOfferMismatch
| BSEProductUnavailable
| BSEPaymentNotEntitled
| BSEPaymentPending
| BSEProviderUnavailable
| BSEProviderNotConfigured -- no verifier deployed: a dev service, not the store failing to answer
| BSERateLimited
| BSECodeInvalid
| BSECodeUsed
| BSECodeExpired
| BSEReceiptInvalid
| BSEReceiptUsed
| BSETransferLimited -- the subscription moved from another key whose credential has not expired yet
| BSETestPurchase -- the store vouched for a purchase that cost nothing: Apple's sandbox, a Play license tester
| BSEInternal
| BSEUnknown Text -- forwards-compatible: service is deployed ahead of clients
data StoreServiceErrorCode
= STEBadRequest
| STEUnsupportedVersion
| STEUnknownPurchaseKey
| STEUnknownOfferId
| STEOfferDisabled
| STEOfferMismatch
| STEProductUnavailable
| STEPaymentNotEntitled
| STEPaymentPending
| STEProviderUnavailable
| STEProviderNotConfigured -- no verifier deployed: a dev service, not the store failing to answer
| STERateLimited
| STECodeInvalid
| STECodeUsed
| STECodeExpired
| STEReceiptInvalid
| STEReceiptUsed
| STETransferLimited -- the subscription moved from another key whose credential has not expired yet
| STETestPurchase -- the store vouched for a purchase that cost nothing: Apple's sandbox, a Play license tester
| STEInternal
| STEUnknown Text -- forwards-compatible: service is deployed ahead of clients
deriving (Eq, Show)
-- | The store's answer as the service last read it. A client reads a state it does not know as not ended.
@@ -267,7 +267,7 @@ data SubscriptionState
-- | Why a renewal request ended without a credential stored. retryable is the service's own view of
-- transience: it gave retryAfter, which holds for codes this version does not know.
data BadgeIssueFailure
= BIFServiceError {code :: BadgeServiceErrorCode, retryable :: Bool}
= BIFServiceError {code :: StoreServiceErrorCode, retryable :: Bool}
| BIFServiceTimeout
| BIFNetwork {agentError :: Text}
| BIFInvalidCredential
@@ -359,58 +359,58 @@ instance FromField BadgeCodePaymentStatus where fromField = fromTextField_ textD
instance ToField BadgeCodePaymentStatus where toField = toField . textEncode
instance TextEncoding BadgeServiceErrorCode where
instance TextEncoding StoreServiceErrorCode where
textEncode = \case
BSEBadRequest -> "bad_request"
BSEUnsupportedVersion -> "unsupported_version"
BSEUnknownPurchaseKey -> "unknown_purchase_key"
BSEUnknownOfferId -> "unknown_offer_id"
BSEOfferDisabled -> "offer_disabled"
BSEOfferMismatch -> "offer_mismatch"
BSEProductUnavailable -> "product_unavailable"
BSEPaymentNotEntitled -> "payment_not_entitled"
BSEPaymentPending -> "payment_pending"
BSEProviderUnavailable -> "provider_unavailable"
BSEProviderNotConfigured -> "provider_not_configured"
BSERateLimited -> "rate_limited"
BSECodeInvalid -> "code_invalid"
BSECodeUsed -> "code_used"
BSECodeExpired -> "code_expired"
BSEReceiptInvalid -> "receipt_invalid"
BSEReceiptUsed -> "receipt_used"
BSETransferLimited -> "transfer_limited"
BSETestPurchase -> "test_purchase"
BSEInternal -> "internal"
BSEUnknown t -> t
STEBadRequest -> "bad_request"
STEUnsupportedVersion -> "unsupported_version"
STEUnknownPurchaseKey -> "unknown_purchase_key"
STEUnknownOfferId -> "unknown_offer_id"
STEOfferDisabled -> "offer_disabled"
STEOfferMismatch -> "offer_mismatch"
STEProductUnavailable -> "product_unavailable"
STEPaymentNotEntitled -> "payment_not_entitled"
STEPaymentPending -> "payment_pending"
STEProviderUnavailable -> "provider_unavailable"
STEProviderNotConfigured -> "provider_not_configured"
STERateLimited -> "rate_limited"
STECodeInvalid -> "code_invalid"
STECodeUsed -> "code_used"
STECodeExpired -> "code_expired"
STEReceiptInvalid -> "receipt_invalid"
STEReceiptUsed -> "receipt_used"
STETransferLimited -> "transfer_limited"
STETestPurchase -> "test_purchase"
STEInternal -> "internal"
STEUnknown t -> t
textDecode s = Just $ case s of
"bad_request" -> BSEBadRequest
"unsupported_version" -> BSEUnsupportedVersion
"unknown_purchase_key" -> BSEUnknownPurchaseKey
"unknown_offer_id" -> BSEUnknownOfferId
"offer_disabled" -> BSEOfferDisabled
"offer_mismatch" -> BSEOfferMismatch
"product_unavailable" -> BSEProductUnavailable
"payment_not_entitled" -> BSEPaymentNotEntitled
"payment_pending" -> BSEPaymentPending
"provider_unavailable" -> BSEProviderUnavailable
"provider_not_configured" -> BSEProviderNotConfigured
"rate_limited" -> BSERateLimited
"code_invalid" -> BSECodeInvalid
"code_used" -> BSECodeUsed
"code_expired" -> BSECodeExpired
"receipt_invalid" -> BSEReceiptInvalid
"receipt_used" -> BSEReceiptUsed
"transfer_limited" -> BSETransferLimited
"test_purchase" -> BSETestPurchase
"internal" -> BSEInternal
t -> BSEUnknown t
"bad_request" -> STEBadRequest
"unsupported_version" -> STEUnsupportedVersion
"unknown_purchase_key" -> STEUnknownPurchaseKey
"unknown_offer_id" -> STEUnknownOfferId
"offer_disabled" -> STEOfferDisabled
"offer_mismatch" -> STEOfferMismatch
"product_unavailable" -> STEProductUnavailable
"payment_not_entitled" -> STEPaymentNotEntitled
"payment_pending" -> STEPaymentPending
"provider_unavailable" -> STEProviderUnavailable
"provider_not_configured" -> STEProviderNotConfigured
"rate_limited" -> STERateLimited
"code_invalid" -> STECodeInvalid
"code_used" -> STECodeUsed
"code_expired" -> STECodeExpired
"receipt_invalid" -> STEReceiptInvalid
"receipt_used" -> STEReceiptUsed
"transfer_limited" -> STETransferLimited
"test_purchase" -> STETestPurchase
"internal" -> STEInternal
t -> STEUnknown t
instance ToJSON BadgeServiceErrorCode where
instance ToJSON StoreServiceErrorCode where
toJSON = textToJSON
toEncoding = textToEncoding
instance FromJSON BadgeServiceErrorCode where
parseJSON = textParseJSON "BadgeServiceErrorCode"
instance FromJSON StoreServiceErrorCode where
parseJSON = textParseJSON "StoreServiceErrorCode"
instance TextEncoding SubscriptionState where
textEncode = \case
@@ -465,7 +465,7 @@ instance StrEncoding BadgeIssueFailure where
"retry" -> pure True
"final" -> pure False
_ -> fail "bad BadgeIssueFailure retry flag"
codeP = A.takeByteString >>= maybe (fail "bad BadgeServiceErrorCode") pure . textDecode . safeDecodeUtf8
codeP = A.takeByteString >>= maybe (fail "bad StoreServiceErrorCode") pure . textDecode . safeDecodeUtf8
restP = safeDecodeUtf8 <$> (A.space *> A.takeByteString)
instance ToField BadgeIssueFailure where toField = toField . decodeLatin1 . strEncode
+6 -6
View File
@@ -85,7 +85,7 @@ import qualified Simplex.Messaging.Agent.Store.DB as DB
import Simplex.Messaging.Client (HostMode (..), SMPProxyFallback (..), SMPProxyMode (..), SMPWebPortServers (..), SocksMode (..))
import qualified Simplex.Messaging.Crypto as C
import Simplex.Chat.Badges (BadgeCredential, FileSizeLimits, LocalBadge)
import Simplex.Chat.Badges.Service (BadgeServiceErrorCode, StatementEntry)
import Simplex.Chat.StoreService (StoreServiceErrorCode, StatementEntry)
import Simplex.Chat.Badges.Types (BadgeAlert (..), BadgeAlertKind, BadgeIssueFailure, BadgeState (..), OpenStorePurchase (..), StoreReceiptOrigin, SubscriptionState)
import Simplex.Chat.PaymentService (ServicePayment)
import Simplex.Messaging.Crypto.BBS (BBSPublicKey)
@@ -149,15 +149,15 @@ data ChatConfig = ChatConfig
callVRange :: VersionRangeCall,
-- issuer public keys by index: credentials and proofs name the key that signed them, for rotation
badgePublicKeys :: Map Int BBSPublicKey,
-- Nothing until the badge service is deployed
badgeServiceAddress :: Maybe (ConnectTarget 'CMContact),
-- Nothing until the store service is deployed
storeServiceAddress :: Maybe (ConnectTarget 'CMContact),
-- the only clock badge code reads, so tests can shift it; production arithmetic is unchanged
badgeCurrentTime :: IO UTCTime,
-- how long a badge worker waits before repeating a renewal that failed for a passing reason
badgeRetryInterval :: RetryInterval,
-- attempts a store receipt gets in one turn before its next one waits for the stored schedule
badgeConsecutiveRetries :: Int,
-- set only by builds for a dev badge service: allows /_badge request, sent off the shared schedule
-- set only by builds for a dev store service: allows /_badge request, sent off the shared schedule
badgeDevRequests :: Bool,
-- Local testing only: the badge worker treats a request as due this often, instead of near the
-- credential's expiry, so a renewal can be watched without waiting weeks.
@@ -676,7 +676,7 @@ data ChatCommand
| UpdateProfileImage (Maybe ImageData) -- UserId (not used in UI)
| UpdateProfileImageFromFile FilePath -- set profile image from a .png/.jpg/.jpeg file
| AddBadge BadgeCredential -- attach an issued badge credential (testing; credential from `simplex-chat badge sign`)
| APIRedeemBadgeCode {userId :: UserId, code :: Text} -- redeem a badge code with the configured badge service
| APIRedeemBadgeCode {userId :: UserId, code :: Text} -- redeem a badge code with the configured store service
| APIPurchaseBadge {userId :: UserId, echoedInvoiceId :: Maybe Text, origin :: StoreReceiptOrigin, payment :: ServicePayment} -- hand over an App Store or Google Play receipt, held until a worker credits it; answers from the record and sends nothing
| APISetBadgeSubscriptionStatus {status :: SubscriptionState, payment :: ServicePayment} -- the device store's view of a credited subscription, which changes what is shown and alerted, and retires its badge once ended
| APICreateBadgeInvoice {userId :: UserId} -- the record of a store purchase, created before the store charges; answers the id the store echoes
@@ -1548,7 +1548,7 @@ data BadgeRedeemError
| BREServiceNotConfigured
| BREBadgeActive
| BREStorePurchaseOpen -- a store receipt held for this profile may still be credited
| BREServiceError {serviceError :: BadgeServiceErrorCode}
| BREServiceError {serviceError :: StoreServiceErrorCode}
| BREInvalidResponse {message :: String}
| BREUnknownKeyIndex
| BRECredentialNotVerified
+51 -51
View File
@@ -64,7 +64,7 @@ import Simplex.Chat.Badges (BadgeCredential (..), BadgeInfo (..), BadgeMasterKey
import qualified Simplex.Chat.Badges.Ledger as L
import Simplex.Chat.Badges.Types (BadgeAlert (..), BadgeAlertKind (..), BadgeIssueError (..), BadgeIssueFailure (..), BadgeState (..), BadgeSubscription (..), OpenStorePurchase (..), StoreReceiptOrigin (..))
import Simplex.Chat.Badges.Code (badgeCodeText, parseBadgeCode)
import Simplex.Chat.Badges.Service (BadgeBalance (..), BadgeServiceCommand (..), BadgeServiceErrorCode (..), BadgeServiceRequest (..), BadgeServiceResponse (..), BadgeStatement (..), StatementDebitType (..), StatementEntry (..), StatementEntryType (..), SubscriptionState (..), currentBadgeServiceVersion)
import Simplex.Chat.StoreService (BadgeBalance (..), BadgeStatement (..), StatementDebitType (..), StatementEntry (..), StatementEntryType (..), StoreServiceCommand (..), StoreServiceErrorCode (..), StoreServiceRequest (..), StoreServiceResponse (..), SubscriptionState (..), currentStoreServiceVersion)
import Simplex.Chat.Badges.StorePlan (storePlan)
import Simplex.Chat.Names (SimplexDomainProof (..), SimplexDomainClaim (..), claimDomain, mkDomainClaim)
import Simplex.Chat.Wallet (deriveAccount, masterMnemonic, newEntropy)
@@ -3680,7 +3680,7 @@ processChatCommand cxt nm = \case
APIPurchaseBadge userId echoedInvoiceId origin payment -> withUserId userId $ \user -> handOverStoreReceipt user echoedInvoiceId origin payment
APISetBadgeSubscriptionStatus status payment -> recordStoreSubscriptionStatus status payment >> ok_
APICreateBadgeInvoice userId -> withUserId userId $ \user -> do
void requireBadgeService
void requireStoreService
refuseWhileBadgeHeld user
refuseWhileStoreReceiptPending user Nothing
g <- asks random
@@ -5477,7 +5477,7 @@ presentUserBadgeToContacts user'@User {userId, profile = LocalProfile {localBadg
redeemBadgeCode :: NetworkRequestMode -> User -> Text -> CM ChatResponse
redeemBadgeCode nm user@User {userId} codeText = do
code <- maybe (throwRedeemError BREInvalidCode) pure $ parseBadgeCode codeText
sendTarget <- requireBadgeService
sendTarget <- requireStoreService
g <- asks random
now <- liftIO getCurrentTime
let codeSent = badgeCodeText code
@@ -5486,7 +5486,7 @@ redeemBadgeCode nm user@User {userId} codeText = do
(present_, redeemed) <- withEntityLock "badgeRedeem" (CLBadgeUser userId) $ do
stash_ <- withStore' $ \db -> getBadgeCodeRedemption db user codeSent
stash@BadgeStash {masterKey} <- stashBadgeKeys user stash_ $ \db -> createBadgeCodeRedemption db g user codeSent now
requestBadgeStash nm user sendTarget stash BSCRedeemBadgeCode {masterKey, code = codeSent} >>= \case
requestBadgeStash nm user sendTarget stash STCRedeemBadgeCode {masterKey, code = codeSent} >>= \case
Left (errCode, _) -> do
when (terminalCodeError errCode) $ withStore' $ \db -> deleteBadgeCodeRedemption db user codeSent
throwRedeemError $ BREServiceError errCode
@@ -5497,9 +5497,9 @@ redeemBadgeCode nm user@User {userId} codeText = do
where
-- the code will never work, so the keys stashed for it are dead; a timeout keeps them
terminalCodeError = \case
BSECodeInvalid -> True
BSECodeUsed -> True
BSECodeExpired -> True
STECodeInvalid -> True
STECodeUsed -> True
STECodeExpired -> True
_ -> False
-- | The app hands a receipt over until it is answered credited or refused, under whichever profile is
@@ -5507,7 +5507,7 @@ redeemBadgeCode nm user@User {userId} codeText = do
handOverStoreReceipt :: User -> Maybe Text -> StoreReceiptOrigin -> ServicePayment -> CM ChatResponse
handOverStoreReceipt presentingUser echoedInvoiceId origin payment = do
txRef <- maybe (throwRedeemError BREInvalidReceipt) pure $ storeTransactionRef payment
void requireBadgeService
void requireStoreService
g <- asks random
now <- badgeNow
limited <- case origin of
@@ -5524,7 +5524,7 @@ handOverStoreReceipt presentingUser echoedInvoiceId origin payment = do
_ -> throwChatError $ CEInternalError "store receipt was not recorded"
Just BadgeReceiptRecord {receiptId, ownerId, status} -> do
owner <- withStore $ \db -> getUser db ownerId
when limited $ lift (resumeStoreReceiptWork ownerId) >> throwRedeemError (BREServiceError BSETransferLimited)
when limited $ lift (resumeStoreReceiptWork ownerId) >> throwRedeemError (BREServiceError STETransferLimited)
case status of
RSHeld {} -> lift (resumeStoreReceiptWork ownerId) >> badgeStateResponse owner
RSCredited {badgePurchaseId, refusalRecorded} -> do
@@ -5537,7 +5537,7 @@ handOverStoreReceipt presentingUser echoedInvoiceId origin payment = do
True -> do
unlessM (withStore' (`userHasBadge` owner)) $
whenM (withStore' $ \db -> holdStoreTransfer db g owner txRef payment now) $
lift (resumeStoreReceiptWork ownerId) >> throwRedeemError (BREServiceError BSETransferLimited)
lift (resumeStoreReceiptWork ownerId) >> throwRedeemError (BREServiceError STETransferLimited)
pure True
movedOut <- withStore' (`purchaseMovedOut` badgePurchaseId)
answeredHeld <- case resumeHold now payment of
@@ -5597,13 +5597,13 @@ recordStoreSubscriptionStatus reported payment = do
_ -> True
-- | The receipt will never be credited to its key; any other refusal may pass on a retry.
storeReceiptRefused :: BadgeServiceErrorCode -> Bool
storeReceiptRefused :: StoreServiceErrorCode -> Bool
storeReceiptRefused = \case
BSEReceiptInvalid -> True
BSEReceiptUsed -> True
STEReceiptInvalid -> True
STEReceiptUsed -> True
-- a badge moves only on the user's Restore, never by a retry once the limit has passed
BSETransferLimited -> True
BSETestPurchase -> True
STETransferLimited -> True
STETestPurchase -> True
_ -> False
-- | How far ahead of this device's clock a charge's purchase date may be: a payload dated further ahead is never held.
@@ -5683,8 +5683,8 @@ stashBadgeKeys user stash_ createStash = do
unless replaying $ refuseWhileBadgeHeld user >> refuseWhileStoreReceiptPending user Nothing
maybe (withStore' createStash) pure stash_
requireBadgeService :: CM (ConnectTarget 'CMContact)
requireBadgeService = asks (badgeServiceAddress . config) >>= maybe (throwRedeemError BREServiceNotConfigured) pure
requireStoreService :: CM (ConnectTarget 'CMContact)
requireStoreService = asks (storeServiceAddress . config) >>= maybe (throwRedeemError BREServiceNotConfigured) pure
refuseWhileBadgeHeld :: User -> CM ()
refuseWhileBadgeHeld user = whenM (withStore' (`userHasBadge` user)) $ throwRedeemError BREBadgeActive
@@ -5706,29 +5706,29 @@ refuseWhileStoreReceiptPending user presented_ = do
-- | One attempt to turn a stash into a badge. A refusal is answered rather than thrown, with the
-- service's retryAfter.
requestBadgeStash :: NetworkRequestMode -> User -> ConnectTarget 'CMContact -> BadgeStash -> BadgeServiceCommand -> CM (Either (BadgeServiceErrorCode, Maybe Word32) (Maybe User, ChatResponse))
requestBadgeStash :: NetworkRequestMode -> User -> ConnectTarget 'CMContact -> BadgeStash -> StoreServiceCommand -> CM (Either (StoreServiceErrorCode, Maybe Word32) (Maybe User, ChatResponse))
requestBadgeStash nm user sendTarget stash@BadgeStash {purchaseKey, purchasePrivKey} request = do
let req = BadgeServiceRequest {version = currentBadgeServiceVersion, purchaseKey = Just purchaseKey, request}
let req = StoreServiceRequest {version = currentStoreServiceVersion, purchaseKey = Just purchaseKey, request}
respBytes <- sendServiceRequestBytes nm user sendTarget Nothing (Just purchasePrivKey) req
respData <- either (const $ throwRedeemError $ BREInvalidResponse "not JSON") pure $ J.eitherDecodeStrict' respBytes
case J.fromJSON (J.Object respData) of
J.Error _ -> throwRedeemError $ BREInvalidResponse "not a badge service response"
J.Success BSPError {code, retryAfter} -> pure $ Left (code, retryAfter)
J.Success BSPBadgeCredential {credential = Just cred, statement, subscription} -> Right <$> storeRedeemedBadge user stash cred statement (boundedSubscriptionState <$> subscription)
J.Error _ -> throwRedeemError $ BREInvalidResponse "not a store service response"
J.Success STPError {code, retryAfter} -> pure $ Left (code, retryAfter)
J.Success STPBadgeCredential {credential = Just cred, statement, subscription} -> Right <$> storeRedeemedBadge user stash cred statement (boundedSubscriptionState <$> subscription)
J.Success _ -> throwRedeemError $ BREInvalidResponse "unexpected response type"
throwRedeemError :: BadgeRedeemError -> CM a
throwRedeemError = throwChatError . CEBadgeRedeemError
badgeServiceErrorText :: BadgeServiceErrorCode -> Text
badgeServiceErrorText = textEncode . boundedServiceErrorCode
storeServiceErrorText :: StoreServiceErrorCode -> Text
storeServiceErrorText = textEncode . boundedServiceErrorCode
-- | An unknown code is reported and recorded, since the service is deployed ahead of clients, but
-- its text is the service's - so it is bounded and stripped before it reaches a terminal that acts
-- on controls, or a sentence the app shows the user as its own.
boundedServiceErrorCode :: BadgeServiceErrorCode -> BadgeServiceErrorCode
boundedServiceErrorCode :: StoreServiceErrorCode -> StoreServiceErrorCode
boundedServiceErrorCode = \case
BSEUnknown t -> boundedServiceText BSEUnknown errorCodeChar t
STEUnknown t -> boundedServiceText STEUnknown errorCodeChar t
code -> code
where
errorCodeChar c = isAsciiLower c || isDigit c || c == '_'
@@ -5754,12 +5754,12 @@ badgeNow = asks (badgeCurrentTime . config) >>= liftIO
-- | A signal carries nothing: each pass derives its work from stored state, so a signal lost or
-- duplicated changes no outcome.
startBadgeWork :: User -> CM' ()
startBadgeWork user = whenM (isJust <$> asks (badgeServiceAddress . config)) $ void $ getBadgeWorker user
startBadgeWork user = whenM (isJust <$> asks (storeServiceAddress . config)) $ void $ getBadgeWorker user
-- | Sent off the shared request moment, so only a build for a dev badge service may send it.
-- | Sent off the shared request moment, so only a build for a dev store service may send it.
requestBadgeNow :: User -> CM ChatResponse
requestBadgeNow user@User {userId} = do
unlessM (asks $ badgeDevRequests . config) $ throwCmdError "/_badge request is only available in builds for a dev badge service"
unlessM (asks $ badgeDevRequests . config) $ throwCmdError "/_badge request is only available in builds for a dev store service"
withStore' (`getUserBadgePurchase` user) >>= \case
Just p@UserBadgePurchase {shown = True} -> do
badgeNow >>= requestBadgeIssue userId p >>= \case
@@ -5928,19 +5928,19 @@ creditStoreReceipt a userId receiptId stash@BadgeStash {masterKey} invoiceId_ pa
credit ri delay cmd =
tryAllErrors (attempt cmd) >>= \answer -> serviceAnswered ri delay refuse (failed ri delay) answer $ \(present_, _) -> pure $ SROCredited present_
-- retried takes only a service error that is not a refusal: a thrown error is recorded as a failure as it is
serviceAnswered :: RetryInterval -> Int64 -> (BadgeIssueFailure -> CM StoreReceiptOutcome) -> (BadgeIssueFailure -> Maybe Word32 -> CM StoreReceiptOutcome) -> Either ChatError (Either (BadgeServiceErrorCode, Maybe Word32) r) -> (r -> CM StoreReceiptOutcome) -> CM StoreReceiptOutcome
serviceAnswered :: RetryInterval -> Int64 -> (BadgeIssueFailure -> CM StoreReceiptOutcome) -> (BadgeIssueFailure -> Maybe Word32 -> CM StoreReceiptOutcome) -> Either ChatError (Either (StoreServiceErrorCode, Maybe Word32) r) -> (r -> CM StoreReceiptOutcome) -> CM StoreReceiptOutcome
serviceAnswered ri delay refused retried answer answered = case answer of
Left e -> failed ri delay (badgeIssueFailure e) Nothing
Right (Left (code, retryAfter))
| storeReceiptRefused code -> refused $ serviceFailure code retryAfter
| otherwise -> retried (serviceFailure code retryAfter) retryAfter
Right (Right r) -> answered r
purchaseCmd payment' = BSCPurchaseBadge {masterKey, payment = payment', upgrade = Nothing}
transferCmd payment' = BSCTransferBadge {masterKey, payment = payment'}
purchaseCmd payment' = STCPurchaseBadge {masterKey, payment = payment', upgrade = Nothing}
transferCmd payment' = STCTransferBadge {masterKey, payment = payment'}
attempt cmd = do
user <- withStore $ \db -> getUser db userId
refuseWhileBadgeHeld user
sendTarget <- requireBadgeService
sendTarget <- requireStoreService
payment' <- maybe (throwChatError $ CEInternalError "held store payment does not decode") pure $ decodeJSON payment
requestBadgeStash NRMBackground user sendTarget stash (cmd payment')
-- a held record whose keys already fund a purchase is a resume of that retired subscription, checked before every send
@@ -5959,7 +5959,7 @@ creditStoreReceipt a userId receiptId stash@BadgeStash {masterKey} invoiceId_ pa
| isNewest, Just hold <- resumeHold now =<< decodeJSON payment -> resumeIssue ri delay user p hold now
_ -> refuse receiptInvalid
resumeIssue ri delay user p@UserBadgePurchase {badgePurchaseId} hold now = do
answer <- tryAllErrors $ requireBadgeService >>= \sendTarget -> sendBadgeIssue sendTarget userId p BSCIssueBadge (recordBadgeIssueFailure p) now
answer <- tryAllErrors $ requireStoreService >>= \sendTarget -> sendBadgeIssue sendTarget userId p STCIssueBadge (recordBadgeIssueFailure p) now
answeredAt <- badgeNow
-- a charge the service does not grant, as a revoked one, stops holding the profile once its hold ends
let notCredited failure retryAfter = case hold of
@@ -5978,7 +5978,7 @@ creditStoreReceipt a userId receiptId stash@BadgeStash {masterKey} invoiceId_ pa
lift $ startBadgeWork user'
pure $ SROCredited (Just user')
-- the service's own check interval
_ -> notCredited BIFServiceError {code = BSEPaymentPending, retryable = True} (Just 3600)
_ -> notCredited BIFServiceError {code = STEPaymentPending, retryable = True} (Just 3600)
-- Settles with nothing to announce: a charge expired or no newer than the last one credited, or to a tier that is not
-- higher, the renewal check grants the change, and a badge no longer shown is resumed by the charge's next hand-over.
changeTier ri delay purchaseId = do
@@ -5993,8 +5993,8 @@ creditStoreReceipt a userId receiptId stash@BadgeStash {masterKey} invoiceId_ pa
-- the receipt's failures are recorded on the record, not as the purchase's failed renewal, as the badge shown still covers
upgradeIssue ri delay user p@UserBadgePurchase {badgePurchaseId} payment' tier now = do
failure_ <- newTVarIO Nothing
let upgradeCmd balance = BSCUpgradeBadgeSubscription {payment = payment', balance}
answer <- tryAllErrors $ requireBadgeService >>= \sendTarget -> sendBadgeIssue sendTarget userId p upgradeCmd (atomically . writeTVar failure_ . Just) now
let upgradeCmd balance = STCUpgradeBadgeSubscription {payment = payment', balance}
answer <- tryAllErrors $ requireStoreService >>= \sendTarget -> sendBadgeIssue sendTarget userId p upgradeCmd (atomically . writeTVar failure_ . Just) now
answeredAt <- badgeNow
recorded_ <- readTVarIO failure_
let refusedInSilence failure = SRODeferred <$ withStore' (\db -> refuseStoreReceipt db receiptId payment failure)
@@ -6009,7 +6009,7 @@ creditStoreReceipt a userId receiptId stash@BadgeStash {masterKey} invoiceId_ pa
setUserBadge db user (Just $ OwnBadge cred (mkBadgeStatus answeredAt (Just True) info))
lift $ startBadgeWork user'
pure $ SROCredited (Just user')
_ -> failedHeld ri delay BIFServiceError {code = BSEPaymentPending, retryable = True} (Just 3600)
_ -> failedHeld ri delay BIFServiceError {code = STEPaymentPending, retryable = True} (Just 3600)
-- out of attempts, the record is set aside without a refusal, so the next hand-over holds it again;
-- this attempt's failure is not recorded yet, so it is counted here
failedHeld ri delay failure retryAfter = do
@@ -6018,7 +6018,7 @@ creditStoreReceipt a userId receiptId stash@BadgeStash {masterKey} invoiceId_ pa
then setAside
else failed ri delay failure retryAfter
setAside = SRODeferred <$ withStore' (`settleStoreReceipt` receiptId)
receiptInvalid = BIFServiceError {code = BSEReceiptInvalid, retryable = False}
receiptInvalid = BIFServiceError {code = STEReceiptInvalid, retryable = False}
-- a payment adopted while this one was with the service stays held and is sent next, so nothing is announced
refuse failure = do
refused <- withStore' $ \db -> refuseStoreReceipt db receiptId payment failure
@@ -6312,7 +6312,7 @@ badgeIssueFailure e = case e of
badgeFailureTransient :: BadgeIssueFailure -> Bool
badgeFailureTransient = \case
-- the service withholds retryAfter from internal to avoid being pressed while failing, not because it is final
BIFServiceError {code = BSEInternal} -> True
BIFServiceError {code = STEInternal} -> True
BIFServiceError {retryable} -> retryable
BIFServiceTimeout -> True
BIFNetwork {} -> True
@@ -6329,10 +6329,10 @@ badgeErrorRetry = badgeFailureTransient . badgeIssueFailure
-- since a service error is answered rather than thrown. Any request that
-- ends without a credential the ledger still owes is recorded on the purchase as a failed renewal;
-- nothing else records one.
requestBadgeIssue :: UserId -> UserBadgePurchase -> UTCTime -> CM (Either (BadgeServiceErrorCode, Maybe Word32) (StatementEntry, Maybe SubscriptionState))
requestBadgeIssue :: UserId -> UserBadgePurchase -> UTCTime -> CM (Either (StoreServiceErrorCode, Maybe Word32) (StatementEntry, Maybe SubscriptionState))
requestBadgeIssue userId p now = do
sendTarget <- asks (badgeServiceAddress . config) >>= maybe (throwCmdError "badge service not configured") pure
withEntityLock "badgeIssue" (CLBadgeUser userId) $ sendBadgeIssue sendTarget userId p BSCIssueBadge (recordBadgeIssueFailure p) now
sendTarget <- asks (storeServiceAddress . config) >>= maybe (throwCmdError "store service not configured") pure
withEntityLock "badgeIssue" (CLBadgeUser userId) $ sendBadgeIssue sendTarget userId p STCIssueBadge (recordBadgeIssueFailure p) now
recordBadgeIssueFailure :: UserBadgePurchase -> BadgeIssueFailure -> CM ()
recordBadgeIssueFailure UserBadgePurchase {badgePurchaseId} failure = do
@@ -6340,13 +6340,13 @@ recordBadgeIssueFailure UserBadgePurchase {badgePurchaseId} failure = do
withStore' $ \db -> setBadgeIssueError db badgePurchaseId failedAt failure
-- | 'requestBadgeIssue' for a caller that already holds the owner's badge lock, which is not reentrant.
sendBadgeIssue :: ConnectTarget 'CMContact -> UserId -> UserBadgePurchase -> (BadgeBalance -> BadgeServiceCommand) -> (BadgeIssueFailure -> CM ()) -> UTCTime -> CM (Either (BadgeServiceErrorCode, Maybe Word32) (StatementEntry, Maybe SubscriptionState))
sendBadgeIssue :: ConnectTarget 'CMContact -> UserId -> UserBadgePurchase -> (BadgeBalance -> StoreServiceCommand) -> (BadgeIssueFailure -> CM ()) -> UTCTime -> CM (Either (StoreServiceErrorCode, Maybe Word32) (StatementEntry, Maybe SubscriptionState))
sendBadgeIssue sendTarget userId UserBadgePurchase {badgePurchaseId, badgeType, purchaseKey, purchasePrivKey, masterKey} command recordFailure now = do
user <- withStore $ \db -> getUser db userId
lastEntry <- withStore' (`getBadgeLedgerLastEntry` badgePurchaseId) >>= maybe (throwCmdError "badge ledger has no entry to assert") pure
let req =
BadgeServiceRequest
{ version = currentBadgeServiceVersion,
StoreServiceRequest
{ version = currentStoreServiceVersion,
purchaseKey = Just purchaseKey,
request = command BadgeBalance {lastEntry}
}
@@ -6354,7 +6354,7 @@ sendBadgeIssue sendTarget userId UserBadgePurchase {badgePurchaseId, badgeType,
sendServiceRequestTo NRMBackground user sendTarget Nothing (Just purchasePrivKey) req
`catchAllErrors` \e -> recordFailure (badgeIssueFailure e) >> throwError e
case J.fromJSON (J.Object respData) of
J.Success BSPBadgeCredential {credential = sentCred_, statement, subscription} -> do
J.Success STPBadgeCredential {credential = sentCred_, statement, subscription} -> do
verifiedCred_ <- verifyIssuedCredential masterKey sentCred_
g <- asks random
-- read again: now was taken before a lock wait and an untimed request, and the check reads
@@ -6375,11 +6375,11 @@ sendBadgeIssue sendTarget userId UserBadgePurchase {badgePurchaseId, badgeType,
(_, _, False) -> recordUnexpected "issued badge credential has no ledger row to store it against"
-- no credential is the service saying nothing is owed - the months ran out, or a subscription
-- waits for its store to charge - which its statement then shows; ended after a move leaves the issued month running
(Nothing, _, _) | subscription /= Just SSEnded && maybe False ((> storedAt) . L.paidThrough) balance_ -> recordUnexpected "badge service issued no credential"
(Nothing, _, _) | subscription /= Just SSEnded && maybe False ((> storedAt) . L.paidThrough) balance_ -> recordUnexpected "store service issued no credential"
_ -> pure ()
maybe (throwCmdError "badge ledger has no balance") (pure . Right . (,storedSubscription)) balance_
J.Success BSPError {code, retryAfter} -> do
eToView $ ChatError $ CECommandError $ "badge service error: " <> T.unpack (badgeServiceErrorText code)
J.Success STPError {code, retryAfter} -> do
eToView $ ChatError $ CECommandError $ "store service error: " <> T.unpack (storeServiceErrorText code)
-- retryAfter only marks the failure as one that can clear: the retry waits a stall like any request that
-- issued nothing, since a shorter wait would let the service choose how often activations reach it
recordFailure BIFServiceError {code = boundedServiceErrorCode code, retryable = isJust retryAfter}
@@ -6388,7 +6388,7 @@ sendBadgeIssue sendTarget userId UserBadgePurchase {badgePurchaseId, badgeType,
recordFailure BIFUnexpected {message = unexpectedResponse}
throwCmdError $ T.unpack unexpectedResponse
where
unexpectedResponse = "unexpected badge service response"
unexpectedResponse = "unexpected store service response"
recordUnexpected message = do
eToView $ ChatError $ CEInternalError $ T.unpack message
recordFailure BIFUnexpected {message}
+5 -5
View File
@@ -73,8 +73,8 @@ import Data.Time.Clock (UTCTime, addUTCTime, nominalDay)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Simplex.Chat.Badges
import Simplex.Chat.Badges.Ledger
import Simplex.Chat.Badges.Service (StatementCreditType (..), StatementDebitType (..), StatementEntry (..), StatementEntryType (..))
import Simplex.Chat.Badges.Types (BadgeAlertKind, BadgeIssueError (..), BadgeIssueFailure (..), BadgePurchaseStatus (..), BadgeServiceErrorCode (..), BadgeSubscription (..), OpenStorePurchase (..), StoreReceiptOrigin (..), SubscriptionState (..))
import Simplex.Chat.StoreService (StatementCreditType (..), StatementDebitType (..), StatementEntry (..), StatementEntryType (..))
import Simplex.Chat.Badges.Types (BadgeAlertKind, BadgeIssueError (..), BadgeIssueFailure (..), BadgePurchaseStatus (..), StoreServiceErrorCode (..), BadgeSubscription (..), OpenStorePurchase (..), StoreReceiptOrigin (..), SubscriptionState (..))
import Simplex.Chat.PaymentService (AppleTransactionFacts (..), ServicePayment (..), appleTransactionFacts)
import Simplex.Chat.PaymentService.Types (StoreTransactionRef (..))
import Simplex.Chat.Store.Shared (StoreError, insertedRowId)
@@ -256,7 +256,7 @@ holdStoreTransfer db g user@User {userId} txRef payment now =
(userId, SHKTransfer, now, receiptId, SHKPurchase)
Just _ -> pure False
Just BadgeReceiptRecord {receiptId, status = RSRefused {refusal = Just BIFServiceError {code}}}
| code == BSEReceiptUsed || code == BSETransferLimited -> (code == BSETransferLimited) <$ holdTransfer receiptId
| code == STEReceiptUsed || code == STETransferLimited -> (code == STETransferLimited) <$ holdTransfer receiptId
Just BadgeReceiptRecord {receiptId, ownerId, status = RSCredited {badgePurchaseId}} ->
movesHere ownerId badgePurchaseId >>= \case
False -> pure False
@@ -267,7 +267,7 @@ holdStoreTransfer db g user@User {userId} txRef payment now =
DB.execute db "UPDATE badge_store_receipts SET purchase_key = ?, purchase_priv_key = ?, master_key = ? WHERE badge_store_receipt_id = ? AND payment IS NULL" (purchaseKey, purchasePrivKey, Binary mk, receiptId)
holdTransfer receiptId
pure $ case join lastRefusal of
Just BIFServiceError {code = BSETransferLimited} -> True
Just BIFServiceError {code = STETransferLimited} -> True
_ -> False
_ -> pure False
where
@@ -337,7 +337,7 @@ getReceiptRecord db StoreTransactionRef {provider, transactionRef} =
_ -> maybe (RSRefused refusal) (\badgePurchaseId -> RSCredited {badgePurchaseId, refusalRecorded = maybe False ownRefusal refusal}) purchaseId_
-- only a move is refused transfer_limited, and a refused move must not hold off the purchase's own resume or tier change
ownRefusal = \case
BIFServiceError {code = BSETransferLimited} -> False
BIFServiceError {code = STETransferLimited} -> False
_ -> True
-- | The record made when Buy is tapped, before any receipt: the store echoes its invoice id.
@@ -7,7 +7,7 @@ import Data.Text (Text)
import qualified Data.Text as T
import Text.RawString.QQ (r)
-- the same tables in the client and in the badge service; '@' is replaced with the table name prefix
-- the same tables in the client and in the store service; '@' is replaced with the table name prefix
badgeSchema :: Text -> Text
badgeSchema pfx = withPrefix pfx badgeSchemaTables
@@ -8,7 +8,7 @@ import qualified Data.Text as T
import Database.SQLite.Simple (Query (..))
import Database.SQLite.Simple.QQ (sql)
-- the same tables in the client and in the badge service; '@' is replaced with the table name prefix
-- the same tables in the client and in the store service; '@' is replaced with the table name prefix
badgeSchema :: Text -> Query
badgeSchema pfx = withPrefix pfx badgeSchemaTables
@@ -5,19 +5,19 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}
module Simplex.Chat.Badges.Service
( BadgeServiceRequest (..),
BadgeServiceCommand (..),
BadgeServiceVersion,
VersionBadgeService,
VersionRangeBadgeService,
pattern VersionBadgeService,
initialBadgeServiceVersion,
currentBadgeServiceVersion,
supportedBadgeServiceVRange,
module Simplex.Chat.StoreService
( StoreServiceRequest (..),
StoreServiceCommand (..),
StoreServiceVersion,
VersionStoreService,
VersionRangeStoreService,
pattern VersionStoreService,
initialStoreServiceVersion,
currentStoreServiceVersion,
supportedStoreServiceVRange,
BadgeUpgrade (..),
BadgeServiceResponse (..),
BadgeServiceErrorCode (..),
StoreServiceResponse (..),
StoreServiceErrorCode (..),
SubscriptionState (..),
BadgeCatalog (..),
BadgePrice (..),
@@ -47,63 +47,63 @@ import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, taggedObjectJSON)
import Simplex.Messaging.Version (VersionRange, VersionScope, mkVersionRange)
import Simplex.Messaging.Version.Internal (Version (..))
data BadgeServiceVersion
data StoreServiceVersion
instance VersionScope BadgeServiceVersion
instance VersionScope StoreServiceVersion
type VersionBadgeService = Version BadgeServiceVersion
type VersionStoreService = Version StoreServiceVersion
pattern VersionBadgeService :: Word16 -> VersionBadgeService
pattern VersionBadgeService v = Version v
pattern VersionStoreService :: Word16 -> VersionStoreService
pattern VersionStoreService v = Version v
type VersionRangeBadgeService = VersionRange BadgeServiceVersion
type VersionRangeStoreService = VersionRange StoreServiceVersion
initialBadgeServiceVersion :: VersionBadgeService
initialBadgeServiceVersion = VersionBadgeService 1
initialStoreServiceVersion :: VersionStoreService
initialStoreServiceVersion = VersionStoreService 1
currentBadgeServiceVersion :: VersionBadgeService
currentBadgeServiceVersion = VersionBadgeService 1
currentStoreServiceVersion :: VersionStoreService
currentStoreServiceVersion = VersionStoreService 1
-- the service is deployed ahead of app releases, so it answers within the client's version
supportedBadgeServiceVRange :: VersionRangeBadgeService
supportedBadgeServiceVRange = mkVersionRange initialBadgeServiceVersion currentBadgeServiceVersion
supportedStoreServiceVRange :: VersionRangeStoreService
supportedStoreServiceVRange = mkVersionRange initialStoreServiceVersion currentStoreServiceVersion
data BadgeServiceRequest = BadgeServiceRequest
{ version :: VersionBadgeService,
purchaseKey :: Maybe C.PublicKeyEd25519, -- optional for BSCGetBadgeCatalog, required for other commands
request :: BadgeServiceCommand
data StoreServiceRequest = StoreServiceRequest
{ version :: VersionStoreService,
purchaseKey :: Maybe C.PublicKeyEd25519, -- optional for STCGetBadgeCatalog, required for other commands
request :: StoreServiceCommand
}
data BadgeServiceCommand
= BSCGetBadgeCatalog
| BSCGetBadgeInvoice
data StoreServiceCommand
= STCGetBadgeCatalog
| STCGetBadgeInvoice
{ priceId :: BadgePriceId,
offerId :: Maybe BadgeOfferId, -- absent for 1 month at the badge price
badgeInfo :: BadgeInfo,
paymentVia :: ServicePaymentMethod,
upgrade :: Maybe BadgeUpgrade -- upgrade non-store badge
}
| BSCRedeemBadgeCode
| STCRedeemBadgeCode
{ masterKey :: BadgeMasterKey,
code :: Text -- no badgeRequest: a code carries no tier for the client to state
}
| BSCPurchaseBadge
| STCPurchaseBadge
{ masterKey :: BadgeMasterKey, -- no badgeRequest: the tier is the product's, the expiry the one every credential of that week shares
payment :: ServicePayment,
upgrade :: Maybe BadgeUpgrade -- upgrade store 1-time badge
}
| BSCUpgradeBadgeSubscription
| STCUpgradeBadgeSubscription
{ payment :: ServicePayment, -- names the subscription and the tier to wait for; the store's answer is what is granted
balance :: BadgeBalance
}
| BSCTransferBadge
| STCTransferBadge
{ masterKey :: BadgeMasterKey,
payment :: ServicePayment -- the store receipt of the subscription to move to the signing key
}
| BSCIssueBadge
| STCIssueBadge
{ balance :: BadgeBalance -- no badgeRequest: the service holds the key, the tier and the expiry
}
| BSCPauseBadge
| STCPauseBadge
data BadgeUpgrade = BadgeUpgrade
{ fromPurchaseKey :: C.PublicKeyEd25519,
@@ -112,24 +112,24 @@ data BadgeUpgrade = BadgeUpgrade
balance :: BadgeBalance
}
data BadgeServiceResponse
= BSPBadgeCatalog
data StoreServiceResponse
= STPBadgeCatalog
{ catalog :: BadgeCatalog,
badgeStatement :: Maybe BadgeStatement -- for signed getBadgeCatalog
}
| BSPBadgeInvoice
| STPBadgeInvoice
{ invoice :: ServiceInvoice,
badgeType :: BadgeType,
months :: Word8
}
| BSPBadgeCredential
| STPBadgeCredential
{ credential :: Maybe BadgeCredential, -- Nothing when no balance to issueBadge or no current credential for pause
receipt :: Maybe Text, -- not provided for lifetime badges
statement :: BadgeStatement,
subscription :: Maybe SubscriptionState -- present exactly when a store subscription funds the purchase
}
| BSPError
{ code :: BadgeServiceErrorCode,
| STPError
{ code :: StoreServiceErrorCode,
message :: Maybe Text,
retryAfter :: Maybe Word32
}
@@ -251,9 +251,9 @@ $(JQ.deriveJSON defaultJSON ''BadgeBalance)
$(JQ.deriveJSON defaultJSON ''BadgeUpgrade)
$(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "BSC") ''BadgeServiceCommand)
$(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "STC") ''StoreServiceCommand)
$(JQ.deriveJSON defaultJSON ''BadgeServiceRequest)
$(JQ.deriveJSON defaultJSON ''StoreServiceRequest)
$(JQ.deriveJSON defaultJSON ''BadgePrice)
@@ -261,4 +261,4 @@ $(JQ.deriveJSON defaultJSON ''BadgeOffer)
$(JQ.deriveJSON defaultJSON ''BadgeCatalog)
$(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "BSP") ''BadgeServiceResponse)
$(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "STP") ''StoreServiceResponse)
+4 -4
View File
@@ -41,11 +41,11 @@ import Numeric (showFFloat)
import Simplex.Chat.Call
import Simplex.Chat.Controller
import Simplex.Chat.Help
import Simplex.Chat.Library.Commands (badgeServiceErrorText, maxImageSize)
import Simplex.Chat.Library.Commands (maxImageSize, storeServiceErrorText)
import Simplex.Chat.Markdown
import Simplex.Chat.Badges (BadgeInfo (..), BadgeStatus (..), BadgeType (..), LocalBadge, localBadgeInfo, localBadgeStatus)
import Simplex.Chat.Badges.Ledger (creditTypeTag, debitTypeTag)
import Simplex.Chat.Badges.Service (StatementEntry (..), StatementEntryType (..))
import Simplex.Chat.StoreService (StatementEntry (..), StatementEntryType (..))
import Simplex.Chat.Badges.Types (BadgeAlert (..), BadgeIssueError (..), BadgeState (..), BadgeSubscription (..), OpenStorePurchase (..))
import Simplex.Chat.Messages hiding (NewChatItem (..))
import Simplex.Chat.Messages.CIContent
@@ -2946,10 +2946,10 @@ viewChatError isCmd logLevel testView = \case
let reason = case e of
BREInvalidCode -> "invalid code"
BREInvalidReceipt -> "invalid store receipt"
BREServiceNotConfigured -> "badge service not configured"
BREServiceNotConfigured -> "store service not configured"
BREBadgeActive -> "badge already active"
BREStorePurchaseOpen -> "store purchase open"
BREServiceError code -> "badge service error: " <> T.unpack (badgeServiceErrorText code)
BREServiceError code -> "store service error: " <> T.unpack (storeServiceErrorText code)
BREInvalidResponse m -> "invalid service response: " <> m
BREUnknownKeyIndex -> "credential names an unknown badge key index"
BRECredentialNotVerified -> "credential does not verify against configured key"