Skip to content

Commit 26bdc48

Browse files
committed
Update exports, remove main logic, and fix capitalisation
1 parent 04e4260 commit 26bdc48

File tree

5 files changed

+118
-28
lines changed

5 files changed

+118
-28
lines changed

cardano-wasm/app-wasi/Main.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = return ()

cardano-wasm/cardano-wasm.cabal

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ executable cardano-wasi
6969
import: project-config
7070
main-is: Main.hs
7171
hs-source-dirs:
72-
app
72+
app-wasi
7373
src-wasi
7474

7575
default-language: Haskell2010
7676

7777
if arch(wasm32)
7878
ghc-options:
7979
-no-hs-main
80-
"-optl-Wl,--strip-all,--export=hs_init,--export=newTx,--export=newExperimentalEraTx,--export=newConwayTx,--export=addTxInput,--export=addSimpleTxOut,--export=setFee,--export=estimateMinFee,--export=signWithPaymentKey,--export=alsoSignWithPaymentKey,--export=toCbor,--export=generatePaymentWallet,--export=restorePaymentWalletFromSigningKeyBech32,--export=restoreTestnetPaymentWalletFromSigningKeyBech32,--export=getAddressBech32,--export=getBech32ForVerificationKey,--export=getBech32ForSigningKey,--export=getBase16ForVerificationKeyHash,--export=mallocNBytes,--export=getStrLen,--export=freeMemory"
80+
"-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"
8181
other-modules:
8282
Cardano.Wasi.Internal.Api.GRPC
8383
Cardano.Wasi.Internal.Api.Memory
@@ -90,7 +90,6 @@ executable cardano-wasi
9090
base,
9191
cardano-api,
9292
cardano-wasm:cardano-wasi-lib,
93-
optparse-applicative,
9493
text,
9594
utf8-string,
9695

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Cardano.Wasi.Internal.Api.Tx
66
, newConwayTx
77
, addTxInput
88
, addSimpleTxOut
9+
, appendCertificateToTx
910
, setFee
1011
, estimateMinFee
1112
, signWithPaymentKey
@@ -20,7 +21,7 @@ import Cardano.Wasi.Internal.Conversion
2021
( cstrToInt
2122
, fromCJSON
2223
, intToCStr
23-
, stringTosigningKey
24+
, stringToSigningKey
2425
, toCJSON
2526
, txIdToString
2627
)
@@ -50,6 +51,9 @@ foreign export ccall "addTxInput"
5051
foreign export ccall "addSimpleTxOut"
5152
addSimpleTxOut :: UnsignedTxObjectJSON -> CString -> CString -> IO UnsignedTxObjectJSON
5253

54+
foreign export ccall "appendCertificateToTx"
55+
appendCertificateToTx :: UnsignedTxObjectJSON -> CString -> IO UnsignedTxObjectJSON
56+
5357
foreign export ccall "setFee"
5458
setFee :: UnsignedTxObjectJSON -> CString -> IO UnsignedTxObjectJSON
5559

@@ -91,6 +95,15 @@ addSimpleTxOut unsignedTxObject destAddr lovelaceAmountStr =
9195
<*> (Api.Coin <$> cstrToInt "Lovelace amount" lovelaceAmountStr)
9296
)
9397

98+
appendCertificateToTx :: UnsignedTxObjectJSON -> CString -> IO UnsignedTxObjectJSON
99+
appendCertificateToTx unsignedTxObject certCborStr =
100+
toCJSON
101+
=<< join
102+
( appendCertificateToTxImpl
103+
<$> fromCJSON True "UnsignedTx" unsignedTxObject
104+
<*> peekCString certCborStr
105+
)
106+
94107
setFee :: UnsignedTxObjectJSON -> CString -> IO UnsignedTxObjectJSON
95108
setFee unsignedTxObject feeStr =
96109
toCJSON
@@ -116,7 +129,7 @@ signWithPaymentKey unsignedTxObject signingKeyBech32 =
116129
toCJSON
117130
=<< ( signWithPaymentKeyImpl
118131
<$> fromCJSON True "UnsignedTx" unsignedTxObject
119-
<*> stringTosigningKey signingKeyBech32
132+
<*> stringToSigningKey signingKeyBech32
120133
)
121134

