module Foo.Offchain where
import Plutus.V1.Ledger.Scripts (MintingPolicy)
import Plutus.V1.Ledger.Address (Address)
import Cardano.Hydra.Cardano.API
import Hydra.Prelude
import Test.Hydra.Prelude
import Cardano.Api.UTxO qualified as UTxO
import Foo.Onchain(fooPolicy)
userAddress :: Address ShelleyAddr
...
txFoo = do
let policyScript = fromPlutusScript @PlutusScriptV2
$ getMintingPolicy fooPolicy
policyId = PolicyId $ hashScript $ PlutusScript policyScript
mintingWitness = BuildTxWith . Map.singleton policyId
$ mkScriptWitness policyScript NoScriptDatumForMint (toScriptData ())
mintingValue = valueFromList [(AssetId policyId "", 1)]
...
pparams <- queryProtocolParameters networkId nodeSocket QueryTip
systemStart <- querySystemStart networkId nodeSocket QueryTip
eraHistory <- queryEraHistory networkId nodeSocket QueryTip
stakePools <- queryStakePools networkId nodeSocket QueryTip
utxoSet <- ...
someUtxo <- ...
someTxOut <- ...
...
let unbalancedBody =
TxBodyContent
(withWitness <$> toList (UTxO.inputSet utxoSet))
(TxInsCollateral [someUtxo])
TxInsReferenceNone
[someTxOut]
TxTotalCollateralNone
TxReturnCollateralNone
(TxFeeExplicit 0)
(TxValidityNoLowerBound, TxValidityNoUpperBound)
TxMetadataNone
TxAuxScriptsNone
TxExtraKeyWitnessesNone
(BuildTxWith $ Just pparams)
TxWithdrawalsNone
TxCertificatesNone
TxUpdateProposalNone
(TxMintValue mintingValue mintingWitness)
TxScriptValidityNone
let balancedBody = either (error . show) balancedTxBody $
makeTransactionBodyAutoBalance
BabbageEraInCardanoMode
systemStart
eraHistory
pparams
stakePools
(UTxO.toApi utxoSet)
preBody
(ShelleyAddressInEra userAddress)
Nothing
Became Hot Network Question