diff --git a/api/controllers/BlockchainController.js b/api/controllers/BlockchainController.js index 54ca6aae34cca90939c29cb8c30c86fee0a3936b..35f50238109ab59cc2f7332ad658e108018f4e53 100755 --- a/api/controllers/BlockchainController.js +++ b/api/controllers/BlockchainController.js @@ -21,7 +21,7 @@ const contract = new web3.eth.Contract(contractABI, contractAddress); module.exports = { verify : async function (req, res){ - + sails.log("Verify("+req.params.ots+", "+req.params.file_hash+")"); const file_hash = req.params.file_hash; const base64_ots = req.params.ots; @@ -53,6 +53,7 @@ module.exports = { tx_hash : tx_hash, file_hash : file_hash, 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 = { if(result_verify){ 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({ status : 'success', @@ -73,14 +77,17 @@ module.exports = { block_number : block_number, file_hash : file_hash, ots : ots, + contract_address: contractAddress, + timestamp : block.timestamp, + block_hash : block.hash }); } else { - var new_tx_hash = await sails.helpers.getHash(ots); + var file_hash_by_ots = await sails.helpers.getHash(ots); return res.json({ status : 'fail', - file_hash_by_ots : new_tx_hash, + file_hash_by_ots : file_hash_by_ots, file_hash_send : file_hash, tx_hash : tx_hash, ots : ots, @@ -95,6 +102,7 @@ module.exports = { }, stamp : async function (req, res){ + sails.log("Stamp("+req.body.file_hash+")"); const file_hash = req.body.file_hash; // A partir del Hash recibido, genero el OpenTimeStamp (OTS) const ots = await sails.helpers.getOts(file_hash); diff --git a/api/helpers/get-block.js b/api/helpers/get-block.js new file mode 100755 index 0000000000000000000000000000000000000000..b821ed4e0456bf9d3cc7db4d3d950252f8aac951 --- /dev/null +++ b/api/helpers/get-block.js @@ -0,0 +1,47 @@ +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; + + } + + +}; + diff --git a/config/custom.js b/config/custom.js index 7cc279122dd6f2d2362c3cf59e5731476137db22..d168a0eab61502e3a570e63157553c4313c80888 100755 --- a/config/custom.js +++ b/config/custom.js @@ -19,10 +19,21 @@ module.exports.custom = { // mailgunSecret: 'key-testkeyb183848139913858e8abd9a3', // 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', 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"}], contractAddress: '0xBD89a34041190439d43ec391486819eF5CBfBDBe', - privateKey: '6671485e4250881473c639465464148b5a0285461f136b585623333f22f7ca3f', - + privateKey: '6671485e4250881473c639465464148b5a0285461f136b585623333f22f7ca3f', + */ }; diff --git a/config/security.js b/config/security.js index bd5763165d4635a05c10dd081aba5f5c7d209397..1cc2d9391ee9fee494c4ba6d337a4760f7b8cff6 100755 --- a/config/security.js +++ b/config/security.js @@ -28,11 +28,14 @@ module.exports.security = { * * ***************************************************************************/ - // cors: { - // allRoutes: false, - // allowOrigins: '*', - // allowCredentials: false, - // }, + cors: { + allRoutes: true, + allowOrigins: '*', + allowCredentials: false, + allowRequestHeaders: 'content-type,accept,authorization', + allowRequestMethods: 'GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD', + allowAnyOriginWithCredentialsUnsafe: true + }, /**************************************************************************** @@ -49,6 +52,6 @@ module.exports.security = { * * ****************************************************************************/ - // csrf: false + csrf: false };