Commit d3fcbbbb authored by Kevin Liu's avatar Kevin Liu

Make Eth node configurable for backend

This way it can be run with the Truffle development node as well! And,
the faucet can actually be tested locally.
parent ccf9028d
Pipeline #1983 failed with stages
in 14 minutes and 50 seconds
......@@ -8,6 +8,7 @@ services:
environment:
REACT_APP_DELPHUS_BACKEND: http://localhost:3001
REACT_APP_ETHEREUM_NODE_ENDPOINT: http://localhost:9545
REACT_APP_IPFS_NODE_ENDPOINT: http://localhost:5001
volumes:
- .:/usr/src/app
ports:
......@@ -16,6 +17,8 @@ services:
image: node:12
entrypoint: /usr/src/app/docker/backend-entrypoint.sh
user: ${CURRENT_UID}
environment:
ETHEREUM_NODE_ENDPOINT: http://contracts:9545
volumes:
- .:/usr/src/app
ports:
......
......@@ -4,11 +4,12 @@
"private": true,
"scripts": {
"start": "nodemon -e ts -w ./src -x ts-node-script --files src/index.ts",
"start:dev": "cross-env MNEMONIC=\"inhale angle debate vibrant switch stairs describe pink climb domain snake actual phrase tongue hub\" SMTP=smtp://invalid:25 APP_SECRET=01234567 yarn start",
"start:dev": "cross-env MNEMONIC=\"dust amateur unfold twice offer now chair easily local half shock awesome\" SMTP=smtp://invalid:25 APP_SECRET=01234567 yarn start",
"build": "tsc",
"migration:make": "knex migrate:make -x ts"
},
"dependencies": {
"@types/cors": "^2.8.6",
"@types/express": "^4.16.0",
"@types/express-winston": "^3.0.3",
"@types/express-ws": "^3.0.0",
......@@ -19,6 +20,7 @@
"@types/request-promise": "^4.1.44",
"@types/ws": "^6.0.1",
"cookie-parser": "~1.4.3",
"cors": "^2.8.5",
"debug": "~2.6.9",
"dotenv": "^8.2.0",
"ethers": "^4.0.47",
......
import { ethers } from "ethers";
export const provider = ethers.getDefaultProvider("kovan");
export const provider = process.env.ETHEREUM_NODE_ENDPOINT
? new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_NODE_ENDPOINT)
: ethers.getDefaultProvider("kovan");
......@@ -3,6 +3,7 @@
import express from "express";
import expressWinston from "express-winston";
import { logger } from "./logger";
import cors from "cors";
const app = express();
......@@ -11,6 +12,24 @@ app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.raw({ type: "application/octet-stream", limit: "10mb" }));
const allowedOrigins = ["http://localhost:3000", "https://delph.us"];
app.use(
cors({
origin: (origin, callback) => {
// allow requests with no origin
// (like mobile apps or curl requests)
if (!origin) return callback(null, true);
if (allowedOrigins.indexOf(origin) === -1) {
const msg =
"The CORS policy for this site does not " +
"allow access from the specified Origin.";
return callback(new Error(msg), false);
}
return callback(null, true);
},
})
);
if (process.env.APP_SECRET === undefined) {
throw new Error("Must set APP_SECRET");
}
......
......@@ -17,6 +17,7 @@ if (mnemonic === undefined) {
const wallet = ethers.Wallet.fromMnemonic(mnemonic).connect(provider);
(async () => {
logger.info("Using Ethereum wallet with address " + wallet.address);
logger.info("Provider: " + (await provider.getNetwork()).name);
logger.info(
"Current balance: " +
ethers.utils.formatEther(await wallet.getBalance()) +
......
{
"mnemonic": "dust amateur unfold twice offer now chair easily local half shock awesome"
}
......@@ -8,8 +8,8 @@
"private": true,
"scripts": {
"build": "truffle compile",
"migrate": "truffle migrate",
"develop": "truffle develop",
"migrate": "env XDG_CONFIG_HOME=\"$(pwd)/config\" truffle migrate",
"develop": "env XDG_CONFIG_HOME=\"$(pwd)/config\" truffle develop",
"postinstall": "mkdirp build && cp --force --update maker_artifacts/*.json build/",
"test": "truffle test"
},
......
export const DISCORD_INVITE = "https://discord.gg/Xst7TR3";
export const IPFS_NODE_ENDPOINT = {
host: "ipfs-api-auth.scintillating.us",
port: 443,
protocol: "https",
};
export const IPFS_NODE_ENDPOINT =
process.env.REACT_APP_IPFS_NODE_ENDPOINT ??
"https://ipfs-api-auth.scintillating.us";
export const IPFS_GATEWAY = "https://ipfs.scintillating.us";
export const INFO_EMAIL_HREF = "mailto:info@scintillating.us";
......
......@@ -3569,6 +3569,13 @@
dependencies:
"@types/node" "*"
"@types/cors@^2.8.6":
version "2.8.6"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.6.tgz#cfaab33c49c15b1ded32f235111ce9123009bd02"
integrity sha512-invOmosX0DqbpA+cE2yoHGUlF/blyf7nB0OGYBBiH27crcVm5NmFaZkLP4Ta1hGaesckCi5lVLlydNJCxkTOSg==
dependencies:
"@types/express" "*"
"@types/csv-parse@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@types/csv-parse/-/csv-parse-1.2.2.tgz#713486235759d615dc8e6a6a979170ada76701d5"
......@@ -7419,7 +7426,7 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
cors@^2.8.1:
cors@^2.8.1, cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
......@@ -19195,7 +19202,7 @@ react-dimensions@2.0.0-alpha2:
element-resize-event "^2.0.4"
lodash.debounce "^4.0.6"
react-dom@^16.13.0, react-dom@^16.3.3, react-dom@^16.8.6:
react-dom@^16.3.3, react-dom@^16.8.6:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
......@@ -19498,7 +19505,7 @@ react-transition-group@^4.4.1:
loose-envify "^1.4.0"
prop-types "^15.6.2"
react@^16.13.0, react@^16.3.1, react@^16.8.6:
react@^16.3.1, react@^16.8.6:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment