@@ -2,56 +2,54 @@ module Cardano.Wasm.Internal.Api.GRPC where
22
33import Cardano.Wasm.Internal.Api.Tx qualified as Wasm
44import Cardano.Wasm.Internal.ExceptionHandling (rightOrError , toMonadFail )
5- import Cardano.Wasm.Internal.JavaScript.GRPCTypes
6- ( JSGRPCClient
7- , JSUtxos
8- )
95
106import Data.ByteString.Base16 qualified as Base16
117import Data.ByteString.Base64 qualified as Base64
128import Data.ByteString.Char8 qualified as BS
139
14- -- | Internal data for the GrpcConnection virtual object. Currently, it is just a wrapper around the JSGRPCClient ,
15- -- which is a JavaScript object that allows us to interact with the Cardano Node via gRPC-web.
16- newtype GrpcObject
17- = GrpcObject JSGRPCClient
10+ -- | Internal data for the GrpcConnection virtual object. Currently, it is just a wrapper around the grpcClient ,
11+ -- which is some object that allows us to interact with the Cardano Node via gRPC or GRPC -web.
12+ newtype GrpcObject grpcClient
13+ = GrpcObject grpcClient
1814
1915-- | Create a new unsigned transaction object for making a Conway era transaction.
20- newGrpcConnectionImpl :: (String -> IO JSGRPCClient ) -> String -> IO GrpcObject
21- newGrpcConnectionImpl createClientJsFunc host = GrpcObject <$> createClientJsFunc host
16+ newGrpcConnectionImpl :: (String -> IO grpcClient ) -> String -> IO ( GrpcObject grpcClient )
17+ newGrpcConnectionImpl createClientFunc host = GrpcObject <$> createClientFunc host
2218
23- -- | Get the era from the Cardano Node using GRPC-web.
24- getEraImpl :: (JSGRPCClient -> IO Int ) -> GrpcObject -> IO Int
25- getEraImpl getEraJsFunc (GrpcObject client) = getEraJsFunc client
19+ -- | Get the era from the Cardano Node using gRPC or GRPC-web.
20+ getEraImpl :: (grpcClient -> IO Int ) -> GrpcObject grpcClient -> IO Int
21+ getEraImpl getEraFunc (GrpcObject client) = getEraFunc client
2622
27- -- | Get the protocol parameters from the Cardano Node using GRPC-web.
23+ -- | Get the protocol parameters from the Cardano Node using gRPC or GRPC-web.
2824getProtocolParamsImpl
29- :: (JSGRPCClient -> IO Wasm. ProtocolParamsJSON ) -> GrpcObject -> IO Wasm. ProtocolParamsJSON
30- getProtocolParamsImpl getProtocolParamsJsFunc (GrpcObject client) = getProtocolParamsJsFunc client
25+ :: (grpcClient -> IO Wasm. ProtocolParamsJSON )
26+ -> GrpcObject grpcClient
27+ -> IO Wasm. ProtocolParamsJSON
28+ getProtocolParamsImpl getProtocolParamsFunc (GrpcObject client) = getProtocolParamsFunc client
3129
32- -- | Get all UTXOs from the node using a GRPC-web client.
30+ -- | Get all UTXOs from the node using a gRPC or GRPC-web client.
3331getAllUtxosImpl
34- :: (JSGRPCClient -> IO JSUtxos )
35- -> GrpcObject
36- -> IO JSUtxos
37- getAllUtxosImpl getUtxosJsFunc (GrpcObject client) = getUtxosJsFunc client
32+ :: (grpcClient -> IO utxos )
33+ -> GrpcObject grpcClient
34+ -> IO utxos
35+ getAllUtxosImpl getUtxosFunc (GrpcObject client) = getUtxosFunc client
3836
39- -- | Get UTXOs for a given address using a GRPC-web client.
37+ -- | Get UTXOs for a given address using a gRPC or GRPC-web client.
4038getUtxosForAddressImpl
41- :: (JSGRPCClient -> String -> IO JSUtxos )
42- -> GrpcObject
39+ :: (grpcClient -> String -> IO utxos )
40+ -> GrpcObject grpcClient
4341 -> String
44- -> IO JSUtxos
45- getUtxosForAddressImpl getUtxosForAddressJsFunc (GrpcObject client) = getUtxosForAddressJsFunc client
42+ -> IO utxos
43+ getUtxosForAddressImpl getUtxosForAddressFunc (GrpcObject client) = getUtxosForAddressFunc client
4644
47- -- | Submit a transaction to the Cardano Node using GRPC-web.
45+ -- | Submit a transaction to the Cardano Node using gRPC or GRPC-web.
4846submitTxImpl
49- :: (JSGRPCClient -> String -> IO (Either String String ))
50- -> GrpcObject
47+ :: (grpcClient -> String -> IO (Either String String ))
48+ -> GrpcObject grpcClient
5149 -> String
5250 -> IO String
53- submitTxImpl submitTxJsFunc (GrpcObject client) tx =
54- toMonadFail . rightOrError . (base64ToBase16 =<< ) =<< submitTxJsFunc client tx
51+ submitTxImpl submitTxFunc (GrpcObject client) tx =
52+ toMonadFail . rightOrError . (base64ToBase16 =<< ) =<< submitTxFunc client tx
5553 where
5654 -- We reencode as Base16 because it is a more common format for txIds
5755 base64ToBase16 :: String -> Either String String
0 commit comments