import index from './index.js' let DataUtil = { transactionData: function(type, dataType, address, contract, pageNum, pageSize, success) { console.log(type, dataType, address, contract, pageNum, pageSize, 1111) switch (type) { case 'BTC': success([]); break; case 'ETH': this.ethTransactionData(contract, dataType, address, pageNum, pageSize, success); break; case 'TRX': this.trxTransactionData(contract, dataType, address, pageNum, pageSize, success); break; } }, ethTransactionData: function(contract, dataType, address, pageNum, pageSize, success) { let dataList = []; if (!contract) { uni.request({ url: 'http://scan.weirui0755.com/eth/api/eth/address/normal/' + address + '/' + pageNum + '/' + pageSize, //请求接口 header: { 'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息 }, success: (res) => { console.log(res, 1234654) if (res.data.code === 1) { var data = res.data.data; for (let i = 0; i < data.length; i++) { if (!data[i].toAlias) { debugger; if ((data[i].from != address && dataType == 'send') || (data[i] .to != address && dataType == 'receive')) { continue; } var transactionData = { value: data[i].value, from: data[i].from, to: data[i].to, fee: data[i].fee, txid: data[i].txid, confirmations: data[i].confirmations, block_no: data[i].block_no, time: index.formatyymmddhhmmss33(data[i].time * 1000) } if (data[i].from === address) { let address = data[i].to; address = address.substring(0, 6) + '...' + address.substring( 25, address.length) transactionData.address = address; transactionData.type = 'out'; } else { let address = data[i].from; address = address.substring(0, 6) + '...' + address.substring( 25, address.length) transactionData.address = address; transactionData.type = 'in'; } dataList.push(transactionData) } } } success(dataList) }, error: (res) => { success(dataList) } }); } else { uni.request({ url: 'http://scan.weirui0755.com/eth/api/eth/address/tokentrans/' + address + '/' + contract + '/' + pageNum + '/' + pageSize, //请求接口 header: { 'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息 }, success: (res) => { console.log(res, 1234654) if (res.data.code === 1) { var data = res.data.data; for (let i = 0; i < data.length; i++) { if (!data[i].toAlias) { if ((data[i].from != address && dataType == 'send') || (data[i] .to != address && dataType == 'receive')) { continue; } var transactionData = { value: data[i].value / Math.pow(10, data[i].tokenDecimals), from: data[i].from, to: data[i].to, txid: data[i].txid, fee: data[i].fee, confirmations: data[i].conformations, block_no: data[i].block_no, time: index.formatyymmddhhmmss33(data[i].time * 1000) } if (data[i].from === address) { let address = data[i].to; address = address.substring(0, 6) + '...' + address.substring( 36, address.length) transactionData.address = address; transactionData.type = 'out'; } else { let address = data[i].from; address = address.substring(0, 6) + '...' + address.substring( 36, address.length) transactionData.address = address; transactionData.type = 'in'; } dataList.push(transactionData) } } } success(dataList) } }); } } , trxTransactionData: function(contract, dataType, address, pageNum, pageSize, success) { let dataList = []; let add = address if (contract == null || contract == '') { uni.request({ url: 'http://scan.weirui0755.com/trx/api/trx/address/normal/' + address + '/' + pageNum + '/' + pageSize, //请求接口 header: { 'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息 }, success: (res) => { console.log(res.data.code) if (res.data.code === 1) { var data = res.data.data; for (let i = 0; i < data.length; i++) { if ((data[i].from != add && dataType == 'send') || (data[i] .to != add && dataType == 'receive') || data[i].tType != 'Transfer') { continue; } var transactionData = { value: data[i].value, from: data[i].from, to: data[i].to, fee: data[i].fee, txid: data[i].txid, confirmations: data[i].confirmations, block_no: data[i].block_no, time: index.formatyymmddhhmmss33(data[i].time * 1000) } if (data[i].from === address) { var address = data[i].to address = address.substring(0, 6) + '...' + address.substring(36, address.length); transactionData.address = address; transactionData.type = 'out'; } else { var address = data[i].from address = address.substring(0, 6) + '...' + address.substring(36, address.length); transactionData.address = address; transactionData.type = 'in'; } console.log(transactionData.address, 123456) dataList.push(transactionData) } } success(dataList) } }); } else { uni.request({ url: 'http://scan.weirui0755.com/trx/api/trx/address/tokentrans/' + address + '/' + contract + '/' + pageNum + '/' + pageSize, //请求接口 header: { 'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息 }, success: (res) => { console.log(res, 12346545555) console.log(dataType, 5555555555) if (res.data.code === 1) { var data = res.data.data; for (let i = 0; i < data.length; i++) { console.log(!data[i].toAlias, 5555555555,data[i].to == add) if ((data[i].to == add && dataType == 'send') || (data[i] .from == add && dataType == 'receive')) { continue; } var transactionData = { value: data[i].value / Math.pow(10, data[i].tokenDecimals), from: data[i].from, to: data[i].to, txid: data[i].txid, fee: data[i].fee, confirmations: data[i].conformations, block_no: data[i].block_no, time: index.formatyymmddhhmmss33(data[i].time * 1000) } if (data[i].from === address) { var address = data[i].to address = address.substring(0, 6) + '...' + address.substring( 25, address.length); transactionData.address = address; transactionData.type = 'out'; } else { var address = data[i].from address = address.substring(0, 6) + '...' + address.substring( 25, address.length); transactionData.address = address; transactionData.type = 'in'; } dataList.push(transactionData) } } success(dataList) } }); } } } export default DataUtil