Skip to content

Commit 3bb641f

Browse files
committed
Update pure WASI API
1 parent 89fd9e3 commit 3bb641f

File tree

3 files changed

+112
-17
lines changed

3 files changed

+112
-17
lines changed

cardano-wasm/cardano-wasm.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ executable cardano-wasi
7979
if arch(wasm32)
8080
ghc-options:
8181
-no-hs-main
82-
"-optl-Wl,--strip-all,--export=hs_init,--export=newTx,--export=newExperimentalEraTx,--export=newConwayTx,--export=addTxInput,--export=addSimpleTxOut,--export=appendCertificateToTx,--export=setFee,--export=estimateMinFee,--export=signWithPaymentKey,--export=alsoSignWithPaymentKey,--export=toCbor,--export=generatePaymentWallet,--export=generateStakeWallet,--export=restorePaymentWalletFromSigningKeyBech32,--export=restoreStakeWalletFromSigningKeyBech32,--export=generateTestnetPaymentWallet,--export=generateTestnetStakeWallet,--export=restoreTestnetPaymentWalletFromSigningKeyBech32,--export=restoreTestnetStakeWalletFromSigningKeyBech32,--export=getAddressBech32,--export=getBech32ForPaymentVerificationKey,--export=getBech32ForPaymentSigningKey,--export=getBech32ForStakeVerificationKey,--export=getBech32ForStakeSigningKey,--export=getBase16ForPaymentVerificationKeyHash,--export=getBase16ForStakeVerificationKeyHash,--export=mallocNBytes,--export=getStrLen,--export=freeMemory"
82+
"-optl-Wl,--strip-all,--export=hs_init,--export=newTx,--export=newUpcomingEraTx,--export=addTxInput,--export=addSimpleTxOut,--export=appendCertificateToTx,--export=setFee,--export=estimateMinFee,--export=signWithPaymentKey,--export=alsoSignWithPaymentKey,--export=toCbor,--export=makeStakeAddressStakeDelegationCertificate,--export=makeStakeAddressStakeDelegationCertificateUpcomingEra,--export=makeStakeAddressRegistrationCertificate,--export=makeStakeAddressRegistrationCertificateUpcomingEra,--export=makeStakeAddressUnregistrationCertificate,--export=makeStakeAddressUnregistrationCertificateUpcomingEra,--export=generatePaymentWallet,--export=generateStakeWallet,--export=restorePaymentWalletFromSigningKeyBech32,--export=restoreStakeWalletFromSigningKeyBech32,--export=generateTestnetPaymentWallet,--export=generateTestnetStakeWallet,--export=restoreTestnetPaymentWalletFromSigningKeyBech32,--export=restoreTestnetStakeWalletFromSigningKeyBech32,--export=getAddressBech32,--export=getBech32ForPaymentVerificationKey,--export=getBech32ForPaymentSigningKey,--export=getBech32ForStakeVerificationKey,--export=getBech32ForStakeSigningKey,--export=getBase16ForPaymentVerificationKeyHash,--export=getBase16ForStakeVerificationKeyHash,--export=mallocNBytes,--export=getStrLen,--export=freeMemory"
8383
other-modules:
84+
Cardano.Wasi.Internal.Api.Certificate.StakeCertificate
8485
Cardano.Wasi.Internal.Api.GRPC
8586
Cardano.Wasi.Internal.Api.Memory
8687
Cardano.Wasi.Internal.Api.Tx
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
)

cardano-wasm/src-wasi/Cardano/Wasi/Internal/Api/Tx.hs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
module Cardano.Wasi.Internal.Api.Tx
44
( newTx
5-
, newExperimentalEraTx
6-
, newConwayTx
5+
, newUpcomingEraTx
76
, addTxInput
87
, addSimpleTxOut
98
, appendCertificateToTx
@@ -39,11 +38,8 @@ import Foreign.C.String (newCString, peekCString)
3938
foreign export ccall "newTx"
4039
newTx :: IO UnsignedTxObjectJSON
4140

42-
foreign export ccall "newExperimentalEraTx"
43-
newExperimentalEraTx :: IO UnsignedTxObjectJSON
44-
45-
foreign export ccall "newConwayTx"
46-
newConwayTx :: IO UnsignedTxObjectJSON
41+
foreign export ccall "newUpcomingEraTx"
42+
newUpcomingEraTx :: IO UnsignedTxObjectJSON
4743

4844
foreign export ccall "addTxInput"
4945
addTxInput :: UnsignedTxObjectJSON -> CString -> Int -> IO UnsignedTxObjectJSON
@@ -70,11 +66,8 @@ type UnsignedTxObjectJSON = CString
7066
newTx :: IO UnsignedTxObjectJSON
7167
newTx = toCJSON newTxImpl
7268

73-
newExperimentalEraTx :: IO UnsignedTxObjectJSON
74-
newExperimentalEraTx = toCJSON =<< newExperimentalEraTxImpl
75-
76-
newConwayTx :: IO UnsignedTxObjectJSON
77-
newConwayTx = toCJSON newConwayTxImpl
69+
newUpcomingEraTx :: IO UnsignedTxObjectJSON
70+
newUpcomingEraTx = toCJSON =<< newUpcomingEraTxImpl
7871

7972
addTxInput :: UnsignedTxObjectJSON -> CString -> Int -> IO UnsignedTxObjectJSON
8073
addTxInput unsignedTxObject txId txIx =
@@ -113,15 +106,15 @@ setFee unsignedTxObject feeStr =
113106
)
114107

115108
estimateMinFee :: UnsignedTxObjectJSON -> CString -> Int -> Int -> Int -> IO CString
116-
estimateMinFee ptrUnsignedTxObject pparams numInputs numOutputs numShelleyKeyWitnesses = do
109+
estimateMinFee ptrUnsignedTxObject pparams numExtraKeyWitnesses numExtraByronKeyWitnesses totalRefScriptSize = do
117110
(intToCStr . Api.unCoin)
118111
=<< join
119112
( estimateMinFeeImpl
120113
<$> fromCJSON False "UnsignedTx" ptrUnsignedTxObject
121114
<*> (ProtocolParamsJSON <$> fromCJSON False "ProtocolParameters" pparams)
122-
<*> pure (fromIntegral numInputs)
123-
<*> pure (fromIntegral numOutputs)
124-
<*> pure (fromIntegral numShelleyKeyWitnesses)
115+
<*> pure (fromIntegral numExtraKeyWitnesses)
116+
<*> pure (fromIntegral numExtraByronKeyWitnesses)
117+
<*> pure (fromIntegral totalRefScriptSize)
125118
)
126119

127120
signWithPaymentKey :: UnsignedTxObjectJSON -> CString -> IO SignedTxObjectJSON

0 commit comments

Comments
 (0)