mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-02 00:22:27 +00:00
store: add the names codes_only setting
This commit is contained in:
1 parent
958f18c0e3
commit
6ffa6fc56e
6 files changed
+25
-2
No files matched your search
@@ -174,6 +174,8 @@ data NamesConfig = NamesConfig
|
||||
nTermSlackSeconds :: Int,
|
||||
nRevealMarginSeconds :: Int,
|
||||
nMaxOrderMoves :: Int,
|
||||
-- | Only prepaid codes pay for names: every order that would take money for one is refused.
|
||||
nCodesOnly :: Bool,
|
||||
nTerms :: TermsConfig,
|
||||
-- | The operator's community names, keyed by the label hash's bytes, as search receives a name.
|
||||
nCommunity :: Map ByteString Text,
|
||||
@@ -376,7 +378,7 @@ knownSettings =
|
||||
("group", ["display_name", "description"]),
|
||||
("dev", ["accept_unverified_store_receipts", "check_store_during_coverage", "credit_test_purchases"]),
|
||||
("issuer", ["index", "private_key", "dev_keys"]),
|
||||
("names", ["tld", "terms_version", "terms_url", "years", "term_start", "term_slack_seconds", "reveal_margin_seconds", "max_order_moves"]),
|
||||
("names", ["tld", "terms_version", "terms_url", "years", "term_start", "term_slack_seconds", "reveal_margin_seconds", "max_order_moves", "codes_only"]),
|
||||
("chain", ["rpc_url", "chain_id", "controller", "sponsor", "base_registrar", "resolver", "service_key", "confirmations", "gas_limit_cap", "max_fee_per_gas"])
|
||||
]
|
||||
|
||||
@@ -602,10 +604,11 @@ parseConfig ini = do
|
||||
nTermSlackSeconds <- atLeast 0 "names" "term_slack_seconds" 3600
|
||||
nRevealMarginSeconds <- atLeast 0 "names" "reveal_margin_seconds" 900
|
||||
nMaxOrderMoves <- atLeast 0 "names" "max_order_moves" 3
|
||||
nCodesOnly <- bool "names" "codes_only" False
|
||||
nTerms <- termsSetting
|
||||
nCommunity <- communityList nTLD
|
||||
nChain <- chainSection
|
||||
pure (Just NamesConfig {nTLD, nYears, nTermStart, nTermSlackSeconds, nRevealMarginSeconds, nMaxOrderMoves, nTerms, nCommunity, nChain})
|
||||
pure (Just NamesConfig {nTLD, nYears, nTermStart, nTermSlackSeconds, nRevealMarginSeconds, nMaxOrderMoves, nCodesOnly, nTerms, nCommunity, nChain})
|
||||
tldSetting =
|
||||
required "names" "tld" >>= \case
|
||||
"simplex" -> Right TLDSimplex
|
||||
|
||||
@@ -116,6 +116,8 @@ idle_seconds = 60
|
||||
;reveal_margin_seconds = 900
|
||||
; how many times one order may move to another name
|
||||
;max_order_moves = 3
|
||||
; on: only prepaid codes register names, and every paid name order answers 403 codes_only
|
||||
;codes_only = off
|
||||
;
|
||||
; community names, with [names] only: one line per name, `<label> = <what it is for>`, the label in
|
||||
; lower case and listed once, the text 1 to 200 characters without a full stop at the end, which
|
||||
|
||||
@@ -101,6 +101,8 @@ private_key = replace-me
|
||||
;reveal_margin_seconds = 900
|
||||
; how many times one order may move to another name
|
||||
;max_order_moves = 3
|
||||
; on: only prepaid codes register names, and every paid name order answers 403 codes_only
|
||||
;codes_only = off
|
||||
;
|
||||
; community names, with [names] only: one line per name, `<label> = <what it is for>`, the label in
|
||||
; lower case and listed once, the text 1 to 200 characters without a full stop at the end, which
|
||||
|
||||
@@ -658,6 +658,7 @@ namesConfigTests = describe "StoreService names: config" $ do
|
||||
it "refuses a bad service key without quoting it" testNamesBadServiceKey
|
||||
it "keeps the RPC URL and the service key out of errors and the shown config" testNamesSecretsHidden
|
||||
it "names a [names] or [chain] setting nothing reads, and still boots" testNamesUnknownKeys
|
||||
it "reads codes_only on and off as a known setting, off when absent, and refuses any other value" testNamesCodesOnly
|
||||
it "accepts [issuer] dev_keys on chain 31337 only, with [names] on" testDevKeysLocalChain
|
||||
it "refuses a malformed dev_keys entry or an index named twice, quoting no secret" testDevKeysMalformed
|
||||
it "accepts [issuer] dev_keys beside Stripe test keys and a BTCPay on loopback" testDevKeysTestPayments
|
||||
@@ -860,6 +861,19 @@ testNamesUnknownKeys = do
|
||||
NamesConfig {nYears} <- parsedNames (namesSection <> ["yeers = 3"]) (chainSection <> ["rpc = x"])
|
||||
nYears `shouldBe` 2
|
||||
|
||||
testNamesCodesOnly :: IO ()
|
||||
testNamesCodesOnly = do
|
||||
NamesConfig {nCodesOnly = absent} <- parsedNames namesSection chainSection
|
||||
absent `shouldBe` False
|
||||
forM_ [("on", True), ("off", False)] $ \(value, expected) -> do
|
||||
let ns = namesSection <> ["codes_only = " <> value]
|
||||
withIni (namesIni ns chainSection) $ \p -> do
|
||||
Right ini <- readIniFile p
|
||||
unknownKeys ini `shouldBe` []
|
||||
NamesConfig {nCodesOnly} <- parsedNames ns chainSection
|
||||
(value, nCodesOnly) `shouldBe` (value, expected)
|
||||
namesRefusal (namesSection <> ["codes_only = yes"]) chainSection `shouldReturn` "codes_only must be on or off, not yes"
|
||||
|
||||
-- | Names on the local chain with no payment provider, as a run with dev keys has.
|
||||
localNamesIni :: [T.Text] -> T.Text
|
||||
localNamesIni cs = T.unlines (["[listener]"] <> namesSection <> cs)
|
||||
|
||||
@@ -324,6 +324,7 @@ testNamesConfig node =
|
||||
nTermSlackSeconds = slackSeconds,
|
||||
nRevealMarginSeconds = 900,
|
||||
nMaxOrderMoves = 3,
|
||||
nCodesOnly = False,
|
||||
nTerms = TermsConfig {tVersion = termsVersion, tUrl = termsUrl},
|
||||
nCommunity = M.empty,
|
||||
nChain = fakeChainConfig node
|
||||
|
||||
@@ -119,6 +119,7 @@ namesConfig node =
|
||||
nTermSlackSeconds = 3600,
|
||||
nRevealMarginSeconds = 900,
|
||||
nMaxOrderMoves = 3,
|
||||
nCodesOnly = False,
|
||||
nTerms = TermsConfig {tVersion = termsVersion, tUrl = termsUrl},
|
||||
nCommunity = M.empty,
|
||||
nChain = fakeChainConfig node
|
||||
|
||||
Reference in new issue
Block a user