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

Desarrollo de Issue #3 - JSON FTW

parent b5edf143
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
......@@ -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,
})
}
})
......
......@@ -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"
  • Developer

    Me parece que en el repo deberíamos dejar la API de producción.

  • Author Developer

    Dale. Y el chainId molesta o lo dejamos comentado ?

  • Developer

    Yo lo comentaría- Aclararíaque para usar en test debería ser ese chainId pero en prod no hace falta.

  • Please register or sign in to reply
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>
......
......@@ -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 () {
......
......@@ -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(() => {
......
......@@ -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,
}
})
}
......
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