erc20 0.1.2 → 0.1.3

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: 96f0b876fa43c7c6ca87ebd998987fce27fa8a3c1923d906e71d674265083e7a
4
- data.tar.gz: 9b43b005266bb003a086b4457a0d31f1dcd7eba08b82d6301ae5a93f9bfd32d3
3
+ metadata.gz: 429ad43c63c2126e8f57d5adcbe391c573f34f0a4d1174d19427f7f0b121aab2
4
+ data.tar.gz: e354d3bc37396d2c1b35da5ca1800ce01ce90905b9ad9bd64e0617c71e1350b1
5
5
  SHA512:
6
- metadata.gz: 1d3e51d047763a3139c77286b41af1fdfeb40c2d10ed0c86dbfe1f1443d328957a1b37fc27a147ffcfcbb2c40f1071144a781292cf71e58dd5858045740cefd4
7
- data.tar.gz: d4baf3bd795940d5daad717ec0b8b182bc849fc000fd402ae3906d93ad31d371c1ed5aaf82e02af2ccc4ff051bd24b83104c73316c34eeb917c094e747f1f9f0
6
+ metadata.gz: fc5eb0f95f5269cd94b848a05839ac4939b60efef2b0036a2ab693d6f16cc6a1c0d025d5ba580c2f5ce47232c494a64de224b66a47a155464b1401ac022d82f3
7
+ data.tar.gz: 83b0d56783372f8a90eb0e9d89f6eed15101eb7eb0787882833baa73b1d97163b08b175f80c350d1f236e74e363ee9c1ffd4412437baa9630bfa4ee87196d8e2
data/lib/erc20/erc20.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # License:: MIT
26
26
  module ERC20
27
27
  # Current version of the gem (changed by the +.rultor.yml+ on every release)
28
- VERSION = '0.1.2'
28
+ VERSION = '0.1.3'
29
29
  end
data/lib/erc20/wallet.rb CHANGED
@@ -326,54 +326,58 @@ class ERC20::Wallet
326
326
  attempt = []
327
327
  log_url = "ws#{@ssl ? 's' : ''}://#{u.hostname}:#{u.port}"
328
328
  ws.on(:open) do
329
- verbose do
330
- log.debug("Connected to #{log_url}")
329
+ safe do
330
+ verbose do
331
+ log.debug("Connected to #{log_url}")
332
+ end
331
333
  end
332
334
  end
333
335
  ws.on(:message) do |msg|
334
- verbose do
335
- data = to_json(msg)
336
- if data['id']
337
- before = active.to_a
338
- attempt.each do |a|
339
- active.append(a) unless before.include?(a)
340
- end
341
- log.debug(
342
- "Subscribed ##{subscription_id} to #{active.to_a.size} addresses at #{log_url}: " \
343
- "#{active.to_a.map { |a| a[0..6] }.join(', ')}"
344
- )
345
- elsif data['method'] == 'eth_subscription' && data.dig('params', 'result')
346
- event = data['params']['result']
347
- if raw
348
- log.debug("New event arrived from #{event['address']}")
349
- else
350
- event = {
351
- amount: event['data'].to_i(16),
352
- from: "0x#{event['topics'][1][26..].downcase}",
353
- to: "0x#{event['topics'][2][26..].downcase}",
354
- txn: event['transactionHash'].downcase
355
- }
336
+ safe do
337
+ verbose do
338
+ data = to_json(msg)
339
+ if data['id']
340
+ before = active.to_a
341
+ attempt.each do |a|
342
+ active.append(a) unless before.include?(a)
343
+ end
356
344
  log.debug(
357
- "Payment of #{event[:amount]} tokens arrived " \
358
- "from #{event[:from]} to #{event[:to]} in #{event[:txn]}"
345
+ "Subscribed ##{subscription_id} to #{active.to_a.size} addresses at #{log_url}: " \
346
+ "#{active.to_a.map { |a| a[0..6] }.join(', ')}"
359
347
  )
360
- end
361
- begin
348
+ elsif data['method'] == 'eth_subscription' && data.dig('params', 'result')
349
+ event = data['params']['result']
350
+ if raw
351
+ log.debug("New event arrived from #{event['address']}")
352
+ else
353
+ event = {
354
+ amount: event['data'].to_i(16),
355
+ from: "0x#{event['topics'][1][26..].downcase}",
356
+ to: "0x#{event['topics'][2][26..].downcase}",
357
+ txn: event['transactionHash'].downcase
358
+ }
359
+ log.debug(
360
+ "Payment of #{event[:amount]} tokens arrived " \
361
+ "from #{event[:from]} to #{event[:to]} in #{event[:txn]}"
362
+ )
363
+ end
362
364
  yield event
363
- rescue StandardError => e
364
- @log.error(Backtrace.new(e).to_s)
365
365
  end
366
366
  end
367
367
  end
368
368
  end
369
369
  ws.on(:close) do
370
- verbose do
371
- log.debug("Disconnected from #{log_url}")
370
+ safe do
371
+ verbose do
372
+ log.debug("Disconnected from #{log_url}")
373
+ end
372
374
  end
373
375
  end
374
376
  ws.on(:error) do |e|
375
- verbose do
376
- log.debug("Error at #{log_url}: #{e.message}")
377
+ safe do
378
+ verbose do
379
+ log.debug("Error at #{log_url}: #{e.message}")
380
+ end
377
381
  end
378
382
  end
379
383
  EventMachine.add_periodic_timer(delay) do
@@ -420,15 +424,22 @@ class ERC20::Wallet
420
424
  raise e
421
425
  end
422
426
 
427
+ def safe
428
+ yield
429
+ rescue StandardError
430
+ # ignore it
431
+ end
432
+
423
433
  def url(http: true)
424
434
  URI.parse("#{http ? 'http' : 'ws'}#{@ssl ? 's' : ''}://#{@host}:#{@port}#{http ? @http_path : @ws_path}")
425
435
  end
426
436
 
427
437
  def jsonrpc
428
438
  JSONRPC.logger = Loog::NULL
429
- connection =
430
- if @proxy
431
- uri = URI.parse(@proxy)
439
+ opts = {}
440
+ if @proxy
441
+ uri = URI.parse(@proxy)
442
+ opts[:connection] =
432
443
  Faraday.new do |f|
433
444
  f.adapter(Faraday.default_adapter)
434
445
  f.proxy = {
@@ -437,8 +448,8 @@ class ERC20::Wallet
437
448
  password: uri.password
438
449
  }
439
450
  end
440
- end
441
- JSONRPC::Client.new(url, connection:)
451
+ end
452
+ JSONRPC::Client.new(url.to_s, opts)
442
453
  end
443
454
 
444
455
  def to_pay_data(address, amount)
@@ -331,13 +331,14 @@ class TestWallet < ERC20::Test
331
331
  end
332
332
 
333
333
  def test_checks_balance_via_proxy
334
+ b = nil
334
335
  via_proxy do |proxy|
335
336
  on_hardhat do |w|
336
337
  wallet = through_proxy(w, proxy)
337
338
  b = wallet.balance(Eth::Key.new(priv: JEFF).address.to_s)
338
- assert_equal(123_000_100_000, b)
339
339
  end
340
340
  end
341
+ assert_equal(123_000_100_000, b)
341
342
  end
342
343
 
343
344
  def test_checks_balance_via_proxy_on_mainnet
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erc20
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko