Skip to content

Commit cb89b8d

Browse files
committed
Take input pool id hash as String
1 parent 2eb2374 commit cb89b8d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

cardano-wasm/src-lib/Cardano/Wasm/Api/Certificate/StakeCertificate.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,23 @@ instance FromJSON StakeCertificateObject where
121121
, delegateStake
122122
}
123123

124-
-- | Creates an empty stake certificate object for the given stake key hash.
124+
-- | Creates an empty stake certificate object for the given stake key base16 hash.
125125
-- For the certificate to be valid must be either a registration, an unregistration or
126126
-- a delegation certificate. But it can be both registration and delegation.
127-
createStakeKeyCertificateImpl :: Hash StakeKey -> StakeCertificateObject
128-
createStakeKeyCertificateImpl skHash =
129-
StakeCertificateObject
130-
{ era = ConwayEra
131-
, stakeCredential = skHash
132-
, deposit = Nothing
133-
, action = DelegateOnly
134-
, delegateStake = Nothing
135-
}
127+
createStakeKeyCertificateImpl :: MonadThrow m => String -> m StakeCertificateObject
128+
createStakeKeyCertificateImpl skHashStr = do
129+
skHash <- readHash skHashStr
130+
return $
131+
StakeCertificateObject
132+
{ era = ConwayEra
133+
, stakeCredential = skHash
134+
, deposit = Nothing
135+
, action = DelegateOnly
136+
, delegateStake = Nothing
137+
}
138+
where
139+
readHash :: MonadThrow m => String -> m (Hash StakeKey)
140+
readHash = rightOrError . Api.deserialiseFromRawBytesHex . Text.encodeUtf8 . Text.pack
136141

137142
-- | Marks the certificate as a stake registration certificate.
138143
asStakeRegistrationImpl :: StakeCertificateObject -> StakeCertificateObject

0 commit comments

Comments
 (0)