delete config file
This commit is contained in:
parent
982d14a469
commit
ddd5b13945
|
@ -1,2 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
src/config.json
|
config.json
|
4
app.js
4
app.js
|
@ -4,6 +4,8 @@ const ETH = require("./src/chain/eth")
|
||||||
const eth = new ETH()
|
const eth = new ETH()
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
const port = process.argv[2] || 12345
|
const port = process.argv[2] || 12345
|
||||||
|
|
||||||
app.get("/", (req, res) =>{
|
app.get("/", (req, res) =>{
|
||||||
|
@ -15,7 +17,7 @@ app.post("/checkPayment/eth", async(req, res) =>{
|
||||||
let result
|
let result
|
||||||
switch (coin) {
|
switch (coin) {
|
||||||
case "eth":
|
case "eth":
|
||||||
// 校验eth
|
result = await eth.checkETHPaymentStatus(address, amount, ts)
|
||||||
break
|
break
|
||||||
case "usdt":
|
case "usdt":
|
||||||
result = await eth.checkUSDTPaymentStatus(address, amount, ts)
|
result = await eth.checkUSDTPaymentStatus(address, amount, ts)
|
||||||
|
|
13
config.json
13
config.json
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"nodesUrl": {
|
|
||||||
"ETH": {
|
|
||||||
"url":"https://api.etherscan.io/v2/api",
|
|
||||||
"key":"2KKTKZ8MSG6DNUPQ4K9JVWPQ4H33DSUQA3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"abiPath": {
|
|
||||||
"usdt_erc20_abi": "./src/abi/erc20usdt.json",
|
|
||||||
"usdc_erc20_abi": "./src/abi/erc20usdc.json",
|
|
||||||
"usdt_trc20_abi": "./src/abi/trc20usdt.json"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -79,6 +79,49 @@ class ETH {
|
||||||
// return result;
|
// return result;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
async checkETHPaymentStatus(address, amount, ts) {
|
||||||
|
const url = `${app.ethNodeUrl}
|
||||||
|
?chainid=1
|
||||||
|
&module=account
|
||||||
|
&action=txlist
|
||||||
|
&address=${address}
|
||||||
|
&startblock=0
|
||||||
|
&endblock=99999999
|
||||||
|
&page=1
|
||||||
|
&offset=100
|
||||||
|
&sort=desc
|
||||||
|
&apikey=${this.#key}`
|
||||||
|
try {
|
||||||
|
const response = await axios.get(url)
|
||||||
|
const transactions = response.data.result
|
||||||
|
if (!Array.isArray(transactions) || transactions.length === 0) {
|
||||||
|
return { code: -1, result: false, data: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 筛选时间戳 >= ts 的交易
|
||||||
|
const afterTimestampTxs = transactions.filter(tx => parseInt(tx.timeStamp) >= ts);
|
||||||
|
|
||||||
|
if (afterTimestampTxs.length === 0) {
|
||||||
|
return { code: -1, result: false, data: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 筛选出金额等于指定值的交易(ETH 最小单位是 18 位)
|
||||||
|
const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 10 ** 18 === amount && address === tx.to);
|
||||||
|
if (matchedTxs.length === 0) {
|
||||||
|
return { code: -1, result: false, data: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: 0,
|
||||||
|
result: true,
|
||||||
|
data: matchedTxs.length === 1 ? matchedTxs[0] : matchedTxs,
|
||||||
|
};
|
||||||
|
} catch (error){
|
||||||
|
console.error("Error fetching transactions:", error);
|
||||||
|
return {code:-1, result: false, data:[]};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async checkUSDTPaymentStatus(address, amount, ts){
|
async checkUSDTPaymentStatus(address, amount, ts){
|
||||||
const url = `${app.ethNodeUrl}
|
const url = `${app.ethNodeUrl}
|
||||||
?chainid=1
|
?chainid=1
|
||||||
|
@ -108,7 +151,7 @@ class ETH {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 筛选出金额等于指定值的交易(USDT 最小单位是 6 位)
|
// 筛选出金额等于指定值的交易(USDT 最小单位是 6 位)
|
||||||
const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 1_000_000 === amount && tx.functionName === "transfer(address _to, uint256 _value)");
|
const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 1_000_000 === amount && tx.functionName === "transfer(address _to, uint256 _value)" && address === tx.to);
|
||||||
|
|
||||||
if (matchedTxs.length === 0) {
|
if (matchedTxs.length === 0) {
|
||||||
return { code: -1, result: false, data: [] };
|
return { code: -1, result: false, data: [] };
|
||||||
|
@ -154,7 +197,7 @@ class ETH {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 筛选出金额等于指定值的交易(USDT 最小单位是 6 位)
|
// 筛选出金额等于指定值的交易(USDT 最小单位是 6 位)
|
||||||
const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 1_000_000 === amount && tx.functionName === "transfer(address _to, uint256 _value)");
|
const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 1_000_000 === amount && tx.functionName === "transfer(address _to, uint256 _value)" && address === tx.to);
|
||||||
|
|
||||||
if (matchedTxs.length === 0) {
|
if (matchedTxs.length === 0) {
|
||||||
return { code: -1, result: false, data: [] };
|
return { code: -1, result: false, data: [] };
|
||||||
|
|
Loading…
Reference in New Issue