Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TSA NG
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
TSA NG
Commits
d257f8b6
Commit
d257f8b6
authored
5 years ago
by
Blockchain Federal Argentina
Browse files
Options
Downloads
Patches
Plain Diff
Cambios API
parent
005b50d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
api/src/StamperWrapper.js
+43
-5
43 additions, 5 deletions
api/src/StamperWrapper.js
api/src/index.js
+17
-0
17 additions, 0 deletions
api/src/index.js
with
62 additions
and
5 deletions
.gitignore
+
2
−
0
View file @
d257f8b6
847e7d6ea18a417496518dc90b547438bf1b3d05.json
api/nohup.out
www
This diff is collapsed.
Click to expand it.
api/src/StamperWrapper.js
+
43
−
5
View file @
d257f8b6
...
...
@@ -75,6 +75,38 @@ class Stamper {
})
}
async
wait1block
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
max
=
10
;
let
web3
=
this
.
web3
;
web3
.
eth
.
getBlockNumber
()
.
then
(
(
startnum
)
=>
{
setTimeout
(
function
nextblock
()
{
web3
.
eth
.
getBlockNumber
()
.
then
(
(
nownum
)
=>
{
if
(
nownum
!=
startnum
)
resolve
(
nownum
);
else
if
(
max
--
>
0
)
setTimeout
(
nextblock
,
500
)
else
reject
(
'
Timeout. Tal vez no esta sincronizado el nodo local
'
)
},
reject
)
},
500
)
},
(
errtxt
)
=>
{
reject
(
'
No conseguimos el blockNumber.
\n
'
+
errtxt
)
}
)
})
}
async
verify
(
hash
)
{
try
{
let
count
=
await
this
.
contract
.
methods
.
getObjectCount
(
hash
).
call
()
...
...
@@ -85,10 +117,16 @@ class Stamper {
var
stamps
=
[]
for
(
var
i
=
0
;
i
<
count
;
i
++
)
{
let
stampPos
=
await
this
.
contract
.
methods
.
getObjectPos
(
hash
,
i
).
call
()
let
stamp
=
await
this
.
contract
.
methods
.
getStamplistPos
(
stampPos
).
call
()
stamps
.
push
({
stamper
:
stamp
[
1
],
block
:
stamp
[
2
].
toString
()
})
let
stampPos
=
await
this
.
contract
.
methods
.
getObjectPos
(
hash
,
i
).
call
()
let
stamp
=
await
this
.
contract
.
methods
.
getStamplistPos
(
stampPos
).
call
()
let
whostamped
=
stamp
[
1
];
let
blockno
=
stamp
[
2
];
let
block
=
await
this
.
web3
.
eth
.
getBlock
(
blockno
);
stamps
.
push
({
whostamped
:
whostamped
,
blocknumber
:
blockno
.
toString
(),
blocktimestamp
:
block
.
timestamp
});
}
console
.
log
(
`exito verificación
${
hash
}
`
)
...
...
@@ -100,4 +138,4 @@ class Stamper {
}
}
export
default
Stamper
\ No newline at end of file
export
default
Stamper
This diff is collapsed.
Click to expand it.
api/src/index.js
+
17
−
0
View file @
d257f8b6
...
...
@@ -102,6 +102,23 @@ if (process.env.API_USER && process.env.API_PASS) {
/***************************************************/
// API Endpoints
/***************************************************/
app
.
get
(
'
/wait1block
'
,
async
(
req
,
res
)
=>
{
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
try
{
let
blockno
=
await
ss
.
wait1block
()
return
res
.
json
(
{
success
:
true
,
blocknumber
:
blockno
}
)
}
catch
(
e
)
{
console
.
error
(
e
)
res
.
status
(
500
)
res
.
send
(
e
)
}
})
app
.
post
(
'
/stamp
'
,
async
(
req
,
res
)
=>
{
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
...
...
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