Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tsa1
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renzo Mauro Ontivero
tsa1
Commits
32f59500
Commit
32f59500
authored
5 years ago
by
Renzo Mauro Ontivero
⚽
Browse files
Options
Downloads
Patches
Plain Diff
Optimizando el metodo verify()
parent
bf033489
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/controllers/BlockchainController.js
+40
-41
40 additions, 41 deletions
api/controllers/BlockchainController.js
with
40 additions
and
41 deletions
api/controllers/BlockchainController.js
+
40
−
41
View file @
32f59500
...
...
@@ -39,31 +39,45 @@ module.exports = {
const
ots
=
array_ots
[
0
];
// Este es el OpenTimeStamp (OTS) original creado en el método stamp() con el helper getOts(); Es un ID único para cada request.
const
tx_hash
=
array_ots
[
1
];
// Hash de la TX obtenida de la blockchain
// Verifico si el OTS + Hash enviado son válidos
const
result_verify
=
await
sails
.
helpers
.
verifyHash
.
with
({
ots
:
ots
,
file_hash
:
file_hash
,
});
if
(
result_verify
){
const
block_number
=
await
sails
.
helpers
.
getBlockNumber
(
ots
);
// Antes de verificar el contenido del OTS y el HASH
// Verifico el estado de la transacción
var
tx
=
await
web3
.
eth
.
getTransaction
(
tx_hash
,
async
(
err
,
_tx
)
=>
{
if
(
err
){
return
res
.
json
(
err
.
toString
());
}
return
res
.
json
({
status
:
'
success
'
,
tx_hash
:
tx_hash
,
block_number
:
block_number
,
file_hash
:
file_hash
,
ots
:
ots
,
// Significa que la TX aún no se incluye en un bloque.
if
(
!
_tx
.
blockNumber
){
return
res
.
json
({
status
:
'
pending
'
,
tx_hash
:
tx_hash
,
file_hash
:
file_hash
,
ots
:
ots
,
});
}
// Verifico si el OTS + File_Hash enviado son válidos
const
result_verify
=
await
sails
.
helpers
.
verifyHash
.
with
({
ots
:
ots
,
file_hash
:
file_hash
,
});
}
else
{
// Verifico si la Transacción aún no se ha incluido en un bloque
// TODO: Mover la funcion al controlador correspondiente
var
new_tx_hash
=
await
sails
.
helpers
.
getHash
(
ots
);
sails
.
log
(
new_tx_hash
)
// Si el
if
(
tx_hash
!=
new_tx_hash
){
if
(
result_verify
){
const
block_number
=
await
sails
.
helpers
.
getBlockNumber
(
ots
);
return
res
.
json
({
status
:
'
success
'
,
tx_hash
:
tx_hash
,
block_number
:
block_number
,
file_hash
:
file_hash
,
ots
:
ots
,
});
}
else
{
var
new_tx_hash
=
await
sails
.
helpers
.
getHash
(
ots
);
return
res
.
json
({
status
:
'
fail
'
,
file_hash_by_ots
:
new_tx_hash
,
...
...
@@ -72,26 +86,11 @@ module.exports = {
ots
:
ots
,
msg
:
'
El HASH del archivo enviado no se corresponde con el OTS.
'
});
}
// Analizar el tema del estado pendiente de las TX
/*var tx = await web3.eth.getTransaction(tx_hash, (err, _tx) => {
if(err){
return res.json(err.toString());
}
// Significa que la TX aún no se incluye en un bloque. Notificamos para que intente más tarde
if(!_tx.block_number){
return res.json({
status : 'pending',
tx_hash : tx_hash,
file_hash : file_hash,
ots : ots,
});
}
});*/
}
}
});
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment