Skip to content

Commit

Permalink
[NFT Mirror MystenLabs#666] Set up project skeleton for the Oracle se…
Browse files Browse the repository at this point in the history
…rver
  • Loading branch information
666lcz authored Mar 9, 2022
1 parent 94394ec commit 3a0bc1d
Show file tree
Hide file tree
Showing 22 changed files with 14,031 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nft_mirror/oracle_server/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set to production when deploying to production
NODE_ENV=development

# Node.js server configuration
SERVER_PORT=8000

# Alchemy API KEY. Please replace it with your own(https://dashboard.alchemyapi.io/)
ALCHEMY_API_KEY="demo"

# Sui Gateway endpoint
SUI_GATEWAY_ENDPOINT = "http://127.0.0.1:5000"
14 changes: 14 additions & 0 deletions nft_mirror/oracle_server/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"prettier/prettier": 2 // Means error
}
}
17 changes: 17 additions & 0 deletions nft_mirror/oracle_server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
9 changes: 9 additions & 0 deletions nft_mirror/oracle_server/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
coverage/
package-lock.json
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# open-api
gateway-generated-schema.ts
4 changes: 4 additions & 0 deletions nft_mirror/oracle_server/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"tabWidth": 4
}
66 changes: 66 additions & 0 deletions nft_mirror/oracle_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Sui Oracle Service

The oracle service is a trusted entity that faciliates the cross-chain airdrop of NFT tokens on Sui. This implementation is a MVP
version that's not indended for any production use. The service currently only supports the copying of Ethereum
ERC-721 token to Sui.

As shown in the graph below, the main job of the oracle is to validate the user ownership of the NFT, call the Airdrop contract to claim the token, and return the Sui explorer link of the newly minted NFT.

![user flow](./docs/flow.png 'User Flow')

## Get Started

1. Set up the `.env` file through `cp .env.sample .env`. Rememeber to replace any placeholder value(e.g., ALCHEMY_API_KEY).
2. Install the dependencies through `npm i`
3. Start the server through `npm run dev`
4. The easiest way to test out an endpoint is through [http://localhost:8000/docs](http://localhost:8000/docs) by clicking on "Try it out". No need to manually write curl command or example data.

## Useful Commands for Development

**Requirements**: Node 14.0.0 or later version

In the project directory, you can run:

### `npm i`

Before running any of the following scripts `npm i` must run in order to install the necessary dependencies.

### `npm run dev`

Runs the app in the development mode.\
Open [http://localhost:8000](http://localhost:8000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm run build`

Builds the app for production to the `build` folder.\
It bundles React in production mode and optimizes the build for the best performance.

### `npm run start`

Run the production version

### `npm run lint`

Run linting check (prettier/eslint/stylelint).

### `npm run lint:fix`

Run linting check but also try to fix any issues.

### `npm run prettier:fix:watch`

Run prettier in watch mode and format any file that changes. (Also runs prettier once in the beginning for all the files)\
It can be useful during development to format automatically all the files that change.

## Documentation

Swagger UI is available at [http://localhost:8000/docs](http://localhost:8000/docs). The UI will always show the latest documentation during development.

Aside from allowing developers to inspect the documentation, the Swagger UI also allows the developer to quickly test out the endpoint by clicking the "Try it out" button with pre-populated example data.

The syntax for documentation annotation can be found in the [tsoa docs](https://tsoa-community.github.io/docs/getting-started.html).

![swagger ui](./docs/swagger.png 'Swagger UI')
Binary file added nft_mirror/oracle_server/docs/flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nft_mirror/oracle_server/docs/swagger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3a0bc1d

Please sign in to comment.