122135
-- * SignedTxObject
@@ -138,7 +151,7 @@ alsoSignWithPaymentKey signedTxObject signingKeyBech32 =
138151
toCJSON
139152
=<< ( alsoSignWithPaymentKeyImpl
140153
<$> fromCJSON True "SignedTx" signedTxObject
141-
<*> stringTosigningKey signingKeyBech32
154+
<*> stringToSigningKey signingKeyBech32
142155
)
143156

144157
toCbor :: SignedTxObjectJSON -> IO CString

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

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
module Cardano.Wasi.Internal.Api.Wallet
44
( generatePaymentWallet
5+
, generateStakeWallet
56
, restorePaymentWalletFromSigningKeyBech32
7+
, restoreStakeWalletFromSigningKeyBech32
8+
, generateTestnetPaymentWallet
9+
, generateTestnetStakeWallet
610
, restoreTestnetPaymentWalletFromSigningKeyBech32
11+
, restoreTestnetStakeWalletFromSigningKeyBech32
712
, getAddressBech32
8-
, getBech32ForVerificationKey
9-
, getBech32ForSigningKey
10-
, getBase16ForVerificationKeyHash
13+
, getBech32ForPaymentVerificationKey
14+
, getBech32ForPaymentSigningKey
15+
, getBech32ForStakeVerificationKey
16+
, getBech32ForStakeSigningKey
17+
, getBase16ForPaymentVerificationKeyHash
18+
, getBase16ForStakeVerificationKeyHash
1119
)
1220
where
1321

@@ -24,23 +32,47 @@ import Foreign.C.String (newCString, peekCString)
2432
foreign export ccall "generatePaymentWallet"
2533
generatePaymentWallet :: IO WalletObjectJSON
2634

35+
foreign export ccall "generateStakeWallet"
36+
generateStakeWallet :: IO WalletObjectJSON
37+
2738
foreign export ccall "restorePaymentWalletFromSigningKeyBech32"
2839
restorePaymentWalletFromSigningKeyBech32 :: CString -> IO WalletObjectJSON
2940

41+
foreign export ccall "restoreStakeWalletFromSigningKeyBech32"
42+
restoreStakeWalletFromSigningKeyBech32 :: CString -> CString -> IO WalletObjectJSON
43+
44+
foreign export ccall "generateTestnetPaymentWallet"
45+
generateTestnetPaymentWallet :: Int -> IO WalletObjectJSON
46+
47+
foreign export ccall "generateTestnetStakeWallet"
48+
generateTestnetStakeWallet :: Int -> IO WalletObjectJSON
49+
3050
foreign export ccall "restoreTestnetPaymentWalletFromSigningKeyBech32"
3151
restoreTestnetPaymentWalletFromSigningKeyBech32 :: Int -> CString -> IO WalletObjectJSON
3252

53+
foreign export ccall "restoreTestnetStakeWalletFromSigningKeyBech32"
54+
restoreTestnetStakeWalletFromSigningKeyBech32 :: Int -> CString -> CString -> IO WalletObjectJSON
55+
3356
foreign export ccall "getAddressBech32"
3457
getAddressBech32 :: WalletObjectJSON -> IO CString
3558

36-
foreign export ccall "getBech32ForVerificationKey"
37-
getBech32ForVerificationKey :: WalletObjectJSON -> IO CString
59+
foreign export ccall "getBech32ForPaymentVerificationKey"
60+
getBech32ForPaymentVerificationKey :: WalletObjectJSON -> IO CString
3861

