Plutus 游乐场中的 Plutus 解释器错误
Plutus Interpreter Error in Plutus Playground
此代码可以编译,但是当我单击“评估”时出现此错误。我不确定这是否来自操场,因为我使用了他们新教程中的相同代码。
错误在我编译时没有出现,它只在我尝试通过单击“评估”查看交易时出现。我不确定这是否是代码的问题,因为它通过了编译。
错误消息似乎与代码本身无关。哎呀,它甚至在测试区块链上出现零交易错误。我尝试了不同的交易变体。我知道这些更新本周刚刚发布。我仔细检查了文档。而且我没看到它在说什么。
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 [])```
您缺少 endpoints
声明。您必须为 UI 的任何 Plutus Playground 合约定义端点,类型为:
endpoints :: Contract SplitSchema T.Text ()
对于有问题的 Split App:
endpoints = (lock >>= lockFunds . mkSplitData) `select` (unlock >>= unlockFunds . mkSplitData)
...
endpoints = (lock >>= lockFunds . mkSplitData) `select` (unlock >>= unlockFunds . mkSplitData)
mkSchemaDefinitions ''SplitSchema
$(mkKnownCurrencies [])
此代码可以编译,但是当我单击“评估”时出现此错误。我不确定这是否来自操场,因为我使用了他们新教程中的相同代码。
错误在我编译时没有出现,它只在我尝试通过单击“评估”查看交易时出现。我不确定这是否是代码的问题,因为它通过了编译。
错误消息似乎与代码本身无关。哎呀,它甚至在测试区块链上出现零交易错误。我尝试了不同的交易变体。我知道这些更新本周刚刚发布。我仔细检查了文档。而且我没看到它在说什么。
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 [])```
您缺少 endpoints
声明。您必须为 UI 的任何 Plutus Playground 合约定义端点,类型为:
endpoints :: Contract SplitSchema T.Text ()
对于有问题的 Split App:
endpoints = (lock >>= lockFunds . mkSplitData) `select` (unlock >>= unlockFunds . mkSplitData)
...
endpoints = (lock >>= lockFunds . mkSplitData) `select` (unlock >>= unlockFunds . mkSplitData)
mkSchemaDefinitions ''SplitSchema
$(mkKnownCurrencies [])