From 543ad4f4f9c92a2920d325feada1b8dc3742df4f Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 22 Oct 2026 01:35:41 +0000 Subject: [PATCH] store: build the oracle's exception map once --- .../src/StoreService/Names/Contracts.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/simplex-store-service/src/StoreService/Names/Contracts.hs b/apps/simplex-store-service/src/StoreService/Names/Contracts.hs index 0102b8c8a0..49d30626f9 100644 --- a/apps/simplex-store-service/src/StoreService/Names/Contracts.hs +++ b/apps/simplex-store-service/src/StoreService/Names/Contracts.hs @@ -29,8 +29,8 @@ import Control.Monad.Except (ExceptT (..), runExceptT) import Data.Bifunctor (first) import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as B -import Data.IORef (IORef, atomicWriteIORef, newIORef, readIORef) import Data.Functor.Compose (Compose (..)) +import Data.IORef (IORef, atomicWriteIORef, newIORef, readIORef) import qualified Data.Map.Strict as M import Data.Maybe (fromMaybe) import Data.Text (Text) @@ -137,7 +137,8 @@ codeLengthFor :: Contracts -> Int -> Int -> IO (Either ChainError (Maybe Int)) codeLengthFor ct cents years = runExceptT $ do oracle <- ExceptT $ call ct (controller ct) ("prices()", "") decodeAddress (basePerYear, exceptions) <- ExceptT $ call ct oracle ("prices()", "") decodePrices - let perYear len = M.findWithDefault basePerYear (toInteger len) $ M.fromList exceptions + let exceptionPrices = M.fromList exceptions + perYear len = M.findWithDefault basePerYear (toInteger len) exceptionPrices covered len = perYear len * toInteger years <= toInteger cents pure $ case takeWhile covered [maxNameLength, maxNameLength - 1 .. minNameLength] of [] -> Nothing