39-
foreign export ccall "getBech32ForSigningKey"
40-
getBech32ForSigningKey :: WalletObjectJSON -> IO CString
62+
foreign export ccall "getBech32ForPaymentSigningKey"
63+
getBech32ForPaymentSigningKey :: WalletObjectJSON -> IO CString
4164

42-
foreign export ccall "getBase16ForVerificationKeyHash"
43-
getBase16ForVerificationKeyHash :: WalletObjectJSON -> IO CString
65+
foreign export ccall "getBech32ForStakeVerificationKey"
66+
getBech32ForStakeVerificationKey :: WalletObjectJSON -> IO CString
67+
68+
foreign export ccall "getBech32ForStakeSigningKey"
69+
getBech32ForStakeSigningKey :: WalletObjectJSON -> IO CString
70+
71+
foreign export ccall "getBase16ForPaymentVerificationKeyHash"
72+
getBase16ForPaymentVerificationKeyHash :: WalletObjectJSON -> IO CString
73+
74+
foreign export ccall "getBase16ForStakeVerificationKeyHash"
75+
getBase16ForStakeVerificationKeyHash :: WalletObjectJSON -> IO CString
4476

4577
#endif
4678

@@ -49,11 +81,28 @@ type WalletObjectJSON = CString
4981
generatePaymentWallet :: IO WalletObjectJSON
5082
generatePaymentWallet = toCJSON =<< Wallet.generatePaymentWalletImpl
5183

84+
generateStakeWallet :: IO WalletObjectJSON
85+
generateStakeWallet = toCJSON =<< Wallet.generateStakeWalletImpl
86+
5287
restorePaymentWalletFromSigningKeyBech32 :: CString -> IO WalletObjectJSON
5388
restorePaymentWalletFromSigningKeyBech32 signingKeyBech32CStr = do
5489
signingKeyBech32 <- peekCString signingKeyBech32CStr
5590
toCJSON =<< Wallet.restorePaymentWalletFromSigningKeyBech32Impl signingKeyBech32
5691

92+
restoreStakeWalletFromSigningKeyBech32 :: CString -> CString -> IO WalletObjectJSON
93+
restoreStakeWalletFromSigningKeyBech32 paymentSigningKeyCStr stakeSigningKeyCStr = do
94+
paymentSigningKey <- peekCString paymentSigningKeyCStr
95+
stakeSigningKey <- peekCString stakeSigningKeyCStr
96+
toCJSON =<< Wallet.restoreStakeWalletFromSigningKeyBech32Impl paymentSigningKey stakeSigningKey
97+
98+
generateTestnetPaymentWallet :: Int -> IO WalletObjectJSON
99+
generateTestnetPaymentWallet networkMagic =
100+
toCJSON =<< Wallet.generateTestnetPaymentWalletImpl (fromIntegral networkMagic)
101+
102+
generateTestnetStakeWallet :: Int -> IO WalletObjectJSON
103+
generateTestnetStakeWallet networkMagic =
104+
toCJSON =<< Wallet.generateTestnetStakeWalletImpl (fromIntegral networkMagic)
105+
57106
restoreTestnetPaymentWalletFromSigningKeyBech32 :: Int -> CString -> IO WalletObjectJSON
58107
restoreTestnetPaymentWalletFromSigningKeyBech32 networkMagic signingKeyBech32CStr =
59108
toCJSON
@@ -62,22 +111,47 @@ restoreTestnetPaymentWalletFromSigningKeyBech32 networkMagic signingKeyBech32CSt
62111
=<< peekCString signingKeyBech32CStr
63112
)
64113

