Compare commits

..

No commits in common. "df646a2a8fe90bb4db098e29f94935ef63171762" and "88e397d197986c640db60efbe06cd480a723e731" have entirely different histories.

12 changed files with 22 additions and 92 deletions

View File

@ -1,9 +1,9 @@
{
"localhost": {
"DAO": "0x4774670f82A590e7eD6072bd7098836B06FFd8ce",
"Work1": "0xc72A4CF5499D0de850457C0d4C0a4b8071441C6f",
"Onboarding": "0xadB35d0E9d7B33441C7ED26add5D42F873430790",
"Proposals": "0xE9aa427d985aE50AdD10a3404bF7a1300fa9f667"
"DAO": "0x4C767e62c92b58B2308E02ba5Cc4A3BD246060ac",
"Work1": "0x39B7522Ee1A5B13aE5580C40114239D4cE0e7D29",
"Onboarding": "0xC0Bb36820Ba891DE4ed6D60f75066805361dbeB8",
"Proposals": "0x268A0A6bB80282542e0Be0864Cfa1c2206c5491F"
},
"sepolia": {
"DAO": "0x8e5bd58B2ca8910C5F9be8de847d6883B15c60d2",

View File

@ -15,7 +15,6 @@
"dotenv": "^16.4.5",
"ethers": "^6.12.0",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"level": "^8.0.1",
"object-hash": "^3.0.0"
},
@ -1814,14 +1813,6 @@
"node": ">= 0.10.0"
}
},
"node_modules/express-async-errors": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/express-async-errors/-/express-async-errors-3.1.1.tgz",
"integrity": "sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng==",
"peerDependencies": {
"express": "^4.16.2"
}
},
"node_modules/express/node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",

View File

@ -15,7 +15,6 @@
"dotenv": "^16.4.5",
"ethers": "^6.12.0",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"level": "^8.0.1",
"object-hash": "^3.0.0"
},

View File

