Skip to content

Commit

Permalink
🔄 synced file(s) with circlefin/pw-sdk-nodejs-server-internal (#9)
Browse files Browse the repository at this point in the history
synced local file(s) with
[circlefin/pw-sdk-nodejs-server-internal](https://github.com/circlefin/pw-sdk-nodejs-server-internal).



<details>
<summary>Changed files</summary>
<ul>
<li>synced local <code>package.json</code> with remote
<code>package.json</code></li><li>synced local <code>yarn.lock</code>
with remote <code>yarn.lock</code></li><li>synced local directory
<code>src/</code> with remote directory <code>src/</code></li>
</ul>
</details>

---

This PR was created automatically by the
[repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action)
workflow run
[#9488780285](https://github.com/circlefin/pw-sdk-nodejs-server-internal/actions/runs/9488780285)
  • Loading branch information
heondokim committed Jun 21, 2024
2 parents 8ea10ca + 521488d commit e5f8ea6
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "@circle-fin",
"license": "ISC",
"dependencies": {
"@circle-fin/user-controlled-wallets": "^3.0.0",
"@circle-fin/user-controlled-wallets": "^4.0.0",
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.1",
Expand Down
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';
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@circle-fin/user-controlled-wallets@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@circle-fin/user-controlled-wallets/-/user-controlled-wallets-3.0.0.tgz#be0fb94f127828ee17d854db742e8792b063cc7f"
integrity sha512-uO+64680yC3nWVweMDIc8o2gSmh1oYn/ydXy3rMT232auyY/jPNbu6Ff2Luqrn+QIPIn19TNqmgguCAhXCmi+g==
"@circle-fin/user-controlled-wallets@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@circle-fin/user-controlled-wallets/-/user-controlled-wallets-4.0.0.tgz#6b7fc3b27ba69fa8ffbdc20259aeb256b5589d09"
integrity sha512-n7RKX2+XaqNLzgv60TSaKLZrU/O4jUcwd+pL9tvcIbuo3zuyPT0pVjws2QA3RODu5Y847km4HcAlfX61mUINSA==
dependencies:
axios "^1.6.2"

Expand Down

0 comments on commit e5f8ea6

Please sign in to comment.