增加主动查询 api

This commit is contained in:
2026-02-03 15:05:06 +08:00
parent 922f6df4e8
commit 753bd4a4d6
6 changed files with 358 additions and 47 deletions

View File

@@ -34,11 +34,23 @@
</div>
<div class="section">
<h3>收款记录</h3>
<h3>收款记录(监听缓存)</h3>
<button onclick="getPayments()">刷新</button>
<div id="payments"></div>
</div>
<div class="section">
<h3>主动查询交易记录</h3>
<input type="text" id="queryAddress" placeholder="TRON 地址">
<input type="datetime-local" id="startTime" placeholder="开始时间">
<input type="datetime-local" id="endTime" placeholder="结束时间">
<input type="number" id="minAmount" placeholder="最小金额 (USDT)" step="0.01">
<input type="number" id="minConfirmations" placeholder="最小确认数" value="6">
<input type="number" id="queryLimit" placeholder="查询数量" value="50">
<button onclick="queryTransactions()">查询</button>
<div id="queryResults"></div>
</div>
<div class="section">
<h3>实时日志 (WebSocket)</h3>
<div id="log"></div>
@@ -113,7 +125,7 @@
data.data.payments.map(p =>
'<tr><td>' + new Date(p.Timestamp).toLocaleString() + '</td>' +
'<td>' + p.Address.substring(0, 10) + '...</td>' +
'<td>' + (p.Amount / 1000000).toFixed(6) + ' USDT</td>' +
'<td>' + p.Amount.toFixed(6) + ' USDT</td>' +
'<td>' + p.From.substring(0, 10) + '...</td>' +
'<td>' + p.Confirmations + '</td>' +
'<td><a href="https://tronscan.org/#/transaction/' + p.TxID + '" target="_blank">' +
@@ -125,6 +137,52 @@
}
}
async function queryTransactions() {
const address = document.getElementById('queryAddress').value.trim();
if (!address) {
alert('请输入地址');
return;
}
const startTime = document.getElementById('startTime').value;
const endTime = document.getElementById('endTime').value;
const minAmount = document.getElementById('minAmount').value;
const minConfirmations = document.getElementById('minConfirmations').value;
const limit = document.getElementById('queryLimit').value;
const body = {
address: address,
startTime: startTime ? new Date(startTime).getTime() : 0,
endTime: endTime ? new Date(endTime).getTime() : 0,
minAmount: minAmount ? (parseFloat(minAmount) * 1000000).toString() : '',
minConfirmations: parseInt(minConfirmations) || 0,
limit: parseInt(limit) || 50,
};
const res = await fetch('/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
const data = await res.json();
if (data.success && data.data.payments && data.data.payments.length > 0) {
const html = '<div class="success">找到 ' + data.data.count + ' 条记录</div>' +
'<table><tr><th>时间</th><th>金额</th><th>来源</th><th>确认数</th><th>TxID</th></tr>' +
data.data.payments.map(p =>
'<tr><td>' + new Date(p.Timestamp).toLocaleString() + '</td>' +
'<td>' + p.Amount.toFixed(6) + ' USDT</td>' +
'<td>' + p.From.substring(0, 10) + '...</td>' +
'<td>' + p.Confirmations + '</td>' +
'<td><a href="https://tronscan.org/#/transaction/' + p.TxID + '" target="_blank">' +
p.TxID.substring(0, 10) + '...</a></td></tr>'
).join('') + '</table>';
document.getElementById('queryResults').innerHTML = html;
} else {
document.getElementById('queryResults').innerHTML = '<div class="error">' + (data.message || '未找到记录') + '</div>';
}
}
listAddresses();
getPayments();
</script>