Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TSA NG
Manage
Activity
Members
Labels
Plan
Issues
2
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
blockchain
TSA NG
Commits
55efae6e
Commit
55efae6e
authored
5 years ago
by
Mariano Absatz (git)
Browse files
Options
Downloads
Patches
Plain Diff
Agrego comentarios y aclaraciones. El código de la API en sí es idéntico
parent
a7027dc8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/src/StamperWrapper.js
+43
-43
43 additions, 43 deletions
api/src/StamperWrapper.js
with
43 additions
and
43 deletions
api/src/StamperWrapper.js
+
43
−
43
View file @
55efae6e
import
{
sign
}
from
"
crypto
"
;
import
{
sign
}
from
"
crypto
"
;
//const stamperInterface = require('../../contract/build/contracts/Stamper.json')
class
Stamper
{
class
Stamper
{
constructor
(
web3
,
contractAbi
,
contractAddress
)
{
constructor
(
web3
,
contractAbi
,
contractAddress
)
{
this
.
web3
=
web3
this
.
web3
=
web3
...
@@ -9,21 +7,23 @@ class Stamper {
...
@@ -9,21 +7,23 @@ class Stamper {
this
.
contract
=
new
web3
.
eth
.
Contract
(
contractAbi
,
contractAddress
)
this
.
contract
=
new
web3
.
eth
.
Contract
(
contractAbi
,
contractAddress
)
}
}
// stampea un conjunto de hashes.
// stampea un conjunto de objects (hashes) recibido como array
// si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount
// utiliza la cuenta walletAccount para enviar la transaccion
async
stamp
(
hashes
,
walletAccount
)
{
// (o defaultAccount si no se especifica)
console
.
log
(
`stamping
${
hashes
}
`
)
async
stamp
(
objects
,
walletAccount
)
{
console
.
log
(
`stamping
${
objects
}
`
)
// si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount
let
defaultAccount
=
(
walletAccount
)
?
walletAccount
.
address
:
this
.
web3
.
eth
.
defaultAccount
let
defaultAccount
=
(
walletAccount
)
?
walletAccount
.
address
:
this
.
web3
.
eth
.
defaultAccount
let
hashe
sToStamp
=
[]
let
object
sToStamp
=
[]
for
(
let
i
=
0
;
i
<
hashe
s
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
object
s
.
length
;
i
++
)
{
let
blockNo
=
await
this
.
contract
.
methods
.
getBlockNo
(
hashe
s
[
i
],
defaultAccount
).
call
()
let
blockNo
=
await
this
.
contract
.
methods
.
getBlockNo
(
object
s
[
i
],
defaultAccount
).
call
()
if
(
blockNo
==
0
)
hashe
sToStamp
.
push
(
hashe
s
[
i
])
if
(
blockNo
==
0
)
object
sToStamp
.
push
(
object
s
[
i
])
}
}
if
(
hashe
sToStamp
.
length
==
0
)
return
new
Promise
(
(
resolve
)
=>
{
if
(
object
sToStamp
.
length
==
0
)
return
new
Promise
(
(
resolve
)
=>
{
console
.
log
(
`Los
hashe
s enviados ya están stampeados`
)
console
.
log
(
`Los
object
s enviados ya están stampeados`
)
resolve
()
resolve
()
})
})
...
@@ -31,7 +31,7 @@ class Stamper {
...
@@ -31,7 +31,7 @@ class Stamper {
let
gasLimit
=
2000000
let
gasLimit
=
2000000
if
(
walletAccount
)
{
if
(
walletAccount
)
{
let
methodPut
=
this
.
contract
.
methods
.
put
(
hashe
sToStamp
)
let
methodPut
=
this
.
contract
.
methods
.
put
(
object
sToStamp
)
let
encodedABI
=
methodPut
.
encodeABI
()
let
encodedABI
=
methodPut
.
encodeABI
()
let
tx
=
{
let
tx
=
{
...
@@ -52,15 +52,15 @@ class Stamper {
...
@@ -52,15 +52,15 @@ class Stamper {
// txPromise = this.web3.eth.sendSignedTransaction('0x' + signedTx.serialize().toString('hex'))
// txPromise = this.web3.eth.sendSignedTransaction('0x' + signedTx.serialize().toString('hex'))
txPromise
=
this
.
web3
.
eth
.
sendSignedTransaction
(
signedTx
.
rawTransaction
)
txPromise
=
this
.
web3
.
eth
.
sendSignedTransaction
(
signedTx
.
rawTransaction
)
}
else
{
}
else
{
txPromise
=
this
.
contract
.
methods
.
put
(
hashe
sToStamp
).
send
({
txPromise
=
this
.
contract
.
methods
.
put
(
object
sToStamp
).
send
({
from
:
defaultAccount
,
from
:
defaultAccount
,
gasLimit
:
gasLimit
gasLimit
:
gasLimit
})
})
}
}
txPromise
.
then
((
receipt
)
=>
{
txPromise
.
then
((
receipt
)
=>
{
console
.
log
(
`>
hashe
s stampeados en bloque:
${
receipt
.
blockNumber
}
`
)
console
.
log
(
`>
object
s stampeados en bloque:
${
receipt
.
blockNumber
}
`
)
console
.
log
(
hashe
sToStamp
)
console
.
log
(
object
sToStamp
)
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
console
.
error
(
error
)
})
})
...
@@ -77,34 +77,34 @@ class Stamper {
...
@@ -77,34 +77,34 @@ class Stamper {
async
wait1block
()
{
async
wait1block
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
max
=
10
;
let
max
=
10
;
let
web3
=
this
.
web3
;
let
web3
=
this
.
web3
;
web3
.
eth
.
getBlockNumber
()
web3
.
eth
.
getBlockNumber
()
.
then
(
.
then
(
(
startnum
)
=>
{
(
startnum
)
=>
{
setTimeout
(
setTimeout
(
function
nextblock
()
function
nextblock
()
{
{
web3
.
eth
.
getBlockNumber
()
web3
.
eth
.
getBlockNumber
()
.
then
(
.
then
(
(
nownum
)
=>
{
(
nownum
)
=>
{
if
(
nownum
!=
startnum
)
if
(
nownum
!=
startnum
)
resolve
(
nownum
);
resolve
(
nownum
);
else
else
if
(
max
--
>
0
)
if
(
max
--
>
0
)
setTimeout
(
nextblock
,
500
)
setTimeout
(
nextblock
,
500
)
else
else
reject
(
'
Timeout. Tal vez no esta sincronizado el nodo local
'
)
reject
(
'
Timeout. Tal vez no esta sincronizado el nodo local
'
)
},
},
reject
reject
)
)
},
},
500
500
)
)
},
},
(
errtxt
)
=>
{
reject
(
'
No conseguimos el blockNumber.
\n
'
+
errtxt
)
}
(
errtxt
)
=>
{
reject
(
'
No conseguimos el blockNumber.
\n
'
+
errtxt
)
}
)
)
})
})
}
}
async
verify
(
hash
)
{
async
verify
(
hash
)
{
...
...
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