Class 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.
    • Constructor Summary

      Constructors 
      Constructor Description
      Client​(java.lang.String url)
      Construct only by url, with Muta's default OkHttpClient.
      Client​(java.lang.String url, okhttp3.OkHttpClient okHttpClient)  
    • 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 test
      Block getBlock​(GUint64 height)
      Start a GetBlock GraphQl query
      Receipt getReceipt​(GHash txHash)
      Start a GetReceipt GraphQl query
      SignedTransaction getTransaction​(GHash txHash)
      Start a GetTransaction GraphQl query
      protected <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 T
      ServiceResponse 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 services
      protected okhttp3.Response send​(java.lang.String payload)
      Ask httpClient to send a http request containing GraphQl query/mutation payload
      GHash sendTransaction​(InputRawTransaction inputRaw, InputTransactionEncryption inputEncryption)
      Start a SendTransaction GraphQl query, which do write operations on services
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 respone
        operation - The name of GraphQl's operation, you could see GraphQl schema for more details
        clazz - 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 service
        method - the name of method under the service
        payload - the input data of the method
        height - on which height this queryService should run
        caller - give a caller of this queryService
        cyclePrice - a cyclePrice you want to use
        cycleLimit - 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 SendTransaction
        inputEncryption - The signature of transaction of SendTransaction
        Returns:
        The transaction hash
        Throws:
        java.io.IOException - Exception, maybe HTTP/network error, or GraphQl execution failure