Commit 62601f17 authored by Quentin Bramas's avatar Quentin Bramas
Browse files

first commit

parents
0x48b0b04edef0228d607b6c0fc07837b13e723f5daf47edae80eef08b3dfe20f7
0xde86e6248d5f58cca63a58ec9bbbdfaa324d75e95049a52e08bf429e3a2f95b7
0x8f1e68b36a134a342b876d32da70948d6ec70230a2b190e176e4c6e7aae0ffa1
0xd47cd1815e8d6d37940bf6d5f4c2859349bc60d95e4678a54d5555cbc18f1f1b
\ No newline at end of file
0xb70737e7b09b7d426e24f1d8916bec6e0ca1092ffb5d247a8398b1a61e663709
0x079bc103bcfaa35379ab7bf6e60ac6fa7b47b853689b14bcf5779e661f9cb6c8
\ No newline at end of file
0x96f91e2c35ab2e51f5bbe92b0e426cc9d0c4f8fef6b02f64e3f023ee8e23457b
\ No newline at end of file
0x0512bfa6cf2a886263c8b374815edf4f1f38d1479b4e7d1e7e3ded7e26c4654d
\ No newline at end of file
0x6ea907ed3dad32b5fbe2d8fa8c847d435cacd93b334799c6cbf59cbcdaba6063
\ No newline at end of file
0x9ab39278929c65ff18040e7482d31044befb4601a24b9e66735e7984a923d418
\ No newline at end of file
node_modules
.cache
const fs = require('fs');
const solc = require('solc');
module.exports = function(filename)
{
const solContractSource = fs.readFileSync(filename, 'utf8');
const input = {
language: 'Solidity',
sources: {
'file.sol': {
content: solContractSource
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
}
const output = solc.compile(solContractSource)//JSON.stringify(input));
//console.log(rawOutput)
//const output = JSON.parse(rawOutput)
if(output.errors)
{
console.log(output.errors);
process.exit(1);
}
fs.writeFileSync(filename+'.abi.json', output.contracts[':paperBlock'].interface);
//console.log(output.contracts);
return output.contracts[':paperBlock']//.contracts['file.sol'];
}
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';
}
const buildContract = require('./buildContract');
console.log('building contract')
const createContract = module.exports.createContract = async () => {
try{
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;
} catch(e) {
console.error('error while building contract', e);
}
const nonce = await web3.eth.getTransactionCount(web3.eth.defaultAccount, 'pending')
return contract.deploy({
arguments: []
})
.send({gas: 1500000, nonce}, (a,b) => console.log('send callback', a,b))
.on('error', (a,b) => console.log('error', a,b))
.on('transactionHash', (a,b) => console.log('transactionHash', a,b))
.on('receipt', (a,b) => console.log('receipt', a,b))
.on('confirmation', (a,b) => console.log('confirmation', a,b))
.then((a,b) => console.log('transaction sent', a,b));
}
const fs = require('fs');
const web3 = require('./web3');
module.exports = function(accountFile) {
if(fs.existsSync(accountFile))
{
return web3.eth.accounts.privateKeyToAccount(fs.readFileSync(accountFile, 'utf8'));
}
let account = web3.eth.accounts.create();
fs.writeFileSync(accountFile, account.privateKey, 'utf8');
return account;
}
const buildContract = require('./buildContract');
const compiledSource = buildContract('contract/paperBlock2.sol').paperBlock;
fs.writeFileSync('contract/paperBlock2.abi.json', JSON.stringify(compiledSource.abi));
const network = 'rinkeby';
//const network = 'ropsten';
//const url = 'https://'+network+'.infura.io/v3/e87193e49f004a36bb4de0c0594fea1c';
const url = 'http://127.0.0.1:8501';
const Web3 = require('web3');
module.exports = new Web3(url);
//'wss://'+network+'.infura.io/ws/v3/e87193e49f004a36bb4de0c0594fea1c');
{
"presets":["env"],
"plugins": ["@babel/plugin-transform-runtime"]
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
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