Class: Cns::Apibc
- Inherits:
-
Object
- Object
- Cns::Apibc
- Defined in:
- lib/cns/apibc.rb
Overview
classe para acesso dados blockchains
Constant Summary collapse
- ESPS =
Etherscan maximum records per page
10_000
Instance Method Summary collapse
-
#account_es(ads) ⇒ Array<Hash>
Get account balances for multiple ETH addresses.
-
#block_es(add) ⇒ Array<Hash>
Get mined blocks for ETH address.
-
#initialize ⇒ Apibc
constructor
A new instance of Apibc.
-
#inter_es(add, days: nil) ⇒ Array<Hash>
Get internal transactions for ETH address.
-
#norml_es(add, days: nil) ⇒ Array<Hash>
Get normal transactions for ETH address.
-
#token_es(add, days: nil) ⇒ Array<Hash>
Get token transfers for ETH address.
-
#withw_es(add, days: nil) ⇒ Array<Hash>
Get withdrawals for ETH address.
Constructor Details
#initialize ⇒ Apibc
Returns a new instance of Apibc.
13 14 15 16 17 |
# File 'lib/cns/apibc.rb', line 13 def initialize @escn = bccn('https://api.etherscan.io') @esky = ENV.fetch('ETHERSCAN_API_KEY', nil) @blks = {} # Cache to store block numbers so we don't ask API repeatedly end |
Instance Method Details
#account_es(ads) ⇒ Array<Hash>
Get account balances for multiple ETH addresses
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cns/apibc.rb', line 22 def account_es(ads) return [] if ads.nil? || ads.empty? # Batch addresses into groups of 20 (Etherscan limit) and fetch balances ads.each_slice(20).flat_map do |b| res = es_req('balancemulti', b.join(','), 1, tag: 'latest') res[:status] == '1' ? Array(res[:result]) : [] end rescue StandardError [] end |
#block_es(add) ⇒ Array<Hash>
Get mined blocks for ETH address
54 55 56 |
# File 'lib/cns/apibc.rb', line 54 def block_es(add) pag_es_req('getminedblocks', add, blocktype: 'blocks') end |
#inter_es(add, days: nil) ⇒ Array<Hash>
Get internal transactions for ETH address
46 47 48 49 |
# File 'lib/cns/apibc.rb', line 46 def inter_es(add, days: nil) prm = days ? {startblock: start_block(days)} : {} pag_es_req('txlistinternal', add, prm) end |
#norml_es(add, days: nil) ⇒ Array<Hash>
Get normal transactions for ETH address
38 39 40 41 |
# File 'lib/cns/apibc.rb', line 38 def norml_es(add, days: nil) prm = days ? {startblock: start_block(days)} : {} pag_es_req('txlist', add, prm) end |
#token_es(add, days: nil) ⇒ Array<Hash>
Get token transfers for ETH address
69 70 71 72 |
# File 'lib/cns/apibc.rb', line 69 def token_es(add, days: nil) prm = days ? {startblock: start_block(days)} : {} pag_es_req('tokentx', add, prm) end |
#withw_es(add, days: nil) ⇒ Array<Hash>
Get withdrawals for ETH address
61 62 63 64 |
# File 'lib/cns/apibc.rb', line 61 def withw_es(add, days: nil) prm = days ? {startblock: start_block(days)} : {} pag_es_req('txsBeaconWithdrawal', add, prm) end |