Skip to content

Commit 5e450da

Browse files
authored
Merge branch 'develop' into master
2 parents 64ad5bc + 1632698 commit 5e450da

File tree

4 files changed

+93
-36
lines changed

4 files changed

+93
-36
lines changed

package-lock.json

+22-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"dotenv-flow": "3.2.0",
117117
"duckdb": "0.9.2",
118118
"ecpair": "2.1.0",
119-
"elliptic": "6.5.7",
119+
"elliptic": "6.6.0",
120120
"escape-goat": "3.0.0",
121121
"evt": "1.10.1",
122122
"express": "4.21.2",

src/api/routes/faucets.ts

+36-9
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,39 @@ export const FaucetRoutes: FastifyPluginAsync<
7474
preHandler: missingBtcConfigMiddleware,
7575
schema: {
7676
operationId: 'run_faucet_btc',
77-
summary: 'Add testnet BTC tokens to address',
78-
description: `Add 1 BTC token to the specified testnet BTC address.
77+
summary: 'Add regtest BTC tokens to address',
78+
description: `Add 0.01 BTC token to the specified regtest BTC address.
7979
80-
The endpoint returns the transaction ID, which you can use to view the transaction in a testnet Bitcoin block
80+
The endpoint returns the transaction ID, which you can use to view the transaction in a regtest Bitcoin block
8181
explorer. The tokens are delivered once the transaction has been included in a block.
8282
83-
**Note:** This is a testnet only endpoint. This endpoint will not work on the mainnet.`,
83+
**Note:** This is a Bitcoin regtest-only endpoint. This endpoint will not work on the Bitcoin mainnet.`,
8484
tags: ['Faucets'],
8585
querystring: Type.Object({
8686
address: Type.Optional(
8787
Type.String({
88-
description: 'A valid testnet BTC address',
88+
description: 'A valid regtest BTC address',
8989
examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'],
9090
})
9191
),
92+
large: Type.Optional(
93+
Type.Boolean({
94+
description: 'Request a large amount of regtest BTC than the default',
95+
default: false,
96+
})
97+
),
98+
xlarge: Type.Optional(
99+
Type.Boolean({
100+
description: 'Request an extra large amount of regtest BTC than the default',
101+
default: false,
102+
})
103+
),
92104
}),
93105
body: OptionalNullable(
94106
Type.Object({
95107
address: Type.Optional(
96108
Type.String({
97-
description: 'A valid testnet BTC address',
109+
description: 'A valid regtest BTC address',
98110
examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'],
99111
})
100112
),
@@ -112,7 +124,7 @@ export const FaucetRoutes: FastifyPluginAsync<
112124
{
113125
title: 'RunFaucetResponse',
114126
description:
115-
'POST request that initiates a transfer of tokens to a specified testnet address',
127+
'POST request that initiates a transfer of tokens to a specified Bitcoin regtest address',
116128
}
117129
),
118130
'4xx': Type.Object({
@@ -125,6 +137,21 @@ export const FaucetRoutes: FastifyPluginAsync<
125137
async (req, reply) => {
126138
await btcFaucetRequestQueue.add(async () => {
127139
const address = req.query.address || req.body?.address;
140+
let btcAmount = 0.0001;
141+
142+
if (req.query.large && req.query.xlarge) {
143+
return await reply.status(400).send({
144+
error: 'cannot simultaneously request a large and xlarge amount',
145+
success: false,
146+
});
147+
}
148+
149+
if (req.query.large) {
150+
btcAmount = 0.01;
151+
} else if (req.query.xlarge) {
152+
btcAmount = 0.5;
153+
}
154+
128155
if (!address) {
129156
return await reply.status(400).send({
130157
error: 'address required',
@@ -156,7 +183,7 @@ export const FaucetRoutes: FastifyPluginAsync<
156183
});
157184
}
158185

159-
const tx = await makeBtcFaucetPayment(btc.networks.regtest, address, 0.5);
186+
const tx = await makeBtcFaucetPayment(btc.networks.regtest, address, btcAmount);
160187
await fastify.writeDb?.insertFaucetRequest({
161188
ip: `${ip}`,
162189
address: address,
@@ -183,7 +210,7 @@ export const FaucetRoutes: FastifyPluginAsync<
183210
tags: ['Faucets'],
184211
params: Type.Object({
185212
address: Type.String({
186-
description: 'A valid testnet BTC address',
213+
description: 'A valid regtest BTC address',
187214
examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'],
188215
}),
189216
}),

tests/btc-faucet/faucet-btc.test.ts

+34
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,40 @@ describe('btc faucet', () => {
156156
`/extended/v1/faucets/btc/${addr}`
157157
);
158158
expect(balanceResponse.status).toBe(200);
159+
expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.0001 });
160+
});
161+
162+
test('faucet http balance endpoint large', async () => {
163+
const addr = getKeyAddress(ECPair.makeRandom({ network: regtest }));
164+
const response = await supertest(apiServer.server).post(
165+
`/extended/v1/faucets/btc?address=${addr}&large=true`
166+
);
167+
expect(response.status).toBe(200);
168+
await getRpcClient().generatetoaddress({
169+
address: getKeyAddress(ECPair.makeRandom({ network: regtest })),
170+
nblocks: 1,
171+
});
172+
const balanceResponse = await supertest(apiServer.server).get(
173+
`/extended/v1/faucets/btc/${addr}`
174+
);
175+
expect(balanceResponse.status).toBe(200);
176+
expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.01 });
177+
});
178+
179+
test('faucet http balance endpoint xlarge', async () => {
180+
const addr = getKeyAddress(ECPair.makeRandom({ network: regtest }));
181+
const response = await supertest(apiServer.server).post(
182+
`/extended/v1/faucets/btc?address=${addr}&xlarge=true`
183+
);
184+
expect(response.status).toBe(200);
185+
await getRpcClient().generatetoaddress({
186+
address: getKeyAddress(ECPair.makeRandom({ network: regtest })),
187+
nblocks: 1,
188+
});
189+
const balanceResponse = await supertest(apiServer.server).get(
190+
`/extended/v1/faucets/btc/${addr}`
191+
);
192+
expect(balanceResponse.status).toBe(200);
159193
expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.5 });
160194
});
161195

0 commit comments

Comments
 (0)