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 +4 -4
- data/lib/erc20/erc20.rb +1 -1
- data/lib/erc20/wallet.rb +50 -39
- data/test/erc20/test_wallet.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 429ad43c63c2126e8f57d5adcbe391c573f34f0a4d1174d19427f7f0b121aab2
|
4
|
+
data.tar.gz: e354d3bc37396d2c1b35da5ca1800ce01ce90905b9ad9bd64e0617c71e1350b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc5eb0f95f5269cd94b848a05839ac4939b60efef2b0036a2ab693d6f16cc6a1c0d025d5ba580c2f5ce47232c494a64de224b66a47a155464b1401ac022d82f3
|
7
|
+
data.tar.gz: 83b0d56783372f8a90eb0e9d89f6eed15101eb7eb0787882833baa73b1d97163b08b175f80c350d1f236e74e363ee9c1ffd4412437baa9630bfa4ee87196d8e2
|
data/lib/erc20/erc20.rb
CHANGED
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
|
-
|
330
|
-
|
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
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
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
|
-
"
|
358
|
-
"
|
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
|
-
|
361
|
-
|
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
|
-
|
371
|
-
|
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
|
-
|
376
|
-
|
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
|
-
|
430
|
-
|
431
|
-
|
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
|
-
|
441
|
-
JSONRPC::Client.new(url,
|
451
|
+
end
|
452
|
+
JSONRPC::Client.new(url.to_s, opts)
|
442
453
|
end
|
443
454
|
|
444
455
|
def to_pay_data(address, amount)
|
data/test/erc20/test_wallet.rb
CHANGED
@@ -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
|