Skip to content

Commit

Permalink
🔄 synced local 'src/' with remote 'src/'
Browse files Browse the repository at this point in the history
  • Loading branch information
circle-github-action-bot committed Jun 12, 2024
1 parent 3966359 commit 521488d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
tokens as tokensRouter,
wallets as walletsRouter,
transactions as transactionsRouter,
authTransRouter
authTransRouter,
faucet as faucetRouter
} from './routers';

export const app: Express = express();
Expand Down Expand Up @@ -91,6 +92,7 @@ app.use('/users', usersRouter, authUserRouter);
app.use('/tokens', tokensRouter);
app.use('/wallets', authMiddleware, walletsRouter);
app.use('/transactions', transactionsRouter, authTransRouter);
app.use('/faucet', authMiddleware, faucetRouter);

// Error handling
app.use(errorHandler);
36 changes: 36 additions & 0 deletions src/controllers/faucet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { NextFunction, Request, Response } from 'express';
import { circleUserSdk } from '../services';

export const dripFaucet = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
await circleUserSdk.requestTestnetTokens({
address: req.body.address,
blockchain: req.body.blockchain,
usdc: true
});

res.status(200).send();
} catch (error: unknown) {
next(error);
}
};
1 change: 1 addition & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './onboarding';
export * from './wallets';
export * from './transactions';
export * from './tokens';
export * from './faucet';
1 change: 1 addition & 0 deletions src/controllers/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const signInCallback = (req: Request, res: Response) =>
res.sendStatus(401);
return;
}

// valid credentials
const tokenResponse = await circleUserSdk.createUserToken({
userId: user.userId
Expand Down
11 changes: 11 additions & 0 deletions src/middleware/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,14 @@ export const getTokenDetailsSchema = yup.object({
.noUnknown(true)
.strict()
});

// Faucet
export const postFaucetDripSchema = yup.object({
body: yup
.object({
address: yup.string().required(),
blockchain: yup.string().required()
})
.noUnknown(true)
.strict()
});
36 changes: 36 additions & 0 deletions src/routers/faucet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import express from 'express';
import { postFaucetDripSchema, validate } from '../middleware';
import { dripFaucet } from '../controllers';

const faucet = express.Router();

/**
* POST - /faucet/drips
* Request testnet tokens to specified wallet.
*
* Params:
* address: string - Wallet address
* blockchain: string - Specified blockchain
*
* Returns: null
*
*/
faucet.post('/drips', validate(postFaucetDripSchema), dripFaucet);

export { faucet };
1 change: 1 addition & 0 deletions src/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './transactions';
export * from './wallets';
export * from './tokens';
export * from './users';
export * from './faucet';

0 comments on commit 521488d

Please sign in to comment.