Skip to content
Snippets Groups Projects
Commit b267446a authored by Renzo Mauro Ontivero's avatar Renzo Mauro Ontivero
Browse files

Avances Renzo

parent 32f59500
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ const contract = new web3.eth.Contract(contractABI, contractAddress); ...@@ -21,7 +21,7 @@ const contract = new web3.eth.Contract(contractABI, contractAddress);
module.exports = { module.exports = {
verify : async function (req, res){ verify : async function (req, res){
sails.log("Verify("+req.params.ots+", "+req.params.file_hash+")");
const file_hash = req.params.file_hash; const file_hash = req.params.file_hash;
const base64_ots = req.params.ots; const base64_ots = req.params.ots;
...@@ -53,6 +53,7 @@ module.exports = { ...@@ -53,6 +53,7 @@ module.exports = {
tx_hash : tx_hash, tx_hash : tx_hash,
file_hash : file_hash, file_hash : file_hash,
ots : ots, ots : ots,
msg : 'La Transacción aún no es incluida en un Bloque. Intente nuevamente en unos minutos.'
}); });
} }
...@@ -66,6 +67,9 @@ module.exports = { ...@@ -66,6 +67,9 @@ module.exports = {
if(result_verify){ if(result_verify){
const block_number = await sails.helpers.getBlockNumber(ots); const block_number = await sails.helpers.getBlockNumber(ots);
// Tengo que obtener el bloque entero, para sacar su timestamp
const block = await sails.helpers.getBlock(block_number);
return res.json({ return res.json({
status : 'success', status : 'success',
...@@ -73,14 +77,17 @@ module.exports = { ...@@ -73,14 +77,17 @@ module.exports = {
block_number : block_number, block_number : block_number,
file_hash : file_hash, file_hash : file_hash,
ots : ots, ots : ots,
contract_address: contractAddress,
timestamp : block.timestamp,
block_hash : block.hash
}); });
} else { } else {
var new_tx_hash = await sails.helpers.getHash(ots); var file_hash_by_ots = await sails.helpers.getHash(ots);
return res.json({ return res.json({
status : 'fail', status : 'fail',
file_hash_by_ots : new_tx_hash, file_hash_by_ots : file_hash_by_ots,
file_hash_send : file_hash, file_hash_send : file_hash,
tx_hash : tx_hash, tx_hash : tx_hash,
ots : ots, ots : ots,
...@@ -95,6 +102,7 @@ module.exports = { ...@@ -95,6 +102,7 @@ module.exports = {
}, },
stamp : async function (req, res){ stamp : async function (req, res){
sails.log("Stamp("+req.body.file_hash+")");
const file_hash = req.body.file_hash; const file_hash = req.body.file_hash;
// A partir del Hash recibido, genero el OpenTimeStamp (OTS) // A partir del Hash recibido, genero el OpenTimeStamp (OTS)
const ots = await sails.helpers.getOts(file_hash); const ots = await sails.helpers.getOts(file_hash);
......
const Web3 = require('web3');
const url = sails.config.custom.urlRpc;
const web3 = new Web3(url);
module.exports = {
friendlyName: 'Get block',
description: '',
inputs: {
block_number : {
type: 'number',
require: true,
},
},
exits: {
success: {
outputFriendlyName: 'Block',
},
},
fn: async function (inputs) {
var result = await web3.eth.getBlock(inputs.block_number, (err, result) => {
if(err){
return err.toString();
}
return result;
});
return result;
}
};
...@@ -19,10 +19,21 @@ module.exports.custom = { ...@@ -19,10 +19,21 @@ module.exports.custom = {
// mailgunSecret: 'key-testkeyb183848139913858e8abd9a3', // mailgunSecret: 'key-testkeyb183848139913858e8abd9a3',
// stripeSecret: 'sk_test_Zzd814nldl91104qor5911gjald', // stripeSecret: 'sk_test_Zzd814nldl91104qor5911gjald',
// … // …
//Datos para Ropsten
urlRpc: 'https://ropsten.infura.io/v3/a59f70f1e62e4db4babb69284e37672f',
accountAddress : '0x59060CF376DeB6729da45C729EbecC171C2c16b9',
contractABI : [{"constant":true,"inputs":[{"name":"ots","type":"string"}],"name":"getHash","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"ots","type":"string"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"ots","type":"string"},{"name":"file_hash","type":"string"}],"name":"verify","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"selfDestroy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ots","type":"string"},{"name":"file_hash","type":"string"}],"name":"stamp","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"hash","type":"string"},{"indexed":true,"name":"ots","type":"string"}],"name":"Stamped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"}],"name":"Deploy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"}],"name":"SelfDestroy","type":"event"}],
contractAddress: '0x96a716f91da961639f685100b12d13ef30ba89dc',
privateKey: 'D51E9F04E45381E1CC3C450CB296E73BBD0BDFCA7EE22FF2533D71631B9F536C',
/* Datos para localhost
urlRpc: 'http://localhost:8545', urlRpc: 'http://localhost:8545',
accountAddress : '0xDBF0C927F9E92dFE7C31e045e0Ba1067Ee205f73', accountAddress : '0xDBF0C927F9E92dFE7C31e045e0Ba1067Ee205f73',
contractABI : [{"constant":true,"inputs":[{"name":"ots","type":"string"}],"name":"getHash","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"ots","type":"string"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"ots","type":"string"},{"name":"file_hash","type":"string"}],"name":"verify","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"selfDestroy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ots","type":"string"},{"name":"file_hash","type":"string"}],"name":"stamp","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"accountAddress"},{"indexed":true,"name":"hash","type":"string"},{"indexed":true,"name":"ots","type":"string"}],"name":"Stamped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"accountAddress"}],"name":"Deploy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"accountAddress"}],"name":"SelfDestroy","type":"event"}], contractABI : [{"constant":true,"inputs":[{"name":"ots","type":"string"}],"name":"getHash","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"ots","type":"string"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"ots","type":"string"},{"name":"file_hash","type":"string"}],"name":"verify","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"selfDestroy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"ots","type":"string"},{"name":"file_hash","type":"string"}],"name":"stamp","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"accountAddress"},{"indexed":true,"name":"hash","type":"string"},{"indexed":true,"name":"ots","type":"string"}],"name":"Stamped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"accountAddress"}],"name":"Deploy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"accountAddress"}],"name":"SelfDestroy","type":"event"}],
contractAddress: '0xBD89a34041190439d43ec391486819eF5CBfBDBe', contractAddress: '0xBD89a34041190439d43ec391486819eF5CBfBDBe',
privateKey: '6671485e4250881473c639465464148b5a0285461f136b585623333f22f7ca3f', privateKey: '6671485e4250881473c639465464148b5a0285461f136b585623333f22f7ca3f',
*/
}; };
...@@ -28,11 +28,14 @@ module.exports.security = { ...@@ -28,11 +28,14 @@ module.exports.security = {
* * * *
***************************************************************************/ ***************************************************************************/
// cors: { cors: {
// allRoutes: false, allRoutes: true,
// allowOrigins: '*', allowOrigins: '*',
// allowCredentials: false, allowCredentials: false,
// }, allowRequestHeaders: 'content-type,accept,authorization',
allowRequestMethods: 'GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD',
allowAnyOriginWithCredentialsUnsafe: true
},
/**************************************************************************** /****************************************************************************
...@@ -49,6 +52,6 @@ module.exports.security = { ...@@ -49,6 +52,6 @@ module.exports.security = {
* * * *
****************************************************************************/ ****************************************************************************/
// csrf: false csrf: false
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment