Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

template haskell - Plutus Interpreter Error in Plutus Playground

This code compiles but when I click on Evaluate I get this error. I'm not sure if this is from the playground or not because I used the same code from their new tutorial .

The error doesn't show up when I compile it only happens when I attempt view transactions by clicking Evaluate. I'm not sure if this is an issue with the code because it passed compile.

The Error message doesn't seem about the code itself. Heck it even errors out with zero transactions on the test block chain. I tried with with different variations on transactions. I know these updates just came out this week. I double checked the documentation. And I'm not seeing what its talking about.

https://docs.cardano.org/projects/plutus/en/latest/tutorials/plutus-playground.html

https://playground.plutus.iohkdev.io/

Interpreter Errors
 error:
    ? Variable not in scope: endpoints :: Contract s0 T.Text a0
    ? Perhaps you meant ‘endpoint’ (imported from Language.Plutus.Contract)
    |
101 | main = printJson $ stage endpoints ""[{\"blocks\":10,\"tag\":\"AddBlocks\"},{\"blocks\":10,\"tag\":\"AddBlocks\"}]"" "[{"simulatorWalletBalance":{"getValue":[[{"unCurrencySymbol":""},[[{"unTokenName":""},10]]]]},"simulatorWalletWallet":{"getWallet":1}},{"simulatorWalletBalance":{"getValue":[[{"unCurrencySymbol":""},[[{"unTokenName":""},10]]]]},"simulatorWalletWallet":{"getWallet":2}}]"
    |                          ^^^^^^^^
import           Control.Monad             (void)
import           Data.Aeson                (FromJSON, ToJSON)
import qualified Data.Text                 as T
import           GHC.Generics              (Generic)
import           Language.Plutus.Contract
import qualified Language.PlutusTx         as PlutusTx
import           Language.PlutusTx.Prelude
import           Ledger
import qualified Ledger.Ada                as Ada
import qualified Ledger.Constraints        as Constraints
import qualified Ledger.Typed.Scripts      as Scripts
import           Schema
import           Wallet.Emulator.Wallet
import           Playground.Contract


data SplitData = 
    SplitData
        { recipient1 :: PubKeyHash -- First Recipent of the funds
        , recipient2 :: PubKeyHash -- Second Recipentt of the funds
        , amount     :: Ada        -- How much ADA gets locked
        }
    deriving stock (Show, Generic)

PlutusTx.makeIsData ''SplitData
PlutusTx.makeLift ''SplitData


validateSplit :: SplitData -> () -> ValidatorCtx -> Bool
validateSplit SplitData{recipient1, recipient2, amount} _ ValidatorCtx{valCtxTxInfo} =
    let half = Ada.divide amount 2 in 
    Ada.fromValue (valuePaidTo valCtxTxInfo recipient1) >= half &&
    Ada.fromValue (valuePaidTo valCtxTxInfo recipient2) >= (amount - half)

data Split 
instance Scripts.ScriptType Split where
    type instance RedeemerType Split = ()
    type instance DatumType Split = SplitData

splitInstance :: Scripts.ScriptInstance Split
splitInstance = Scripts.validator @Split 
    $$(PlutusTx.compile [|| validateSplit ||])
    $$(PlutusTx.compile [|| warp ||]) where
        warp = Scripts.wrapValidator @SplitData @()

data LockArgs = 
        LockArgs
        {  recipient1Wallet :: Wallet
        ,  recipient2Wallet :: Wallet
        ,  totalAda         :: Ada 
        }
    deriving stock (Show, Generic)
    deriving anyclass (ToJSON, FromJSON, ToSchema)

type SplitSchema = 
    BlockchainActions
        ./ Endpoint "lock" LockArgs
        ./ Endpoint "unlock" LockArgs

lock :: Contract SplitSchema T.Text LockArgs
lock = endpoint @"lock"

unlock :: Contract SplitSchema T.Text LockArgs
unlock = endpoint @"unlock"

mkSplitData :: LockArgs -> SplitData
mkSplitData LockArgs{recipient1Wallet, recipient2Wallet, totalAda} =
    let convert :: Wallet -> PubKeyHash
        convert = pubKeyHash . walletPubKey
    in
    SplitData
    { recipient1 = convert recipient1Wallet
    , recipient2 = convert recipient2Wallet
    , amount = totalAda
    }

lockFunds :: SplitData -> Contract SplitSchema T.Text ()
lockFunds s@SplitData{amount} = do
    logInfo $ "Locking" <> show amount
    let tx = Constraints.mustPayToTheScript s (Ada.toValue amount)
    void $ submitTxConstraints splitInstance tx

unlockFunds :: SplitData -> Contract SplitSchema T.Text ()
unlockFunds SplitData{recipient1, recipient2, amount} = do
    let contractAddress = (Ledger.scriptAddress (Scripts.validatorScript splitInstance))
    utxos <- utxoAt contractAddress
    let half = Ada.divide amount 2
        tx = 
            collectFromScript utxos ()
            <> Constraints.mustPayToPubKey recipient1 (Ada.toValue half)
            <> Constraints.mustPayToPubKey recipient2 (Ada.toValue  $ amount - half)
    void $ submitTxConstraintsSpending splitInstance utxos tx 


mkSchemaDefinitions ''SplitSchema

$(mkKnownCurrencies [])```
question from:https://stackoverflow.com/questions/65939945/plutus-interpreter-error-in-plutus-playground

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...