@ -35,14 +35,12 @@ const getContract = (name) => new ethers.Contract(
DAOArtifact.abi,
signer,
);
const dao = getContract('DAO');
const fetchPaperInfo = async (paperId, retryDelay = 5000) => {
const url = `https://api.semanticscholar.org/graph/v1/paper/${paperId}?`
+ 'fields=title,url,authors,references.title,references.url,references.authors';
let retry = false;
let paper;
let requestError;
const response = await axios.get(url, {
headers: {
'api-key': process.env.SEMANTIC_SCHOLAR_API_KEY,
@ -54,11 +52,9 @@ const fetchPaperInfo = async (paperId, retryDelay = 5000) => {
return;
}
// Some other error occurred
requestError = error;
throw new Error(error);
});
if (requestError) {
throw requestError;
} else if (retry) {
if (retry) {
console.log('retry delay (sec):', retryDelay / 1000);
await new Promise((resolve) => {
setTimeout(resolve, retryDelay);
@ -142,6 +138,7 @@ HREF ${paper.url}`;
};
module.exports = async (req, res) => {
const dao = await getContract('DAO');
const {
body: {
paperId,
@ -155,10 +152,9 @@ module.exports = async (req, res) => {
console.log('references count:', paper.references.length);
const references = paper.references.filter((x) => !!x.paperId);
const eachCitationWeightPercent = Math.floor(PPM_TO_CITATIONS / references.length);
const eachCitationWeightPercent = Math.floor(PPM_TO_CITATIONS / paper.references.length);
const citations = await Promise.mapSeries(
references,
paper.references.filter((x) => !!x.paperId),
async (citedPaper) => {
// We need to fetch this paper so we can generate the post we WOULD add to the forum.
// That way, if we later add the cited paper to the blockchain it will have the correct hash.
@ -191,12 +187,12 @@ module.exports = async (req, res) => {
} catch (e) {
if (e.reason === 'A post with this contentId already exists') {
console.log(`Post already added for paper ${paperId}`);
res.json({ alreadyAdded: true, postId: hash });
res.status(204).end();
return;
}
throw e;
}
console.log(`Added post to blockchain for paper ${paperId}`);
res.json({ postId: hash });
res.status(201).end();
};

View File

@ -5,7 +5,6 @@ const write = require('./write');
const importFromSS = require('./import-from-ss');
require('dotenv').config();
require('express-async-errors');
const app = express();
const port = process.env.PORT || 3000;
@ -21,14 +20,6 @@ app.get('*', (req, res) => {
res.status(404).json({ errorCode: 404 });
});
app.use((err, req, res, next) => {
const status = err.response?.status ?? 500;
const message = err.response?.data?.error ?? err.message;
console.error(`error: ${message}`);
res.status(status).send(message);
next();
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});

View File

@ -23,6 +23,8 @@ module.exports = async (req, res) => {
authors, content, signature, embeddedData,
} = data;
console.log({ content, embeddedData });
// Verify hash
const derivedHash = objectHash({
authors, content, signature, embeddedData,

View File

@ -1,9 +1,9 @@
{
"localhost": {
"DAO": "0x4774670f82A590e7eD6072bd7098836B06FFd8ce",
"Work1": "0xc72A4CF5499D0de850457C0d4C0a4b8071441C6f",
"Onboarding": "0xadB35d0E9d7B33441C7ED26add5D42F873430790",
"Proposals": "0xE9aa427d985aE50AdD10a3404bF7a1300fa9f667"
"DAO": "0x4C767e62c92b58B2308E02ba5Cc4A3BD246060ac",
"Work1": "0x39B7522Ee1A5B13aE5580C40114239D4cE0e7D29",
"Onboarding": "0xC0Bb36820Ba891DE4ed6D60f75066805361dbeB8",
"Proposals": "0x268A0A6bB80282542e0Be0864Cfa1c2206c5491F"
},
"sepolia": {
"DAO": "0x8e5bd58B2ca8910C5F9be8de847d6883B15c60d2",

View File

@ -1,9 +1,9 @@
{
"localhost": {
"DAO": "0x4774670f82A590e7eD6072bd7098836B06FFd8ce",
"Work1": "0xc72A4CF5499D0de850457C0d4C0a4b8071441C6f",
"Onboarding": "0xadB35d0E9d7B33441C7ED26add5D42F873430790",
"Proposals": "0xE9aa427d985aE50AdD10a3404bF7a1300fa9f667"
"DAO": "0x4C767e62c92b58B2308E02ba5Cc4A3BD246060ac",
"Work1": "0x39B7522Ee1A5B13aE5580C40114239D4cE0e7D29",
"Onboarding": "0xC0Bb36820Ba891DE4ed6D60f75066805361dbeB8",
"Proposals": "0x268A0A6bB80282542e0Be0864Cfa1c2206c5491F"
},
"sepolia": {
"DAO": "0x8e5bd58B2ca8910C5F9be8de847d6883B15c60d2",

View File

@ -1,7 +1,3 @@
.post-content {
white-space: pre-line;
}
.input-paper-id {
width: 30em !important;
}

View File

@ -25,7 +25,6 @@ import AddPostModal from './components/posts/AddPostModal';
import ViewPostModal from './components/posts/ViewPostModal';
import Post from './utils/Post';
import Proposals from './components/Proposals';
import Import from './components/Import';
import getAddressName from './utils/get-address-name';
function App() {
@ -574,9 +573,6 @@ function App() {
<Tab eventKey="proposals" title="Proposals">
<Proposals />
</Tab>
<Tab eventKey="import" title="Import">
<Import />
</Tab>
</Tabs>
</>
)}

View File

@ -1,42 +0,0 @@
import { useState } from 'react';
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
import axios from 'axios';
function Import() {
const [paperId, setPaperId] = useState();
const [status, setStatus] = useState('');
const handleImport = async () => {
setStatus(`Importing paper ${paperId}...`);
const { data: { alreadyAdded, postId } } = await axios.post('/api/importFromSemanticScholar', { paperId })
.catch((error) => {
setStatus(`Error: ${error.response?.data ?? error.message}`);
});
if (alreadyAdded) {
setStatus(`Paper ${paperId} was already imported as post ${postId}`);
} else {
setStatus(`Imported paper ${paperId} as post ${postId}`);
}
};
return (
<>
<h1>Semantic Scholar Import</h1>
<Form>
<Form.Group controlId="SSImport.paperId">
<Form.Label>Paper ID</Form.Label>
<Form.Control
as="input"
className="input-paper-id mb-3"
onChange={(e) => setPaperId(e.target.value)}
/>
</Form.Group>
</Form>
<Button className="mb-2" onClick={handleImport}>Import</Button>
<p>{status}</p>
</>
);
}
export default Import;

View File

@ -1,4 +1,5 @@
import axios from 'axios';
// trailing slash is deliberate, to differentiate this package from the core node module
import { Buffer } from 'buffer';
import { recoverPersonalSignature } from '@metamask/eth-sig-util';
import objectHash from 'object-hash/dist/object_hash';