cns 0.7.7 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cns/apibc.rb +24 -20
- data/lib/cns/version.rb +1 -1
- 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: 48a02e454e207a6aa48b986a36958b09eaa5c2c62ed68afb03ce29e65037fc34
|
4
|
+
data.tar.gz: 10303468b212b86461eb1065b4c1a9da252c5eaec764983a167b6277657a62e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16cf654b5201898eb5fcbd4a4531244969b80042bbaa79ff120501140ffedd3eaf4345cf7aaa46cae8930374ad8622a7f667aebccd3fc24a8e76e10dac8fab1c
|
7
|
+
data.tar.gz: f0e7ab1c9f1c83e6977e833b7e13b548419ab6b98f941c1f76765b4edd7b4832c13c0dc2ff3fd4752bec16862ee0545ad178c2622dc424caa7e4120d64fa26d1
|
data/Gemfile.lock
CHANGED
data/lib/cns/apibc.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require(
|
4
|
-
require(
|
3
|
+
require('faraday')
|
4
|
+
require('json')
|
5
5
|
|
6
6
|
# @author Hernani Rodrigues Vaz
|
7
7
|
module Cns
|
@@ -11,15 +11,15 @@ module Cns
|
|
11
11
|
# @param addresses [Array<String>] List of ETH addresses (max 20)
|
12
12
|
# @return [Array<Hash>] List of addresses with balances
|
13
13
|
def account_es(addresses)
|
14
|
-
response = etherscan_req(
|
15
|
-
response[:status] ==
|
14
|
+
response = etherscan_req('balancemulti', addresses.join(','), 1, tag: 'latest')
|
15
|
+
response[:status] == '1' ? response.dig(:result) : []
|
16
16
|
end
|
17
17
|
|
18
18
|
# Get EOS account information
|
19
19
|
# @param address [String] EOS account name
|
20
20
|
# @return [Hash] Account details with resources
|
21
21
|
def account_gm(address)
|
22
|
-
response = greymass_req(
|
22
|
+
response = greymass_req('/v1/chain/get_account', { account_name: address })
|
23
23
|
response || { core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } }
|
24
24
|
end
|
25
25
|
|
@@ -27,35 +27,35 @@ module Cns
|
|
27
27
|
# @param [String] address endereco ETH
|
28
28
|
# @return [Array<Hash>] lista transacoes normais etherscan
|
29
29
|
def norml_es(address)
|
30
|
-
pag_etherscan_req(
|
30
|
+
pag_etherscan_req('txlist', address)
|
31
31
|
end
|
32
32
|
|
33
33
|
# Get internal transactions for ETH address
|
34
34
|
# @param (see norml_es)
|
35
35
|
# @return [Array<Hash>] lista transacoes internas etherscan
|
36
36
|
def inter_es(address)
|
37
|
-
pag_etherscan_req(
|
37
|
+
pag_etherscan_req('txlistinternal', address)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Get mined blocks for ETH address
|
41
41
|
# @param (see norml_es)
|
42
42
|
# @return [Array<Hash>] lista blocos etherscan
|
43
43
|
def block_es(address)
|
44
|
-
pag_etherscan_req(
|
44
|
+
pag_etherscan_req('getminedblocks', address, blocktype: 'blocks')
|
45
45
|
end
|
46
46
|
|
47
47
|
# Get withdrawals for ETH address
|
48
48
|
# @param (see norml_es)
|
49
49
|
# @return [Array<Hash>] lista blocos etherscan
|
50
50
|
def withw_es(address)
|
51
|
-
pag_etherscan_req(
|
51
|
+
pag_etherscan_req('txsBeaconWithdrawal', address)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Get token transfers for ETH address
|
55
55
|
# @param (see norml_es)
|
56
56
|
# @return [Array<Hash>] lista token transfer events etherscan
|
57
57
|
def token_es(address)
|
58
|
-
pag_etherscan_req(
|
58
|
+
pag_etherscan_req('tokentx', address)
|
59
59
|
end
|
60
60
|
|
61
61
|
# Get complete transaction history for EOS account
|
@@ -65,7 +65,7 @@ module Cns
|
|
65
65
|
actions = []
|
66
66
|
pos = 0
|
67
67
|
loop do
|
68
|
-
response = greymass_req(
|
68
|
+
response = greymass_req('/v1/history/get_actions', { account_name: address, pos: pos, offset: 100 })
|
69
69
|
batch = response[:actions] || []
|
70
70
|
actions += batch
|
71
71
|
break if batch.size < 100
|
@@ -80,23 +80,27 @@ module Cns
|
|
80
80
|
# Reusable Faraday connection
|
81
81
|
def connection(base_url)
|
82
82
|
Faraday.new(base_url) do |conn|
|
83
|
-
conn.headers = {
|
84
|
-
|
83
|
+
conn.headers = {
|
84
|
+
content_type: 'application/json',
|
85
|
+
accept: 'application/json',
|
86
|
+
user_agent: 'blockchain-api-client'
|
87
|
+
}
|
88
|
+
conn.adapter(Faraday.default_adapter)
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
92
|
# Generic Etherscan API request handler
|
89
93
|
def etherscan_req(action, address, page = 1, params = {})
|
90
94
|
params = {
|
91
|
-
module:
|
95
|
+
module: 'account',
|
92
96
|
action: action,
|
93
97
|
address: address,
|
94
98
|
page: page,
|
95
|
-
apikey: ENV.fetch(
|
99
|
+
apikey: ENV.fetch('ETHERSCAN_API_KEY')
|
96
100
|
}.merge(params)
|
97
|
-
parse_json(connection(
|
101
|
+
parse_json(connection('https://api.etherscan.io').get('/api', params).body)
|
98
102
|
rescue Faraday::Error, JSON::ParserError
|
99
|
-
{ status:
|
103
|
+
{ status: '0', result: [] }
|
100
104
|
end
|
101
105
|
|
102
106
|
# Generic method for paginated Etherscan requests
|
@@ -109,11 +113,11 @@ module Cns
|
|
109
113
|
page = 1
|
110
114
|
loop do
|
111
115
|
response = etherscan_req(action, address, page, params)
|
112
|
-
break unless response[:status] ==
|
116
|
+
break unless response[:status] == '1'
|
113
117
|
|
114
118
|
batch = response[:result] || []
|
115
119
|
results += batch
|
116
|
-
break if batch.size <
|
120
|
+
break if batch.size < 10_000
|
117
121
|
|
118
122
|
page += 1
|
119
123
|
end
|
@@ -122,7 +126,7 @@ module Cns
|
|
122
126
|
|
123
127
|
# Generic Greymass API request handler
|
124
128
|
def greymass_req(endpoint, payload)
|
125
|
-
parse_json((connection(
|
129
|
+
parse_json((connection('https://eos.greymass.com').post(endpoint) { |req| req.body = payload.to_json }).body)
|
126
130
|
rescue Faraday::Error, JSON::ParserError
|
127
131
|
nil
|
128
132
|
end
|
data/lib/cns/version.rb
CHANGED