114+
restoreTestnetStakeWalletFromSigningKeyBech32 :: Int -> CString -> CString -> IO WalletObjectJSON
115+
restoreTestnetStakeWalletFromSigningKeyBech32 networkMagic paymentSigningKeyCStr stakeSigningKeyCStr = do
116+
paymentKey <- peekCString paymentSigningKeyCStr
117+
stakeKey <- peekCString stakeSigningKeyCStr
118+
toCJSON
119+
=<< Wallet.restoreTestnetStakeWalletFromSigningKeyBech32Impl
120+
(fromIntegral networkMagic)
121+
paymentKey
122+
stakeKey
123+
65124
getAddressBech32 :: WalletObjectJSON -> IO CString
66125
getAddressBech32 walletCStr =
67-
newCString . Wallet.getAddressBech32
126+
newCString . Wallet.getAddressBech32Impl
127+
=<< fromCJSON False "WalletObject" walletCStr
128+
129+
getBech32ForPaymentVerificationKey :: WalletObjectJSON -> IO CString
130+
getBech32ForPaymentVerificationKey walletCStr =
131+
newCString . Wallet.getBech32ForPaymentVerificationKeyImpl
132+
=<< fromCJSON False "WalletObject" walletCStr
133+
134+
getBech32ForPaymentSigningKey :: WalletObjectJSON -> IO CString
135+
getBech32ForPaymentSigningKey walletCStr =
136+
newCString . Wallet.getBech32ForPaymentSigningKeyImpl
137+
=<< fromCJSON False "WalletObject" walletCStr
138+
139+
getBech32ForStakeVerificationKey :: WalletObjectJSON -> IO CString
140+
getBech32ForStakeVerificationKey walletCStr =
141+
newCString . Wallet.getBech32ForStakeVerificationKeyImpl
68142
=<< fromCJSON False "WalletObject" walletCStr
69143

70-
getBech32ForVerificationKey :: WalletObjectJSON -> IO CString
71-
getBech32ForVerificationKey walletCStr =
72-
newCString . Wallet.getBech32ForVerificationKeyImpl
144+
getBech32ForStakeSigningKey :: WalletObjectJSON -> IO CString
145+
getBech32ForStakeSigningKey walletCStr =
146+
newCString . Wallet.getBech32ForStakeSigningKeyImpl
73147
=<< fromCJSON False "WalletObject" walletCStr
74148

75-
getBech32ForSigningKey :: WalletObjectJSON -> IO CString
76-
getBech32ForSigningKey walletCStr =
77-
newCString . Wallet.getBech32ForSigningKeyImpl
149+
getBase16ForPaymentVerificationKeyHash :: WalletObjectJSON -> IO CString
150+
getBase16ForPaymentVerificationKeyHash walletCStr =
151+
newCString . Wallet.getBase16ForPaymentVerificationKeyHashImpl
78152
=<< fromCJSON False "WalletObject" walletCStr
79153

80-
getBase16ForVerificationKeyHash :: WalletObjectJSON -> IO CString
81-
getBase16ForVerificationKeyHash walletCStr =
82-
newCString . Wallet.getBase16ForVerificationKeyHashImpl
154+
getBase16ForStakeVerificationKeyHash :: WalletObjectJSON -> IO CString
155+
getBase16ForStakeVerificationKeyHash walletCStr =
156+
newCString . Wallet.getBase16ForStakeVerificationKeyHashImpl
83157
=<< fromCJSON False "WalletObject" walletCStr

cardano-wasm/src-wasi/Cardano/Wasi/Internal/Conversion.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Cardano.Wasi.Internal.Conversion
66
, intToCStr
77
, cstrToInt
88
, txIdToString
9-
, stringTosigningKey
9+
, stringToSigningKey
1010
)
1111
where
1212

@@ -55,7 +55,7 @@ txIdToString txIdCString = do
5555
txId <- peekCString txIdCString
5656
rightOrError $ Api.deserialiseFromRawBytesHex (fromString txId)
5757

58-
stringTosigningKey :: CString -> IO (Api.SigningKey Api.PaymentKey)
59-
stringTosigningKey signingKeyCString = do
58+
stringToSigningKey :: CString -> IO (Api.SigningKey Api.PaymentKey)
59+
stringToSigningKey signingKeyCString = do
6060
string <- peekCString signingKeyCString
6161
rightOrError $ Api.deserialiseFromBech32 (Text.pack string)

0 commit comments

Comments
 (0)