mirror of
https://github.com/FiloSpaTeam/plutus-pioneer-program.git
synced 2024-11-22 06:42:00 +01:00
completed oracle validation
This commit is contained in:
parent
e5fa37a0b5
commit
af90b54f0e
1 changed files with 27 additions and 12 deletions
|
@ -39,6 +39,7 @@ import Ledger hiding (singleton)
|
||||||
import Ledger.Constraints as Constraints
|
import Ledger.Constraints as Constraints
|
||||||
import qualified Ledger.Typed.Scripts as Scripts
|
import qualified Ledger.Typed.Scripts as Scripts
|
||||||
import Ledger.Value as Value
|
import Ledger.Value as Value
|
||||||
|
import Ledger.Ada as Ada
|
||||||
import Plutus.Contracts.Currency as Currency
|
import Plutus.Contracts.Currency as Currency
|
||||||
import Prelude (Semigroup (..))
|
import Prelude (Semigroup (..))
|
||||||
|
|
||||||
|
@ -73,20 +74,25 @@ oracleValue o f = do
|
||||||
|
|
||||||
{-# INLINABLE mkOracleValidator #-}
|
{-# INLINABLE mkOracleValidator #-}
|
||||||
mkOracleValidator :: Oracle -> Integer -> OracleRedeemer -> ScriptContext -> Bool
|
mkOracleValidator :: Oracle -> Integer -> OracleRedeemer -> ScriptContext -> Bool
|
||||||
mkOracleValidator _ _ Use _ = True
|
mkOracleValidator oracle x r ctx =
|
||||||
mkOracleValidator oracle _ Update ctx =
|
traceIfFalse "token missing from input" inputHasToken &&
|
||||||
traceIfFalse "operator signature missing" (txSignedBy info $ oOperator oracle) &&
|
traceIfFalse "token missing from output" outputHasToken &&
|
||||||
traceIfFalse "token missing from input" inputHasToken &&
|
case r of
|
||||||
traceIfFalse "token missing from output" outputHasToken &&
|
Update -> traceIfFalse "operator signature missing" (txSignedBy info $ oOperator oracle) &&
|
||||||
traceIfFalse "invalid output datum" validOutputDatum
|
traceIfFalse "invalid output datum" validOutputDatum
|
||||||
|
Use -> traceIfFalse "oracle value changed" (outputDatum == Just x) &&
|
||||||
|
traceIfFalse "fees not paid" feesPaid
|
||||||
where
|
where
|
||||||
info :: TxInfo
|
info :: TxInfo
|
||||||
info = scriptContextTxInfo ctx
|
info = scriptContextTxInfo ctx
|
||||||
|
|
||||||
|
ownInput :: TxOut
|
||||||
|
ownInput = case findOwnInput ctx of
|
||||||
|
Nothing -> traceError "oracle input missing"
|
||||||
|
Just i -> txInInfoResolved i
|
||||||
|
|
||||||
inputHasToken :: Bool
|
inputHasToken :: Bool
|
||||||
inputHasToken = case findOwnInput ctx of
|
inputHasToken = assetClassValueOf (txOutValue ownInput) (oracleAsset oracle) == 1
|
||||||
Nothing -> False
|
|
||||||
Just i -> assetClassValueOf (txOutValue $ txInInfoResolved i) (oracleAsset oracle) == 1
|
|
||||||
|
|
||||||
ownOutput :: TxOut
|
ownOutput :: TxOut
|
||||||
ownOutput = case getContinuingOutputs ctx of
|
ownOutput = case getContinuingOutputs ctx of
|
||||||
|
@ -96,10 +102,19 @@ mkOracleValidator oracle _ Update ctx =
|
||||||
outputHasToken :: Bool
|
outputHasToken :: Bool
|
||||||
outputHasToken = assetClassValueOf (txOutValue ownOutput) (oracleAsset oracle) == 1
|
outputHasToken = assetClassValueOf (txOutValue ownOutput) (oracleAsset oracle) == 1
|
||||||
|
|
||||||
|
outputDatum :: Maybe Integer
|
||||||
|
outputDatum = oracleValue ownOutput (`findDatum` info)
|
||||||
|
|
||||||
validOutputDatum :: Bool
|
validOutputDatum :: Bool
|
||||||
validOutputDatum = case oracleValue ownOutput (`findDatum` info) of
|
validOutputDatum = isJust outputDatum
|
||||||
Nothing -> False
|
|
||||||
Just _ -> True
|
feesPaid :: Bool
|
||||||
|
feesPaid =
|
||||||
|
let
|
||||||
|
inVal = txOutValue ownInput
|
||||||
|
outVal = txOutValue ownOutput
|
||||||
|
in
|
||||||
|
outVal `geq` (inVal <> Ada.lovelaceValueOf (oFee oracle))
|
||||||
|
|
||||||
data Oracling
|
data Oracling
|
||||||
instance Scripts.ScriptType Oracling where
|
instance Scripts.ScriptType Oracling where
|
||||||
|
|
Loading…
Reference in a new issue