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
8078e7b8
Commit
8078e7b8
authored
5 years ago
by
Otto Zaiser
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' of gitlab.bfa.ar:blockchain/tsa2 into develop
parents
8395f5bc
b3b4ae4f
No related branches found
Branches containing commit
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
+12
-3
12 additions, 3 deletions
api/src/StamperWrapper.js
api/src/index.js
+6
-0
6 additions, 0 deletions
api/src/index.js
api/start.sh
+46
-0
46 additions, 0 deletions
api/start.sh
with
64 additions
and
3 deletions
api/src/StamperWrapper.js
+
12
−
3
View file @
8078e7b8
...
...
@@ -11,7 +11,7 @@ class Stamper {
// utiliza la cuenta walletAccount para enviar la transaccion
// (o defaultAccount si no se especifica)
async
stamp
(
objects
,
walletAccount
)
{
console
.
log
(
`stamp
ing
${
objects
}
`
)
console
.
log
(
`
asked to
stamp
${
objects
}
`
)
// si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount
let
defaultAccount
=
(
walletAccount
)
?
walletAccount
.
address
:
this
.
web3
.
eth
.
defaultAccount
...
...
@@ -19,13 +19,21 @@ class Stamper {
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
])
if
(
blockNo
==
0
)
{
objectsToStamp
.
push
(
objects
[
i
])
}
else
{
console
.
log
(
`already stamped: `
+
objects
[
i
]
);
}
}
if
(
objectsToStamp
.
length
==
0
)
return
new
Promise
(
(
resolve
)
=>
{
console
.
log
(
`Los objects enviados ya están stampeados`
)
resolve
()
})
console
.
log
(
`stamping `
+
objectsToStamp
.
join
(
'
,
'
)
);
let
txPromise
let
gasLimit
=
2000000
...
...
@@ -42,7 +50,8 @@ class Stamper {
//chainId: '200941592',
gas
:
gasLimit
,
// gasLimit: gasLimit,
data
:
encodedABI
data
:
encodedABI
,
nonce
:
this
.
web3
.
bfa
.
txnonce
++
}
// tx.v = Buffer.from([47525974938])
// tx.nonce = this.web3.utils.toHex(await this.web3.eth.getTransactionCount(defaultAccount))
...
...
This diff is collapsed.
Click to expand it.
api/src/index.js
+
6
−
0
View file @
8078e7b8
...
...
@@ -43,6 +43,9 @@ async function setupWeb3() {
// se trata de utilizar una que haya abierta
web3
.
eth
.
defaultAccount
=
(
await
web3
.
eth
.
getAccounts
())[
0
]
}
web3
.
bfa
=
{
txnonce
:
await
web3
.
eth
.
getTransactionCount
(
web3
.
eth
.
defaultAccount
),
}
/***************************************************/
// Carga de contrato
...
...
@@ -102,6 +105,7 @@ if ( process.env.API_USER && process.env.API_PASS ) {
// API Endpoints
/***************************************************/
app
.
get
(
'
/wait1block
'
,
async
(
req
,
res
)
=>
{
console
.
log
(
Date
()
+
"
: /wait1block
"
);
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
try
{
...
...
@@ -119,6 +123,7 @@ app.get('/wait1block', async (req, res) => {
}
})
app
.
post
(
'
/stamp
'
,
async
(
req
,
res
)
=>
{
console
.
log
(
Date
()
+
"
: /stamp
"
+
req
.
body
.
hashes
.
join
(
'
,
'
)
);
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
if
(
!
(
"
hashes
"
in
req
.
body
)
)
...
...
@@ -158,6 +163,7 @@ app.post('/stamp', async (req, res) => {
})
app
.
get
(
'
/verify/:hash
'
,
async
(
req
,
res
)
=>
{
console
.
log
(
Date
()
+
"
: /verify/:
"
+
req
.
params
.
hash
);
let
ss
=
new
Stamper
(
web3
,
contractAbi
,
contractAddress
)
var
value
=
req
.
params
.
hash
...
...
This diff is collapsed.
Click to expand it.
api/start.sh
0 → 100755
+
46
−
0
View file @
8078e7b8
#!/bin/bash
# Example startup script
if
ip a |
grep
-q
inet.200.108.146.180/
then
mode
=
test2
else
mode
=
${
1
:-
prod
}
fi
cd
`
dirname
$0
`
case
"
$mode
"
in
"prod"
)
modedir
=
$(
echo
~bfa/bfa/network
)
export
CONTRACT_ADDRESS
=
"0x7e56220069CAaF8367EA42817EA9210296AeC7c6"
;;
"test2"
)
modedir
=
$(
echo
~bfa/bfa/test2network
)
export
CONTRACT_ADDRESS
=
"0xFc0f01A88bD08b988173A2354952087C9492d947"
;;
"*"
)
echo
"Unsupported mode."
>
&2
echo
"Usage:
$0
<test2|prod>"
>
&2
exit
1
;;
esac
export
GETH_ACCOUNT_JSON
=
$(
ls
-1
${
modedir
}
/node/keystore/UTC
*
|
head
-1
)
export
GETH_ACCOUNT_PASSWORD
=
""
export
GETH_HOST
=
http://localhost:8545
export
CONTRACT_ABI_PATH
=
"
${
PWD
}
/abi.json"
# roll logs
higher
=
10
for
n
in
{
9..0
}
do
if
[
$n
-eq
0
]
then
mv
-f
"nohup.out"
"nohup.out.
$higher
"
else
mv
-f
"nohup.out.
$n
"
"nohup.out.
$higher
"
fi
higher
=
$n
done
nohup
npm run serve &
sleep
1
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