diff --git a/Dockerfile b/Dockerfile index ce7de56..7bd2568 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,17 @@ FROM node:18-alpine + +# install postgres and run databse +# RUN apk add postgresql +# RUN mkdir /run/postgresql +# RUN chown postgres:postgres /run/postgresql +# USER postgres +# RUN mkdir /var/lib/postgresql/data +# RUN chmod 0700 /var/lib/postgresql/data +# RUN initdb -D /var/lib/postgresql/data +# RUN pg_ctl start -D /var/lib/postgresql/data +# su postgres -c 'pg_ctl start -D /var/lib/postgresql/data'; + + WORKDIR /validator_dapp COPY package*.json ./ RUN npm install @@ -6,4 +19,8 @@ COPY . . RUN npx prisma generate RUN npm run build EXPOSE 3000 -CMD ["sh", "-c", "npx prisma migrate deploy && npm run start"] \ No newline at end of file +RUN chmod +x callApi.sh +RUN chmod 0644 crntab +COPY crntab /etc/crontabs/root +ENV DATABASE_URL="postgres://postgres:postgres@localhost:5432/postgres" +CMD ["sh", "-c", "npx prisma migrate deploy && npm run start && crond"] diff --git a/abis/ValidatorMetadataTest.abi.json b/abis/ValidatorMetadataTest.abi.json index 37843f6..b47e135 100644 --- a/abis/ValidatorMetadataTest.abi.json +++ b/abis/ValidatorMetadataTest.abi.json @@ -1,91 +1,91 @@ [ - { - "constant": false, - "inputs": [ - { - "name": "_firstName", - "type": "string" - }, - { - "name": "_lastName", - "type": "string" - }, - { - "name": "_contactEmail", - "type": "string" - }, - { - "name": "_researchInstitute", - "type": "string" - }, - { - "name": "_researchField", - "type": "string" - }, - { - "name": "_instituteAddress", - "type": "string" - } - ], - "name": "createMetadata", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "memberAddress", - "type": "address" - } - ], - "name": "CreatedMetadata", - "type": "event" - }, - { - "constant": true, - "inputs": [ - { - "name": "memberAddress", - "type": "address" - } - ], - "name": "validatorsMetadata", - "outputs": [ - { - "name": "firstName", - "type": "string" - }, - { - "name": "lastName", - "type": "string" - }, - { - "name": "contactEmail", - "type": "string" - }, - { - "name": "researchInstitute", - "type": "string" - }, - { - "name": "researchField", - "type": "string" - }, - { - "name": "instituteAddress", - "type": "string" - }, - { - "name": "sender", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } + { + "constant": false, + "inputs": [ + { + "name": "_firstName", + "type": "string" + }, + { + "name": "_lastName", + "type": "string" + }, + { + "name": "_contactEmail", + "type": "string" + }, + { + "name": "_researchInstitute", + "type": "string" + }, + { + "name": "_researchField", + "type": "string" + }, + { + "name": "_instituteAddress", + "type": "string" + } + ], + "name": "createMetadata", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "memberAddress", + "type": "address" + } + ], + "name": "CreatedMetadata", + "type": "event" + }, + { + "constant": true, + "inputs": [ + { + "name": "memberAddress", + "type": "address" + } + ], + "name": "validatorsMetadata", + "outputs": [ + { + "name": "firstName", + "type": "string" + }, + { + "name": "lastName", + "type": "string" + }, + { + "name": "contactEmail", + "type": "string" + }, + { + "name": "researchInstitute", + "type": "string" + }, + { + "name": "researchField", + "type": "string" + }, + { + "name": "instituteAddress", + "type": "string" + }, + { + "name": "sender", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } ] diff --git a/callApi.js b/callApi.js new file mode 100644 index 0000000..fb419c3 --- /dev/null +++ b/callApi.js @@ -0,0 +1,13 @@ +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; // Remove in production + +const axios = require('axios'); + +const callApi = async () => { + try { + const response = await axios.post('https://bloxberg-qa-traefik.mpdl.mpg.de/api/update-validators-details'); + } catch (error) { + console.log('Error calling API:', error); + } +}; + +callApi(); \ No newline at end of file diff --git a/callApi.sh b/callApi.sh new file mode 100644 index 0000000..e6772ac --- /dev/null +++ b/callApi.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/usr/local/bin/node /validator_dapp/callApi.js \ No newline at end of file diff --git a/crntab b/crntab new file mode 100644 index 0000000..e0e9330 --- /dev/null +++ b/crntab @@ -0,0 +1 @@ +*/5 * * * * /validator_dapp/callApi.sh 2>> /validator_dapp/logg.log \ No newline at end of file diff --git a/pages/inactiveValidators.js b/pages/inactiveValidators.js index 6d96572..74b3a5b 100644 --- a/pages/inactiveValidators.js +++ b/pages/inactiveValidators.js @@ -12,7 +12,7 @@ import { const inactiveValidators = ({ validators }) => { const [searchTerm, setSearchTerm] = useState(""); - const [isValidKey, setiIsValidKey] = useState(false); + // const [isValidKey, setiIsValidKey] = useState(false); useEffect(() => { if (checkEthereumExists()) { @@ -22,28 +22,24 @@ const inactiveValidators = ({ validators }) => { window.ethereum.on("chainChanged", () => { window.location.reload(); }); - getConnectedAccounts() - .then((value) => { - checkAccessKey(value).then((finalvalue) => { - setiIsValidKey(finalvalue); - }); - }) - .catch((err) => { - console.log(err); - }); + // getConnectedAccounts() + // .then((value) => { + // checkAccessKey(value).then((finalvalue) => { + // setiIsValidKey(finalvalue); + // }); + // }) + // .catch((err) => { + // console.log(err); + // }); } }, []); - return isValidKey ? ( + return (
{AllValidators({ validators, searchTerm })}
- ) : ( -
- -
- ); + ) }; export async function getServerSideProps() { diff --git a/pages/index.js b/pages/index.js index dcc952f..58457b7 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,7 +1,10 @@ +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; + import { useState } from "react"; import { AllValidators } from "@/components/AllValidators"; import { SearchBar } from "@/components/SearchBar"; import { prisma } from "../server/db/client"; +import axios from "axios"; export default function Home({ validators }) { const [searchTerm, setSearchTerm] = useState(""); @@ -21,7 +24,7 @@ export default function Home({ validators }) { export async function getServerSideProps() { // will always run on the server // newest first - const validators = await prisma.validators.findMany({ + let validators = await prisma.validators.findMany({ where: { active: true, }, @@ -29,6 +32,21 @@ export async function getServerSideProps() { users: true, }, }); + + if (validators.length == 0) { + await axios.post('https://bloxberg-qa-traefik.mpdl.mpg.de/api/save-validators-details'); + validators = await prisma.validators.findMany({ + where: { + active: true, + }, + include: { + users: true, + }, + }); + await axios.post('https://bloxberg-qa-traefik.mpdl.mpg.de/api/update-validators-details'); + } + // await axios.post('https://bloxberg-qa-traefik.mpdl.mpg.de/api/update-validators-details'); + return { props: { validators: JSON.parse(JSON.stringify(validators)), diff --git a/pages/setMetadata.js b/pages/setMetadata.js index 1c4ffe4..d9df4dd 100644 --- a/pages/setMetadata.js +++ b/pages/setMetadata.js @@ -8,6 +8,7 @@ import { checkMiningKey, getConnectedAccounts, checkAccessKey, + getMetadata, } from "../utils/contractData"; import Loading from "@/components/Loading"; @@ -90,12 +91,22 @@ const setmetadata = () => { window.ethereum.on("chainChanged", () => { window.location.reload(); }); + getConnectedAccounts() .then((value) => { setAccount(value); checkAccessKey(value).then((finalvalue) => { setiIsValidVotingKey(finalvalue); }); + getMetadata(value).then((output)=>{ + setFirstName(output.firstName); + setLastName(output.lastName); + setInstituteAddress(output.instituteAddress); + setContactEmail(output.contactEmail); + setResearchField(output.researchField); + setResearchInstitute(output.researchInstitute); + } + ) }) .catch((err) => { console.log(err); @@ -119,6 +130,8 @@ const setmetadata = () => { className="px-2 rounded drop-shadow-lg focus:outline-none focus:ring focus:ring-opacity-40 focus:ring-light-blue" id="first-name" onChange={({ target }) => setFirstName(target?.value)} + defaultValue={firstName} + type="text" required /> @@ -130,6 +143,8 @@ const setmetadata = () => { required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" onChange={({ target }) => setContactEmail(target?.value)} + defaultValue={contactEmail} + type="text" />
@@ -139,6 +154,8 @@ const setmetadata = () => { id="research-field" onChange={({ target }) => setResearchField(target?.value)} required + defaultValue={researchField} + type="text" />
@@ -150,6 +167,8 @@ const setmetadata = () => { id="last-name" onChange={({ target }) => setLastName(target?.value)} required + defaultValue={lastName} + type="text" />
@@ -159,6 +178,8 @@ const setmetadata = () => { id="institute-name" onChange={({ target }) => setResearchInstitute(target?.value)} required + defaultValue={researchInstitute} + type="text" />
@@ -168,6 +189,8 @@ const setmetadata = () => { id="institute-address" onChange={({ target }) => setInstituteAddress(target?.value)} required + defaultValue={instituteAddress} + type="text" />