Commit 7fac1395 authored by Quentin Bramas's avatar Quentin Bramas
Browse files

add author tab

parent 4b86a5bf
0x48b0b04edef0228d607b6c0fc07837b13e723f5daf47edae80eef08b3dfe20f7
0xe265f3d8a3e234b07697c5c8001c6f4fb74bab408a0e9d4ac34c259305e6db56
0xde86e6248d5f58cca63a58ec9bbbdfaa324d75e95049a52e08bf429e3a2f95b7
0xb2f58e997910534986cbe488a105c72720706feeb1ac073010b3d775b886c1c6
0x8f1e68b36a134a342b876d32da70948d6ec70230a2b190e176e4c6e7aae0ffa1
0x484146a0df7268b35705d743102c6a369e5345c28223d6d69a9c1144f7c99116
0x2afe0235e0c1ed8e5cf7327f03db1c514a4b4e60f1450518ed4ea450cb289d98
\ No newline at end of file
0x292ddd93c7552780d3ef9994f1eb74b733189abe2e2f5ac7e0bd83533f3ca226
0x6f636956bf54a478b1c21e6d0753ae0fbe5f807025913c9118e3bed6523000dc
if(process.argv.length < 4)
{
console.log('Usage:\nnode index.js PRIVATE_KEY_FILE COMMAND ARGS');
process.exit(1);
}
const web3 = require('common/web3');
const createOrLoadAccount = require('cli/createOrLoadAccount');
let account = createOrLoadAccount(process.argv[2] || '.defaultAccount');
web3.eth.defaultAccount = account.address;
web3.eth.accounts.wallet.add(account);
console.log('account: '+account.address)
const commands = require('common/commands');
const command = process.argv[3];
if(!commands[command])
{
console.log('Available commands:');
Object.keys(commands).forEach(c => console.log(' -',c));
process.exit(1);
}
console.log('running command', command)
try{
commands[command].apply(null, process.argv.slice(4)).then(console.log);
}
catch (e)
{
console.error('error while running command', command, e);
}
require = require("esm")(module)
require('./cli/index');
const fs = require('fs');
const web3 = require('../common/web3');
import fs from 'fs';
import web3 from '../common/web3';
module.exports = function(accountFile) {
export default function(accountFile) {
if(fs.existsSync(accountFile))
{
return web3.eth.accounts.privateKeyToAccount(fs.readFileSync(accountFile, 'utf8'));
......
import web3 from '../common/web3';
import createOrLoadAccount from './createOrLoadAccount';
import * as commands from '../common/commands';
if(process.argv.length < 4)
{
console.log('Usage:\nnode index.js PRIVATE_KEY_FILE COMMAND ARGS');
process.exit(1);
}
let account = createOrLoadAccount(process.argv[2] || '.defaultAccount');
web3.eth.defaultAccount = account.address;
web3.eth.accounts.wallet.add(account);
console.log('account: '+account.address)
commands.setFrom(account.address)
const command = process.argv[3];
if(!commands[command])
{
console.log('Available commands:');
Object.keys(commands).forEach(c => console.log(' -',c));
process.exit(1);
}
console.log('running command', command);
try{
commands[command].apply(null, process.argv.slice(4)).then(console.log);
}
catch (e)
{
console.error('error while running command', command, e);
}
const buildContract = require('./buildContract');
import buildContract from './buildContract';
const compiledSource = buildContract('../contract/paperBlock2.sol').paperBlock;
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 * as commands from '../common/commands';
import { dispatchAsync } from "./dispatchAsync"
import JournalPaper from './JournalPaper'
import { fetchJournalPaper } from './JournalPaper'
import PaperForm from './PaperForm'
import account from './account';
const submitPaper = dispatchAsync((state) => async dispatch => {
console.log('add paper')
dispatch({...state,
addPaperDisabled: true
});
const r = await commands.addPaper(
state.journalAdr,
state.paperFormJson
);
console.log(r);
dispatch({...state,
paperIdxInput: state.numPapers,
addPaperDisabled: false
});
dispatch(fetchJournalPaper);
})
export default ({state}) => !state.privateKey
? 'You must be connected'
: <div class="row">
<div class="col-5">
<PaperForm state={state} />
</div>
<div class="col-7">
<form>
<div class="form-group">
<button
disabled={!!state.addPaperDisabled}
class="btn btn-info"
onclick={preventDefault(submitPaper)}>{
state.addPaperDisabled
? 'Waiting'
: 'Submit the paper'
}</button>{' '}
</div>
</form>
</div>
</div>
......@@ -2,12 +2,13 @@ import { h } from 'hyperapp';
import { preventDefault, targetValue } from "@hyperapp/events"
import web3 from "../common/web3"
import commands from './common/commands';
import * as commands from '../common/commands';
import { dispatchAsync } from "./dispatchAsync"
import JournalPaper from './JournalPaper'
import account from './account';
import { fetchJournalPaper } from './JournalPaper'
import PaperForm from './PaperForm'
import account from './account';
const addReviewerSignatureInput = (state, value) => {
let from = 'impossible to recover signature';
......@@ -75,7 +76,11 @@ export default ({state}) => !state.privateKey
? 'You must be connected'
: (account(state).address !== state.journalAdr
? 'You are not the editor'
: <div>
: <div class="row">
<div class="col-5">
<PaperForm state={state} />
</div>
<div class="col-7">
<JournalPaper state={state}/><br/>
<form>
<div class="form-group">
......@@ -128,4 +133,5 @@ export default ({state}) => !state.privateKey
</div>
</form>
</div>
</div>
)
......@@ -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 '../common/commands';
import * as commands from '../common/commands';
const printState = (s) => {
switch(parseInt(s)){
......
......@@ -4,7 +4,7 @@ import { preventDefault, targetValue } from "@hyperapp/events"
import { dispatchAsync } from "./dispatchAsync"
import web3 from "../common/web3"
import account from "./account"
import commands from "./common/commands"
import * as commands from '../common/commands';
const setPrivatKey = (state) => {
const value = document.getElementById('privateKeyInput').value
......
@import './node_modules/bootstrap/dist/css/bootstrap.css';
@import '../node_modules/bootstrap/dist/css/bootstrap.css';
.tab-content
{
......
import { h, app } from "hyperapp";
import { preventDefault, targetValue } from "@hyperapp/events"
import commands from './common/commands';
import * as commands from '../common/commands';
import web3 from '../common/web3';
import PrivateKeyForm from './PrivateKeyForm'
import Reader from './Reader'
import Editor from './Editor'
import Reviewer from './Reviewer'
import Author from './Author'
import { dispatchAsync } from "./dispatchAsync"
import {v, _} from './utils'
import account from './account'
......@@ -46,6 +47,7 @@ const setActiveTab = (activeTab) => (state) => ({...state, activeTab});
const tabs = [
{title:'Reader', component: Reader},
{title:'Author', component: Author},
{title:'Reviewer', component: Reviewer},
{title:'Editor', component: Editor},
];
......@@ -86,7 +88,14 @@ const Layout = (state) => {
</ul>
<div class="tab-content" id="myTabContent">
{
tabs.map(t => <div title={t.title} class={'tab-pane show'+(state.activeTab === t.title?' active':'')} role="tabpanel"><t.component state={state} /></div>)
tabs
.filter(t => state.activeTab === t.title)
.map(t => <div
title={t.title}
class={'tab-pane show'+(state.activeTab === t.title?' active':'')}
role="tabpanel">
<t.component state={state} />
</div>)
}
</div>
</div>
......
const web3 = require('../web3');
//const fs = require('fs');
const contractAbi = require('../contract/paperBlock2.sol.abi.json');
import web3 from './web3';
import contractAbi from '../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) => {
export const setFrom = (addr) => {
contract.options.from = addr;
console.log('contract set from:',addr)
}
const contractOwner = module.exports.contractOwner = async (journalAdr) => {
export const contractOwner = async (journalAdr) => {
try{
const resp2 = await web3.eth.getStorageAt(contract.options.address);
console.log(resp2);
......@@ -32,7 +28,7 @@ const contractOwner = module.exports.contractOwner = async (journalAdr) => {
}
}
const journal = module.exports.journal = async (journalAdr) => {
export const journal = async (journalAdr) => {
try{
const resp = await contract.methods.journals(journalAdr).call();
return resp
......@@ -42,7 +38,7 @@ const journal = module.exports.journal = async (journalAdr) => {
}
const createJournal = module.exports.createJournal = async () => {
export const createJournal = async () => {
try{
const gasEstimate = await contract.methods.createJournal().estimateGas();
......@@ -55,7 +51,7 @@ const createJournal = module.exports.createJournal = async () => {
}
}
const addPaper = module.exports.addPaper = async (journalAdr, fileContent) => {
export const addPaper = async (journalAdr, fileContent) => {
try{
//const fileContent = fs.readFileSync(paperFile,'utf8');
// Check if the JSON is well formed
......@@ -76,7 +72,7 @@ const addPaper = module.exports.addPaper = async (journalAdr, fileContent) => {
}
const addReviewer = module.exports.addReviewer = async (paperIdx, reviewerSignature) => {
export const addReviewer = async (paperIdx, reviewerSignature) => {
console.log('contract from:',contract.options.from);
......@@ -88,7 +84,7 @@ const addReviewer = module.exports.addReviewer = async (paperIdx, reviewerSignat
.on('transactionHash', (a,b) => console.log('transactionHash', a,b))
}
const payReviewers = module.exports.payReviewers = async (...reviewersAddresses) => {
export const payReviewers = async (...reviewersAddresses) => {
const data = reviewersAddresses
console.log(data);
......@@ -97,7 +93,7 @@ const payReviewers = module.exports.payReviewers = async (...reviewersAddresses)
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const payReviewer = module.exports.payReviewer = async (...reviewersAddresses) => {
export const payReviewer = async (...reviewersAddresses) => {
const data = reviewersAddresses
console.log(data);
......@@ -106,28 +102,30 @@ const payReviewer = module.exports.payReviewer = async (...reviewersAddresses) =
.send({gas: gasEstimate})
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const acceptPaper = module.exports.acceptPaper = async (paperIdx) => {
export const 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) => {
export const 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) => {
export const 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) => {
export const journalPaper = async (journalAdr, idx) => {
let results = await contract.methods.journalPaper(journalAdr, parseInt(idx)).call();
results = {
paperInfo: results[0],
......@@ -140,7 +138,7 @@ const journalPaper = module.exports.journalPaper = async (journalAdr, idx) => {
}
const checkReviewer = module.exports.checkReviewer = async (journalAdr, paperIdx, reviewerSignature) =>
export const checkReviewer = async (journalAdr, paperIdx, reviewerSignature) =>
{
const reviewerSignatureHash = web3.utils.sha3(reviewerSignature)
const jp = await journalPaper(journalAdr, paperIdx);
......@@ -152,7 +150,7 @@ const checkReviewer = module.exports.checkReviewer = async (journalAdr, paperIdx
return web3.eth.accounts.recover(jp.paperInfo, reviewerSignature);
}
const signPaper = module.exports.signPaper = async (fileContent) =>
export const signPaper = async (fileContent) =>
{
const fileRawData = JSON.stringify(JSON.parse(fileContent));
......@@ -162,7 +160,7 @@ const signPaper = module.exports.signPaper = async (fileContent) =>
return reviewerSignature
}
const sendEth = module.exports.sendEth = async (addr, value) =>
export const sendEth = async (addr, value) =>
{
const amountToSend = web3.utils.toWei(value, "ether");
return await web3.eth.sendTransaction({
......@@ -174,16 +172,16 @@ const sendEth = module.exports.sendEth = async (addr, value) =>
.on('transactionHash', (a,b) => console.log('transactionHash', a,b));
}
const adrInfo = module.exports.info = async () => {
export const 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) => {
export const mineAddr = async (startsWith) => {
let max = 2000000000;
console.log(startsWith)
startsWith = '0x'+startsWith.split('').map(a => a.charCodeAt(0)).join('');
startsWith = '0x'+startsWith.split('').map(a => a.charCodeAt(0).toString(16)).join('');
console.log(startsWith)
while(0 <-- max){
if((max % 1000) == 0) console.log(max);
......@@ -196,3 +194,5 @@ const mineAddr = module.exports.mineAddr = async (startsWith) => {
}
return 'not found';
}
export default null;
......@@ -7,6 +7,7 @@ const network = 'rinkeby';
const url = 'http://127.0.0.1:8501';
const Web3 = require('web3');
module.exports = new Web3(url);
//'wss://'+network+'.infura.io/ws/v3/e87193e49f004a36bb4de0c0594fea1c');
export default new Web3(url);
This diff is collapsed.
......@@ -117,7 +117,7 @@ parcelRequire = (function (modules, cache, entry, globalName) {
}
return newRequire;
})({"../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/bundle-url.js":[function(require,module,exports) {
})({"../node_modules/parcel-bundler/src/builtins/bundle-url.js":[function(require,module,exports) {
var bundleURL = null;
function getBundleURLCached() {
......@@ -149,7 +149,7 @@ function getBaseURL(url) {
exports.getBundleURL = getBundleURLCached;
exports.getBaseURL = getBaseURL;
},{}],"../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/css-loader.js":[function(require,module,exports) {
},{}],"../node_modules/parcel-bundler/src/builtins/css-loader.js":[function(require,module,exports) {
var bundle = require('./bundle-url');
function updateLink(link) {
......@@ -184,17 +184,17 @@ function reloadCSS() {
}
module.exports = reloadCSS;
},{"./bundle-url":"../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/bundle-url.js"}],"node_modules/bootstrap/dist/css/bootstrap.css":[function(require,module,exports) {
},{"./bundle-url":"../node_modules/parcel-bundler/src/builtins/bundle-url.js"}],"../node_modules/bootstrap/dist/css/bootstrap.css":[function(require,module,exports) {
var reloadCSS = require('_css_loader');
module.hot.dispose(reloadCSS);
module.hot.accept(reloadCSS);
},{"_css_loader":"../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/css-loader.js"}],"index.css":[function(require,module,exports) {
},{"_css_loader":"../node_modules/parcel-bundler/src/builtins/css-loader.js"}],"index.css":[function(require,module,exports) {
var reloadCSS = require('_css_loader');
module.hot.dispose(reloadCSS);
module.hot.accept(reloadCSS);
},{"./node_modules/bootstrap/dist/css/bootstrap.css":"node_modules/bootstrap/dist/css/bootstrap.css","_css_loader":"../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/css-loader.js"}],"../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/hmr-runtime.js":[function(require,module,exports) {
},{"../node_modules/bootstrap/dist/css/bootstrap.css":"../node_modules/bootstrap/dist/css/bootstrap.css","_css_loader":"../node_modules/parcel-bundler/src/builtins/css-loader.js"}],"../node_modules/parcel-bundler/src/builtins/hmr-runtime.js":[function(require,module,exports) {
var global = arguments[3];
var OVERLAY_ID = '__parcel__error__overlay__';
var OldModule = module.bundle.Module;
......@@ -222,7 +222,7 @@ var parent = module.bundle.parent;
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
var hostname = "" || location.hostname;
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
var ws = new WebSocket(protocol + '://' + hostname + ':' + "49795" + '/');
var ws = new WebSocket(protocol + '://' + hostname + ':' + "56138" + '/');
ws.onmessage = function (event) {
checkedAssets = {};
......@@ -253,8 +253,9 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
assetsToAccept.forEach(function (v) {
hmrAcceptRun(v[0], v[1]);
});
} else {
window.location.reload();
} else if (location.reload) {
// `location` global exists in a web worker context but lacks `.reload()` function.
location.reload();
}
}
......@@ -397,5 +398,5 @@ function hmrAcceptRun(bundle, id) {
return true;
}
}
},{}]},{},["../../../../../../../usr/local/lib/node_modules/parcel-bundler/src/builtins/hmr-runtime.js"], null)
},{}]},{},["../node_modules/parcel-bundler/src/builtins/hmr-runtime.js"], null)
//# sourceMappingURL=/client.9ad09f98.js.map
\ No newline at end of file
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