diff --git a/app.js b/app.js new file mode 100644 index 0000000..340f3b3 --- /dev/null +++ b/app.js @@ -0,0 +1,35 @@ +const express = require("express") +const ETH = require("./src/chain/eth") + +const eth = new ETH() + +const app = express() +const port = process.argv[2] || 12345 + +app.get("/", (req, res) =>{ + res.send("connect success") +}) + +app.post("/checkPayment/eth", async(req, res) =>{ + const {coin, address, amount, ts} = req.body + let result + switch (coin) { + case "eth": + // 校验eth + break + case "usdt": + result = await eth.checkUSDTPaymentStatus(address, amount, ts) + break + case "usdc": + result = await eth.checkUSDCPaymentStatus(address, amount, ts) + break + default: + result = {code:-2, result:false, data:[]} + break + } + res.send(JSON.stringify(result)) +}) + +app.listen(port, () =>{ + console.log(`Balance Server Start At http://127.0.0.1:${port}`); +}) \ No newline at end of file diff --git a/src/abi/erc20usdc.json b/src/abi/erc20usdc.json new file mode 100644 index 0000000..7f5844e --- /dev/null +++ b/src/abi/erc20usdc.json @@ -0,0 +1,948 @@ +[{ + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + }], + "name": "Approval", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "authorizer", + "type": "address" + }, { + "indexed": true, + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + }], + "name": "AuthorizationCanceled", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "authorizer", + "type": "address" + }, { + "indexed": true, + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + }], + "name": "AuthorizationUsed", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "_account", + "type": "address" + }], + "name": "Blacklisted", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "newBlacklister", + "type": "address" + }], + "name": "BlacklisterChanged", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "burner", + "type": "address" + }, { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }], + "name": "Burn", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "newMasterMinter", + "type": "address" + }], + "name": "MasterMinterChanged", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "minter", + "type": "address" + }, { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }], + "name": "Mint", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "minter", + "type": "address" + }, { + "indexed": false, + "internalType": "uint256", + "name": "minterAllowedAmount", + "type": "uint256" + }], + "name": "MinterConfigured", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "oldMinter", + "type": "address" + }], + "name": "MinterRemoved", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": false, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, { + "indexed": false, + "internalType": "address", + "name": "newOwner", + "type": "address" + }], + "name": "OwnershipTransferred", + "type": "event" +}, { + "anonymous": false, + "inputs": [], + "name": "Pause", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + }], + "name": "PauserChanged", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "newRescuer", + "type": "address" + }], + "name": "RescuerChanged", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + }], + "name": "Transfer", + "type": "event" +}, { + "anonymous": false, + "inputs": [{ + "indexed": true, + "internalType": "address", + "name": "_account", + "type": "address" + }], + "name": "UnBlacklisted", + "type": "event" +}, { + "anonymous": false, + "inputs": [], + "name": "Unpause", + "type": "event" +}, { + "inputs": [], + "name": "CANCEL_AUTHORIZATION_TYPEHASH", + "outputs": [{ + "internalType": "bytes32", + "name": "", + "type": "bytes32" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ + "internalType": "bytes32", + "name": "", + "type": "bytes32" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [{ + "internalType": "bytes32", + "name": "", + "type": "bytes32" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "RECEIVE_WITH_AUTHORIZATION_TYPEHASH", + "outputs": [{ + "internalType": "bytes32", + "name": "", + "type": "bytes32" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "TRANSFER_WITH_AUTHORIZATION_TYPEHASH", + "outputs": [{ + "internalType": "bytes32", + "name": "", + "type": "bytes32" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "owner", + "type": "address" + }, { + "internalType": "address", + "name": "spender", + "type": "address" + }], + "name": "allowance", + "outputs": [{ + "internalType": "uint256", + "name": "", + "type": "uint256" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "spender", + "type": "address" + }, { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }], + "name": "approve", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "authorizer", + "type": "address" + }, { + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + }], + "name": "authorizationState", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "account", + "type": "address" + }], + "name": "balanceOf", + "outputs": [{ + "internalType": "uint256", + "name": "", + "type": "uint256" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_account", + "type": "address" + }], + "name": "blacklist", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "blacklister", + "outputs": [{ + "internalType": "address", + "name": "", + "type": "address" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "authorizer", + "type": "address" + }, { + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + }, { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + }], + "name": "cancelAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "minter", + "type": "address" + }, { + "internalType": "uint256", + "name": "minterAllowedAmount", + "type": "uint256" + }], + "name": "configureMinter", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "currency", + "outputs": [{ + "internalType": "string", + "name": "", + "type": "string" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "decimals", + "outputs": [{ + "internalType": "uint8", + "name": "", + "type": "uint8" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "spender", + "type": "address" + }, { + "internalType": "uint256", + "name": "decrement", + "type": "uint256" + }], + "name": "decreaseAllowance", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "spender", + "type": "address" + }, { + "internalType": "uint256", + "name": "increment", + "type": "uint256" + }], + "name": "increaseAllowance", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "string", + "name": "tokenName", + "type": "string" + }, { + "internalType": "string", + "name": "tokenSymbol", + "type": "string" + }, { + "internalType": "string", + "name": "tokenCurrency", + "type": "string" + }, { + "internalType": "uint8", + "name": "tokenDecimals", + "type": "uint8" + }, { + "internalType": "address", + "name": "newMasterMinter", + "type": "address" + }, { + "internalType": "address", + "name": "newPauser", + "type": "address" + }, { + "internalType": "address", + "name": "newBlacklister", + "type": "address" + }, { + "internalType": "address", + "name": "newOwner", + "type": "address" + }], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "string", + "name": "newName", + "type": "string" + }], + "name": "initializeV2", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "lostAndFound", + "type": "address" + }], + "name": "initializeV2_1", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_account", + "type": "address" + }], + "name": "isBlacklisted", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "account", + "type": "address" + }], + "name": "isMinter", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "masterMinter", + "outputs": [{ + "internalType": "address", + "name": "", + "type": "address" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_to", + "type": "address" + }, { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }], + "name": "mint", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "minter", + "type": "address" + }], + "name": "minterAllowance", + "outputs": [{ + "internalType": "uint256", + "name": "", + "type": "uint256" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "name", + "outputs": [{ + "internalType": "string", + "name": "", + "type": "string" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "owner", + "type": "address" + }], + "name": "nonces", + "outputs": [{ + "internalType": "uint256", + "name": "", + "type": "uint256" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "owner", + "outputs": [{ + "internalType": "address", + "name": "", + "type": "address" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "paused", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "pauser", + "outputs": [{ + "internalType": "address", + "name": "", + "type": "address" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "owner", + "type": "address" + }, { + "internalType": "address", + "name": "spender", + "type": "address" + }, { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + }], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "from", + "type": "address" + }, { + "internalType": "address", + "name": "to", + "type": "address" + }, { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, { + "internalType": "uint256", + "name": "validAfter", + "type": "uint256" + }, { + "internalType": "uint256", + "name": "validBefore", + "type": "uint256" + }, { + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + }, { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + }], + "name": "receiveWithAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "minter", + "type": "address" + }], + "name": "removeMinter", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "contract IERC20", + "name": "tokenContract", + "type": "address" + }, { + "internalType": "address", + "name": "to", + "type": "address" + }, { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }], + "name": "rescueERC20", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "rescuer", + "outputs": [{ + "internalType": "address", + "name": "", + "type": "address" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "symbol", + "outputs": [{ + "internalType": "string", + "name": "", + "type": "string" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "totalSupply", + "outputs": [{ + "internalType": "uint256", + "name": "", + "type": "uint256" + }], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "to", + "type": "address" + }, { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }], + "name": "transfer", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "from", + "type": "address" + }, { + "internalType": "address", + "name": "to", + "type": "address" + }, { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }], + "name": "transferFrom", + "outputs": [{ + "internalType": "bool", + "name": "", + "type": "bool" + }], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "newOwner", + "type": "address" + }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "from", + "type": "address" + }, { + "internalType": "address", + "name": "to", + "type": "address" + }, { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, { + "internalType": "uint256", + "name": "validAfter", + "type": "uint256" + }, { + "internalType": "uint256", + "name": "validBefore", + "type": "uint256" + }, { + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + }, { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + }], + "name": "transferWithAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_account", + "type": "address" + }], + "name": "unBlacklist", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_newBlacklister", + "type": "address" + }], + "name": "updateBlacklister", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_newMasterMinter", + "type": "address" + }], + "name": "updateMasterMinter", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "_newPauser", + "type": "address" + }], + "name": "updatePauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{ + "internalType": "address", + "name": "newRescuer", + "type": "address" + }], + "name": "updateRescuer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "version", + "outputs": [{ + "internalType": "string", + "name": "", + "type": "string" + }], + "stateMutability": "view", + "type": "function" +}] \ No newline at end of file diff --git a/src/abi/erc20usdt.json b/src/abi/erc20usdt.json new file mode 100644 index 0000000..96214de --- /dev/null +++ b/src/abi/erc20usdt.json @@ -0,0 +1,390 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_upgradedAddress", "type": "address" }], + "name": "deprecate", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_value", "type": "uint256" } + ], + "name": "approve", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "deprecated", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_evilUser", "type": "address" }], + "name": "addBlackList", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_from", "type": "address" }, + { "name": "_to", "type": "address" }, + { "name": "_value", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "upgradedAddress", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "", "type": "address" }], + "name": "balances", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "maximumFee", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "_totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "unpause", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_maker", "type": "address" }], + "name": "getBlackListStatus", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "", "type": "address" }, + { "name": "", "type": "address" } + ], + "name": "allowed", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "paused", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "who", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "pause", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getOwner", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_to", "type": "address" }, + { "name": "_value", "type": "uint256" } + ], + "name": "transfer", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "newBasisPoints", "type": "uint256" }, + { "name": "newMaxFee", "type": "uint256" } + ], + "name": "setParams", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "amount", "type": "uint256" }], + "name": "issue", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "amount", "type": "uint256" }], + "name": "redeem", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "_owner", "type": "address" }, + { "name": "_spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "name": "remaining", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "basisPointsRate", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "", "type": "address" }], + "name": "isBlackListed", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_clearedUser", "type": "address" }], + "name": "removeBlackList", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_UINT", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_blackListedUser", "type": "address" }], + "name": "destroyBlackFunds", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "name": "_initialSupply", "type": "uint256" }, + { "name": "_name", "type": "string" }, + { "name": "_symbol", "type": "string" }, + { "name": "_decimals", "type": "uint256" } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }], + "name": "Issue", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }], + "name": "Redeem", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "newAddress", "type": "address" }], + "name": "Deprecate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "name": "feeBasisPoints", "type": "uint256" }, + { "indexed": false, "name": "maxFee", "type": "uint256" } + ], + "name": "Params", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "name": "_blackListedUser", "type": "address" }, + { "indexed": false, "name": "_balance", "type": "uint256" } + ], + "name": "DestroyedBlackFunds", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "_user", "type": "address" }], + "name": "AddedBlackList", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "_user", "type": "address" }], + "name": "RemovedBlackList", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "owner", "type": "address" }, + { "indexed": true, "name": "spender", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "from", "type": "address" }, + { "indexed": true, "name": "to", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "Pause", "type": "event" }, + { "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" } +] \ No newline at end of file diff --git a/src/abi/trc20usdt.json b/src/abi/trc20usdt.json new file mode 100644 index 0000000..3fdb0b5 --- /dev/null +++ b/src/abi/trc20usdt.json @@ -0,0 +1,412 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_upgradedAddress", "type": "address" }], + "name": "deprecate", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_value", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "deprecated", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_evilUser", "type": "address" }], + "name": "addBlackList", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_from", "type": "address" }, + { "name": "_to", "type": "address" }, + { "name": "_value", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "upgradedAddress", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "maximumFee", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "_totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "unpause", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_maker", "type": "address" }], + "name": "getBlackListStatus", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "paused", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_subtractedValue", "type": "uint256" } + ], + "name": "decreaseApproval", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "who", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_value", "type": "uint256" }], + "name": "calcFee", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "pause", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_to", "type": "address" }, + { "name": "_value", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "who", "type": "address" }], + "name": "oldBalanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "newBasisPoints", "type": "uint256" }, + { "name": "newMaxFee", "type": "uint256" } + ], + "name": "setParams", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "amount", "type": "uint256" }], + "name": "issue", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_addedValue", "type": "uint256" } + ], + "name": "increaseApproval", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "amount", "type": "uint256" }], + "name": "redeem", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "_owner", "type": "address" }, + { "name": "_spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "name": "remaining", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "basisPointsRate", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "", "type": "address" }], + "name": "isBlackListed", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_clearedUser", "type": "address" }], + "name": "removeBlackList", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_UINT", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_blackListedUser", "type": "address" }], + "name": "destroyBlackFunds", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "name": "_initialSupply", "type": "uint256" }, + { "name": "_name", "type": "string" }, + { "name": "_symbol", "type": "string" }, + { "name": "_decimals", "type": "uint8" } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_blackListedUser", "type": "address" }, + { "indexed": false, "name": "_balance", "type": "uint256" } + ], + "name": "DestroyedBlackFunds", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }], + "name": "Issue", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }], + "name": "Redeem", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "newAddress", "type": "address" }], + "name": "Deprecate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "name": "_user", "type": "address" }], + "name": "AddedBlackList", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "name": "_user", "type": "address" }], + "name": "RemovedBlackList", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "name": "feeBasisPoints", "type": "uint256" }, + { "indexed": false, "name": "maxFee", "type": "uint256" } + ], + "name": "Params", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "Pause", "type": "event" }, + { "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "previousOwner", "type": "address" }, + { "indexed": true, "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "owner", "type": "address" }, + { "indexed": true, "name": "spender", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "from", "type": "address" }, + { "indexed": true, "name": "to", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + } + ] + \ No newline at end of file diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..6a327a2 --- /dev/null +++ b/src/app.js @@ -0,0 +1,32 @@ +const fs = require("fs") + +function loadConfig() { + const configPath = "./config.json"; + if (!fs.existsSync(configPath)) { + throw new Error("Configuration file not found: " + configPath); + } + const configContent = fs.readFileSync(configPath, "utf-8"); + if (!configContent) { + throw new Error("Configuration file is empty: " + configPath); + } + try { + return JSON.parse(configContent); + } catch (error) { + throw new Error("Error parsing configuration file: " + error.message); + } +} + +class App { + constructor(){ + const config = loadConfig(); + this.ethNodeUrl = config.nodesUrl.ETH + const usdterc20_abi = JSON.parse(fs.readFileSync(config.abiPath.usdt_erc20_abi, "utf-8")); + const usdcerc20_abi = JSON.parse(fs.readFileSync(config.abiPath.usdc_erc20_abi, "utf-8")); + const usdttrc20_abi = JSON.parse(fs.readFileSync(config.abiPath.usdt_trc20_abi, "utf-8")); + this.abis = {usdcerc20_abi, usdterc20_abi, usdttrc20_abi}; + } +} + +const app = new App(); + +module.exports = app; \ No newline at end of file diff --git a/src/chain/eth.js b/src/chain/eth.js new file mode 100644 index 0000000..151cebd --- /dev/null +++ b/src/chain/eth.js @@ -0,0 +1,174 @@ +const app = require("../app"); +const abiDecoder = require("abi-decoder"); +const Web3 = require("web3"); +const axios = require("axios"); + +class ETH { + #key = "2KKTKZ8MSG6DNUPQ4K9JVWPQ4H33DSUQA3" + constructor(){ + const apiUrl = app.ethNodeUrl + const usdt_abi = app.abis.usdterc20_abi; + const usdc_abi = app.abis.usdcerc20_abi; + this.web3 = new Web3(new Web3.providers.HttpProvider(apiUrl)); + abiDecoder.addABI(usdt_abi); + abiDecoder.addABI(usdc_abi); + this.decoder = abiDecoder; + } + + decodeInput(input){ + try{ + return this.decoder.decodeMethod(input); + } catch (error) { + console.error("Error decoding input data:", error); + return null; + } + } + + async decodeTxInput(txHash) { + try{ + const tx = await this.web3.eth.getTransaction(txHash); + if (!tx || !tx.input) { + console.error("Transaction not found or has no input data."); + return null; + } + return this.decodeInput(tx.input); + } catch (error) { + console.error("Error decoding transaction input:", error); + return null; + } + } + + decodeUSDT(input){ + const decoded = this.decodeInput(input) + const result = [] + if (decoded && decoded.name === "transfer") { + for (let item of decoded.params) { + const obj = {} + if (item.name === "_to") { + obj.toAddress = item.value; + } + if (item.name === "_value") { + obj.amount = this.web3.utils.fromWei(item.value, "ether"); + } + if (Object.keys(obj).length > 0) { + result.push(obj); + } + } + } + return result; + } + + decodeUSDC(input){ + const decoded = this.decodeInput(input) + const result = [] + if (decoded && decoded.name === "transfer") { + for (let item of decoded.params) { + const obj = {} + if (item.name === "to") { + obj.toAddress = item.value; + } + if (item.name === "value") { + obj.amount = this.web3.utils.fromWei(item.value, "mwei"); + } + if (Object.keys(obj).length > 0) { + result.push(obj); + } + } + } + return result; + } + + async checkUSDTPaymentStatus(address, amount, ts){ + const url = `${app.ethNodeUrl} + ?chainid=1 + &module=account + &action=tokentx + &contractaddress=0xdAC17F958D2ee523a2206206994597C13D831ec7 + &address=${address} + &page=1 + &offset=100 + &startblock=0 + &endblock=27025780 + &sort=asc + &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: [] }; + } + + // 筛选出金额等于指定值的交易(USDT 最小单位是 6 位) + const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 1_000_000 === amount && tx.functionName === "transfer(address _to, uint256 _value)"); + + 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 checkUSDCPaymentStatus(address, amount, ts) { + const url = `${app.ethNodeUrl} + ?chainid=1 + &module=account + &action=tokentx + &contractaddress=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 + &address=${address} + &page=1 + &offset=100 + &startblock=0 + &endblock=27025780 + &sort=asc + &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: [] }; + } + + // 筛选出金额等于指定值的交易(USDT 最小单位是 6 位) + const matchedTxs = afterTimestampTxs.filter(tx => parseFloat(tx.value) / 1_000_000 === amount && tx.functionName === "transfer(address _to, uint256 _value)"); + + 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:[]}; + } + } +} + +module.exports = ETH \ No newline at end of file diff --git a/src/config.json b/src/config.json new file mode 100644 index 0000000..9152086 --- /dev/null +++ b/src/config.json @@ -0,0 +1,10 @@ +{ + "nodesUrl": { + "ETH": "https://api.etherscan.io/v2/api" + }, + "abiPath": { + "usdt_erc20_abi": "./abi/erc20usdt.json", + "usdc_erc20_abi": "./abi/erc20usdc.json", + "usdt_trc20_abi": "./abi/trc20usdt.json" + } +} \ No newline at end of file diff --git a/wallet b/wallet new file mode 160000 index 0000000..94bd816 --- /dev/null +++ b/wallet @@ -0,0 +1 @@ +Subproject commit 94bd816ecb424138d5fcf99f568505ec9d466d08