Package org.nervos.muta.client
Class Client
- java.lang.Object
-
- org.nervos.muta.client.Client
-
- Direct Known Subclasses:
BatchClient
public class Client extends java.lang.Object
Client plays role between remote GraphQl and local api. It handles all communications.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Client
defaultClient()
Create a Default Client to http://localhost:8000/graphql, That's the easiest way to talk to default Muta-Chain for testBlock
getBlock(GUint64 height)
Start a GetBlock GraphQl queryReceipt
getReceipt(GHash txHash)
Start a GetReceipt GraphQl querySignedTransaction
getTransaction(GHash txHash)
Start a GetTransaction GraphQl queryprotected <T> T
parseGraphQlResponse(@NonNull okhttp3.Response response, java.lang.String operation, java.lang.Class<T> clazz)
Parse a graphql query/mutation result into class with given type param TServiceResponse
queryService(@NonNull java.lang.String serviceName, @NonNull java.lang.String method, @NonNull java.lang.String payload, GUint64 height, @NonNull GAddress caller, GUint64 cyclePrice, GUint64 cycleLimit)
Start a QueryService GraphQl query, which do read operations on servicesprotected okhttp3.Response
send(java.lang.String payload)
Ask httpClient to send a http request containing GraphQl query/mutation payloadGHash
sendTransaction(InputRawTransaction inputRaw, InputTransactionEncryption inputEncryption)
Start a SendTransaction GraphQl query, which do write operations on services
-
-
-
Constructor Detail
-
Client
public Client(java.lang.String url)
Construct only by url, with Muta's default OkHttpClient. If you want to custom your OWN OkHttpClient- Parameters:
url
-url
- See Also:
Client(String, OkHttpClient)
-
Client
public Client(java.lang.String url, okhttp3.OkHttpClient okHttpClient)
- Parameters:
url
-url
okHttpClient
-httpClient
-
-
Method Detail
-
defaultClient
public static Client defaultClient()
Create a Default Client to http://localhost:8000/graphql, That's the easiest way to talk to default Muta-Chain for test- Returns:
- A pre-defined Client
-
send
protected okhttp3.Response send(java.lang.String payload) throws java.io.IOException
Ask httpClient to send a http request containing GraphQl query/mutation payload- Parameters:
payload
- HTTP request body- Returns:
- HTTP response
- Throws:
java.io.IOException
- HTTP/network exceptions
-
parseGraphQlResponse
protected <T> T parseGraphQlResponse(@NonNull @NonNull okhttp3.Response response, java.lang.String operation, java.lang.Class<T> clazz) throws java.io.IOException
Parse a graphql query/mutation result into class with given type param T- Type Parameters:
T
- To which type you want to convert- Parameters:
response
- OkHttp's HTTP responeoperation
- The name of GraphQl's operation, you could see GraphQl schema for more detailsclazz
- To hold type param- Returns:
- Result of type T, note this may be null
- Throws:
java.io.IOException
- Exception, maybe HTTP/network error, or GraphQl execution failure
-
getBlock
public Block getBlock(GUint64 height) throws java.io.IOException
Start a GetBlock GraphQl query- Parameters:
height
- The height want to query, leave null for the latest- Returns:
- The block info, note the block could be null
- Throws:
java.io.IOException
- Exception, maybe HTTP/network error, or GraphQl execution failure
-
getTransaction
public SignedTransaction getTransaction(GHash txHash) throws java.io.IOException
Start a GetTransaction GraphQl query- Parameters:
txHash
- The transaction hash of transaction you want to query- Returns:
- The SignedTransaction when it sends, maybe null
- Throws:
java.io.IOException
- Exception, maybe HTTP/network error, or GraphQl execution failure
-
getReceipt
public Receipt getReceipt(GHash txHash) throws java.io.IOException
Start a GetReceipt GraphQl query- Parameters:
txHash
- The transaction hash of transaction you want to query- Returns:
- The Receipt of the transaction's execution result, maybe null
- Throws:
java.io.IOException
- Exception, maybe HTTP/network error, or GraphQl execution failure
-
queryService
public ServiceResponse queryService(@NonNull @NonNull java.lang.String serviceName, @NonNull @NonNull java.lang.String method, @NonNull @NonNull java.lang.String payload, GUint64 height, @NonNull @NonNull GAddress caller, GUint64 cyclePrice, GUint64 cycleLimit) throws java.io.IOException
Start a QueryService GraphQl query, which do read operations on services- Parameters:
serviceName
- the name of the servicemethod
- the name of method under the servicepayload
- the input data of the methodheight
- on which height this queryService should runcaller
- give a caller of this queryServicecyclePrice
- a cyclePrice you want to usecycleLimit
- a cyclePrice you want to use- Returns:
- The response of the execution of service
- Throws:
java.io.IOException
- Exception, maybe HTTP/network error, or GraphQl execution failure
-
sendTransaction
public GHash sendTransaction(InputRawTransaction inputRaw, InputTransactionEncryption inputEncryption) throws java.io.IOException
Start a SendTransaction GraphQl query, which do write operations on services- Parameters:
inputRaw
- The information of transaction of SendTransactioninputEncryption
- The signature of transaction of SendTransaction- Returns:
- The transaction hash
- Throws:
java.io.IOException
- Exception, maybe HTTP/network error, or GraphQl execution failure
-
-