Changes in faucet for shopify app #4
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
[server]
|
[server]
|
||||||
port = 3000
|
port = 3000
|
||||||
|
enableRateLimit=false
|
||||||
transferAmount = 10000000000 # 1 * 10^10 alnt
|
transferAmount = 10000000000 # 1 * 10^10 alnt
|
||||||
periodTransferLimit = 30000000000 # 3 * 10^10 alnt
|
periodTransferLimit = 30000000000 # 3 * 10^10 alnt
|
||||||
dbDir = "db"
|
dbDir = "db"
|
||||||
|
@ -13,7 +13,6 @@ import KeyvSqlite from '@keyv/sqlite';
|
|||||||
const CONFIG_PATH = 'environments/local.toml';
|
const CONFIG_PATH = 'environments/local.toml';
|
||||||
const FAUCET_DATA_FILE = 'faucet_data.sqlite';
|
const FAUCET_DATA_FILE = 'faucet_data.sqlite';
|
||||||
const FAUCET_DATA_TTL = 86400000; // 24 hrs
|
const FAUCET_DATA_TTL = 86400000; // 24 hrs
|
||||||
const DISABLE_RATE_LIMIT = true;
|
|
||||||
|
|
||||||
interface Config {
|
interface Config {
|
||||||
upstream: {
|
upstream: {
|
||||||
@ -26,6 +25,7 @@ interface Config {
|
|||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
port: number
|
port: number
|
||||||
|
enableRateLimit: boolean
|
||||||
transferAmount: string
|
transferAmount: string
|
||||||
periodTransferLimit: string
|
periodTransferLimit: string
|
||||||
dbDir: string
|
dbDir: string
|
||||||
@ -60,7 +60,7 @@ async function main (): Promise<void> {
|
|||||||
const faucetStoreKey = `${accountAddress}:${today}`;
|
const faucetStoreKey = `${accountAddress}:${today}`;
|
||||||
const amountSentToAddress = await faucetDataStore.get(faucetStoreKey) || '0';
|
const amountSentToAddress = await faucetDataStore.get(faucetStoreKey) || '0';
|
||||||
|
|
||||||
if (!DISABLE_RATE_LIMIT) {
|
if (config.server.enableRateLimit) {
|
||||||
// Check rate limit
|
// Check rate limit
|
||||||
if (BigInt(amountSentToAddress) + BigInt(amount) > BigInt(config.server.periodTransferLimit)) {
|
if (BigInt(amountSentToAddress) + BigInt(amount) > BigInt(config.server.periodTransferLimit)) {
|
||||||
return res.status(429).json({ error: 'Limit exceeded' });
|
return res.status(429).json({ error: 'Limit exceeded' });
|
||||||
@ -72,7 +72,7 @@ async function main (): Promise<void> {
|
|||||||
console.log(`Sent tokens to address: ${accountAddress}, txHash: ${txHash}`);
|
console.log(`Sent tokens to address: ${accountAddress}, txHash: ${txHash}`);
|
||||||
|
|
||||||
// Update rate limit
|
// Update rate limit
|
||||||
!DISABLE_RATE_LIMIT && await faucetDataStore.set(faucetStoreKey, (BigInt(amountSentToAddress) + BigInt(amount)).toString(), FAUCET_DATA_TTL);
|
config.server.enableRateLimit && await faucetDataStore.set(faucetStoreKey, (BigInt(amountSentToAddress) + BigInt(amount)).toString(), FAUCET_DATA_TTL);
|
||||||
|
|
||||||
res.json({ success: true, txHash });
|
res.json({ success: true, txHash });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user