Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
nucleo
Commits
a1facbe7
Commit
a1facbe7
authored
4 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Adding script to print events logged to the blockchain
parent
c11bc64b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/events.js
+96
-0
96 additions, 0 deletions
bin/events.js
with
96 additions
and
0 deletions
bin/events.js
0 → 100755
+
96
−
0
View file @
a1facbe7
#!/usr/bin/node
// 20200828 Robert Martin-Legene
// License: GPLv2-only
// (c) Secretaria Legal y Tecnica, Presidencia De La Nacion, Argentina
// Looks for the contract you're specifying as argument.
// Tries to show you all the events that contract has ever logged on the blockchain.
// The contract's ABI must be in a text file in ${BFANETWORKDIR}/contracts/${contractaddr}/abi
const
Web3
=
require
(
"
web3
"
);
const
fs
=
require
(
"
fs
"
);
const
web3
=
new
Web3
(
"
http://127.0.0.1:8545
"
);
function
writeEvent
(
ev
)
{
console
.
log
(
""
);
console
.
log
(
"
Block number:
"
+
ev
.
blockNumber
);
console
.
log
(
"
TX hash:
"
+
ev
.
transactionHash
);
console
.
log
(
"
Event name:
"
+
ev
.
event
);
Object
.
keys
(
ev
.
returnValues
).
forEach
(
function
writeEventValue
(
value
)
{
// Will skip keys which are made entirely of digits.
if
(
!
value
.
match
(
/^
[
0-9
]
+$/
)
)
{
console
.
log
(
"
*
"
+
value
+
"
:
"
+
ev
.
returnValues
[
value
]
)
}
}
);
}
function
gotPastEvents
(
e
,
result
)
{
// We are called a single time.
// Either success or failure.
if
(
e
)
{
console
.
error
(
e
);
process
.
exit
(
1
);
}
result
.
forEach
(
writeEvent
);
console
.
log
(
"
\n
"
+
result
.
length
+
"
events.
"
);
}
var
contractname
=
process
.
argv
[
2
];
if
(
contractname
===
undefined
)
{
console
.
error
(
"
Usage:
"
+
process
.
argv
[
1
]
+
"
<contractname|contractaddr>
"
);
process
.
exit
(
1
);
}
if
(
process
.
env
.
BFANETWORKDIR
===
undefined
)
{
console
.
error
(
"
$BFANETWORKDIR must be defined
"
);
process
.
exit
(
1
);
}
var
pathprefix
=
process
.
env
.
BFANETWORKDIR
+
"
/contracts/
"
;
var
filename
;
if
(
fs
.
existsSync
(
contractname
))
filename
=
contractname
;
else
if
(
fs
.
existsSync
(
contractname
.
toLowerCase
()
))
filename
=
contractname
.
toLowerCase
();
else
if
(
fs
.
existsSync
(
pathprefix
+
contractname
))
filename
=
pathprefix
+
contractname
;
else
if
(
fs
.
existsSync
(
pathprefix
+
contractname
.
toLowerCase
()
))
filename
=
pathprefix
+
contractname
.
toLowerCase
();
if
(
filename
===
undefined
)
{
console
.
error
(
"
Contract not found.
"
);
process
.
exit
(
1
);
}
var
contractaddr
=
filename
;
var
dirname
=
""
;
var
idx
=
filename
.
lastIndexOf
(
"
/
"
);
if
(
idx
>
-
1
)
{
dirname
=
filename
.
substr
(
0
,
idx
+
1
);
filename
=
filename
.
substr
(
idx
+
1
)
contractaddr
=
filename
;
}
var
stats
=
fs
.
lstatSync
(
dirname
+
filename
);
if
(
stats
.
isSymbolicLink
()
)
{
let
linkname
=
fs
.
readlinkSync
(
dirname
+
filename
,
{
encoding
:
'
utf8
'
}
);
filename
=
dirname
+
linkname
;
contractaddr
=
linkname
;
}
filename
+=
"
/abi
"
;
var
abi_str
=
fs
.
readFileSync
(
filename
,
{
encoding
:
'
utf8
'
}
);
var
abi
=
JSON
.
parse
(
abi_str
);
var
contract
=
new
web3
.
eth
.
Contract
(
abi
,
contractaddr
);
console
.
log
(
"
Address:
"
+
contractaddr
);
contract
.
getPastEvents
(
"
allEvents
"
,
{
fromBlock
:
"
earliest
"
,
toBlock
:
"
latest
"
},
gotPastEvents
);
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