erc20 0.0.3 → 0.0.4

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: 9b1ea9500a3c12a4b5f84d2aa2101e16c3cfcf1fef9f0d8ccb95433aba9798cb
4
- data.tar.gz: dcd57712fa1fd1adb99511cbc42cb1c2315e7178b9d90862bddfb632ec83b0fc
3
+ metadata.gz: 6b5bccf0ea259136bad39ab36f01240da8a029958b627ed337cd20477a7a13c9
4
+ data.tar.gz: 4c5d605e086d38755d25d8153c0bf6b220460f5b984607fd304706fe0b3d942f
5
5
  SHA512:
6
- metadata.gz: dada085699673561fff510ba8d2071d983c36634b7a7bdf0232536ee4319469a4cd19d7f6b5b48ec6572ec974eeaa5fe192052210b985fb3a094bfbf5b97c8be
7
- data.tar.gz: 306828e368f07f87274eeaf1439075bc11a7b858260997419df4620b94682156b3d77000d9d5245aba5397507a0de107339f4d13b354cf3291cf592437884a69
6
+ metadata.gz: 0adbab22a3b752f63e1e001eac554ba8bcc8a40a2fea7234b9d674608eb281c912fb2e21931497006509b8cf2ae80e82d9de8dd49b7727f48759796da375d43b
7
+ data.tar.gz: ae3387a6c71c5ba367c8bd5814d2eebced21d6de6087dc214b083659811e2ed60efb5d0d981b7ba57b10030435566645ddd8328ac99ef4f9574b534192385383
data/.rubocop.yml CHANGED
@@ -43,6 +43,8 @@ Layout/MultilineMethodCallIndentation:
43
43
  Enabled: false
44
44
  Metrics/AbcSize:
45
45
  Enabled: false
46
+ Metrics/ParameterLists:
47
+ Enabled: false
46
48
  Metrics/BlockLength:
47
49
  Max: 100
48
50
  Metrics/CyclomaticComplexity:
data/README.md CHANGED
@@ -22,8 +22,8 @@ as simple as they can be, if you have a provider of
22
22
  require 'erc20'
23
23
  w = ERC20::Wallet.new(
24
24
  contract: ERC20::Wallet.USDT, # hex of it
25
- rpc: 'https://mainnet.infura.io/v3/<your-key>',
26
- wss: 'wss://mainnet.infura.io/v3/<your-key>',
25
+ host: 'mainnet.infura.io',
26
+ path: '/v3/<your-key>',
27
27
  log: $stdout
28
28
  )
29
29
 
data/lib/erc20/wallet.rb CHANGED
@@ -41,11 +41,28 @@ class ERC20::Wallet
41
41
  # @param [String] contract Hex of the contract in Etherium
42
42
  # @param [String] rpc The URL of Etherium JSON-RPC provider
43
43
  # @param [Integer] chain The ID of the chain (1 for mainnet)
44
+ # @param [String] host The host to connect to
45
+ # @param [Integer] port TCP port to use
46
+ # @param [String] path The path in the connection URL
47
+ # @param [Boolean] ssl Should we use SSL (for https and wss)
44
48
  # @param [Object] log The destination for logs
45
- def initialize(contract: USDT, rpc: nil, wss: nil, chain: 1, log: $stdout)
49
+ def initialize(contract: USDT, rpc: nil, wss: nil, chain: 1, log: $stdout,
50
+ host: nil, port: 443, path: '/', ssl: true)
46
51
  @contract = contract
47
- @rpc = rpc
48
- @wss = wss
52
+ raise 'Use either host or rpc' if rpc && host
53
+ raise 'Use either host or wss' if wss && host
54
+ if rpc
55
+ @rpc = rpc
56
+ else
57
+ raise 'Either rpc or host+port+path are required' unless host && port && path
58
+ @rpc = "http#{ssl ? 's' : ''}://#{host}:#{port}#{path}"
59
+ end
60
+ if wss
61
+ @wss = wss
62
+ else
63
+ raise 'Either wss or host+port+path are required' unless host && port && path
64
+ @wss = "http#{ssl ? 's' : ''}://#{host}:#{port}#{path}"
65
+ end
49
66
  @log = log
50
67
  @chain = chain
51
68
  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.3'
30
+ VERSION = '0.0.4'
31
31
  end
@@ -62,6 +62,7 @@ class TestWallet < Minitest::Test
62
62
  def test_fails_with_invalid_infura_key
63
63
  w = ERC20::Wallet.new(
64
64
  rpc: 'https://mainnet.infura.io/v3/invalid-key-here',
65
+ wss: 'https://mainnet.infura.io/v3/another-invalid-key-here',
65
66
  log: Loog::NULL
66
67
  )
67
68
  assert_raises(StandardError) { w.balance(STABLE_ADDRESS) }
@@ -146,8 +147,8 @@ class TestWallet < Minitest::Test
146
147
  [
147
148
  "https://mainnet.infura.io/v3/#{env('INFURA_KEY')}",
148
149
  "https://go.getblock.io/#{env('GETBLOCK_KEY')}"
149
- ].map do |rpc|
150
- ERC20::Wallet.new(rpc:, log: Loog::NULL)
150
+ ].map do |url|
151
+ ERC20::Wallet.new(rpc: url, wss: url, log: Loog::NULL)
151
152
  end.sample
152
153
  end
153
154
 
@@ -155,8 +156,8 @@ class TestWallet < Minitest::Test
155
156
  [
156
157
  "https://sepolia.infura.io/v3/#{env('INFURA_KEY')}",
157
158
  "https://go.getblock.io/#{env('GETBLOCK_SEPOILA_KEY')}"
158
- ].map do |rpc|
159
- ERC20::Wallet.new(rpc:, log: Loog::NULL)
159
+ ].map do |url|
160
+ ERC20::Wallet.new(rpc: url, wss: url, log: Loog::NULL)
160
161
  end.sample
161
162
  end
162
163
 
@@ -184,8 +185,7 @@ class TestWallet < Minitest::Test
184
185
  ).split("\n").last
185
186
  wallet = ERC20::Wallet.new(
186
187
  contract:, chain: 4242,
187
- rpc: "http://localhost:#{port}",
188
- wss: "ws://localhost:#{port}",
188
+ host: 'localhost', port:, path: '/', ssl: false,
189
189
  log: Loog::NULL
190
190
  )
191
191
  yield wallet
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko