/*内部交易*/------------

CREATE TABLE `internal_txlist` (
`blockNumber` varchar(255) DEFAULT NULL,
`tx_timeStamp` varchar(255) DEFAULT NULL,
`hash` varchar(255) DEFAULT NULL,
`tx_from` varchar(255) DEFAULT NULL,
`tx_to` varchar(255) DEFAULT NULL,
`tx_value` varchar(255) DEFAULT NULL,
`contractAddress` varchar(255) DEFAULT NULL,
`input` varchar(255) DEFAULT NULL,
`type` varchar(255) DEFAULT NULL,
`gas` varchar(255) DEFAULT NULL,
`gasUsed` varchar(255) DEFAULT NULL,
`traceId` varchar(255) DEFAULT NULL,
`isError` varchar(255) DEFAULT NULL,
`errCode` varchar(255) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 /*正常交易*/------------
CREATE TABLE `txlist` (
`address` varchar(255) DEFAULT NULL,
`tx_type` varchar(100) DEFAULT NULL,
`blockNumber` varchar(255) DEFAULT NULL,
`tx_timeStamp` varchar(255) DEFAULT NULL,
`hash` varchar(255) DEFAULT NULL,
`nonce` varchar(255) DEFAULT NULL,
`blockHash` varchar(255) DEFAULT NULL,
`transactionIndex` varchar(255) DEFAULT NULL,
`tx_from` varchar(255) DEFAULT NULL,
`tx_to` varchar(255) DEFAULT NULL,
`tx_value` varchar(255) DEFAULT NULL,
`gas` varchar(255) DEFAULT NULL,
`gasPrice` varchar(255) DEFAULT NULL,
`isError` varchar(255) DEFAULT NULL,
`txreceipt_status` varchar(255) DEFAULT NULL,
`input` varchar(255) DEFAULT NULL,
`contractAddress` varchar(255) DEFAULT NULL,
`cumulativeGasUsed` varchar(255) DEFAULT NULL,
`gasUsed` varchar(255) DEFAULT NULL,
`confirmations` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 /*基本数据统计* 粗略统计,详细数据需要查eth签名库识别出哪些是mint nft操作/ SELECT * FROM (
SELECT address,CONVERT((SUM(tx_value)/ POWER(10,18)),DECIMAL(10,3)) total_eth,CONVERT((SUM(gasPrice*gasUsed)/ POWER(10,18)),DECIMAL(10,3)) gas_eth,COUNT(1) num, 'all' tx_type FROM txlist WHERE 1=1 GROUP BY address
UNION ALL
SELECT address,CONVERT((SUM(tx_value)/ POWER(10,18)),DECIMAL(10,3)) total_eth,CONVERT((SUM(gasPrice*gasUsed)/ POWER(10,18)),DECIMAL(10,3)) gas_eth,COUNT(1) num, 'in' tx_type FROM txlist WHERE tx_to = address AND input = '0x' GROUP BY address
UNION ALL
SELECT address,CONVERT((SUM(tx_value)/ POWER(10,18)),DECIMAL(10,3)) total_eth,CONVERT((SUM(gasPrice*gasUsed)/ POWER(10,18)),DECIMAL(10,3)) gas_eth,COUNT(1) num, 'out' tx_type FROM txlist WHERE tx_from = address AND input = '0x' GROUP BY address
UNION ALL
SELECT address,CONVERT((SUM(tx_value)/ POWER(10,18)),DECIMAL(10,3)) total_eth,CONVERT((SUM(gasPrice*gasUsed)/ POWER(10,18)),DECIMAL(10,3)) gas_eth,COUNT(1) num, 'free_call' tx_type FROM txlist WHERE tx_from = address AND input != '0x' AND tx_value=0 GROUP BY address
UNION ALL
SELECT address,CONVERT((SUM(tx_value)/ POWER(10,18)),DECIMAL(10,3)) total_eth,CONVERT((SUM(gasPrice*gasUsed)/ POWER(10,18)),DECIMAL(10,3)) gas_eth,COUNT(1) num, 'eth_call' tx_type FROM txlist WHERE tx_from = address AND input != '0x' AND tx_value!=0 GROUP BY address
) A WHERE 1=1 AND address = '0xc0ac56cf556b41da25354cc0199200bf36f79ccc'

  

/*内部交易简单统计 统计内部交易获利eth数量,粗略统计  详细获利需要筛选 from:

opensea:0x7f268357A8c2552623316e2562D90e642bB538E5等 或者来源是x2y2等nft交易平台

*/
SELECT A.address,A.total_eth,A.total, CONVERT((A.total_eth/A.total) , DECIMAL(10,6)) avg_sell FROM (
SELECT
address,
SUM(tx_value)/POWER(10, 18) total_eth,
COUNT(1) total FROM
internal_txlist
WHERE 1=1 AND address = '0xc0ac56cf556b41da25354cc0199200bf36f79ccc' GROUP BY address ) A ORDER BY avg_sell DESC

  

#coding=utf-8
import requests
import time
import json
import math
import datetime
from requests.packages.urllib3 import disable_warnings
from selenium_chrome.MySqlUtils import getMysql
from termcolor import colored
disable_warnings()
#正常交易数据
if __name__ == '__main__':
select_sql = "SELECT address,COUNT(1) num ,SUM(balance) total FROM nft_analytics WHERE time_type = '1d' GROUP BY address ORDER BY COUNT(1) DESC, SUM(balance) DESC LIMIT 100;"
mysql = getMysql()
sql_rep = mysql.select_db(select_sql)
num = 0
for one in sql_rep:
try:
address = one['address']
print(colored(address,'green'))
tx_url = f'https://api.etherscan.io/api?module=account&action=txlist&address={address}&startblock=0&endblock=99999999&page=1&offset=10000&sort=asc&apikey=65AM1ATEMHUTF1KAY454C1KWIY9I7JXG1K'
txlist_resp = requests.get(tx_url,timeout=60,verify=False)
if txlist_resp.status_code == 200 :
resp = json.loads(txlist_resp.text)
if resp['message'] == 'OK':
for tx in resp['result']:
'''
"blockNumber": "14903204",
"timeStamp": "1654344938",
"hash": "0x9888d4c16e3bb9265730c93f1fd08bf0254816c6ce4d335469943632d4445908",
"nonce": "0",
"blockHash": "0x710051cfa3bb48c7eabdf53b92fe4b0dc857f7659adb53f2345a41f16b0ad97e",
"transactionIndex": "21",
"from": "0x51cb9c51e003d5b885f2446a048d664b91f44d6c",
"to": "0x56197a6ef508d6cb6b24dc2afd6d594b4260e2a7",
"value": "80000000000000000",
"gas": "21000",
"gasPrice": "32294834880",
"isError": "0",
"txreceipt_status": "1",
"input": "0x",
"contractAddress": "",
"cumulativeGasUsed": "1407082",
"gasUsed": "21000",
"confirmations": "50652"
'''
values = {}
values['blockNumber'] = tx['blockNumber']
values['timeStamp'] = tx['timeStamp']
values['hash'] = tx['hash']
values['nonce'] = tx['nonce']
values['blockHash'] = tx['blockHash']
values['transactionIndex'] = tx['transactionIndex']
values['from'] = tx['from']
values['to'] = tx['to']
values['value'] = tx['value']
values['gas'] = tx['gas']
values['gasPrice'] = tx['gasPrice']
values['isError'] = tx['isError']
values['txreceipt_status'] = tx['txreceipt_status']
values['input'] = tx['input'][0:10]
values['contractAddress'] = tx['contractAddress']
values['cumulativeGasUsed'] = tx['cumulativeGasUsed']
values['gasUsed'] = tx['gasUsed']
values['confirmations'] = tx['confirmations']
values['address'] = address
values_list = []
values_str = ''
for k in values:
v = values[k]
values_list.append(f"'{v}'")
if values_list:
values_str = ','.join(values_list)
insert_sql = f'insert into txlist (blockNumber,tx_timeStamp,hash,nonce,blockHash,transactionIndex,tx_from,tx_to,tx_value,gas,gasPrice,isError,txreceipt_status,input,contractAddress,cumulativeGasUsed,gasUsed,confirmations,address) values ({values_str})'
mysql.execute_db(insert_sql)
num+=1
print(colored(str(num)+':数据获取完成!!!','red'))
except BaseException as e:
print(e)

  

#coding=utf-8
import requests
import time
import json
import math
import datetime
from requests.packages.urllib3 import disable_warnings
from selenium_chrome.MySqlUtils import getMysql
from termcolor import colored
disable_warnings()
#内部交易数据
if __name__ == '__main__':
select_sql = "SELECT address,COUNT(1) num ,SUM(balance) total FROM nft_analytics WHERE time_type = '1d' GROUP BY address ORDER BY COUNT(1) DESC, SUM(balance) DESC LIMIT 100;"
mysql = getMysql()
sql_rep = mysql.select_db(select_sql)
num = 0
for one in sql_rep:
try:
address = one['address']
print(colored(address,'green'))
tx_url = f'https://api.etherscan.io/api?module=account&action=txlistinternal&address={address}&startblock=0&endblock=99999999&page=1&offset=10000&sort=asc&apikey=65AM1ATEMHUTF1KAY454C1KWIY9I7JXG1K'
txlist_resp = requests.get(tx_url,timeout=60,verify=False)
if txlist_resp.status_code == 200 :
resp = json.loads(txlist_resp.text)
if resp['message'] == 'OK':
for tx in resp['result']:
'''
"blockNumber": "14909063",
"timeStamp": "1654431441",
"hash": "0x7f70c67f0f892cb96c168f44eaf942af241434315822e909e2490e1c47585787",
"from": "0x7f268357a8c2552623316e2562d90e642bb538e5",
"to": "0x51cb9c51e003d5b885f2446a048d664b91f44d6c",
"value": "9081000000000000",
"contractAddress": "",
"input": "",
"type": "call",
"gas": "2300",
"gasUsed": "0",
"traceId": "7_2",
"isError": "0",
"errCode": ""
'''
values = {}
values['blockNumber'] = tx['blockNumber']
values['timeStamp'] = tx['timeStamp']
values['hash'] = tx['hash']
values['from'] = tx['from']
values['to'] = tx['to']
values['value'] = tx['value']
values['contractAddress'] = tx['contractAddress']
values['input'] = tx['input'][0:10]
values['type'] = tx['type']
values['gas'] = tx['gas']
values['gasUsed'] = tx['gasUsed']
values['traceId'] = tx['traceId']
values['isError'] = tx['isError']
values['errCode'] = tx['errCode']
values['address'] = address
values_list = []
values_str = ''
for k in values:
v = values[k]
values_list.append(f"'{v}'")
if values_list:
values_str = ','.join(values_list)
insert_sql = f'insert into internal_txlist (blockNumber,tx_timeStamp,hash,tx_from,tx_to,tx_value,contractAddress,input,type,gas,gasUsed,traceId,isError,errCode,address) values ({values_str})'
mysql.execute_db(insert_sql)
num+=1
print(colored(str(num)+':数据获取完成!!!','red'))
except BaseException as e:
print(e)

  

  

最新文章

  1. 从OOP的角度看Golang
  2. python opencv 利用Lab空间把春天的场景改为秋天
  3. HTML5 – 2.新元素
  4. AJAX回调(调用后台方法返回数据)
  5. POJ3169 Layout
  6. javascript prototype 剖析
  7. string与数值之间的转换
  8. A9.linux驱动
  9. centos7/RHEL7安装LibreOffice
  10. html file选中图片后 不经过服务器 立刻显示在页面
  11. ng指令控制一个元素的影藏的与显示几种方法的使用
  12. cURL模拟网页登陆
  13. [福大软工] W班 软件产品案例分析
  14. 倒影问题(reflect:below)
  15. SSIS使用事务回滚
  16. Ansible安装 入门教程
  17. 随机森林学习-sklearn
  18. 动态生成PictureBox控件,涉及:PictureBox控件和flowLayoutPanel面板
  19. PCL常见错误集锦
  20. Css3帧动画深入探寻,讲点项目中实际会碰到的问题

热门文章

  1. vscode开发vue3+ts环境搭建
  2. 2022-05-06内部群每日三题-清辉PMP
  3. allure安装配置
  4. npm发布和修改详细教程
  5. Blockchain for Edge of Things: Applications, Opportunities, and Challenges
  6. Spring @aspect
  7. Java基础学习:6、方法的重载和可变参数
  8. oracle导出csv文件后导入mysql
  9. oracle job的使用
  10. 51电子-STC89C51开发板:使用KEIL编译汇编代码