diff --git a/api/src/StamperWrapper.js b/api/src/StamperWrapper.js index 41b6140e93dd2d18c74a07851d6fe4f2f1a23ff7..38459f45d65a98a2c1d29943578f1c7255728908 100644 --- a/api/src/StamperWrapper.js +++ b/api/src/StamperWrapper.js @@ -15,25 +15,30 @@ class Stamper { // si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount let defaultAccount = (walletAccount) ? walletAccount.address : this.web3.eth.defaultAccount - let objectsToStamp = [] + let objectsToStamp = [] // Guardo los hashes que seran enviados a la BFA + let objectsStamped = [] // Guardo los objetos que ya fueron enviados a la BFA for (let i=0; i < objects.length; i++) { let blockNo = await this.contract.methods.getBlockNo(objects[i], defaultAccount).call() - if (blockNo == 0) - { - objectsToStamp.push(objects[i]) - } - else - { - console.log(`already stamped: ` + objects[i] ); - } + if (blockNo == 0){ + objectsToStamp.push(objects[i]); + } else { + console.log(`already stamped: ` + objects[i] + ' blockNro: ' + blockNo); + let new_object = { + hash: objects[i], + block_number: blockNo, + status: 'already_stamped_by_this_TSA', + } + objectsStamped.push(new_object); + } } if (objectsToStamp.length == 0) return new Promise( (resolve) => { - console.log(`Los objects enviados ya están stampeados`) - resolve() - }) - console.log(`stamping ` + objectsToStamp.join(', ') ); + console.log(`Los objects enviados ya están stampeados`) + resolve(objectsStamped) + }) + + console.log(`stamping ` + objectsToStamp.join(', ')); let txPromise let gasLimit = 2000000 @@ -46,12 +51,12 @@ class Stamper { to: this.contractAddress, // v: 47525974938 * 35 + 2, // v: 47525974938, - // Parece que sin chainId funciona igual - hasta a veces mejor. - //chainId: '200941592', + // Parece que sin chainId funciona igual - hasta a veces mejor. Pero en la red Testnet, hay que agregar el chainID 99118822 + chainId: '99118822', gas: gasLimit, // gasLimit: gasLimit, data: encodedABI, - nonce: this.web3.bfa.txnonce++ + nonce: this.web3.bfa.txnonce++ } // tx.v = Buffer.from([47525974938]) // tx.nonce = this.web3.utils.toHex(await this.web3.eth.getTransactionCount(defaultAccount)) @@ -60,29 +65,64 @@ class Stamper { // console.log(signedTx) // txPromise = this.web3.eth.sendSignedTransaction(signedTx) // txPromise = this.web3.eth.sendSignedTransaction('0x' + signedTx.serialize().toString('hex')) - txPromise = this.web3.eth.sendSignedTransaction(signedTx.rawTransaction) + txPromise = await this.web3.eth.sendSignedTransaction(signedTx.rawTransaction) // Apliqué el await para que espere a que finalice la operación + + let tx_result = []; // Objeto que contiene la info de la TX + + if(txPromise.status == true){ + tx_result = { + status: 'stamped', + block_number: txPromise.blockNumber, + hash: txPromise.transactionHash, + }; + } else { + tx_result = { + status: 'error', + block_number: '-', + hash: '-', + }; + } + + + for (let i=0; i < objectsToStamp.length; i++) { + // Creo un nuevo objeto con la info de la tx realizada + let new_object = { + hash: objectsToStamp[i], + block_number: tx_result.block_number, + status: tx_result.status, + tx_hash: tx_result.hash, + } + // Agrego el objeto al array de objetos stampados (incluye los que ya fueron stampados, si los hubiese, y los nuevos) + objectsStamped.push(new_object) + } } else { - txPromise = this.contract.methods.put(objectsToStamp).send({ + txPromise = await this.contract.methods.put(objectsToStamp).send({ from: defaultAccount, gasLimit: gasLimit }) } - txPromise.then((receipt) => { + // Retorno un array con todos los objetos stampados + return objectsStamped; + + // Código anterior, comentado a la espera de confirmar el cambio + /*txPromise.then((receipt) => { console.log(`> objects stampeados en bloque: ${receipt.blockNumber}`) + console.log(`> Hash de la Tx: ${receipt.transactionHash}`) + console.log(`> Hash/es enviado/s:`) console.log(objectsToStamp) }).catch((error) => { console.error(error) - }) + })*/ - return new Promise((resolve, reject) => { + /*return new Promise((resolve, reject) => { txPromise.on('transactionHash', (txHash) => { - resolve(txHash) + resolve(objectsStamped) }) txPromise.catch((error) => { reject(error) }) - }) + })*/ } async wait1block() { diff --git a/api/src/index.js b/api/src/index.js index 51a8a124376cacecdc7aec3ec888cc1c020f4cbd..9f8fa79faf86389d9323157aeaaa3a368cbda9d1 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -150,15 +150,25 @@ app.post('/stamp', async (req, res) => { hashes[i] = hash } + // Ahora retorno un JSON con el resultado de la operación try { let txHash = await ss.stamp(hashes, walletAccount) - //let fullUrl = req.protocol + '://' + req.get('host') - res.status(200).send('success') + //let fullUrl = req.protocol + '://' + req.get('host') + console.log(">>>> Stamp OK <<<<"); + res.json({ + status: 'ok', + txHash + }); } catch (e) { + console.log(">>>> Stamp ERROR <<<<"); console.error(e) - res.status(500) - res.send('Error interno. Chequee el log de la aplicación para más detalles') + //res.status(500) + //res.send('Error interno. Chequee el log de la aplicación para más detalles') + res.json({ + status: 'error', + error: e, + }) } }) diff --git a/ui/public/index.html b/ui/public/index.html index e423ea355bb8a778a982482e50781a694ebb05b8..1feb3c33fc4e408ef54d5e61beb940e8272fe343 100644 --- a/ui/public/index.html +++ b/ui/public/index.html @@ -32,7 +32,7 @@ <p>El servicio de Sello de Tiempo de BFA permite demostrar que el contenido de cualquier documento digital existió en un momento y que desde entonces, no ha cambiado. Al sellar un archivo, cualquiera podrá verificar el dÃa y la hora en que su hash fue almacenado en Blockchain Federal Argentina. Tené en cuenta que el documento seleccionado nunca se sube a la red, garantizando su privacidad.</p> <p class="font_small"><a href="https://bfa.ar/sello">Si tenés un archivo con Recibo Digital (.rd) verificalo aquÃ</a></p> <div id="app" - apiurl="https://tsa2.buenosaires.gob.ar" + apiurl="http://10.10.0.7:3000" lb_00=" El archivo " lb_01=" fue enviado con éxito para ser sellado" lb_02="Se ha producido un error al intentar sellar " @@ -54,6 +54,7 @@ lb_18="Seleccionar otros archivos" lb_19=" Solo se pueden agregar " lb_20=" archivos por vez" + lb_21=" ya se encuentra sellado en la BFA" ></div> </div> diff --git a/ui/src/App.vue b/ui/src/App.vue index 4643f9f20002f1a22c27d2723d347d6d6f95feff..1062ca5b2c29a60473e00a28ff7fcdc44b075a5d 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -6,7 +6,19 @@ <div> <div v-if="state=='stamped'"> <div v-for="(value, index) in allFiles" :key="index"> - <div class="success-verify alert alert-success" role="alert"> + <div v-if="value.status == 'already_stamped_by_this_TSA'" class="success-verify alert alert-success" role="alert"> + <p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> <span v-html="lb_00"></span> <b>{{value.fileName}}</b><span v-html="lb_21"></span> <span v-html="lb_04"></span> <b>{{ value.block }}</b></p> + <div class="copiar"> + <label class="font_small" v-html="lb_16" :for="'id_'+index"></label> + <div class="input-group"> + <input class="form-control input-sm" type="textfield" readonly :value="getHashURL(index)" :id="'id_'+index" > + <span class="input-group-btn"> + <button class="btn btn-default btn-sm" v-on:click="copiarURL(index)"><span class="glyphicon glyphicon-copy text-success" aria-hidden="true"></span> <span v-html="lb_15"></span></button> + </span> + </div> + </div> + </div> + <div v-if="value.status == 'stamped'" class="success-verify alert alert-success" role="alert"> <p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> <span v-html="lb_00"></span> <b>{{value.fileName}}</b> <span v-html="lb_01"></span></p> <div class="copiar"> <label class="font_small" v-html="lb_16" :for="'id_'+index"></label> @@ -88,6 +100,7 @@ :lb_18="lb_18" :lb_19="lb_19" :lb_20="lb_20" + :lb_21="lb_21" v-if="state == 'visible-drop'" v-on:stamp="onStamp" v-on:failed-stamp="onFailedStamp()" @@ -126,7 +139,8 @@ 'lb_17', 'lb_18', 'lb_19', - 'lb_20' + 'lb_20', + 'lb_21', ], computed: { hash () { diff --git a/ui/src/components/DropFile.vue b/ui/src/components/DropFile.vue index 7783cc71d8f76672c08478b82e99ea3f9d685966..c21aa3e5d4e1f2477e010338ad58f6b701a60433 100644 --- a/ui/src/components/DropFile.vue +++ b/ui/src/components/DropFile.vue @@ -87,7 +87,7 @@ export default { 'lb_17', 'lb_18', 'lb_19', - 'lb_20' + 'lb_20', ], data: function() { return { @@ -221,7 +221,32 @@ export default { hashes: self.allHashes }).then(function(response) { - self.$emit('stamp', self.uploadedFiles); + if(response.data.status == 'ok'){ + // Itero por los archivos que fueron enviados a sellar + for (var i = 0; i < self.uploadedFiles.length; i++) { + + //Itero por los archivos que me retorno el metodo stamp de la api rest + for (var k = 0; k < response.data.txHash.length; k++) { + + var hash = self.uploadedFiles[i].hash; + if ( ! hash.startsWith('0x') ) { + hash = '0x' + hash; + } + + //Agrego nueva info para ser mostrada por pantalla, en cas + if(hash == response.data.txHash[k].hash){ + self.uploadedFiles[i].block = response.data.txHash[k].block_number; + self.uploadedFiles[i].status = response.data.txHash[k].status; + } + } + + } + + self.$emit('stamp', self.uploadedFiles); + } else { + self.$emit('failed-stamp') + } + // console.log(response) // axios.get(`${self.apiurl}/wait1block`).then(function(response){ // axios.get(`${self.apiurl}/wait1block`).then(() => { diff --git a/ui/src/main.js b/ui/src/main.js index 9eba9aa7b5d8864fc3d9b337e97895325f265361..bcaa8a9884863d12c1c3a28aef273c8fb2fb653a 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -44,6 +44,7 @@ new Vue({ lb_18: this.$el.attributes.lb_18.value, lb_19: this.$el.attributes.lb_19.value, lb_20: this.$el.attributes.lb_20.value, + lb_21: this.$el.attributes.lb_21.value, } }) }