@@ -8,17 +8,16 @@ import Control.Monad.IO.Class (MonadIO)
8
8
import Control.Monad.Trans.Class (lift )
9
9
import Core.Context (WithContext , askMpfs , askSubmit )
10
10
import Core.Types.Basic (TokenId )
11
- import Core.Types.Fact (Fact (.. ), parseFacts )
12
11
import Core.Types.Tx (WithTxHash (.. ))
13
12
import Core.Types.Wallet (Wallet )
14
13
import Data.Functor (void )
14
+ import Facts (FactsSelection (.. ), factsCmd )
15
15
import MPFS.API
16
16
import Oracle.Config.Types
17
17
import Submitting (Submission (.. ))
18
18
import Text.JSON.Canonical
19
19
20
20
data ConfigCmd a where
21
- GetConfig :: TokenId -> ConfigCmd (Maybe Config )
22
21
SetConfig :: TokenId -> Wallet -> Config -> ConfigCmd (WithTxHash () )
23
22
24
23
deriving instance Show (ConfigCmd a )
@@ -29,15 +28,11 @@ configCmd
29
28
configCmd (SetConfig tokenId wallet config) = do
30
29
mpfs <- askMpfs
31
30
Submission submit <- ($ wallet) <$> askSubmit
32
- present <- configCmd ( GetConfig tokenId)
31
+ present <- lift $ factsCmd mpfs tokenId ConfigFact
33
32
jkey <- toJSON ConfigKey
34
33
jvalue <- toJSON config
35
34
case present of
36
- Nothing -> do
37
- lift $ fmap void $ submit $ \ address ->
38
- mpfsRequestInsert mpfs address tokenId
39
- $ RequestInsertBody {key = jkey, value = jvalue}
40
- Just oldConfig -> do
35
+ [oldConfig] -> do
41
36
oldValue <- toJSON oldConfig
42
37
lift $ fmap void $ submit $ \ address ->
43
38
mpfsRequestUpdate mpfs address tokenId
@@ -46,12 +41,7 @@ configCmd (SetConfig tokenId wallet config) = do
46
41
, newValue = jvalue
47
42
, oldValue
48
43
}
49
- configCmd (GetConfig tokenId) = do
50
- mpfs <- askMpfs
51
- facts :: [Fact ConfigKey Config ] <-
52
- fmap parseFacts
53
- $ lift
54
- $ mpfsGetTokenFacts mpfs tokenId
55
- pure $ case facts of
56
- [Fact _ c] -> Just c
57
- _ -> Nothing
44
+ _ -> do
45
+ lift $ fmap void $ submit $ \ address ->
46
+ mpfsRequestInsert mpfs address tokenId
47
+ $ RequestInsertBody {key = jkey, value = jvalue}
0 commit comments