Commit 4b86a5bf authored by Quentin Bramas's avatar Quentin Bramas
Browse files

clean up structure

parent 62601f17
......@@ -7,8 +7,8 @@ if(process.argv.length < 4)
}
const web3 = require('src/web3');
const createOrLoadAccount = require('src/createOrLoadAccount');
const web3 = require('common/web3');
const createOrLoadAccount = require('cli/createOrLoadAccount');
let account = createOrLoadAccount(process.argv[2] || '.defaultAccount');
......@@ -18,7 +18,7 @@ web3.eth.accounts.wallet.add(account);
console.log('account: '+account.address)
const commands = require('src/commands');
const commands = require('common/commands');
const command = process.argv[3];
if(!commands[command])
{
......
const web3 = require('../web3');
//const fs = require('fs');
const contractAbi = require('../contract/paperBlock2.sol.abi.json');
let contract = new web3.eth.Contract(contractAbi, {
from: web3.eth.defaultAccount,
gasPrice: web3.utils.toWei('50', 'gwei')
});
console.log('web3.utils.toWei',web3.utils.toWei('50', 'gwei'))
console.log('from', web3.eth.defaultAccount)
// chain2
contract.options.address = '0xC3CafB1A1d2e7898d19d0188b615dF5aF089010e';
module.exports.setFrom = (addr) => {
contract.options.from = addr;
console.log('contract set from:',addr)
}
const contractOwner = module.exports.contractOwner = async (journalAdr) => {
try{
const resp2 = await web3.eth.getStorageAt(contract.options.address);
console.log(resp2);
const resp = await contract.methods.chairperson().call();
return resp;
} catch (e) {
console.log('ERROR', e);
}
}
const journal = module.exports.journal = async (journalAdr) => {
try{
const resp = await contract.methods.journals(journalAdr).call();
return resp
} catch (e) {
console.log('ERROR', e);
}
}
const createJournal = module.exports.createJournal = async () => {
try{
const gasEstimate = await contract.methods.createJournal().estimateGas();
return await contract.methods.createJournal()
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
} catch(err)
{
console.log(err);
}
}
const addPaper = module.exports.addPaper = async (journalAdr, fileContent) => {
try{
//const fileContent = fs.readFileSync(paperFile,'utf8');
// Check if the JSON is well formed
const paperContent = JSON.stringify(JSON.parse(fileContent));
const paperHash = web3.utils.sha3(paperContent)
const value = web3.utils.toWei('1', 'finney');
const gasEstimate = await contract.methods.createPaper(journalAdr, paperHash).estimateGas({value:value});
return await contract.methods.createPaper(journalAdr, paperHash)
.send({gas: gasEstimate, value:value})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
} catch(err)
{
console.log(err);
}
}
const addReviewer = module.exports.addReviewer = async (paperIdx, reviewerSignature) => {
console.log('contract from:',contract.options.from);
const reviewerSignatureHash = web3.utils.sha3(reviewerSignature)
const gasEstimate = await contract.methods.addReviewer(paperIdx, reviewerSignatureHash).estimateGas();
return await contract.methods.addReviewer(paperIdx, reviewerSignatureHash)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b))
}
const payReviewers = module.exports.payReviewers = async (...reviewersAddresses) => {
const data = reviewersAddresses
console.log(data);
const gasEstimate = await contract.methods.payReviewers(data).estimateGas();
return await contract.methods.payReviewers(data)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const payReviewer = module.exports.payReviewer = async (...reviewersAddresses) => {
const data = reviewersAddresses
console.log(data);
const gasEstimate = await contract.methods.payReviewer(data).estimateGas();
return await contract.methods.payReviewer(data)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const acceptPaper = module.exports.acceptPaper = async (paperIdx) => {
const gasEstimate = await contract.methods.acceptPaper(paperIdx).estimateGas();
return await contract.methods.acceptPaper(paperIdx)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const rejectPaper = module.exports.rejectPaper = async (paperIdx) => {
const gasEstimate = await contract.methods.rejectPaper(paperIdx).estimateGas();
return await contract.methods.rejectPaper(paperIdx)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const setPaperInReview = module.exports.setPaperInReview = async (paperIdx) => {
const gasEstimate = await contract.methods.setPaperInReview(paperIdx).estimateGas();
return await contract.methods.setPaperInReview(paperIdx)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const journalPaper = module.exports.journalPaper = async (journalAdr, idx) => {
let results = await contract.methods.journalPaper(journalAdr, parseInt(idx)).call();
results = {
paperInfo: results[0],
state: results[1],
reviewersHash: results[2],
numReviewers: parseInt(results[3])
}
results.reviewersHash = results.reviewersHash.slice(0, results.numReviewers); // get non-null elements
return results;
}
const checkReviewer = module.exports.checkReviewer = async (journalAdr, paperIdx, reviewerSignature) =>
{
const reviewerSignatureHash = web3.utils.sha3(reviewerSignature)
const jp = await journalPaper(journalAdr, paperIdx);
if(jp.reviewersHash.indexOf(reviewerSignatureHash) === -1)
{
return false;
}
return web3.eth.accounts.recover(jp.paperInfo, reviewerSignature);
}
const signPaper = module.exports.signPaper = async (fileContent) =>
{
const fileRawData = JSON.stringify(JSON.parse(fileContent));
const paperHash = web3.utils.sha3(fileRawData)
console.log(web3.eth.accounts.wallet[0]);
const reviewerSignature = web3.eth.accounts.wallet[0].sign(paperHash).signature
return reviewerSignature
}
const sendEth = module.exports.sendEth = async (addr, value) =>
{
const amountToSend = web3.utils.toWei(value, "ether");
return await web3.eth.sendTransaction({
to:addr,
value:amountToSend,
gas: 30000,
gasPrice: web3.utils.toWei('50', 'gwei')
})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const adrInfo = module.exports.info = async () => {
const balance = await web3.eth.getBalance(web3.eth.defaultAccount)
console.log('balance:', web3.utils.fromWei(balance,'ether')+' ether');
console.log('transaction count : ', await web3.eth.getTransactionCount(web3.eth.defaultAccount, 'pending'))
}
const mineAddr = module.exports.mineAddr = async (startsWith) => {
let max = 2000000000;
console.log(startsWith)
startsWith = '0x'+startsWith.split('').map(a => a.charCodeAt(0)).join('');
console.log(startsWith)
while(0 <-- max){
if((max % 1000) == 0) console.log(max);
let account = web3.eth.accounts.create();
if(account.address.toLowerCase().startsWith(startsWith))
{
return account;
}
}
return 'not found';
}
......@@ -4,7 +4,7 @@ const buildContract = require('./buildContract');
const createContract = module.exports.createContract = async () => {
try{
const compiledSource = buildContract('./contract/paperBlock2.sol')
const compiledSource = buildContract('../contract/paperBlock2.sol')
contract.options.address = '';
// Smart contract EVM bytecode as hex
contract.options.data = '0x' + compiledSource.bytecode;//.paperBlock.evm.bytecode.object;
......
const fs = require('fs');
const web3 = require('./web3');
const web3 = require('../common/web3');
module.exports = function(accountFile) {
if(fs.existsSync(accountFile))
......
const buildContract = require('./buildContract');
const compiledSource = buildContract('contract/paperBlock2.sol').paperBlock;
const compiledSource = buildContract('../contract/paperBlock2.sol').paperBlock;
fs.writeFileSync('contract/paperBlock2.abi.json', JSON.stringify(compiledSource.abi));
fs.writeFileSync('../contract/paperBlock2.abi.json', JSON.stringify(compiledSource.abi));
import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import web3 from "../common/web3"
import commands from './common/commands';
import { dispatchAsync } from "./dispatchAsync"
import JournalPaper from './JournalPaper'
import web3 from "../web3"
import commands from './commands';
import account from './account';
import { fetchJournalPaper } from './JournalPaper'
......
......@@ -3,7 +3,7 @@ import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import { dispatchAsync } from "./dispatchAsync"
import {v, _} from './utils.js'
import commands from './commands';
import commands from '../common/commands';
const printState = (s) => {
switch(parseInt(s)){
......
import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import web3 from "../web3"
import web3 from "../common/web3"
export const updatePaperForm = (state) => {
const paperForm = {
......
......@@ -2,9 +2,9 @@
import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import { dispatchAsync } from "./dispatchAsync"
import web3 from "../web3"
import web3 from "../common/web3"
import account from "./account"
import commands from "./commands"
import commands from "./common/commands"
const setPrivatKey = (state) => {
const value = document.getElementById('privateKeyInput').value
......
import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import web3 from "../web3"
import web3 from "../common/web3"
import JournalPaper from './JournalPaper'
import PaperForm from './PaperForm'
import prettyAddr from './prettyAddr'
......
import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import web3 from "../web3"
import web3 from "../common/web3"
import JournalPaper from './JournalPaper'
import PaperForm from './PaperForm'
import account from './account'
......
import web3 from '../web3'
import web3 from '../common/web3'
const cacheAccount = {};
......
......@@ -9,7 +9,7 @@
<body>
<div id="app"/>
<script src="src/index.js"></script>
<script src="./index.js"></script>
</body>
</html>
import { h, app } from "hyperapp";
import commands from './commands';
import web3 from '../web3';
import { preventDefault, targetValue } from "@hyperapp/events"
import commands from './common/commands';
import web3 from '../common/web3';
import PrivateKeyForm from './PrivateKeyForm'
import Reader from './Reader'
import Editor from './Editor'
......
This diff is collapsed.
{
"name": "paper-block",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "parcel index.html --open",
"build": "parcel build index.html"
},
"author": "",
"license": "ISC",
"dependencies": {
"@hyperapp/events": "^0.0.3",
"bootstrap": "^4.3.1",
"hyperapp": "^2.0.1",
"parcel-bundler": "^1.12.3",
"solc": "^0.5.11",
"web3": "^1.2.1"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/plugin-transform-runtime": "^7.6.0",
"babel-preset-env": "^1.7.0"
}
}
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