mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-23 00:18:27 +00:00
store: read the names codes_only setting
This commit is contained in:
1 parent
cf76edcd2b
commit
3597155531
4 files changed
+50
-2
No files matched your search
@@ -159,6 +159,8 @@ data NamesConfig = NamesConfig
|
||||
nYears :: Int,
|
||||
nTermStart :: UTCTime,
|
||||
nTermSlackSeconds :: Int,
|
||||
-- | Only prepaid codes pay for names: every order that would take money for one is refused.
|
||||
nCodesOnly :: Bool,
|
||||
nChain :: ChainConfig
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
@@ -306,7 +308,7 @@ knownSettings =
|
||||
("group", ["display_name", "description"]),
|
||||
("dev", ["accept_unverified_store_receipts", "check_store_during_coverage", "credit_test_purchases"]),
|
||||
("issuer", ["index", "private_key"]),
|
||||
("names", ["tld", "years", "term_start", "term_slack_seconds"]),
|
||||
("names", ["tld", "years", "term_start", "term_slack_seconds", "codes_only"]),
|
||||
("chain", ["rpc_url", "chain_id", "controller", "sponsor", "base_registrar", "resolver", "service_key", "gas_limit_cap"])
|
||||
]
|
||||
|
||||
@@ -506,8 +508,9 @@ parseConfig ini = do
|
||||
when (nYears < minNameYears) $ Left ("names.years must be at least " <> show minNameYears)
|
||||
nTermStart <- termStart
|
||||
nTermSlackSeconds <- atLeast 0 "names" "term_slack_seconds" 3600
|
||||
nCodesOnly <- bool "names" "codes_only" False
|
||||
nChain <- chainSection
|
||||
pure (Just NamesConfig {nTLD, nYears, nTermStart, nTermSlackSeconds, nChain})
|
||||
pure (Just NamesConfig {nTLD, nYears, nTermStart, nTermSlackSeconds, nCodesOnly, nChain})
|
||||
tldSetting =
|
||||
required "names" "tld" >>= \case
|
||||
"simplex" -> Right TLDSimplex
|
||||
|
||||
@@ -108,6 +108,8 @@ idle_seconds = 60
|
||||
;term_start = 2027-01-01T00:00:00Z
|
||||
; how far an order's duration may be from the one the service computes
|
||||
;term_slack_seconds = 3600
|
||||
; on: only prepaid codes register names, and every paid name order answers 403 codes_only
|
||||
;codes_only = off
|
||||
;
|
||||
; the chain the names are registered on. rpc_url can carry a provider's API key and service_key
|
||||
; is the registrar key: keep both secret. Neither is ever logged.
|
||||
|
||||
@@ -84,6 +84,35 @@ private_key = replace-me
|
||||
;display_name = SimpleX Badges
|
||||
;description = Welcome to the badges group
|
||||
|
||||
; the names store: omit [names] and [chain] together to turn it off.
|
||||
;[names]
|
||||
; testing until the .simplex TLD is deployed
|
||||
;tld = testing
|
||||
; the paid years of a name; at least 2, the controller's minimum
|
||||
;years = 2
|
||||
; a name's term starts here; the days until then are free
|
||||
;term_start = 2027-01-01T00:00:00Z
|
||||
; how far an order's duration may be from the one the service computes
|
||||
;term_slack_seconds = 3600
|
||||
; on: only prepaid codes register names, and every paid name order answers 403 codes_only
|
||||
;codes_only = off
|
||||
;
|
||||
; the chain the names are registered on. rpc_url can carry a provider's API key and service_key
|
||||
; is the registrar key: keep both secret. Neither is ever logged.
|
||||
;[chain]
|
||||
; the reth node
|
||||
;rpc_url = http://127.0.0.1:8545
|
||||
; 1 for Ethereum mainnet
|
||||
;chain_id = 1
|
||||
;controller = 0x...
|
||||
;sponsor = 0x...
|
||||
;base_registrar = 0x...
|
||||
;resolver = 0x...
|
||||
; 0x and 64 hex digits: the registrar key the service sends transactions with
|
||||
;service_key = 0x...
|
||||
; the most gas any one transaction may use
|
||||
;gas_limit_cap = 8000000
|
||||
|
||||
; local testing only, in both run modes: accepts any well-formed App Store or Play receipt without
|
||||
; verifying it, so anyone who can reach this service can mint badges. The service refuses to start
|
||||
; with this on beside an [apple] or [google] section. Its issuer key is always one released apps
|
||||
|
||||
@@ -660,6 +660,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
|
||||
|
||||
rpcUrl :: T.Text
|
||||
rpcUrl = "https://eth.example.org/v2/rpc-token-value"
|
||||
@@ -845,3 +846,16 @@ testNamesUnknownKeys = do
|
||||
unknownKeys ini `shouldMatchList` ["names.yeers", "chain.rpc"]
|
||||
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"
|
||||
Reference in new issue
Block a user