etherscan 0.3.0 → 0.4.0

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: 2ae5a3c27f579a927ac49bf966f739638880883ea3427329e68f77a6d94fa84f
4
+ data.tar.gz: 2a88c324132a2a6cad32e36b290d50410abb9d19a54293566454ed26dc0615d6
5
5
  SHA512:
6
- metadata.gz: 674a4e2c6fb06d13f1a075706658014f141ca6be9ffa74cfbcfa985ce49e0a3b476086c06a3c2759f88124d38872912df7d0776a316d0e01102650d09a0f158e
7
- data.tar.gz: 711af9556a2a5efbf870fa90168ca39f5cecafc1c918b8c45b0830a82e65bc65be389ab361c16679027695d67de8c3ea15ddd65c93bd617af7c67a3778321b53
6
+ metadata.gz: a0ae0a1a1092fae3b479260a95f1725724b685a305c8aab475a573855f5226b74e88fc67b8f62b8c85662f7e615d55470735971eaff8a4cab9eb3bf51b9a427e
7
+ data.tar.gz: 599c757ea7a9812a3a9a46f045708d936858bfc7670049d75d7ed9a1453b7e54409b9b9119544349e4fd28e69ebd5ab37cd203f184842fc6b91ed5a88a89b27e
@@ -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.0'
5
5
  end
data/lib/etherscan.rb CHANGED
@@ -9,6 +9,40 @@ 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
+
12
46
  # https://chainid.network/chains.json
13
47
  # key is the underscore(short name) of the chain in chains.json
14
48
  # https://blockscan.com/
@@ -50,19 +84,26 @@ module Etherscan
50
84
 
51
85
  # https://tronscan.org/#/developer/api
52
86
  TRON_CHAINS = {
53
- 'tron' => 'https://apilist.tronscanapi.com/api',
87
+ 'tron' => 'https://apilist.tronscanapi.com/api'
54
88
  }
55
89
 
56
90
  SUBSCAN_CHAINS = {
57
91
  'pangolin' => 'https://pangolin.api.subscan.io/api',
58
92
  'crab' => 'https://crab.api.subscan.io/api',
59
- 'darwinia' => 'https://darwinia.api.subscan.io/api',
93
+ 'darwinia' => 'https://darwinia.api.subscan.io/api'
60
94
  }
61
95
 
62
96
  class << self
63
97
  attr_accessor :logger
64
98
 
65
- def api(chain_short_name, api_key = nil)
99
+ def api(chain_id_or_short_name, api_key = nil)
100
+ if chain_id_or_short_name.is_a?(Integer)
101
+ chain_short_name = CHAIN_SHORT_NAME_BY_ID[chain_id_or_short_name]
102
+ raise "Chain id `#{chain_id_or_short_name}` is not supported." if chain_short_name.nil?
103
+ else
104
+ chain_short_name = chain_id_or_short_name
105
+ end
106
+
66
107
  url = CHAINS[chain_short_name]
67
108
  url = CHAINS[chain_short_name.underscore] if url.nil?
68
109
 
@@ -72,14 +113,17 @@ module Etherscan
72
113
  subscan_url = SUBSCAN_CHAINS[chain_short_name]
73
114
  subscan_url = SUBSCAN_CHAINS[chain_short_name.underscore] if url.nil?
74
115
 
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?
116
+ if url.nil? && tron_url.nil? && subscan_url.nil?
117
+ raise "Chain `#{chain_short_name}` is not supported. Only " \
118
+ "ETHERSCAN #{CHAINS.keys} & " \
119
+ "SUBSCAN #{SUBSCAN_CHAINS.keys} & " \
120
+ "TRONSCAN #{TRON_CHAINS.keys} are supported."
121
+ end
79
122
 
80
123
  return Etherscan::Api.new(url, api_key) if url
81
124
  return Tronscan::Api.new(tron_url, api_key) if tron_url
82
- return Subscan::Api.new(subscan_url, api_key) if subscan_url
125
+
126
+ Subscan::Api.new(subscan_url, api_key) if subscan_url
83
127
  end
84
128
 
85
129
  # 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.0
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