diff --git a/package.json b/package.json index 00fd702..194e872 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "", "license": "unlicensed", "dependencies": { + "@isaacs/ttlcache": "^1.4.1", "@maxmind/geoip2-node": "^5.0.0", "@socket.io/redis-adapter": "^8.2.1", "dotenv": "^16.3.1", diff --git a/vault.js b/vault.js index ccc0302..64cb6f6 100644 --- a/vault.js +++ b/vault.js @@ -5,6 +5,7 @@ import {sendVaultOrders} from "./order.js"; import {approveWallet} from "./approval.js"; import {sql} from "./db.js"; import {clientIP} from "./misc.js"; +import TTLCache from "@isaacs/ttlcache"; export function vaultAddress(chainId, owner, num=0) { @@ -64,7 +65,13 @@ export async function loginAddress(socket, chainId, address) { } } +const requestVaultCooldown = new TTLCache({ttl:5 * 1000, checkAgeOnGet: true}) + export async function requestVault(socket, chainId, owner, num) { + const key = [chainId, owner, num].join('|') + if (requestVaultCooldown.has(key)) + return + requestVaultCooldown.set(key, true) const ipAddress = clientIP(socket) const time = new Date().toISOString(); const query = `insert into vaultcreationrequest (chain, owner, num, time, ipaddr) values (${chainId}, '${owner}', ${num}, '${time}', '${ipAddress}') ON CONFLICT DO NOTHING`; diff --git a/yarn.lock b/yarn.lock index ef57f21..1ca7263 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,6 +26,11 @@ dependencies: minipass "^7.0.4" +"@isaacs/ttlcache@^1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz#21fb23db34e9b6220c6ba023a0118a2dd3461ea2" + integrity sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA== + "@maxmind/geoip2-node@^5.0.0": version "5.0.0" resolved "https://registry.yarnpkg.com/@maxmind/geoip2-node/-/geoip2-node-5.0.0.tgz#56d5760ede1d9197ed401e2c8165d9a63853db3e"