lib/cns/etherscan1.rb in cns-0.3.0 vs lib/cns/etherscan1.rb in cns-0.3.1

- old
+ new

@@ -30,10 +30,20 @@ # @return [Array<Hash>] lista transacoes normais novas def novtx @novtx ||= bcd.map { |obc| obc[:tx].select { |obj| idt.include?(obj[:itx]) } }.flatten end + # @return [Array<Hash>] lista transacoes internas novas + def novix + @novix ||= bcd.map { |obc| obc[:ix].select { |obj| idi.include?(obj[:itx]) } }.flatten + end + + # @return [Array<Hash>] lista transacoes block novas + def novpx + @novpx ||= bcd.map { |obc| obc[:px].select { |obj| idp.include?(obj[:itx]) } }.flatten + end + # @return [Array<Hash>] lista transacoes token novas def novkx @novkx ||= bcd.map { |obc| obc[:kx].select { |obj| idk.include?(obj[:itx]) } }.flatten end @@ -56,10 +66,22 @@ def idt @idt ||= bcd.map { |obc| obc[:tx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nt].map { |obq| obq[:itx] }) end + # @return [Array<Integer>] lista indices transacoes internas novas + def idi + @idi ||= bcd.map { |obc| obc[:ix].map { |obj| obj[:itx] } }.flatten - + (ops[:t] ? [] : bqd[:ni].map { |obq| obq[:itx] }) + end + + # @return [Array<Integer>] lista indices transacoes block novas + def idp + @idp ||= bcd.map { |obc| obc[:px].map { |obj| obj[:itx] } }.flatten - + (ops[:t] ? [] : bqd[:np].map { |obq| obq[:itx] }) + end + # @return [Array<Integer>] lista indices transacoes token novas def idk @idk ||= bcd.map { |obc| obc[:kx].map { |obj| obj[:itx] } }.flatten - (ops[:t] ? [] : bqd[:nk].map { |obq| obq[:itx] }) end @@ -69,12 +91,14 @@ # @return [Hash] dados etherscan - address, saldo & transacoes def base_bc(abc) acc = abc[:account].downcase { ax: acc, - sl: (abc[:balance].to_d / 10**18).round(10), + sl: (abc[:balance].to_d / 10**18), tx: filtrar_tx(acc, api.norml_es(acc)), + ix: filtrar_tx(acc, api.inter_es(acc)), + px: filtrar_px(acc, api.block_es(acc)), kx: filtrar_tx(acc, api.token_es(acc)) } end # @param [Hash] wbq wallet bigquery @@ -84,13 +108,17 @@ { id: wbq[:id], ax: xbq = wbq[:ax], bs: wbq[:sl], bt: bqd[:nt].select { |ont| ont[:iax] == xbq }, + bi: bqd[:ni].select { |oni| oni[:iax] == xbq }, + bp: bqd[:np].select { |onp| onp[:iax] == xbq }, bk: bqd[:nk].select { |onk| onk[:iax] == xbq }, es: hbc[:sl], et: hbc[:tx], + ei: hbc[:ix], + ep: hbc[:px], ek: hbc[:kx] } end # @param add (see Apibc#norml_es) @@ -101,12 +129,30 @@ # elimina chaves irrelevantes (DL) & adiciona chave indice itx & adiciona identificador da carteira iax ary.delete_if { |odl| add.casecmp?(odl[:to]) && lax.include?(odl[:from].downcase) } .map { |omp| omp.delete_if { |key, _| DL.include?(key) }.merge(itx: Integer(omp[:blockNumber]), iax: add) } end + # @param add (see Apibc#norml_es) + # @param [Array<Hash>] ary lista blocks events + # @return [Array<Hash>] lista blocks events filtrada + def filtrar_px(add, ary) + # adiciona chave indice itx & adiciona identificador da carteira iax + ary.map { |omp| omp.merge(itx: Integer(omp[:blockNumber]), iax: add) } + end + # @return [Array<Hash>] lista ordenada transacoes normais novas def sortx novtx.sort { |ant, prx| ant[:itx] <=> prx[:itx] } + end + + # @return [Array<Hash>] lista ordenada transacoes internas novas + def sorix + novix.sort { |ant, prx| ant[:itx] <=> prx[:itx] } + end + + # @return [Array<Hash>] lista ordenada transacoes block novas + def sorpx + novpx.sort { |ant, prx| ant[:itx] <=> prx[:itx] } end # @return [Array<Hash>] lista ordenada transacoes token novas def sorkx novkx.sort { |ant, prx| ant[:itx] <=> prx[:itx] }