solana-ruby 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/solana-ruby/client.rb +27 -6
- data/lib/solana-ruby/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 610330d9aad4553f79f8d9101c8e1180491a6a59a8f8451f23d149cf3590222f
         | 
| 4 | 
            +
              data.tar.gz: c797a3326c255ff331fb5f112a65839eb20ca941fd4120728263b84555baa0af
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7cd1980321c6947394ac1e9456d4312395670977d3774195ce93d6b0faa8c44377185aad3aad0b8d5706fa82a0e58ea0ca6fcea79b28ecdd43c1593702900913
         | 
| 7 | 
            +
              data.tar.gz: 1b389ab381b782be91396fd0f8aea16ae9bf094ecff2f3dce366e9674fee6a50779d44a1d900206dd556ddc46a4ff99178409311fe76646c4d2aa5ebcc04c764
         | 
    
        data/lib/solana-ruby/client.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            require 'faye/websocket'
         | 
| 2 2 | 
             
            require 'httpx'
         | 
| 3 3 | 
             
            require 'json'
         | 
| 4 | 
            +
            require 'thread'
         | 
| 4 5 |  | 
| 5 6 | 
             
            require_relative 'utils'
         | 
| 6 7 |  | 
| @@ -688,11 +689,16 @@ module Solana | |
| 688 689 |  | 
| 689 690 | 
             
                private
         | 
| 690 691 | 
             
                ##
         | 
| 691 | 
            -
                # Sends a JSON-RPC request to the Solana API.
         | 
| 692 | 
            +
                # Sends a JSON-RPC request to the Solana API over HTTP.
         | 
| 693 | 
            +
                #
         | 
| 694 | 
            +
                # This method constructs a JSON-RPC request and sends it to the Solana API endpoint using HTTP.
         | 
| 695 | 
            +
                # It then handles the response asynchronously.
         | 
| 692 696 | 
             
                #
         | 
| 693 697 | 
             
                # @param [String] method The RPC method to call.
         | 
| 694 698 | 
             
                # @param [Array] params The parameters for the RPC method.
         | 
| 695 699 | 
             
                # @yield [Object] The parsed response from the API.
         | 
| 700 | 
            +
                # @return [Object, nil] The parsed response from the API if no block is given, otherwise nil.
         | 
| 701 | 
            +
                # @raise [RuntimeError] If the request fails (non-success response).
         | 
| 696 702 | 
             
                def request_http(method, params = nil, &block)
         | 
| 697 703 | 
             
                  body = {
         | 
| 698 704 | 
             
                    jsonrpc: '2.0',
         | 
| @@ -711,12 +717,16 @@ module Solana | |
| 711 717 | 
             
                ##
         | 
| 712 718 | 
             
                # Handles the API response, checking for success and parsing the result.
         | 
| 713 719 | 
             
                #
         | 
| 714 | 
            -
                #  | 
| 715 | 
            -
                #  | 
| 720 | 
            +
                # This method processes the HTTP response from the Solana API, checking if the request was successful.
         | 
| 721 | 
            +
                # If successful, it parses the JSON response and yields the result to the provided block.
         | 
| 722 | 
            +
                #
         | 
| 723 | 
            +
                # @param [HTTPX::Response] response The HTTP response object.
         | 
| 716 724 | 
             
                # @yield [Object] The parsed result from the API response.
         | 
| 725 | 
            +
                # @return [Object] The parsed result from the API response.
         | 
| 726 | 
            +
                # @raise [RuntimeError] If the request fails (non-success response).
         | 
| 717 727 | 
             
                def handle_response_http(response, &block)
         | 
| 718 728 | 
             
                  if response.status == 200
         | 
| 719 | 
            -
                    result = JSON.parse(response.body) | 
| 729 | 
            +
                    result = JSON.parse(response.body)
         | 
| 720 730 | 
             
                    if block_given?
         | 
| 721 731 | 
             
                      yield result
         | 
| 722 732 | 
             
                    else
         | 
| @@ -730,11 +740,16 @@ module Solana | |
| 730 740 | 
             
                ##
         | 
| 731 741 | 
             
                # Sends a JSON-RPC request to the Solana API over WebSocket.
         | 
| 732 742 | 
             
                #
         | 
| 743 | 
            +
                # This method constructs a JSON-RPC request and sends it to the Solana API endpoint using WebSocket.
         | 
| 744 | 
            +
                # It then handles the response asynchronously, providing the result to the provided block or returning it via a queue.
         | 
| 745 | 
            +
                #
         | 
| 733 746 | 
             
                # @param [String] method The RPC method to call.
         | 
| 734 747 | 
             
                # @param [Array] params The parameters for the RPC method.
         | 
| 735 748 | 
             
                # @yield [Object] The parsed response from the API.
         | 
| 736 | 
            -
             | 
| 749 | 
            +
                # @return [Object, nil] The parsed response from the API if no block is given, otherwise nil.
         | 
| 750 | 
            +
                # @raise [RuntimeError] If the WebSocket connection fails or an error occurs during communication.
         | 
| 737 751 | 
             
                def request_ws(method, params = nil, &block)
         | 
| 752 | 
            +
                  result_queue = Queue.new
         | 
| 738 753 | 
             
                  EM.run do
         | 
| 739 754 | 
             
                    ws = Faye::WebSocket::Client.new(@api_endpoint::WS)
         | 
| 740 755 |  | 
| @@ -751,7 +766,11 @@ module Solana | |
| 751 766 |  | 
| 752 767 | 
             
                    ws.on :message do |event|
         | 
| 753 768 | 
             
                      response = JSON.parse(event.data)
         | 
| 754 | 
            -
                       | 
| 769 | 
            +
                      if block_given?
         | 
| 770 | 
            +
                        yield response['result']
         | 
| 771 | 
            +
                      else
         | 
| 772 | 
            +
                        result_queue.push(response['result'])
         | 
| 773 | 
            +
                      end
         | 
| 755 774 | 
             
                      ws.close
         | 
| 756 775 | 
             
                    end
         | 
| 757 776 |  | 
| @@ -762,10 +781,12 @@ module Solana | |
| 762 781 |  | 
| 763 782 | 
             
                    ws.on :error do |event|
         | 
| 764 783 | 
             
                      puts "WebSocket error: #{event.message}"
         | 
| 784 | 
            +
                      result_queue.push(nil)
         | 
| 765 785 | 
             
                      ws = nil
         | 
| 766 786 | 
             
                      EM.stop
         | 
| 767 787 | 
             
                    end
         | 
| 768 788 | 
             
                  end
         | 
| 789 | 
            +
                  result_queue.pop unless block_given?
         | 
| 769 790 | 
             
                end
         | 
| 770 791 | 
             
              end
         | 
| 771 792 | 
             
            end
         | 
    
        data/lib/solana-ruby/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: solana-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Fabrice Renard
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-07-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: httpx
         |