|
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | + |
| 3 | +module Cardano.Wasi.Internal.Api.Certificate.StakeCertificate |
| 4 | + ( makeStakeAddressStakeDelegationCertificate |
| 5 | + , makeStakeAddressStakeDelegationCertificateUpcomingEra |
| 6 | + , makeStakeAddressRegistrationCertificate |
| 7 | + , makeStakeAddressRegistrationCertificateUpcomingEra |
| 8 | + , makeStakeAddressUnregistrationCertificate |
| 9 | + , makeStakeAddressUnregistrationCertificateUpcomingEra |
| 10 | + ) |
| 11 | +where |
| 12 | + |
| 13 | +import Cardano.Wasi.Internal.Conversion (cstrToInt) |
| 14 | +import Cardano.Wasm.Api.Certificate.StakeCertificate qualified as Wasm |
| 15 | + |
| 16 | +import Control.Monad (join) |
| 17 | + |
| 18 | +import Foreign.C (CString) |
| 19 | +import Foreign.C.String (newCString, peekCString) |
| 20 | + |
| 21 | +#if defined(wasm32_HOST_ARCH) |
| 22 | + |
| 23 | +foreign export ccall "makeStakeAddressStakeDelegationCertificate" |
| 24 | + makeStakeAddressStakeDelegationCertificate :: CString -> CString -> IO CString |
| 25 | + |
| 26 | +foreign export ccall "makeStakeAddressStakeDelegationCertificateUpcomingEra" |
| 27 | + makeStakeAddressStakeDelegationCertificateUpcomingEra :: CString -> CString -> IO CString |
| 28 | + |
| 29 | +foreign export ccall "makeStakeAddressRegistrationCertificate" |
| 30 | + makeStakeAddressRegistrationCertificate :: CString -> CString -> IO CString |
| 31 | + |
| 32 | +foreign export ccall "makeStakeAddressRegistrationCertificateUpcomingEra" |
| 33 | + makeStakeAddressRegistrationCertificateUpcomingEra :: CString -> CString -> IO CString |
| 34 | + |
| 35 | +foreign export ccall "makeStakeAddressUnregistrationCertificate" |
| 36 | + makeStakeAddressUnregistrationCertificate :: CString -> CString -> IO CString |
| 37 | + |
| 38 | +foreign export ccall "makeStakeAddressUnregistrationCertificateUpcomingEra" |
| 39 | + makeStakeAddressUnregistrationCertificateUpcomingEra :: CString -> CString -> IO CString |
| 40 | + |
| 41 | +#endif |
| 42 | + |
| 43 | +-- | Make a certificate that delegates a stake address to a stake pool in the current era. |
| 44 | +makeStakeAddressStakeDelegationCertificate :: CString -> CString -> IO CString |
| 45 | +makeStakeAddressStakeDelegationCertificate stakeKeyHashCStr poolIdCStr = |
| 46 | + newCString |
| 47 | + =<< join |
| 48 | + ( Wasm.makeStakeAddressStakeDelegationCertificateImpl |
| 49 | + <$> peekCString stakeKeyHashCStr |
| 50 | + <*> peekCString poolIdCStr |
| 51 | + ) |
| 52 | + |
| 53 | +-- | Make a certificate that delegates a stake address to a stake pool in the upcoming era. |
| 54 | +makeStakeAddressStakeDelegationCertificateUpcomingEra :: CString -> CString -> IO CString |
| 55 | +makeStakeAddressStakeDelegationCertificateUpcomingEra stakeKeyHashCStr poolIdCStr = |
| 56 | + newCString |
| 57 | + =<< join |
| 58 | + ( Wasm.makeStakeAddressStakeDelegationCertificateUpcomingEraImpl |
| 59 | + <$> peekCString stakeKeyHashCStr |
| 60 | + <*> peekCString poolIdCStr |
| 61 | + ) |
| 62 | + |
| 63 | +-- | Make a stake address registration certificate in the current era. |
| 64 | +makeStakeAddressRegistrationCertificate :: CString -> CString -> IO CString |
| 65 | +makeStakeAddressRegistrationCertificate stakeKeyHashCStr depositCStr = |
| 66 | + newCString |
| 67 | + =<< join |
| 68 | + ( Wasm.makeStakeAddressRegistrationCertificateImpl |
| 69 | + <$> peekCString stakeKeyHashCStr |
| 70 | + <*> (toInteger <$> cstrToInt "deposit" depositCStr) |
| 71 | + ) |
| 72 | + |
| 73 | +-- | Make a stake address registration certificate in the upcoming era. |
| 74 | +makeStakeAddressRegistrationCertificateUpcomingEra :: CString -> CString -> IO CString |
| 75 | +makeStakeAddressRegistrationCertificateUpcomingEra stakeKeyHashCStr depositCStr = |
| 76 | + newCString |
| 77 | + =<< join |
| 78 | + ( Wasm.makeStakeAddressRegistrationCertificateUpcomingEraImpl |
| 79 | + <$> peekCString stakeKeyHashCStr |
| 80 | + <*> (toInteger <$> cstrToInt "deposit" depositCStr) |
| 81 | + ) |
| 82 | + |
| 83 | +-- | Make a stake address unregistration certificate in the current era. |
| 84 | +makeStakeAddressUnregistrationCertificate :: CString -> CString -> IO CString |
| 85 | +makeStakeAddressUnregistrationCertificate stakeKeyHashCStr depositCStr = |
| 86 | + newCString |
| 87 | + =<< join |
| 88 | + ( Wasm.makeStakeAddressUnregistrationCertificateImpl |
| 89 | + <$> peekCString stakeKeyHashCStr |
| 90 | + <*> (toInteger <$> cstrToInt "deposit" depositCStr) |
| 91 | + ) |
| 92 | + |
| 93 | +-- | Make a stake address unregistration certificate in the upcoming era. |
| 94 | +makeStakeAddressUnregistrationCertificateUpcomingEra :: CString -> CString -> IO CString |
| 95 | +makeStakeAddressUnregistrationCertificateUpcomingEra stakeKeyHashCStr depositCStr = |
| 96 | + newCString |
| 97 | + =<< join |
| 98 | + ( Wasm.makeStakeAddressUnregistrationCertificateUpcomingEraImpl |
| 99 | + <$> peekCString stakeKeyHashCStr |
| 100 | + <*> (toInteger <$> cstrToInt "deposit" depositCStr) |
| 101 | + ) |
0 commit comments