Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Enabling V2 scripts #151

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion src/BotPlutusInterface/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ balanceTxIO' balanceCfg pabConf ownPkh unbalancedTx' =
balanceCfg
pabConf
changeAddr

lift $ printBpiLog @w (Debug [TxBalancingLog]) $ viaShow utxos
privKeys <- newEitherT $ Files.readPrivateKeys @w pabConf

let utxoIndex :: Map TxOutRef TxOut
Expand Down
2 changes: 1 addition & 1 deletion src/BotPlutusInterface/CardanoAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Ledger.Tx (ChainIndexTxOut (..))
import Ledger.Tx.CardanoAPI qualified as TxApi
import Ouroboros.Consensus.HardFork.History qualified as Consensus
import Ouroboros.Consensus.HardFork.History.Qry qualified as HF
import Plutus.Script.Utils.Scripts qualified as ScriptUtils
import Plutus.Script.Utils.V2.Scripts qualified as ScriptUtils
import Plutus.V1.Ledger.Api (Credential (..))
import Plutus.V2.Ledger.Tx qualified as V2
import PlutusTx.Prelude qualified as PlutusTx
Expand Down
9 changes: 4 additions & 5 deletions src/BotPlutusInterface/CardanoCLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import Ledger.Interval (
UpperBound (UpperBound),
)
import Ledger.Scripts (Datum, DatumHash (..))
import Ledger.Scripts qualified as Scripts
import Ledger.Tx (
RedeemerPtr (RedeemerPtr),
Redeemers,
Expand All @@ -97,7 +96,7 @@ import Ledger.Tx (
import Ledger.Tx.CardanoAPI (toCardanoAddressInEra)
import Ledger.Value (Value)
import Ledger.Value qualified as Value
import Plutus.Script.Utils.Scripts qualified as ScriptUtils
import Plutus.Script.Utils.V2.Scripts qualified as ScriptUtils
import Plutus.V1.Ledger.Api (
CurrencySymbol (unCurrencySymbol),
ExBudget (ExBudget),
Expand Down Expand Up @@ -258,7 +257,7 @@ txInOpts spendIndex pabConf =
mconcat
[
[ "--tx-in-script-file"
, validatorScriptFilePath pabConf (Scripts.validatorHash validator)
, validatorScriptFilePath pabConf (ScriptUtils.validatorHash validator)
]
,
[ "--tx-in-datum-file"
Expand Down Expand Up @@ -295,11 +294,11 @@ mintOpts mintIndex pabConf mintingPolicies redeemers mintValue =
( \(idx, policy) ->
let redeemerPtr = RedeemerPtr Mint idx
redeemer = Map.lookup redeemerPtr redeemers
curSymbol = Value.mpsSymbol $ Scripts.mintingPolicyHash policy
curSymbol = Value.mpsSymbol $ ScriptUtils.mintingPolicyHash policy
exBudget =
Map.findWithDefault
mempty
(Scripts.mintingPolicyHash policy)
(ScriptUtils.mintingPolicyHash policy)
mintIndex
toOpts r =
(,exBudget) $
Expand Down
2 changes: 1 addition & 1 deletion src/BotPlutusInterface/Contract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ awaitTxStatusChange contractEnv txId = do
printBpiLog @w (Debug [PABLog]) $ pretty $ "Awaiting status change for " ++ show txId

let txStatusPolling = contractEnv.cePABConfig.pcTxStatusPolling
pollInterval = fromIntegral $ txStatusPolling.spInterval
pollInterval = fromIntegral txStatusPolling.spInterval
pollTimeout = txStatusPolling.spBlocksTimeOut
cutOffBlock = checkStartedBlock + fromIntegral pollTimeout

Expand Down
10 changes: 7 additions & 3 deletions src/BotPlutusInterface/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ data ShellArgs a = ShellArgs
}

instance Show (ShellArgs a) where
show ShellArgs {cmdName, cmdArgs} = Text.unpack $ cmdName <> mconcat cmdArgs
show ShellArgs {cmdName, cmdArgs} = Text.unpack $ cmdName <> mconcat [" " <> a | a <- cmdArgs]

data PABEffect (w :: Type) (r :: Type) where
CallCommand :: ShellArgs a -> PABEffect w (Either Text a)
Expand Down Expand Up @@ -158,8 +158,12 @@ handlePABEffect contractEnv =
( \case
CallCommand shellArgs ->
case contractEnv.cePABConfig.pcCliLocation of
Local -> callLocalCommand shellArgs
Remote ipAddr -> callRemoteCommand ipAddr shellArgs
Local -> do
putStrLn $ "CallCommand: " <> show (Local, shellArgs)
callLocalCommand shellArgs
Remote ipAddr -> do
putStrLn $ "CallCommand: " <> show (Remote ipAddr, shellArgs)
callRemoteCommand ipAddr shellArgs
CreateDirectoryIfMissing createParents filePath ->
Directory.createDirectoryIfMissing createParents filePath
CreateDirectoryIfMissingCLI createParents filePath ->
Expand Down
7 changes: 3 additions & 4 deletions src/BotPlutusInterface/Files.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ import Cardano.Api (
FileError,
Key (VerificationKey),
PaymentKey,
PlutusScriptV2,
SigningKey,
getVerificationKey,
serialiseToRawBytes,
)
import Cardano.Api.Shelley (
PlutusScript (PlutusScriptSerialised),
PlutusScriptV1,
ScriptDataJsonSchema (ScriptDataJsonDetailedSchema),
fromPlutusData,
scriptDataToJson,
Expand All @@ -70,8 +70,7 @@ import Ledger.Crypto qualified as Crypto
import Ledger.Tx (Tx)
import Ledger.Tx qualified as Tx
import Ledger.Value qualified as Value
import Plutus.Script.Utils.Scripts qualified as ScriptUtils
import Plutus.Script.Utils.V1.Scripts qualified as ScriptUtils
import Plutus.Script.Utils.V2.Scripts qualified as ScriptUtils
import Plutus.V1.Ledger.Api (
CurrencySymbol,
Datum (getDatum),
Expand Down Expand Up @@ -295,7 +294,7 @@ mkDummyPrivateKey (PubKey (LedgerBytes pubkey)) =
Crypto.xprv $
mconcat [dummyPrivKey, dummyPrivKeySuffix, pubkeyBS, dummyChainCode]

serialiseScript :: Script -> PlutusScript PlutusScriptV1
serialiseScript :: Script -> PlutusScript PlutusScriptV2
serialiseScript =
PlutusScriptSerialised
. ShortByteString.toShort
Expand Down
65 changes: 32 additions & 33 deletions test/Spec/BotPlutusInterface/Contract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ import Data.Row (Row)
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Void (Void)
import Ledger (validatorHash)
import Ledger (StakePubKeyHash (StakePubKeyHash))
import Ledger qualified
import Ledger.Ada qualified as Ada
import Ledger.Address (scriptHashAddress)
import Ledger.Address qualified as Address
import Ledger.Constraints qualified as Constraints
import Ledger.Interval (interval)
import Ledger.Scripts qualified as Scripts
import Ledger.Slot (Slot)
import Ledger.Time (POSIXTime (POSIXTime))
import Ledger.Tx (
CardanoTx,
ChainIndexTxOut (PublicKeyChainIndexTxOut, ScriptChainIndexTxOut),
Expand All @@ -48,7 +45,9 @@ import Plutus.Contract (
utxosAt,
waitNSlots,
)
import Plutus.Script.Utils.Scripts qualified as ScriptUtils
import Plutus.Script.Utils.V2.Address qualified as ScriptUtils
import Plutus.Script.Utils.V2.Scripts qualified as ScriptUtils
import Plutus.V2.Ledger.Api (Address, CurrencySymbol, Datum (Datum), DatumHash (DatumHash), MintingPolicy, POSIXTime (POSIXTime), RedeemerHash (RedeemerHash), Validator, ValidatorHash (ValidatorHash))
import PlutusTx qualified
import PlutusTx.Builtins (fromBuiltin)
import Pretty.Diff (
Expand Down Expand Up @@ -210,7 +209,7 @@ sendAdaStaking = do
initState = def & utxos <>~ [(txOutRef, txOut)]
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef

stakePkh3 = Address.StakePubKeyHash pkh3
stakePkh3 = StakePubKeyHash pkh3
addr2Staking = unsafeSerialiseAddress Mainnet (Ledger.pubKeyHashAddress paymentPkh2 (Just stakePkh3))

contract :: Plutus.Contract.Contract () (Plutus.Contract.Endpoint "SendAda" ()) Text CardanoTx
Expand Down Expand Up @@ -443,23 +442,23 @@ mintTokens = do
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
collateralTxId = encodeByteString $ fromBuiltin $ Tx.getTxId theCollateralTxId

mintingPolicy :: Scripts.MintingPolicy
mintingPolicy :: MintingPolicy
mintingPolicy = Scripts.mkMintingPolicyScript $$(PlutusTx.compile [||(\_ _ -> ())||])

curSymbol :: Ledger.CurrencySymbol
curSymbol = Ledger.scriptCurrencySymbol mintingPolicy
curSymbol :: CurrencySymbol
curSymbol = ScriptUtils.scriptCurrencySymbol mintingPolicy

curSymbol' :: Text
curSymbol' = encodeByteString $ fromBuiltin $ Value.unCurrencySymbol curSymbol

redeemerHash =
let (Scripts.RedeemerHash rh) = ScriptUtils.redeemerHash Scripts.unitRedeemer
let (RedeemerHash rh) = ScriptUtils.redeemerHash Scripts.unitRedeemer
in encodeByteString $ fromBuiltin rh

contract :: Plutus.Contract.Contract () (Plutus.Contract.Endpoint "SendAda" ()) Text CardanoTx
contract = do
let lookups =
Constraints.plutusV1MintingPolicy mintingPolicy
Constraints.plutusV2MintingPolicy mintingPolicy
let constraints =
Constraints.mustMintValue (Value.singleton curSymbol "testToken" 5)
<> Constraints.mustPayToPubKey
Expand Down Expand Up @@ -521,33 +520,33 @@ spendToValidator = do
initState = def & utxos <>~ [(txOutRef, txOut)]
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef

validator :: Scripts.Validator
validator :: Validator
validator =
Scripts.mkValidatorScript
$$(PlutusTx.compile [||(\_ _ _ -> ())||])

valHash :: Ledger.ValidatorHash
valHash = Ledger.validatorHash validator
valHash :: ValidatorHash
valHash = ScriptUtils.validatorHash validator

valAddr :: Ledger.Address
valAddr = scriptHashAddress $ validatorHash validator
valAddr :: Address
valAddr = ScriptUtils.mkValidatorAddress validator

valAddr' :: Text
valAddr' = unsafeSerialiseAddress Mainnet valAddr

valHash' :: Text
valHash' =
let (Scripts.ValidatorHash vh) = valHash
let (ValidatorHash vh) = valHash
in encodeByteString $ fromBuiltin vh

datum :: Scripts.Datum
datum = Scripts.Datum $ PlutusTx.toBuiltinData (11 :: Integer)
datum :: Datum
datum = Datum $ PlutusTx.toBuiltinData (11 :: Integer)

datumHash :: ScriptUtils.DatumHash
datumHash :: DatumHash
datumHash = ScriptUtils.datumHash datum

datumHash' =
let (Scripts.DatumHash dh) = datumHash
let (DatumHash dh) = datumHash
in encodeByteString $ fromBuiltin dh

contract :: Plutus.Contract.Contract () (Plutus.Contract.Endpoint "SendAda" ()) Text CardanoTx
Expand Down Expand Up @@ -610,46 +609,46 @@ redeemFromValidator = do
(Ada.lovelaceValueOf 1250)
(datumHash, Nothing)
Nothing
(validatorHash validator, Just validator)
(ScriptUtils.validatorHash validator, Just validator)
initState = def & utxos <>~ [(txOutRef, txOut), (txOutRef', txOut')]
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
collateralTxId = encodeByteString $ fromBuiltin $ Tx.getTxId theCollateralTxId

validator :: Scripts.Validator
validator :: Validator
validator =
Scripts.mkValidatorScript
$$(PlutusTx.compile [||(\_ _ _ -> ())||])

valHash :: Scripts.ValidatorHash
valHash = Scripts.validatorHash validator
valHash :: ValidatorHash
valHash = ScriptUtils.validatorHash validator

valAddr :: Ledger.Address
valAddr = scriptHashAddress $ validatorHash validator
valAddr = ScriptUtils.mkValidatorAddress validator

valHash' :: Text
valHash' =
let (Scripts.ValidatorHash vh) = valHash
let (ValidatorHash vh) = valHash
in encodeByteString $ fromBuiltin vh

datum :: Scripts.Datum
datum = Scripts.Datum $ PlutusTx.toBuiltinData (11 :: Integer)
datum :: Datum
datum = Datum $ PlutusTx.toBuiltinData (11 :: Integer)

datumHash :: Scripts.DatumHash
datumHash :: DatumHash
datumHash = ScriptUtils.datumHash datum

datumHash' =
let (Scripts.DatumHash dh) = datumHash
let (DatumHash dh) = datumHash
in encodeByteString $ fromBuiltin dh

redeemerHash =
let (Scripts.RedeemerHash rh) = ScriptUtils.redeemerHash Scripts.unitRedeemer
let (RedeemerHash rh) = ScriptUtils.redeemerHash Scripts.unitRedeemer
in encodeByteString $ fromBuiltin rh

contract :: Plutus.Contract.Contract () (Plutus.Contract.Endpoint "SendAda" ()) Text CardanoTx
contract = do
utxos' <- Plutus.Contract.utxosAt valAddr
let lookups =
Constraints.plutusV1OtherScript validator
Constraints.plutusV2OtherScript validator
<> Constraints.otherData datum
<> Constraints.unspentOutputs utxos'
let constraints =
Expand Down