3 Commits
Author SHA1 Message Date
nabarunandShreerang Kale 39613f9ee3 Changes in faucet for shopify app (#4)
Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75)

Co-authored-by: Shreerang Kale <shreerangkale@gmail.com>
Reviewed-on: cerc-io/laconic-faucet#4
2024-10-28 07:19:50 +00:00
3649cfb2fa Update config with alnt token denom (#3)
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Co-authored-by: Shreerang Kale <shreerangkale@gmail.com>
Reviewed-on: cerc-io/laconic-faucet#3
Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
2024-07-30 11:40:36 +00:00
prathamesh fd27cd141c Add netcat installation in Dockerfile (#2)
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)

Reviewed-on: cerc-io/laconic-faucet#2
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-07-26 12:23:30 +00:00
3 changed files with 16 additions and 10 deletions
+2
View File
@@ -2,6 +2,8 @@ FROM node:20-bullseye
WORKDIR /app
RUN apt-get update && apt-get install -y netcat
# Copy the application code
COPY . .
+5 -4
View File
@@ -1,13 +1,14 @@
[upstream]
rpcEndpoint = "http://localhost:26657"
chainId = "laconic_9000-1"
denom = "photon"
denom = "alnt"
prefix = "laconic"
gasPrice = "0.01"
gasPrice = "1"
faucetKey = ""
[server]
port = 3000
transferAmount = 1000000
periodTransferLimit = 3000000
enableRateLimit=false
transferAmount = 10000000000 # 1 * 10^10 alnt
periodTransferLimit = 30000000000 # 3 * 10^10 alnt
dbDir = "db"
+9 -6
View File
@@ -25,6 +25,7 @@ interface Config {
},
server: {
port: number
enableRateLimit: boolean
transferAmount: string
periodTransferLimit: string
dbDir: string
@@ -44,7 +45,7 @@ async function main (): Promise<void> {
app.use(cors());
app.post('/faucet', async (req, res) => {
const { address: accountAddress } = req.body;
const { address: accountAddress, amount } = req.body;
if (!accountAddress) {
return res.status(400).json({ error: 'address is required' });
@@ -54,22 +55,24 @@ async function main (): Promise<void> {
return res.status(400).json({ error: 'invalid address' });
}
// Check rate limit
const now = Date.now();
const today = new Date(now).toISOString().split('T')[0];
const faucetStoreKey = `${accountAddress}:${today}`;
const amountSentToAddress = await faucetDataStore.get(faucetStoreKey) || '0';
if (BigInt(amountSentToAddress) + BigInt(config.server.transferAmount) > BigInt(config.server.periodTransferLimit)) {
return res.status(429).json({ error: 'Limit exceeded' });
if (config.server.enableRateLimit) {
// Check rate limit
if (BigInt(amountSentToAddress) + BigInt(amount) > BigInt(config.server.periodTransferLimit)) {
return res.status(429).json({ error: 'Limit exceeded' });
}
}
try {
const txHash = await sendTokens(config, accountAddress, String(config.server.transferAmount));
const txHash = await sendTokens(config, accountAddress, String(amount));
console.log(`Sent tokens to address: ${accountAddress}, txHash: ${txHash}`);
// Update rate limit
await faucetDataStore.set(faucetStoreKey, (BigInt(amountSentToAddress) + BigInt(config.server.transferAmount)).toString(), FAUCET_DATA_TTL);
config.server.enableRateLimit && await faucetDataStore.set(faucetStoreKey, (BigInt(amountSentToAddress) + BigInt(amount)).toString(), FAUCET_DATA_TTL);
res.json({ success: true, txHash });
} catch (error) {