Method: Hive::Jsonrpc#get_all_signatures

Defined in:
lib/hive/jsonrpc.rb

#get_all_signatures(&block) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/hive/jsonrpc.rb', line 62

def get_all_signatures(&block)
  request_object = []
  method_names = []
  method_map = {}
  signatures = {}
  offset = 0
  
  get_api_methods do |api, methods|
    request_object += methods.map do |method|
      method_name = "#{api}.#{method}"
      method_names << method_name
      current_rpc_id = @rpc_client.rpc_id
      offset += 1
      method_map[current_rpc_id] = [api, method]
      
      {
        jsonrpc: '2.0',
        id: current_rpc_id,
        method: 'jsonrpc.get_signature',
        params: {method: method_name}
      }
    end
  end
  
  chunks = if request_object.size > Hive::RPC::HttpClient::JSON_RPC_BATCH_SIZE_MAXIMUM
    request_object.each_slice(Hive::RPC::HttpClient::JSON_RPC_BATCH_SIZE_MAXIMUM)
  else
    request_object
  end
  
  for request_object in chunks do
    @rpc_client.rpc_batch_execute(api_name: self.class.api_name, request_object: request_object) do |result, error, id|
      api, method = method_map[id]
      api = api.to_sym
      method = method.to_sym
      
      signatures[api] ||= {}
      signatures[api][method] = result
    end
    
    if !!block
      signatures.each do |api, methods|
        yield api, methods
      end
    end
  end
  
  return signatures unless !!block
end