huginn_callisto_network_agent 0.1.1 → 0.1.2

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: a34cfcc3b5d25db5651545a82953cfd64b9c0cf4b2437b6bc3f26fc01858192d
4
- data.tar.gz: 321d0527f4426e15f1144e903f2895cd04b5bdebe8b2371f91c1ef96dfc527c6
3
+ metadata.gz: b4b37c85b89f42d88795533af510d0b3ff2d94320edf3a936ef3379d9806e40c
4
+ data.tar.gz: 5bc21dbf0277a3d8733f01d436ea3f18e4ffe542f3863c9b7a6450fc43e8538a
5
5
  SHA512:
6
- metadata.gz: 82194e7960c723df546852a21ea890ff5b032f7fd3318de857b23256311dd5e457aa52f03cc3d48b3a8f26587410bfb14749f7da0f9767716ee9b46527355219
7
- data.tar.gz: 5c3bb73c088b1d3935ac14656eaf9d48bce12e59a38ae829c58987561fedbfd6ec44740a2d7d640841bc29f2b0f230b1d9c03c963f98f24c4a41ff9085344766
6
+ metadata.gz: 54e5207f1838f243149ff25d0daca6b01fb3372677f94299ee93bb44995685a6680c62611adcae92125518c65dcc59ae3b4f1fd1e9c5e1905cebb82a4daf5f41
7
+ data.tar.gz: d2e011b3a03779e631e534400cea895b2cfa0d777f12ce85887e883fea4974f8868571cdb968947476e958435f176d7b96f93c622dd6e40aa8fa0919cdc8e75f
@@ -52,6 +52,7 @@ module Agents
52
52
  'wallet_dest' => '',
53
53
  'changes_only' => 'true',
54
54
  'filter_for_method_id' => '',
55
+ 'first_block' => '',
55
56
  'last_block' => ''
56
57
  }
57
58
  end
@@ -60,7 +61,7 @@ module Agents
60
61
  form_configurable :emit_events, type: :boolean
61
62
  form_configurable :expected_receive_period_in_days, type: :string
62
63
  form_configurable :changes_only, type: :boolean
63
- form_configurable :type, type: :array, values: ['get_balance', 'net_peerCount', 'net_version', 'eth_protocolVersion', 'eth_gasPrice', 'eth_getTransactionCount', 'stake_reward_clo', 'get_tokens_balance', 'eth_getBlockByNumber', 'soy_farming_soy_clo_pending_rewards', 'soy_farming_soy_cloe_pending_rewards', 'stake_reward_soy', 'soy_farming_soy_btt_pending_rewards', 'soy_cs_pending_rewards', 'clo_sendtx', 'get_tx_by_address_with_filter', 'start_cs_clo', 'withdraw_cs_clo']
64
+ form_configurable :type, type: :array, values: ['get_balance', 'net_peerCount', 'net_version', 'eth_protocolVersion', 'eth_gasPrice', 'eth_getTransactionCount', 'stake_reward_clo', 'get_tokens_balance', 'eth_getBlockByNumber', 'soy_farming_soy_clo_pending_rewards', 'soy_farming_soy_cloe_pending_rewards', 'stake_reward_soy', 'soy_farming_soy_btt_pending_rewards', 'soy_cs_pending_rewards', 'clo_sendtx', 'get_tx_by_address_with_filter', 'start_cs_clo', 'withdraw_cs_clo', 'get_tx_stats']
64
65
  form_configurable :wallet, type: :string
65
66
  form_configurable :rpc_server, type: :string
66
67
  form_configurable :wallet_password, type: :string
@@ -68,9 +69,10 @@ module Agents
68
69
  form_configurable :round, type: :string
69
70
  form_configurable :wallet_dest, type: :string
70
71
  form_configurable :filter_for_method_id, type: :string
71
- form_configurable :last_block, type: :string
72
+ form_configurable :first_block, type: :number
73
+ form_configurable :last_block, type: :number
72
74
  def validate_options
