Method: Radiator::Transaction#process

Defined in:
lib/radiator/transaction.rb

#process(broadcast = false) ⇒ Object

[View source]

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/radiator/transaction.rb', line 101

def process(broadcast = false)
  prepare

  if broadcast
    loop do
      response = broadcast_payload(payload)

      if !!response.error
        parser = ErrorParser.new(response)

        if parser.can_reprepare?
          debug "Error code: #{parser}, repreparing transaction ..."
          prepare
          redo
        end
      end

      return response
    end
  else
    self
  end
rescue OperationError => e
  trx_builder, network_api = case @chain.to_sym
  when :steem then [
    Steem::TransactionBuilder.new(wif: @wif),
    Steem::NetworkBroadcastApi.new(url: @url)
  ]
  when :hive then [
    Hive::TransactionBuilder.new(wif: @wif),
    Hive::NetworkBroadcastApi.new(url: @url)
  ]
  end
  
  raise e if trx_builder.nil?
  
  @operations.each do |op|
    type = op.delete(:type)
    trx_builder.put({type => op})
  end
  
  network_api.broadcast_transaction_synchronous(trx_builder.transaction)
ensure
  shutdown
end