Module: IOTA::API::Transport

Included in:
Api
Defined in:
lib/iota/api/transport.rb

Instance Method Summary collapse

Instance Method Details

#sendBatchedCommand(command, &callback) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/iota/api/transport.rb', line 8

def sendBatchedCommand(command, &callback)
  # Key and value both should be symbols
  mapping = {
    getTrytes: [ :hashes ],
    getBalances: [ :addresses ],
    wereAddressesSpentFrom: [ :addresses ],
    getInclusionStates: [ :transactions ],
    findTransactions: [ :bundles, :addresses, :tags, :approvees ]
  }

  command_name = command[:command].to_sym
  if mapping[command_name]
    results = []

    keys_to_batch = mapping[command_name]
    keys_to_batch.each do |key|
      if command[key]
        command[key].each_slice(@batch_size) do |group|
          batchedCommand = command.clone.merge({ key => group })
          sendCommand(batchedCommand) do |status, response|
            if !status
              return sendData(false, response, &callback)
            end
            results += response
          end
        end
      end
    end
    return sendData(true, results, &callback)
  else
    return sendCommand(command, &callback)
  end
end

#sendCommand(command, &callback) ⇒ Object


4
5
6
# File 'lib/iota/api/transport.rb', line 4

def sendCommand(command, &callback)
  @broker.send(command, &callback)
end