etherscan 0.3.0 → 0.4.1

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: '0227579db92861939267b0cac5f56646f809f4a4d1db84800f77401e68404717'
4
- data.tar.gz: f1451aa9dc8117abe7070f80908b6cc764bcba3407968b02aaa9af36f371961d
3
+ metadata.gz: a4d5ec6886432a0abcb073b8e17053be4a0f03ce6ad95f956cc2af34d2ece2c3
4
+ data.tar.gz: a527e4a0a3c221851db4e7d881c4bea20f313ef00ff9ad7c4fbdf5bec26b094b
5
5
  SHA512:
6
- metadata.gz: 674a4e2c6fb06d13f1a075706658014f141ca6be9ffa74cfbcfa985ce49e0a3b476086c06a3c2759f88124d38872912df7d0776a316d0e01102650d09a0f158e
7
- data.tar.gz: 711af9556a2a5efbf870fa90168ca39f5cecafc1c918b8c45b0830a82e65bc65be389ab361c16679027695d67de8c3ea15ddd65c93bd617af7c67a3778321b53
6
+ metadata.gz: b643fed3858d01831668d7f6b80aa5bde9c5a7108927282bca291ef276440d79196422f7b2eccabe1599fb47bd7d0c04be9e2370b5f6ccd65b83ac27ccc54016
7
+ data.tar.gz: 4363b96d1a7aff5e392e9b6f002b0d7305abd997b9ff567daa2e397bc00a931d78eb250f1ab0132314d5d6c560220b938cc2b7a279551bdec8a6aa588a8e6b6a
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Etherscan
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.1'
5
5
  end
data/lib/etherscan.rb CHANGED
@@ -9,6 +9,46 @@ require 'active_support'
9
9
  require 'active_support/core_ext/string'
10
10
 
11
11
  module Etherscan
12
+ CHAIN_SHORT_NAME_BY_ID = {
13
+ 1 => 'eth',
14
+ 5 => 'gor',
15
+ 11_155_111 => 'sep',
16
+ 42_161 => 'arb1',
17
+ 421_613 => 'arb_goerli',
18
+ 421_614 => 'arb_sep',
19
+ 56 => 'bnb',
20
+ 97 => 'bnbt',
21
+ 137 => 'matic',
22
+ 80_001 => 'maticmum',
23
+ 1101 => 'zkevm',
24
+ 14_422 => 'testnet_zk_evm_mango',
25
+ 250 => 'ftm',
26
+ 4002 => 'tftm',
27
+ 10 => 'oeth',
28
+ 1284 => 'mbeam',
29
+ 1285 => 'mriver',
30
+ 1287 => 'mbase',
31
+ 25 => 'cronos',
32
+ 199 => 'btt',
33
+ 1028 => 'tbtt',
34
+ 100 => 'gnosis',
35
+ 42_170 => 'arb_nova',
36
+ 59_144 => 'linea',
37
+ 59_140 => 'linea_testnet',
38
+ 8453 => 'base',
39
+ 84_531 => 'basegor',
40
+ 1111 => 'wemix',
41
+ 534_352 => 'scr',
42
+ 534_351 => 'scr_sepolia',
43
+ 204 => 'obnb',
44
+
45
+ 728_126_428 => 'tron',
46
+ 2_494_104_990 => 'tron_shasta',
47
+ 43 => 'pangolin',
48
+ 44 => 'crab',
49
+ 46 => 'darwinia'
50
+ }
51
+
12
52
  # https://chainid.network/chains.json
13
53
  # key is the underscore(short name) of the chain in chains.json
14
54
  # https://blockscan.com/
@@ -51,18 +91,26 @@ module Etherscan
51
91
  # https://tronscan.org/#/developer/api
52
92
  TRON_CHAINS = {
53
93
  'tron' => 'https://apilist.tronscanapi.com/api',
94
+ 'tron_shasta' => 'https://shastapi.tronscan.org/api'
54
95
  }
55
96
 
56
97
  SUBSCAN_CHAINS = {
57
98
  'pangolin' => 'https://pangolin.api.subscan.io/api',
58
99
  'crab' => 'https://crab.api.subscan.io/api',
59
- 'darwinia' => 'https://darwinia.api.subscan.io/api',
100
+ 'darwinia' => 'https://darwinia.api.subscan.io/api'
60
101
  }
61
102
 
62
103
  class << self
63
104
  attr_accessor :logger
64
105
 
65
- def api(chain_short_name, api_key = nil)
106
+ def api(chain_id_or_short_name, api_key = nil)
107
+ if chain_id_or_short_name.is_a?(Integer)
108
+ chain_short_name = CHAIN_SHORT_NAME_BY_ID[chain_id_or_short_name]
109
+ raise "Chain id `#{chain_id_or_short_name}` is not supported." if chain_short_name.nil?
110
+ else
111
+ chain_short_name = chain_id_or_short_name
112
+ end
113
+
66
114
  url = CHAINS[chain_short_name]
67
115
  url = CHAINS[chain_short_name.underscore] if url.nil?
68
116
 
@@ -72,14 +120,17 @@ module Etherscan
72
120
  subscan_url = SUBSCAN_CHAINS[chain_short_name]
73
121
  subscan_url = SUBSCAN_CHAINS[chain_short_name.underscore] if url.nil?
74
122
 
75
- raise "Chain `#{chain_short_name}` is not supported. Only " \
76
- "Etherscan [#{CHAINS.keys}] & " \
77
- "Subscan [#{SUBSCAN_CHAINS.keys}] & " \
78
- "Tronscan [#{TRON_CHAINS.keys}] are supported." if url.nil? && tron_url.nil? && subscan_url.nil?
123
+ if url.nil? && tron_url.nil? && subscan_url.nil?
124
+ raise "Chain `#{chain_short_name}` is not supported. Only " \
125
+ "ETHERSCAN #{CHAINS.keys} & " \
126
+ "SUBSCAN #{SUBSCAN_CHAINS.keys} & " \
127
+ "TRONSCAN #{TRON_CHAINS.keys} are supported."
128
+ end
79
129
 
80
130
  return Etherscan::Api.new(url, api_key) if url
81
131
  return Tronscan::Api.new(tron_url, api_key) if tron_url
82
- return Subscan::Api.new(subscan_url, api_key) if subscan_url
132
+
133
+ Subscan::Api.new(subscan_url, api_key) if subscan_url
83
134
  end
84
135
 
85
136
  # for example: Etherscan.eth('your_api_key')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etherscan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aki Wu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-04 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport