Skip to content

Commit

Permalink
Extract creation of stake address from plutus script
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Oct 8, 2024
1 parent 0ad0cf5 commit e90f532
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 12 additions & 0 deletions hydra-cardano-api/src/Hydra/Cardano/Api/AddressInEra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ mkScriptAddress networkId script =
where
version = plutusScriptVersion @lang

-- | Construct a stake address from a Plutus script.
mkStakeScriptAddress ::
forall lang.
IsPlutusScriptLanguage lang =>
NetworkId ->
PlutusScript lang ->
StakeAddress
mkStakeScriptAddress networkId script =
makeStakeAddress networkId $ StakeCredentialByScript $ hashScript $ PlutusScript version script
where
version = plutusScriptVersion @lang

-- * Type Conversions

-- | From a ledger 'Addr' to an api 'AddressInEra'
Expand Down
5 changes: 1 addition & 4 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Control.Lens ((^.))
import Data.Map qualified as Map
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Set qualified as Set
import Hydra.Cardano.Api.Prelude (StakeCredential (StakeCredentialByScript))
import Hydra.Cardano.Api.Pretty (renderTxWithUTxO)
import Hydra.Chain.Direct.State (ChainContext (..), HasKnownUTxO (getKnownUTxO), genChainStateWithTx)
import Hydra.Chain.Direct.State qualified as Transition
Expand Down Expand Up @@ -301,9 +300,7 @@ genBlueprintTxWithUTxO =
let scriptWitness = mkScriptWitness alwaysSucceedingScript NoScriptDatumForStake redeemer
alwaysSucceedingScript = PlutusScriptSerialised $ Plutus.alwaysSucceedingNAryFunction 2
redeemer = toScriptData (123 :: Integer)
-- XXX: Depends on hydra-cardano-api prelude (maybe extract a helper to hydra-cardano-api?)
stakeCredential = StakeCredentialByScript $ hashScript $ PlutusScript alwaysSucceedingScript
stakeAddress = makeStakeAddress testNetworkId stakeCredential
stakeAddress = mkStakeScriptAddress testNetworkId alwaysSucceedingScript
pure
( utxo
, txbody
Expand Down

0 comments on commit e90f532

Please sign in to comment.