73
- errors.add(:base, "type has invalid value: should be 'get_balance' 'net_peerCount' 'net_version' 'eth_protocolVersion' 'eth_gasPrice' 'eth_getTransactionCount' 'stake_reward_clo' 'get_tokens_balance' 'eth_getBlockByNumber' 'soy_farming_soy_clo_pending_rewards' 'soy_farming_soy_cloe_pending_rewards' 'stake_reward_soy' 'soy_farming_soy_btt_pending_rewards' 'soy_cs_pending_rewards' 'clo_sendtx' 'get_tx_by_address_with_filter' 'start_cs_clo' 'withdraw_cs_clo'") if interpolated['type'].present? && !%w(get_balance net_peerCount net_version eth_protocolVersion eth_gasPrice eth_getTransactionCount stake_reward_clo get_tokens_balance eth_getBlockByNumber soy_farming_soy_clo_pending_rewards soy_farming_soy_cloe_pending_rewards stake_reward_soy soy_farming_soy_btt_pending_rewards soy_cs_pending_rewards clo_sendtx get_tx_by_address_with_filter start_cs_clo withdraw_cs_clo).include?(interpolated['type'])
75
+ errors.add(:base, "type has invalid value: should be 'get_balance' 'net_peerCount' 'net_version' 'eth_protocolVersion' 'eth_gasPrice' 'eth_getTransactionCount' 'stake_reward_clo' 'get_tokens_balance' 'eth_getBlockByNumber' 'soy_farming_soy_clo_pending_rewards' 'soy_farming_soy_cloe_pending_rewards' 'stake_reward_soy' 'soy_farming_soy_btt_pending_rewards' 'soy_cs_pending_rewards' 'clo_sendtx' 'get_tx_by_address_with_filter' 'start_cs_clo' 'withdraw_cs_clo' 'get_tx_stats'") if interpolated['type'].present? && !%w(get_balance net_peerCount net_version eth_protocolVersion eth_gasPrice eth_getTransactionCount stake_reward_clo get_tokens_balance eth_getBlockByNumber soy_farming_soy_clo_pending_rewards soy_farming_soy_cloe_pending_rewards stake_reward_soy soy_farming_soy_btt_pending_rewards soy_cs_pending_rewards clo_sendtx get_tx_by_address_with_filter start_cs_clo withdraw_cs_clo get_tx_stats).include?(interpolated['type'])
74
76
 
75
77
  unless options['wallet_password'].present? || !['clo_sendtx' 'start_cs_clo' 'withdraw_cs_clo'].include?(options['type'])
76
78
  errors.add(:base, "wallet_password is a required field")
@@ -96,7 +98,11 @@ module Agents
96
98
  errors.add(:base, "wallet is a required field")
97
99
  end
98
100
 
99
- unless options['last_block'].present? || !['get_tx_by_address_with_filter'].include?(options['type'])
101
+ unless options['first_block'].present? || !['get_tx_stats'].include?(options['type'])
102
+ errors.add(:base, "first_block is a required field")
103
+ end
104
+
105
+ unless options['last_block'].present? || !['get_tx_by_address_with_filter' 'get_tx_stats'].include?(options['type'])
100
106
  errors.add(:base, "last_block is a required field")
101
107
  end
102
108
 
@@ -198,8 +204,64 @@ module Agents
198
204
 
199
205
  end
200
206
 
207
+ def percentage(number, total)
208
+ log number
209
+ log total
210
+ (number/total.to_f*100).round(2)
211
+ end
201
212
 
