Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-nameservice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
savoirfairelinux
jami-nameservice
Commits
01cb3376
Commit
01cb3376
authored
8 years ago
by
Adrien Béraud
Committed by
gerrit2
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge "add tool to count and dump registered names"
parents
65494f75
8e6b1930
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
read_names.js
+67
-0
67 additions, 0 deletions
read_names.js
with
67 additions
and
0 deletions
read_names.js
0 → 100644
+
67
−
0
View file @
01cb3376
#!/usr/bin/env nodejs
var
BigNumber
=
require
(
'
bignumber.js
'
);
var
fs
=
require
(
'
fs
'
);
var
Web3
=
require
(
'
web3
'
);
var
web3
=
new
Web3
();
web3
.
SolidityCoder
=
require
(
'
web3/lib/solidity/coder
'
);
web3
.
setProvider
(
new
web3
.
providers
.
HttpProvider
(
'
http://localhost:8545
'
));
var
REG_ADDR_FILE
=
"
contractAddress.txt
"
;
var
REG_ADDR
=
"
0xe53cb2ace8707526a5050bec7bcf979c57f8b44f
"
;
var
REG_ABI_registerFor
=
[
'
bytes32
'
,
'
address
'
,
'
address
'
];
var
NAME_MAP
=
{};
function
readContractAddress
()
{
fs
.
readFile
(
REG_ADDR_FILE
,
function
(
err
,
content
)
{
if
(
err
)
{
console
.
log
(
"
Can't read contract address:
"
+
err
);
}
else
{
REG_ADDR
=
String
(
content
);
}
getAllNames
();
});
}
function
getAllNames
()
{
var
totalBlocks
=
web3
.
eth
.
blockNumber
;
var
nextBlock
=
0
;
var
rem
=
totalBlocks
;
var
cb
=
function
(
error
,
block
)
{
rem
--
;
if
(
error
)
{
console
.
log
(
"
Can't get block:
"
+
error
);
}
else
{
var
transactionNum
=
block
.
transactions
.
length
;
for
(
var
t
=
0
;
t
<
transactionNum
;
t
++
)
{
try
{
var
tr
=
block
.
transactions
[
t
];
if
(
tr
.
to
==
REG_ADDR
)
{
var
p
=
web3
.
SolidityCoder
.
decodeParams
(
REG_ABI_registerFor
,
tr
.
input
.
substr
(
10
));
var
n
=
web3
.
toUtf8
(
p
[
0
]);
console
.
log
(
"
Entry:
"
+
n
+
"
->
"
+
p
[
1
]
+
"
"
+
p
[
2
]);
NAME_MAP
[
n
]
=
{
"
addr
"
:
p
[
2
],
"
owner
"
:
p
[
1
]};
}
else
{
console
.
log
(
"
Wrong contract:
"
+
tr
.
to
+
"
expected
"
+
REG_ADDR
);
}
}
catch
(
err
)
{
console
.
log
(
"
Error reading transaction:
"
+
err
);
}
}
}
if
(
nextBlock
<
totalBlocks
)
web3
.
eth
.
getBlock
(
nextBlock
++
,
true
,
cb
);
if
(
rem
==
0
)
{
console
.
log
(
"
Found
"
+
Object
.
keys
(
NAME_MAP
).
length
+
"
name mappings
"
);
fs
.
writeFile
(
"
names.json
"
,
JSON
.
stringify
(
NAME_MAP
));
}
else
if
(
!
error
&&
block
&&
block
.
transactions
.
length
)
{
console
.
log
(
"
Listing names:
"
+
Math
.
round
(
100
-
100
*
rem
/
totalBlocks
)
+
"
%,
"
+
rem
+
"
remaining...
"
);
}
};
// 256 concurrent requests
for
(;
nextBlock
<
totalBlocks
&&
nextBlock
<
256
;
nextBlock
++
)
web3
.
eth
.
getBlock
(
nextBlock
,
true
,
cb
);
}
readContractAddress
();
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