erc20 0.0.7 → 0.0.9

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: 47883e48393686ed5d357fb9f5f762e0744a30a8f0999724dd2ddba369ac75ae
4
- data.tar.gz: bad63b9aa6269a79cc2276c10c0f6aec02d8bf94bf18057b89fc0e9f896833be
3
+ metadata.gz: c553c2335f6272040af4bd2d361a30a11f0094e6871190799b90688482ad0eda
4
+ data.tar.gz: a5adb387763f6303dfccdcddeefa9a190e51c327f42a299fd25588018f9a9f6b
5
5
  SHA512:
6
- metadata.gz: bf78c2548b09b33c9e67ba7476d9e14576f9be07ca1cbb1620067899451c96c587a87849d7c86c88ec449254362db9d921a4d0fde9534954b8ad9c48405f4b51
7
- data.tar.gz: 224500ace20e3abaa25bbdc4a6be32fe7fca7b57b7d7b2bf4a4b01a8dac50a3fb45bf2a70c13f2f737b502a5ea80c4f452eeda5d0737ed6c5087d1458b590f20
6
+ metadata.gz: 332235aa28a28b38e0d56caf6f223560679b3b2622491cf6351016b6b8e11221f414bd5790d3b393af644b1d6a9c50be807a80126866108afc6c399729c73231
7
+ data.tar.gz: d74969a43d49696bfa5dfa04e26f6f0206772fffed76d94843e28189f2586d7552853361387ae102010ae976f90edcca497b1eee45addfdb101d3734641e091a
data/.rultor.yml CHANGED
@@ -31,8 +31,8 @@ release:
31
31
  [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
32
32
  DONCE_SUDO=true bundle exec rake
33
33
  rm -rf *.gem
34
- sed -i "s/0\.0\.0/${tag}/g" lib/erc20.rb
35
- git add lib/erc20.rb
34
+ sed -i "s/0\.0\.0/${tag}/g" lib/erc20/erc20.rb
35
+ git add lib/erc20/erc20.rb
36
36
  git commit -m "version set to ${tag}"
37
37
  gem build erc20.gemspec
38
38
  chmod 0600 ../rubygems.yml
data/Gemfile.lock CHANGED
@@ -51,7 +51,7 @@ GEM
51
51
  connection_pool (2.5.0)
52
52
  crass (1.0.6)
53
53
  date (3.4.1)
54
- diff-lcs (1.5.1)
54
+ diff-lcs (1.6.0)
55
55
  docile (1.4.1)
56
56
  donce (0.1.0)
57
57
  backtrace (> 0)
@@ -103,7 +103,7 @@ GEM
103
103
  keccak (1.3.2)
104
104
  konstructor (1.0.2)
105
105
  language_server-protocol (3.17.0.4)
106
- logger (1.6.5)
106
+ logger (1.6.6)
107
107
  loofah (2.24.0)
108
108
  crass (~> 1.0.2)
109
109
  nokogiri (>= 1.12.0)
@@ -147,7 +147,7 @@ GEM
147
147
  loog (> 0)
148
148
  tago (> 0)
149
149
  racc (1.8.1)
150
- rack (3.1.9)
150
+ rack (3.1.10)
151
151
  rack-session (2.1.0)
152
152
  base64 (>= 0.1.0)
153
153
  rack (>= 3.0.0)
data/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
  This small Ruby [gem](https://rubygems.org/gems/erc20)
15
15
  makes manipulations with [Etherium] [ERC20] tokens
16
16
  as simple as they can be, if you have a provider of
17
- [JSON-RPC] and [WebSocket] Etherium APIs, for example
17
+ [JSON-RPC] and [WebSockets] Etherium APIs, for example
18
18
  [Infura], [GetBlock], or [Alchemy]:
19
19
 
20
20
  ```ruby
@@ -92,7 +92,7 @@ If it's clean and you don't see any error messages, submit your pull request.
92
92
  [Etherium]: https://en.wikipedia.org/wiki/Ethereum
93
93
  [ERC20]: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/
94
94
  [JSON-RPC]: https://ethereum.org/en/developers/docs/apis/json-rpc/
95
- [Websocket]: https://ethereum.org/en/developers/tutorials/using-websockets/
95
+ [Websockets]: https://ethereum.org/en/developers/tutorials/using-websockets/
96
96
  [Infura]: https://infura.io/
97
97
  [Alchemy]: https://alchemy.com/
98
98
  [GetBlock]: https://getblock.io/
data/erc20.gemspec CHANGED
@@ -21,7 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'English'
24
- require_relative 'lib/erc20'
24
+ require_relative 'lib/erc20/erc20'
25
25
 
26
26
  Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2025 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ # This module makes manipulations with Etherium ERC20 tokens
24
+ # as simple as they can be, if you have a provider of
25
+ # JSON-RPC and WebSockets Etherium APIs, for example
26
+ # Infura, GetBlock, or Alchemy.
27
+ #
28
+ # Start like this:
29
+ #
30
+ # require 'erc20'
31
+ # w = ERC20::Wallet.new(
32
+ # host: 'mainnet.infura.io',
33
+ # http_path: '/v3/<your-infura-key>',
34
+ # ws_path: '/ws/v3/<your-infura-key>'
35
+ # )
36
+ # puts w.balance(address)
37
+ #
38
+ # This should print the balance of the ERC20 address.
39
+ #
40
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
41
+ # Copyright:: Copyright (c) 2025 Yegor Bugayenko
42
+ # License:: MIT
43
+ module ERC20
44
+ # Current version of the gem (changed by the +.rultor.yml+ on every release)
45
+ VERSION = '0.0.9'
46
+ end
data/lib/erc20/wallet.rb CHANGED
@@ -27,12 +27,49 @@ require 'json'
27
27
  require 'jsonrpc/client'
28
28
  require 'loog'
29
29
  require 'uri'
30
- require_relative '../erc20'
30
+ require_relative 'erc20'
31
31
 
32
32
  # A wallet with ERC20 tokens on Etherium.
33
33
  #
34
34
  # Objects of this class are thread-safe.
35
35
  #
36
+ # In order to check the balance of ERC20 address:
37
+ #
38
+ # require 'erc20'
39
+ # w = ERC20::Wallet.new(
40
+ # contract: ERC20::Wallet.USDT, # hex of it
41
+ # host: 'mainnet.infura.io',
42
+ # http_path: '/v3/<your-infura-key>',
43
+ # ws_path: '/ws/v3/<your-infura-key>',
44
+ # log: $stdout
45
+ # )
46
+ # usdt = w.balance(address)
47
+ #
48
+ # In order to send a payment:
49
+ #
50
+ # hex = w.pay(private_key, to_address, amount)
51
+ #
52
+ # In order to catch incoming payments to a set of addresses:
53
+ #
54
+ # addresses = ['0x...', '0x...']
55
+ # w.accept(addresses) do |event|
56
+ # puts event[:txt] # hash of transaction
57
+ # puts event[:amount] # how much, in tokens (1000000 = $1 USDT)
58
+ # puts event[:from] # who sent the payment
59
+ # puts event[:to] # who was the receiver
60
+ # end
61
+ #
62
+ # To connect to the server via HTTP proxy with basic authentication:
63
+ #
64
+ # w = ERC20::Wallet.new(
65
+ # host: 'go.getblock.io',
66
+ # http_path: '/<your-rpc-getblock-key>',
67
+ # ws_path: '/<your-ws-getblock-key>',
68
+ # proxy: 'http://jeffrey:swordfish@example.com:3128' # here!
69
+ # )
70
+ #
71
+ # More information in our README.
72
+ #
36
73
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
37
74
  # Copyright:: Copyright (c) 2025 Yegor Bugayenko
38
75
  # License:: MIT
@@ -118,7 +155,7 @@ class ERC20::Wallet
118
155
  jsonrpc.eth_sendRawTransaction(hex)
119
156
  end
120
157
  @log.debug("Sent #{amount} from #{from} to #{address}: #{tnx}")
121
- tnx
158
+ tnx.downcase
122
159
  end
123
160
 
124
161
  # Wait for incoming transactions and let the block know when they
@@ -179,7 +216,7 @@ class ERC20::Wallet
179
216
  amount: event['data'].to_i(16),
180
217
  from: "0x#{event['topics'][1][26..].downcase}",
181
218
  to: "0x#{event['topics'][2][26..].downcase}",
182
- txn: event['transactionHash']
219
+ txn: event['transactionHash'].downcase
183
220
  }
184
221
  log.debug("Payment of #{event[:amount]} tokens arrived from #{event[:from]} to #{event[:to]}")
185
222
  end
data/lib/erc20.rb CHANGED
@@ -20,12 +20,5 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- # ERC20 module.
24
- #
25
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
- # Copyright:: Copyright (c) 2025 Yegor Bugayenko
27
- # License:: MIT
28
- module ERC20
29
- # Current version of the gem (changed by .rultor.yml on every release)
30
- VERSION = '0.0.7'
31
- end
23
+ require_relative 'erc20/erc20'
24
+ require_relative 'erc20/wallet'
@@ -30,7 +30,6 @@ require 'random-port'
30
30
  require 'shellwords'
31
31
  require 'threads'
32
32
  require 'typhoeus'
33
- require_relative '../../lib/erc20'
34
33
  require_relative '../../lib/erc20/wallet'
35
34
  require_relative '../test__helper'
36
35
 
@@ -63,12 +62,13 @@ class TestWallet < Minitest::Test
63
62
  end
64
63
 
65
64
  def test_fails_with_invalid_infura_key
65
+ skip('Apparently, even with invalid key, Infura returns balance')
66
66
  w = ERC20::Wallet.new(
67
67
  host: 'mainnet.infura.io',
68
68
  http_path: '/v3/invalid-key-here',
69
69
  log: loog
70
70
  )
71
- assert_raises(StandardError) { w.balance(STABLE) }
71
+ assert_raises(StandardError) { p w.balance(STABLE) }
72
72
  end
73
73
 
74
74
  def test_checks_balance_on_testnet
@@ -113,6 +113,7 @@ class TestWallet < Minitest::Test
113
113
  assert_operator(wallet.balance(from), :>, sum * 2)
114
114
  txn = wallet.pay(JEFF, to, sum)
115
115
  assert_equal(66, txn.length)
116
+ assert_match(/^0x[a-f0-9]{64}$/, txn)
116
117
  assert_equal(before + sum, wallet.balance(to))
117
118
  end
118
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erc20
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-13 00:00:00.000000000 Z
11
+ date: 2025-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eth
@@ -122,6 +122,7 @@ files:
122
122
  - hardhat/ignition/modules/Foo.ts
123
123
  - hardhat/package.json
124
124
  - lib/erc20.rb
125
+ - lib/erc20/erc20.rb
125
126
  - lib/erc20/wallet.rb
126
127
  - renovate.json
127
128
  - test/erc20/test_wallet.rb