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
- GMPS =
Greymass maximum actions per request
100
Instance Method Summary collapse
-
#account_es(ads) ⇒ Array<Hash>
Get account balances for multiple ETH addresses.
-
#account_gm(add) ⇒ Hash
Get EOS account information.
-
#block_es(add) ⇒ Array<Hash>
Get mined blocks for ETH address.
-
#initialize ⇒ Apibc
constructor
A new instance of Apibc.
-
#inter_es(add) ⇒ Array<Hash>
Get internal transactions for ETH address.
-
#ledger_gm(add) ⇒ Array<Hash>
Get complete transaction history for EOS account.
-
#norml_es(add) ⇒ Array<Hash>
Get normal transactions for ETH address.
-
#token_es(add) ⇒ Array<Hash>
Get token transfers for ETH address.
-
#withw_es(add) ⇒ Array<Hash>
Get withdrawals for ETH address.
Constructor Details
#initialize ⇒ Apibc
Returns a new instance of Apibc.
14 15 16 17 18 |
# File 'lib/cns/apibc.rb', line 14 def initialize @escn = bccn('https://api.etherscan.io') @gmcn = bccn('https://eos.greymass.com') @esky = ENV.fetch('ETHERSCAN_API_KEY', nil) end |
Instance Method Details
#account_es(ads) ⇒ Array<Hash>
Get account balances for multiple ETH addresses
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cns/apibc.rb', line 23 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 |
#account_gm(add) ⇒ Hash
Get EOS account information
73 74 75 76 |
# File 'lib/cns/apibc.rb', line 73 def account_gm(add) res = gm_req('/v1/chain/get_account', account_name: add) res[:core_liquid_balance]&.to_d&.positive? ? res : gm_erro end |
#block_es(add) ⇒ Array<Hash>
Get mined blocks for ETH address
52 53 54 |
# File 'lib/cns/apibc.rb', line 52 def block_es(add) pag_es_req('getminedblocks', add, blocktype: 'blocks') end |
#inter_es(add) ⇒ Array<Hash>
Get internal transactions for ETH address
45 46 47 |
# File 'lib/cns/apibc.rb', line 45 def inter_es(add) pag_es_req('txlistinternal', add) end |
#ledger_gm(add) ⇒ Array<Hash>
Get complete transaction history for EOS account
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cns/apibc.rb', line 81 def ledger_gm(add) trx = [] pos = 0 loop do res = gm_req('/v1/history/get_actions', account_name: add, pos: pos, offset: GMPS) bth = Array(res[:actions]) trx.concat(bth) break if bth.size < GMPS pos += GMPS end trx rescue StandardError trx end |
#norml_es(add) ⇒ Array<Hash>
Get normal transactions for ETH address
38 39 40 |
# File 'lib/cns/apibc.rb', line 38 def norml_es(add) pag_es_req('txlist', add) end |
#token_es(add) ⇒ Array<Hash>
Get token transfers for ETH address
66 67 68 |
# File 'lib/cns/apibc.rb', line 66 def token_es(add) pag_es_req('tokentx', add) end |
#withw_es(add) ⇒ Array<Hash>
Get withdrawals for ETH address
59 60 61 |
# File 'lib/cns/apibc.rb', line 59 def withw_es(add) pag_es_req('txsBeaconWithdrawal', add) end |