Last active
February 14, 2022 14:54
-
-
Save alxrz/3316c60537b65464cb1c4808e999273b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const fs = require('fs'); | |
const Web3 = require('web3'); | |
const abiDecoder = require('abi-decoder'); | |
const openseaAbi = require('./opensea-abi'); | |
const EtherscanApi = require('etherscan-api'); | |
const {Sequelize, DataTypes} = require('sequelize'); | |
/* | |
xeno | |
https://etherscan.io/tx/0x05a2ec6561336aaff7643a00a58d4e605b629dd6217c987cbbba41336c25a660 | |
token | |
1444 => 5A4 | |
*/ | |
/* | |
slotie | |
https://etherscan.io/tx/0xccd42022c77cc196b79982c6264585d68599901b591e83b7ecfb4567bad8e9cb | |
signature is the same as - xeno | |
*/ | |
const etherscanApiKey = '8BRU9PI2PYTGQ52XT7AUTRBJTFS4JYJX61'; | |
const etherscanApi = EtherscanApi.init(etherscanApiKey); | |
const web3 = new Web3(Web3.givenProvider || "ws://localhost:8545"); | |
abiDecoder.addABI(openseaAbi); | |
const xenoTxHash = '0x05a2ec6561336aaff7643a00a58d4e605b629dd6217c987cbbba41336c25a660'; | |
const slotieTxHash = '0xccd42022c77cc196b79982c6264585d68599901b591e83b7ecfb4567bad8e9cb'; | |
let transaction = etherscanApi.proxy.eth_getTransactionByHash(slotieTxHash); | |
// transaction.then((data) => { | |
// const input = data.result.input; | |
// console.log(getMethodDataBuyFromInput(input)); | |
// const decodedData = abiDecoder.decodeMethod(input); | |
// | |
// console.info(decodedData); | |
// | |
// const calldataBuy = getValueByParameterName(decodedData, 'calldataBuy'); | |
// printBytesByLine(calldataBuy); | |
// | |
// const calldataSell = getValueByParameterName(decodedData, 'calldataSell'); | |
// printBytesByLine(calldataSell); | |
// }); | |
function getMethodDataBuyFromInput(input) { | |
const decodedData = abiDecoder.decodeMethod(input); | |
const calldataBuy = getValueByParameterName(decodedData, 'calldataBuy'); | |
return getMethodFromInput(calldataBuy); | |
} | |
function getValueByParameterName(decodedData, paramName) { | |
for (const param of decodedData['params']) { | |
if (param.hasOwnProperty('name') && param['name'] == paramName) { | |
return param['value']; | |
} | |
} | |
} | |
function printBytesByLine(inp) { | |
const method = inp.slice(2, 10); | |
console.info(`Method: ${method}`); | |
let data = inp.substring(10); | |
var arr = data.split(/(?<=^(?:.{64})+)(?!$)/); | |
console.info(arr); | |
} | |
function getMethodFromInput(inp) { | |
if (inp != null && inp.length > 10 && inp.slice(0, 2) == '0x') { | |
return inp.slice(2, 10); | |
} | |
return null; | |
} | |
function queryDb() { | |
const dbURI = 'postgres://tsdbadmin:[email protected]:31687/tsdb'; | |
const sequelize = new Sequelize(dbURI, { | |
logging: console.log | |
}); | |
sequelize.query('SELECT hash, abi_input FROM os_transactions LIMIT 100000', { | |
type: sequelize.QueryTypes.SELECT | |
}).then((transactions) => { | |
console.log(transactions[0]); | |
let data = {}; | |
for (const transaction of transactions) { | |
let input = transaction.abi_input; | |
let method = getMethodDataBuyFromInput(input); | |
if (data.hasOwnProperty(method)) { | |
data[method] += 1; | |
} else { | |
data[method] = 1; | |
} | |
} | |
console.log(data); | |
}); | |
} | |
queryDb(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment