Class: TezosClient::ComputeOperationArgsCounters

Inherits:
Object
  • Object
show all
Defined in:
lib/tezos_client/compute_operation_args_counters.rb

Instance Method Summary collapse

Constructor Details

#initialize(pending_operations:, operation_args:) ⇒ ComputeOperationArgsCounters

Returns a new instance of ComputeOperationArgsCounters.



5
6
7
8
# File 'lib/tezos_client/compute_operation_args_counters.rb', line 5

def initialize(pending_operations:, operation_args:)
  @pending_operations = pending_operations
  @operation_args = Marshal.load(Marshal.dump(operation_args)) # deep copy of the object
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tezos_client/compute_operation_args_counters.rb', line 10

def call
  max_counter_by_source = group_by_max_counter(
    @pending_operations["applied"].map { |operation| operation["contents"] }
                                  .flatten
                                  .select { |content| content.has_key?("source") }
  )

  @operation_args.each do |operation|
    source = operation[:source]
    # do not update the counter of an operation not present in the mempool
    next unless max_counter_by_source[source]

    operation[:counter] = (max_counter_by_source[source].to_i + 1).to_s
    # update max_counter_by_source as if the current operation was added to the mempool
    max_counter_by_source[source] = operation[:counter]
  end

  @operation_args
end