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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 301f452c31d1989f2565adbf428c90081ca667eac36089e7b0817807a22d1a87
4
- data.tar.gz: dfec2238bd6552db7b625f3016619837d57bd15735ef2c447b98acb3cad97a31
3
+ metadata.gz: 610330d9aad4553f79f8d9101c8e1180491a6a59a8f8451f23d149cf3590222f
4
+ data.tar.gz: c797a3326c255ff331fb5f112a65839eb20ca941fd4120728263b84555baa0af
5
5
  SHA512:
6
- metadata.gz: 4a655cc6132c2c281e7aa798785a33b1cbb10754940d82d17f1ec33d34ce847d3bec11f4ac35a038973cc976e0e69c8b95b4fabaea0d6d007504e536dfe0c390
7
- data.tar.gz: 3af5cefad5a04134b07cc0562a2ed3ed7720cb1d1289b89483480686f181ddc719ec72d9e3a5320d1b7ec46f4446e2e6d6acdd69e7c30e805056d60317a50bf4
6
+ metadata.gz: 7cd1980321c6947394ac1e9456d4312395670977d3774195ce93d6b0faa8c44377185aad3aad0b8d5706fa82a0e58ea0ca6fcea79b28ecdd43c1593702900913
7
+ data.tar.gz: 1b389ab381b782be91396fd0f8aea16ae9bf094ecff2f3dce366e9674fee6a50779d44a1d900206dd556ddc46a4ff99178409311fe76646c4d2aa5ebcc04c764
@@ -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
- # @param [Faraday::Response] response The HTTP response object.
715
- # @raise [RuntimeError] If the request fails (non-success response).
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)['result']
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
- yield response['result'] if block_given?
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
@@ -1,3 +1,3 @@
1
1
  module Solana
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
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.2
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-06-30 00:00:00.000000000 Z
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpx