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 +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +2 -2
- data/lib/erc20/wallet.rb +20 -3
- data/lib/erc20.rb +1 -1
- data/test/erc20/test_wallet.rb +6 -6
- 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: 6b5bccf0ea259136bad39ab36f01240da8a029958b627ed337cd20477a7a13c9
|
4
|
+
data.tar.gz: 4c5d605e086d38755d25d8153c0bf6b220460f5b984607fd304706fe0b3d942f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0adbab22a3b752f63e1e001eac554ba8bcc8a40a2fea7234b9d674608eb281c912fb2e21931497006509b8cf2ae80e82d9de8dd49b7727f48759796da375d43b
|
7
|
+
data.tar.gz: ae3387a6c71c5ba367c8bd5814d2eebced21d6de6087dc214b083659811e2ed60efb5d0d981b7ba57b10030435566645ddd8328ac99ef4f9574b534192385383
|
data/.rubocop.yml
CHANGED
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
|
-
|
26
|
-
|
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
|
-
|
48
|
-
|
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
data/test/erc20/test_wallet.rb
CHANGED
@@ -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 |
|
150
|
-
ERC20::Wallet.new(rpc
|
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 |
|
159
|
-
ERC20::Wallet.new(rpc
|
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
|
-
|
188
|
-
wss: "ws://localhost:#{port}",
|
188
|
+
host: 'localhost', port:, path: '/', ssl: false,
|
189
189
|
log: Loog::NULL
|
190
190
|
)
|
191
191
|
yield wallet
|