Class: Cns::Apibc
- Inherits:
-
Object
- Object
- Cns::Apibc
- Defined in:
- lib/cns/apibc.rb
Overview
classe para acesso dados blockchains
Instance Method Summary collapse
-
#account_es(ads) ⇒ Array<Hash>
Lista enderecos e seus saldos.
-
#account_gm(add) ⇒ Hash
Endereco e seus saldo/recursos.
-
#block_es(add, pag = 0, aes = []) ⇒ Array<Hash>
{ status: ‘1’, message: ‘OK’, result: [ { blockNumber: ‘15737070’, timeStamp: ‘1665638459’, blockReward: ‘8922867945448231’ }, { blockNumber: ‘15592786’, timeStamp: ‘1663896779’, blockReward: ‘44997990286623752’ }, { blockNumber: ‘15570222’, timeStamp: ‘1663622819’, blockReward: ‘261211525682683684’ }, { blockNumber: ‘15568554’, timeStamp: ‘1663602539’, blockReward: ‘41993833217879559’ } ] }.
-
#data_bc(uri) ⇒ Array<Hash>
Lista dados beaconchain.
-
#inter_es(add, pag = 0, aes = []) ⇒ Array<Hash>
{ status: ‘1’, message: ‘OK’, result: [ { blockNumber: ‘15592786’, timeStamp: ‘1663896779’, hash: ‘0x…’, from: ‘0x…’, to: ‘0x…’, value: ‘22000000000000000’, contractAddress: ”, input: ”, type: ‘call’, gas: ‘2300’, gasUsed: ‘0’, traceId: ‘0_1_1’, isError: ‘0’, errCode: ” } ] }.
-
#ledger_gm(add, agm = []) ⇒ Array<Hash>
Lista completa transacoes greymass.
-
#norml_es(add, pag = 0, aes = []) ⇒ Array<Hash>
Lista transacoes normais etherscan.
-
#token_es(add, pag = 0, aes = []) ⇒ Array<Hash>
Lista token transfer events etherscan.
-
#withw_es(add, pag = 0, aes = []) ⇒ Array<Hash>
{ “status”:“1”, “message”:“OK”, “result”:[ { “withdrawalIndex”:“14”, “validatorIndex”:“119023”, “address”:“0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f”, “amount”:“3244098967”, “blockNumber”:“17034877”, “timestamp”:“1681338599” } ] }.
Instance Method Details
#account_es(ads) ⇒ Array<Hash>
Returns lista enderecos e seus saldos.
32 33 34 35 36 37 38 39 |
# File 'lib/cns/apibc.rb', line 32 def account_es(ads) JSON.parse( conn_es.get('/api', action: 'balancemulti', tag: 'latest', address: ads.join(',')).body, symbolize_names: true )[:result] rescue StandardError [] end |
#account_gm(add) ⇒ Hash
Returns endereco e seus saldo/recursos.
93 94 95 96 97 |
# File 'lib/cns/apibc.rb', line 93 def account_gm(add) JSON.parse(conn_gm.post('/v1/chain/get_account', { account_name: add }.to_json).body, symbolize_names: true) rescue StandardError { core_liquid_balance: 0, total_resources: { net_weight: 0, cpu_weight: 0 } } end |
#block_es(add, pag = 0, aes = []) ⇒ Array<Hash>
{
status: '1',
message: 'OK',
result: [
{ blockNumber: '15737070', timeStamp: '1665638459', blockReward: '8922867945448231' },
{ blockNumber: '15592786', timeStamp: '1663896779', blockReward: '44997990286623752' },
{ blockNumber: '15570222', timeStamp: '1663622819', blockReward: '261211525682683684' },
{ blockNumber: '15568554', timeStamp: '1663602539', blockReward: '41993833217879559' }
]
}
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/cns/apibc.rb', line 191 def block_es(add, pag = 0, aes = []) res = JSON.parse( conn_es.get( '/api', action: 'getminedblocks', blocktype: 'blocks', offset: 10_000, address: add, page: pag += 1 ).body, symbolize_names: true )[:result] aes += res res.count < 10_000 ? aes : block_es(add, pag, aes) rescue StandardError aes end |
#data_bc(uri) ⇒ Array<Hash>
Returns lista dados beaconchain.
12 13 14 15 16 17 18 19 |
# File 'lib/cns/apibc.rb', line 12 def data_bc(uri) res = JSON.parse(conn_bc.get(uri).body, symbolize_names: true)[:data] || [] # calls are rate limited to 10 requests/minute/IP sleep(3) res.is_a?(Array) ? res : [res] rescue StandardError [] end |
#inter_es(add, pag = 0, aes = []) ⇒ Array<Hash>
{
status: '1',
message: 'OK',
result: [
{
blockNumber: '15592786',
timeStamp: '1663896779',
hash: '0x...',
from: '0x...',
to: '0x...',
value: '22000000000000000',
contractAddress: '',
input: '',
type: 'call',
gas: '2300',
gasUsed: '0',
traceId: '0_1_1',
isError: '0',
errCode: ''
}
]
}
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cns/apibc.rb', line 167 def inter_es(add, pag = 0, aes = []) res = JSON.parse( conn_es.get('/api', action: 'txlistinternal', offset: 10_000, address: add, page: pag += 1).body, symbolize_names: true )[:result] aes += res res.count < 10_000 ? aes : inter_es(add, pag, aes) rescue StandardError aes end |
#ledger_gm(add, agm = []) ⇒ Array<Hash>
Returns lista completa transacoes greymass.
338 339 340 341 342 343 344 345 346 347 |
# File 'lib/cns/apibc.rb', line 338 def ledger_gm(add, agm = []) res = JSON.parse( conn_gm.post('/v1/history/get_actions', { account_name: add, pos: agm.count, offset: 100 }.to_json).body, symbolize_names: true )[:actions] agm += res res.count < 100 ? agm : ledger_gm(add, agm) rescue StandardError agm end |
#norml_es(add, pag = 0, aes = []) ⇒ Array<Hash>
Returns lista transacoes normais etherscan.
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cns/apibc.rb', line 131 def norml_es(add, pag = 0, aes = []) res = JSON.parse( conn_es.get('/api', action: 'txlist', offset: 10_000, address: add, page: pag += 1).body, symbolize_names: true )[:result] aes += res res.count < 10_000 ? aes : norml_es(add, pag, aes) rescue StandardError aes end |
#token_es(add, pag = 0, aes = []) ⇒ Array<Hash>
Returns lista token transfer events etherscan.
274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/cns/apibc.rb', line 274 def token_es(add, pag = 0, aes = []) # registos duplicados aparecem em token events (ver exemplo acima) # -quando ha erros na blockchain (acho) # -quando ha token events identicos no mesmo block (acho) res = JSON.parse( conn_es.get('/api', action: 'tokentx', offset: 10_000, address: add, page: pag += 1).body, symbolize_names: true )[:result] aes += res res.count < 10_000 ? aes : token_es(add, pag, aes) rescue StandardError aes end |
#withw_es(add, pag = 0, aes = []) ⇒ Array<Hash>
{
"status":"1",
"message":"OK",
"result":[
{
"withdrawalIndex":"14",
"validatorIndex":"119023",
"address":"0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f",
"amount":"3244098967",
"blockNumber":"17034877",
"timestamp":"1681338599"
}
]
}
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/cns/apibc.rb', line 226 def withw_es(add, pag = 0, aes = []) res = JSON.parse( conn_es.get( '/api', action: 'txsBeaconWithdrawal', address: add, offset: 10_000, page: pag += 1 ).body, symbolize_names: true )[:result] aes += res res.count < 10_000 ? aes : withw_es(add, pag, aes) rescue StandardError aes end |