erc20 0.0.6 → 0.0.8

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: ddbc3966b9eec2d455e33dde71df0427a7a99e4d59f0df69191d8f617434c8bf
4
- data.tar.gz: 0d577a397eee74c5dae388ca620f8a681c4bec2af8d9b6cf5514ca32cbebc992
3
+ metadata.gz: 2a6045ef455a8f096b144b8a680abd27df0b56c3d66b55893ad7f0f3dc4e4203
4
+ data.tar.gz: e5276a87ad3ac48ec1df0928e28bc18295e3033a280fe1172d1d9199b582c54f
5
5
  SHA512:
6
- metadata.gz: 1f87ab9c39b5476b9b90bd44020f21970edc8830826129b0a2c6386d562887627e346c55a1e8bb1fcf3e9983d1977e6e0851b7e2fdc162217898951988b2173f
7
- data.tar.gz: 02d6b7e7058dd6c6f3a74b81ece853e674020a4df84b6fa439b74438ff8227616a76cf3abd1a6f82fdfb7f34391c4e541f96791e404e8e84cb3f364d72e92771
6
+ metadata.gz: e964c619368827683031db7eae717c662cc292eb60b0cded4868968e19bdebb1ab091c3ad1edc65e78aa4d0ba2b451587b9f77cf38ac381765776a7b078182f6
7
+ data.tar.gz: 83793a79b62811b4f34589a5d60db5cec07f707e04673ef02adcf29e81eaf7d91f3ad7198d2c4bbfc2645032cf8a6c2ac508ec477a3a60edf5874401864c2e20
data/README.md CHANGED
@@ -37,7 +37,8 @@ hex = w.pay(private_key, to_address, amount)
37
37
  # Stay waiting, and trigger the block when new ERC20 payments show up:
38
38
  addresses = ['0x...', '0x...'] # only wait for payments to these addresses
39
39
  w.accept(addresses) do |event|
40
- puts event[:amount] # how much
40
+ puts event[:txt] # hash of transaction
41
+ puts event[:amount] # how much, in tokens (1000000 = $1 USDT)
41
42
  puts event[:from] # who sent the payment
42
43
  puts event[:to] # who was the receiver
43
44
  end
data/lib/erc20/wallet.rb CHANGED
@@ -118,7 +118,7 @@ class ERC20::Wallet
118
118
  jsonrpc.eth_sendRawTransaction(hex)
119
119
  end
120
120
  @log.debug("Sent #{amount} from #{from} to #{address}: #{tnx}")
121
- tnx
121
+ tnx.downcase
122
122
  end
123
123
 
124
124
  # Wait for incoming transactions and let the block know when they
@@ -178,7 +178,8 @@ class ERC20::Wallet
178
178
  event = {
179
179
  amount: event['data'].to_i(16),
180
180
  from: "0x#{event['topics'][1][26..].downcase}",
181
- to: "0x#{event['topics'][2][26..].downcase}"
181
+ to: "0x#{event['topics'][2][26..].downcase}",
182
+ txn: event['transactionHash'].downcase
182
183
  }
183
184
  log.debug("Payment of #{event[:amount]} tokens arrived from #{event[:from]} to #{event[:to]}")
184
185
  end
data/lib/erc20.rb CHANGED
@@ -27,5 +27,5 @@
27
27
  # License:: MIT
28
28
  module ERC20
29
29
  # Current version of the gem (changed by .rultor.yml on every release)
30
- VERSION = '0.0.6'
30
+ VERSION = '0.0.8'
31
31
  end
@@ -39,7 +39,7 @@ require_relative '../test__helper'
39
39
  # Copyright:: Copyright (c) 2025 Yegor Bugayenko
40
40
  # License:: MIT
41
41
  class TestWallet < Minitest::Test
42
- # At this address, in Etherium mainnet, there are a few USDT tokens. I won't
42
+ # At this address, in Etherium mainnet, there are a ~$27 USDT. I won't
43
43
  # move them anyway, that's why tests can use this address forever.
44
44
  STABLE = '0xEB2fE8872A6f1eDb70a2632EA1f869AB131532f6'
45
45
 
@@ -63,12 +63,13 @@ class TestWallet < Minitest::Test
63
63
  end
64
64
 
65
65
  def test_fails_with_invalid_infura_key
66
+ skip('Apparently, even with invalid key, Infura returns balance')
66
67
  w = ERC20::Wallet.new(
67
68
  host: 'mainnet.infura.io',
68
69
  http_path: '/v3/invalid-key-here',
69
70
  log: loog
70
71
  )
71
- assert_raises(StandardError) { w.balance(STABLE) }
72
+ assert_raises(StandardError) { p w.balance(STABLE) }
72
73
  end
73
74
 
74
75
  def test_checks_balance_on_testnet
@@ -111,7 +112,9 @@ class TestWallet < Minitest::Test
111
112
  sum = 42_000
112
113
  from = Eth::Key.new(priv: JEFF).address.to_s
113
114
  assert_operator(wallet.balance(from), :>, sum * 2)
114
- wallet.pay(JEFF, to, sum)
115
+ txn = wallet.pay(JEFF, to, sum)
116
+ assert_equal(66, txn.length)
117
+ assert_match(/^0x[a-f0-9]{64}$/, txn)
115
118
  assert_equal(before + sum, wallet.balance(to))
116
119
  end
117
120
  end
@@ -152,6 +155,7 @@ class TestWallet < Minitest::Test
152
155
  assert_equal(sum, event[:amount])
153
156
  assert_equal(jeff, event[:from])
154
157
  assert_equal(walter, event[:to])
158
+ assert_equal(66, event[:txn].length)
155
159
  end
156
160
  end
157
161
 
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.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko