mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-04 06:32:59 +00:00
store: build the oracle's exception map once
This commit is contained in:
1 parent
6b2dd903d4
commit
543ad4f4f9
1 file changed
+3
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user