202
- def get_data(x)
213
+ def most_common_from(transactions)
214
+ seen = {}
215
+ transactions.each do |tx|
216
+ seen[tx['from']] = (seen[tx['from']] || 0) + 1
217
+ end
218
+ seen.keys.max_by { |k| seen[k] }
219
+ end
220
+
221
+ def counter(list,patterns)
222
+ total = 0
223
+
224
+ list.each do |element|
225
+ from_value = element["from"].downcase
226
+ if patterns.include?(from_value)
227
+ total += 1
228
+ end
229
+ end
230
+ return total
231
+ end
232
+
233
+ def get_tx_stats()
234
+ all_miners = ['0xf34eaf6e2cf4744b5e29734295135c4213d59149', '0xed15b7b7b5dc81daae277a081b47a04c3a8bea1b' ,'0xd125b3b146d21d058edac7a5b5f7481a571e4c46', '0xe683de43ccfbef16424ecb577f288cf343dfbc5a', '0x0073cf1b9230cf3ee8cab1971b8dbef21ea7b595', '0x40b67778d97a7d15a519d907ed991948e8ea486c', '0x8845ee5cae61b807678415bb8a68773df9d48f8e', '0x52f0458c70af5cdeb555cad800add5f82c3e59f7', '0xd06bb917c099acf24d43552b5aa760aeef7cd4aa', '0xf35074bbd0a9aee46f4ea137971feec024ab704e', '0xd144e30a0571aaf0d0c050070ac435deba461fab', '0x8057c50c6d72f4399862fefbc8d3b8a8757cde57', '0xfbf679d6ed0cb9747e05e7e8ae06e890e6bf2b66', '0x11905bd0863ba579023f662d1935e39d0c671933', '0xe4f3cab1f11d5a917ac73c80927e64ee4b1a445a', '0xae83a3e136e6714e6c1e5483950936d7872fb999', '0x39ec1c88a7a7c1a575e8c8f42eff7630d9278179', '0xd6d27255eaef8c3fcb5433acb5494bf04cb5f2c3', '0x004730417cd2b1d19f6be2679906ded4fa8a64e2', '0x89308111f17a395b82f1e5a2824bd01fd13a53b5', '0x800f25eb68a06ff9671605bd450c29e80f593e0a', '0xa5d9018f6c99ec3230633c1187c5cb607c704ed8', '0xfe59743b65f2afec200ce279a289cb4a43eb7eeb', '0x811bad1a4041a9f6ed8fc2f4e9d421dc82626f81', '0xbd12b4511ec9fd1cf481d5643f307252ae6f55e2', '0x5f7661e493d4f1a318c02e9383568597e8a09b5a', '0xe0bac765ca88706a12e4f5a9c0e92dc823fe6293', '0x40c48b386e15981df5a10552cb97ee6d232c8547', '0x458ddc6a7e924554756f95715a53bf948560ee38', '0x3c6b9edb1f8ec6c85436b7cb384eb607489c732f', '0x2a1efdf9f09869a82e5e6b0f3736aabcb5381206', '0xf30a30315d5214e490458d0511595e42b3d917d0', '0x8c2fdc530815eb4267c8b12f10adafc4ca73484a', '0x254b0e1dee486908345e608da64afe35caa02a1c']
235
+ shitty_wallets = ['0x7971d8defa89bf68ff4142b2bb1e1e3866927b36', '0x33344541086c709fe585caeabc83e5947e783333', '0xcbb8aaf930497c7bd0de6b19903410698e8adab4', '0xc352d245f25fec51ff15c77fc5bf767bf655276a', '0x9daa24510951bc0ac5d1e4f89de5efd89cc8e0b0', '0x941dab361e6d3f0b310f78c2c9eb6779608de0c3', '0x8877e6657f48aee236b47eb1c65be8e7a44f11f8', '0x1a146e329333919542cdb6d2d87de370275124c6', '0xf7d862d42976662d649cc356f4ca3854d595d53d', '0xd125b9d1415b77e0951d5b91dce3ce5d9e4375d0', '0xb94f03ad1b8ddddb82b08cd038b652cbfc47fbb4', '0x8832abcd7248ed2bd740d3eafdeb774ab8332623', '0x6dfb81b6945967e57052e4132a9ca328f8d12f7c', '0x11817fa65a9c2f68fc03bbbc9f2113d59b96908b']
236
+ internal = true
237
+ tx_list = []
238
+ burnt_ether = 0
239
+ (interpolated['first_block']..interpolated['last_block']).each do |i|
240
+ transactions = get_data(i.to_i,internal)
241
+ gas_used = transactions['result']['gasUsed'].to_i(16)
242
+ transactions['result']['transactions'].each do |tx|
243
+ if !tx.empty?
244
+ gas_price = tx['gasPrice'].to_i(16)
245
+ fees = gas_price * gas_used.to_f / 10**18
246
+ tx_list << tx
247
+ end
248
+ burnt_ether += fees
249
+ end
250
+ end
251
+ top_tx = most_common_from(tx_list)
252
+ top_count = tx_list.count { |hash| hash['from'] == top_tx }
253
+ miners_count = tx_list.select { |hash| all_miners.include?(hash['from']) }
254
+ log "miners_count #{miners_count.count}"
255
+ shitty_count = tx_list.select { |hash| shitty_wallets.include?(hash['from']) }
256
+ log "shitty_count #{shitty_count.count}"
257
+ active = tx_list.map { |p| p['from'] }.uniq.count
258
+ log "top_count : #{top_count}"
259
+ log "total : #{tx_list.count}"
260
+ create_event :payload => { 'total_tx' => "#{tx_list.count}", 'total_active' => "#{active}", 'burnt_clo' => "#{burnt_ether}", 'top_wallet': {'address' => "#{top_tx}", 'percentage' => "#{percentage(top_count.to_i,tx_list.count.to_i)}"}, 'shitty': {'address': 'shitty', 'shitty_percentage' => "#{percentage(shitty_count.count,tx_list.count.to_i)}"}, 'miners': {'address': "miners", 'percentage' => "#{percentage(miners_count.count,tx_list.count.to_i)}"}}
261
+
262
+ end
263
+
264
+ def get_data(x,internal=false)
203
265
  hexa_block = x.to_s(16)
