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
f8b9767b
Commit
f8b9767b
authored
6 years ago
by
Andrés Blanco
Browse files
Options
Downloads
Patches
Plain Diff
Mejoras en parametrización de contrato
parent
da2d9422
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/src/StamperWrapper.js
+7
-5
7 additions, 5 deletions
api/src/StamperWrapper.js
api/src/index.js
+25
-4
25 additions, 4 deletions
api/src/index.js
ui/.env
+0
-1
0 additions, 1 deletion
ui/.env
with
32 additions
and
10 deletions
api/src/StamperWrapper.js
+
7
−
5
View file @
f8b9767b
const
stamperInterface
=
require
(
'
../../contract/build/contracts/Stamper.json
'
)
//
const stamperInterface = require('../../contract/build/contracts/Stamper.json')
class
Stamper
{
constructor
(
web3
,
netId
)
{
constructor
(
web3
,
contractAbi
,
contractAddress
)
{
this
.
web3
=
web3
let
address
=
stamperInterface
.
networks
[
netId
].
address
this
.
contract
=
new
web3
.
eth
.
Contract
(
stamperInterface
.
abi
,
address
)
this
.
contract
=
new
web3
.
eth
.
Contract
(
contractAbi
,
contractAddress
)
}
setSender
(
fromAddress
)
{
...
...
@@ -32,7 +31,8 @@ class Stamper {
})
txPromise
.
then
((
receipt
)
=>
{
console
.
log
(
`
${
hash
}
: stamped (bloque:
${
receipt
.
blockNumber
}
)`
)
console
.
log
(
`> hashes stampeados en bloque:
${
receipt
.
blockNumber
}
`
)
console
.
log
(
hashesToStamp
)
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
})
...
...
@@ -51,6 +51,7 @@ class Stamper {
try
{
let
count
=
await
this
.
contract
.
methods
.
getObjectCount
(
hash
).
call
()
if
(
count
==
0
)
{
console
.
log
(
`fallo verificación
${
hash
}
`
)
return
{
stamped
:
false
,
stamps
:
[]
}
}
...
...
@@ -62,6 +63,7 @@ class Stamper {
stamps
.
push
({
stamper
:
stamp
[
1
],
block
:
stamp
[
2
].
toString
()
})
}
console
.
log
(
`exito verificación
${
hash
}
`
)
return
{
stamped
:
true
,
stamps
:
stamps
}
}
catch
(
e
)
{
console
.
error
(
e
)
...
...
This diff is collapsed.
Click to expand it.
api/src/index.js
+
25
−
4
View file @
f8b9767b
...
...
@@ -16,6 +16,7 @@ const accountIsSet = process.env.GETH_ACCOUNT || false
// si no se seteó una account se usa esta const como el indice de accounts de ganache
const
account
=
(
accountIsSet
)
?
process
.
env
.
GETH_ACCOUNT
:
1
var
web3
=
web3
if
(
typeof
web3
!==
'
undefined
'
)
{
console
.
log
(
'
Cargando web3 provider desde el entorno
'
)
...
...
@@ -45,6 +46,28 @@ async function setupWeb3() {
}
}
/***************************************************/
// Carga de contrato
/***************************************************/
let
contractAbi
;
let
contractAddress
;
if
(
process
.
env
.
CONTRACT_ABI_PATH
)
{
contractAbi
=
require
(
process
.
env
.
CONTRACT_ABI_PATH
)
if
(
!
process
.
env
.
CONTRACT_ADDRESS
)
{
console
.
error
(
'
Si se especifica el path de un abi, debe proveerse un address con la env CONTRACT_ADDRESS
'
)
process
.
exit
(
1
)
}
contractAddress
=
process
.
env
.
CONTRACT_ADDRESS
}
else
{
let
path
=
'
../../contract/build/contracts/Stamper.json
'
console
.
log
(
`Intentando cargar
${
path
}
`
)
let
data
=
require
(
path
)
contractAbi
=
data
.
abi
web3
.
eth
.
net
.
getId
().
then
(
function
(
netId
)
{
contractAddress
=
data
.
networks
[
netId
].
address
})
}
/***************************************************/
// Setup API
/***************************************************/
...
...
@@ -72,8 +95,7 @@ if (process.env.API_USER && process.env.API_PASS) {
// API Endpoints
/***************************************************/
app
.
post
(
'
/stamp
'
,
async
(
req
,
res
)
=>
{
let
netId
=
await
web3
.
eth
.
net
.
getId
()
let
ss
=
new
Stamper
(
web3
,
netId
)
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
ss
.
setSender
(
web3
.
eth
.
defaultAccount
)
if
(
!
(
"
hashes
"
in
req
.
body
))
{
...
...
@@ -109,8 +131,7 @@ app.post('/stamp', async (req, res) => {
})
app
.
get
(
'
/verify/:hash
'
,
async
(
req
,
res
)
=>
{
let
netId
=
await
web3
.
eth
.
net
.
getId
()
let
ss
=
new
Stamper
(
web3
,
netId
)
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
ss
.
setSender
(
web3
.
eth
.
defaultAccount
)
var
value
=
req
.
params
.
hash
...
...
This diff is collapsed.
Click to expand it.
ui/.env
deleted
100644 → 0
+
0
−
1
View file @
da2d9422
VUE_APP_API_URL=http://localhost:3000
\ No newline at end of file
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