const router = require('koa-router')() //导入 koa-router const moralis = require("../model/moralis_sdk") //导入 db.js // https://github.com/luin/ioredis#readme router.prefix('/denettest'); const BigNumber = require('bignumber.js') function calculate_total_usdprice(amount, decimals, usdprice) { return parseInt(amount) / (10 ** parseInt(decimals)) * parseFloat(usdprice); // var new_decimals = 15; // var pos = 0; // var new_amount = 0; // var new_amount_bint = 0; // if (parseInt(decimals) > new_decimals) { // pos = parseInt(decimals) - parseInt(decimals) % new_decimals // new_amount = amount.substring(0, pos+1) // new_amount_bint = parseInt(new_amount) // var scale_dec = parseInt((10 ** new_decimals)) // console.log('amount',amount) // console.log('pos',pos) // console.log('new_amount',new_amount) // console.log('new_amount_bint',new_amount_bint) // console.log('scale_dec',scale_dec) // console.log('usdprice',usdprice) // 1000000000000000 // 1000000000000000 // return new_amount_bint / scale_dec * parseInt(usdprice); // } else { // return BigInt(amount) / (10 ** BigInt(decimals) * BigInt(usdprice)); // } } /** * 获取交易记录 * @param {*} ctx */ async function getTransfers(ctx) { const obj = ctx.request.body; console.log("obj", obj); if (!obj.chain)//默认 bsc 币安链 obj.chain = 'bsc' var token_total_usdprice = calculate_total_usdprice('99999999999999999998', '18', 0.1); var data = { nonce: 118, gasPrice: { type: 'BigNumber', hex: '0x02540be400' }, gasLimit: { type: 'BigNumber', hex: '0x5208' }, to: '0x7C7401fcc82D1e53C4090561c3e6fde80d74e317', value: { type: 'BigNumber', hex: '0x039696f3392000' }, data: '0x', chainId: 97, v: 230, r: '0x075149b50e81da71aa72ee73d1b07e8df6fa2416b97133dc3e2dea19b4ed4c88', s: '0x7d8ac906b85275d63233e8f8ba6c0f5b860e9ebea1bc896346fe81824d9ec9c3', from: '0xAD48D13E77011cFE03fF19729B6A247847AfD28E', hash: '0xb9a75efb6a17325f2decaec9fba30fead7664c13a589fe0ccac02f791a7c84c8', type: null, confirmations: 0 } var curGasPrice = BigNumber(data.gasPrice.hex) var curGasLimit = BigNumber(data.gasLimit.hex) if(curGasLimit > 0) { console.log('curGasLimit', curGasLimit.toNumber()) } console.log('curGasPrice', curGasPrice.toNumber()) var a = parseInt('10000000000000000') var b = parseInt('100000000000000000') console.log(token_total_usdprice, a / b); // ctx.body = await moralis.collectCoins(obj); //提交归集任务 if (obj.address) { moralis.pushCollectConisObj(obj) } ctx.body = curGasPrice + '-' + curGasLimit; // await moralis.collectCoins(obj).then((result) => { // ctx.body = result; // }) } //获取交易记录 router.post('/getTransfers', getTransfers) async function crypto_test(ctx) { if (ctx.request == null || ctx.request.body == null) { ctx.body = utils.toJson(-1, null, "request error. "); return; } const obj = ctx.request.body; var crypt_key = obj.key; var message = obj.privateKey; //process.env.NODE_ENV console.log("NDK_HOME", process.env.NDK_HOME); var de_message = utils.decryptPrivityKey(crypt_key, message); console.log("decrypt message:", message); ctx.body = { decrypt: de_message } } router.post('/crypto_test', crypto_test) module.exports = router