204
266
  uri = URI.parse("#{interpolated['rpc_server']}")
205
267
  request = Net::HTTP::Post.new(uri)
@@ -225,68 +287,72 @@ module Agents
225
287
  log_curl_output(response.code,response.body)
226
288
 
227
289
  tx = JSON.parse(response.body)
228
- timestamp = tx['result']['timestamp'].to_i(16)
229
- power = (10 ** 18).to_i
230
- if !tx['result']['transactions'].empty?
231
- tx['result']['transactions'].each do |transaction|
232
- if ( !transaction['from'].nil? && interpolated['wallet'].upcase.include?(transaction['from'].upcase) ) || ( !transaction['to'].nil? && interpolated['wallet_dest'].upcase.include?(transaction['to'].upcase) )
233
- if interpolated['filter_for_method_id'].empty? || interpolated['filter_for_method_id'].include?(transaction['input'][0, 10])
234
- transaction['blockNumber'] = transaction['blockNumber'].to_i(16)
235
- transaction['timestamp'] = timestamp
236
- receipt_data = get_tx_receipt(transaction['hash'])
237
- transaction['status'] = receipt_data['result']['status']
238
- # transaction['input_converted_utf8'] = [transaction['input']].pack("H*")
239
- case transaction['input'][0, 10]
240
- when "0xb88a802f"
241
- transaction['call_type'] = 'claimReward'
242
- transaction['symbol'] = find_symbol(transaction['to'])
243
- when "0xe80233c6"
244
- transaction['call_type'] = 'activateNode'
245
- when "0x65814455"
246
- transaction['call_type'] = 'deactivateNode'
247
- when "0xb199892a"
248
- transaction['call_type'] = 'addNode'
249
- when "0xcdfdb7dc"
250
- transaction['call_type'] = 'setRatios'
251
- when "0x01026099"
252
- transaction['call_type'] = 'addTokens'
253
- when "0xb2b99ec9"
254
- transaction['call_type'] = 'removeNode'
255
- when "0x095ea7b3"
256
- transaction['call_type'] = 'approve'
257
- when "0xf2fde38b"
258
- transaction['call_type'] = 'transferOwnership'
259
- when "0x38ed1739"
260
- transaction['call_type'] = 'swapExactTokensForTokens'
261
- when "0x2e9b3dc3"
262
- transaction['call_type'] = 'swapExactCLOForTokens'
263
- when "0xa6e83852"
264
- transaction['call_type'] = 'swapTokensForExactCLO'
265
- when "0x487cda0d"
266
- transaction['call_type'] = 'depositTokens'
267
- when "0x8803dbee"
268
- transaction['call_type'] = 'swapTokensForExactTokens'
269
- when "0xa9059cbb"
270
- transaction['call_type'] = 'TokenTransfer'
271
- transaction['symbol'] = find_symbol(transaction['to'])
272
- # transaction['to'] = transaction['input'][10, 64]
273
- transaction['to'] = "0x#{transaction['input'][34, 40]}"
274
- transaction['value'] = "#{transaction['input'][74, 64].to_i(16) / power.to_i.to_f}"
275
- when "0x"
276
- transaction['call_type'] = 'Transfer'
277
- transaction['symbol'] = "CLO"
278
- transaction['value'] = "#{transaction['value'].to_i(16) / power.to_i.to_f}"
279
- when "0xa2e62045"
280
- transaction['call_type'] = 'update'
281
- when "0x40c10f19"
282
- transaction['call_type'] = 'mint'
283
- else
284
- transaction['call_type'] = 'unknown'
290
+ if internal == false
291
+ timestamp = tx['result']['timestamp'].to_i(16)
292
+ power = (10 ** 18).to_i
293
+ if !tx['result']['transactions'].empty?
294
+ tx['result']['transactions'].each do |transaction|
295
+ if ( !transaction['from'].nil? && interpolated['wallet'].upcase.include?(transaction['from'].upcase) ) || ( !transaction['to'].nil? && interpolated['wallet_dest'].upcase.include?(transaction['to'].upcase) )
296
+ if interpolated['filter_for_method_id'].empty? || interpolated['filter_for_method_id'].include?(transaction['input'][0, 10])
297
+ transaction['blockNumber'] = transaction['blockNumber'].to_i(16)
298
+ transaction['timestamp'] = timestamp
299
+ receipt_data = get_tx_receipt(transaction['hash'])
300
+ transaction['status'] = receipt_data['result']['status']
301
+ # transaction['input_converted_utf8'] = [transaction['input']].pack("H*")
302
+ case transaction['input'][0, 10]
303
+ when "0xb88a802f"
304
+ transaction['call_type'] = 'claimReward'
305
+ transaction['symbol'] = find_symbol(transaction['to'])
306
+ when "0xe80233c6"
307
+ transaction['call_type'] = 'activateNode'
308
+ when "0x65814455"
309
+ transaction['call_type'] = 'deactivateNode'
310
+ when "0xb199892a"
311
+ transaction['call_type'] = 'addNode'
312
+ when "0xcdfdb7dc"
313
+ transaction['call_type'] = 'setRatios'
314
+ when "0x01026099"
315
+ transaction['call_type'] = 'addTokens'
316
+ when "0xb2b99ec9"
317
+ transaction['call_type'] = 'removeNode'
318
+ when "0x095ea7b3"
319
+ transaction['call_type'] = 'approve'
320
+ when "0xf2fde38b"
321
+ transaction['call_type'] = 'transferOwnership'
322
+ when "0x38ed1739"
323
+ transaction['call_type'] = 'swapExactTokensForTokens'
324
+ when "0x2e9b3dc3"
325
+ transaction['call_type'] = 'swapExactCLOForTokens'
326
+ when "0xa6e83852"
327
+ transaction['call_type'] = 'swapTokensForExactCLO'
328
+ when "0x487cda0d"
329
+ transaction['call_type'] = 'depositTokens'
330
+ when "0x8803dbee"
331
+ transaction['call_type'] = 'swapTokensForExactTokens'
332
+ when "0xa9059cbb"
333
+ transaction['call_type'] = 'TokenTransfer'
334
+ transaction['symbol'] = find_symbol(transaction['to'])
335
+ # transaction['to'] = transaction['input'][10, 64]
336
+ transaction['to'] = "0x#{transaction['input'][34, 40]}"
337
+ transaction['value'] = "#{transaction['input'][74, 64].to_i(16) / power.to_i.to_f}"
338
+ when "0x"
339
+ transaction['call_type'] = 'Transfer'
340
+ transaction['symbol'] = "CLO"
341
+ transaction['value'] = "#{transaction['value'].to_i(16) / power.to_i.to_f}"
342
+ when "0xa2e62045"
343
+ transaction['call_type'] = 'update'
344
+ when "0x40c10f19"
345
+ transaction['call_type'] = 'mint'
346
+ else
347
+ transaction['call_type'] = 'unknown'
348
+ end
349
+ create_event payload: transaction
285
350
  end
286
- create_event payload: transaction
287
351
  end
288
352
  end
289
353
  end
354
+ else
355
+ return tx
290
356
  end
291
357
  end
292
358
 
@@ -1384,6 +1450,8 @@ module Agents
1384
1450
  withdraw_cs_clo()
1385
1451
  when "get_tx_by_address_with_filter"
1386
1452
  get_tx_by_address_with_filter()
1453
+ when "get_tx_stats"
1454
+ get_tx_stats()
1387
1455
  else
1388
1456
  log "Error: type has an invalid value (#{type})"
1389
1457
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huginn_callisto_network_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Germain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-29 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler