Skip to content
GitLab
Explore
Sign in
Register
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
34febcf0
Commit
34febcf0
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
format hex numbers
parent
000727fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.js
+50
-27
50 additions, 27 deletions
index.js
with
50 additions
and
27 deletions
index.js
+
50
−
27
View file @
34febcf0
...
@@ -82,7 +82,6 @@ function initContract() {
...
@@ -82,7 +82,6 @@ function initContract() {
}
}
console
.
log
(
"
Contract compiled, instantiating on blockchain...
"
);
console
.
log
(
"
Contract compiled, instantiating on blockchain...
"
);
REG_ABI
=
compiled
.
GlobalRegistrar
.
info
.
abiDefinition
;
REG_ABI
=
compiled
.
GlobalRegistrar
.
info
.
abiDefinition
;
console
.
log
(
REG_ABI
);
regContract
=
web3
.
eth
.
contract
(
REG_ABI
);
regContract
=
web3
.
eth
.
contract
(
REG_ABI
);
waitForGaz
(
3000000
,
function
(){
waitForGaz
(
3000000
,
function
(){
regContract
.
new
({
from
:
coinbase
,
data
:
compiled
.
GlobalRegistrar
.
code
,
gas
:
3000000
},
function
(
e
,
contract
){
regContract
.
new
({
from
:
coinbase
,
data
:
compiled
.
GlobalRegistrar
.
code
,
gas
:
3000000
},
function
(
e
,
contract
){
...
@@ -105,12 +104,27 @@ function initContract() {
...
@@ -105,12 +104,27 @@ function initContract() {
}
}
function
isHashZero
(
h
)
{
function
isHashZero
(
h
)
{
return
h
==
"
0x
"
||
h
==
"
0x0000000000000000000000000000000000000000
"
;
return
h
==
"
0x
"
||
h
==
"
0x0
"
||
h
==
"
0x0000000000000000000000000000000000000000
"
;
}
}
function
parseString
(
s
)
{
function
parseString
(
s
)
{
return
new
Buffer
(
s
.
substr
(
2
,
s
.
indexOf
(
"
000
"
)
-
2
),
'
hex
'
).
toString
();
return
new
Buffer
(
s
.
substr
(
2
,
s
.
indexOf
(
"
000
"
)
-
2
),
'
hex
'
).
toString
();
}
}
function
formatAddress
(
s
)
{
if
(
s
)
{
try
{
if
(
s
.
startsWith
(
"
ring:
"
))
s
=
s
.
substr
(
5
);
if
(
!
s
.
startsWith
(
"
0x
"
))
s
=
"
0x
"
+
s
;
var
n
=
new
BigNumber
(
s
);
if
(
n
==
0
)
return
undefined
;
return
web3
.
toHex
(
n
);
}
catch
(
err
)
{}
}
return
undefined
;
}
function
startServer
()
{
function
startServer
()
{
console
.
log
(
"
Starting web server
"
);
console
.
log
(
"
Starting web server
"
);
...
@@ -137,33 +151,37 @@ function startServer() {
...
@@ -137,33 +151,37 @@ function startServer() {
});
});
});
});
app
.
get
(
"
/addr/:addr
"
,
function
(
req
,
http_res
)
{
app
.
get
(
"
/addr/:addr
"
,
function
(
req
,
http_res
)
{
if
(
!
req
.
params
.
addr
.
startsWith
(
"
0x
"
))
var
addr
=
formatAddress
(
req
.
params
.
addr
);
req
.
params
.
addr
=
"
0x
"
+
req
.
params
.
addr
;
if
(
!
addr
)
{
reg
.
name
(
req
.
params
.
addr
,
function
(
err
,
res
)
{
console
.
log
(
"
Error parsing input address
"
);
http_res
.
status
(
400
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
return
;
}
reg
.
name
(
addr
,
function
(
err
,
res
)
{
http_res
.
end
(
JSON
.
stringify
({
"
name
"
:
parseString
(
res
)}));
http_res
.
end
(
JSON
.
stringify
({
"
name
"
:
parseString
(
res
)}));
});
});
});
});
app
.
post
(
"
/name/:name
"
,
function
(
req
,
http_res
)
{
app
.
post
(
"
/name/:name
"
,
function
(
req
,
http_res
)
{
var
addr
=
formatAddress
(
req
.
body
.
addr
);
if
(
!
addr
)
{
console
.
log
(
"
Error parsing input address
"
);
http_res
.
status
(
400
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
return
;
}
try
{
try
{
req
.
body
.
addr
=
new
BigNumber
(
req
.
body
.
addr
);
req
.
body
.
owner
=
formatAddress
(
req
.
body
.
owner
);
req
.
body
.
owner
=
new
BigNumber
(
req
.
body
.
owner
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
"
Error parsing input:
"
+
err
);
console
.
log
(
"
Error parsing input:
"
+
err
);
http_res
.
status
(
400
).
end
(
err
);
http_res
.
status
(
400
).
end
(
JSON
.
stringify
({
"
success
"
:
false
,
"
error
"
:
err
}));
return
;
}
if
(
!
req
.
body
.
addr
||
!
req
.
body
.
owner
)
{
http_res
.
status
(
400
).
end
(
err
);
return
;
return
;
}
}
console
.
log
(
"
Got reg request (
"
+
req
.
params
.
name
+
"
->
"
+
req
.
body
.
addr
.
toString
(
16
)
+
"
) from
"
+
req
.
body
.
owner
.
toString
(
16
)
);
console
.
log
(
"
Got reg request (
"
+
req
.
params
.
name
+
"
->
"
+
addr
+
"
) from
"
+
req
.
body
.
owner
);
reg
.
owner
(
req
.
params
.
name
,
function
(
err
,
owner
)
{
reg
.
owner
(
req
.
params
.
name
,
function
(
err
,
owner
)
{
owner
=
new
BigNumber
(
owner
);
if
(
owner
==
0
)
{
if
(
owner
==
0
)
{
console
.
log
(
"
Remaing gaz:
"
+
getRemainingGaz
());
console
.
log
(
"
Remaing gaz:
"
+
getRemainingGaz
());
unlockAccount
();
unlockAccount
();
reg
.
reserveFor
.
sendTransaction
(
req
.
params
.
name
,
req
.
body
.
owner
,
req
.
body
.
addr
,
{
reg
.
reserveFor
.
sendTransaction
(
req
.
params
.
name
,
req
.
body
.
owner
,
addr
,
{
from
:
coinbase
,
from
:
coinbase
,
gas
:
3000000
gas
:
3000000
},
function
(
terr
,
reg_c
)
{
},
function
(
terr
,
reg_c
)
{
...
@@ -173,15 +191,23 @@ function startServer() {
...
@@ -173,15 +191,23 @@ function startServer() {
}
else
{
}
else
{
console
.
log
(
"
Transaction sent
"
+
reg_c
);
console
.
log
(
"
Transaction sent
"
+
reg_c
);
reg
.
PrimaryChanged
({
"
address
"
:
coinbase
},
function
(
error
,
result
)
{
reg
.
PrimaryChanged
({
"
address
"
:
coinbase
},
function
(
error
,
result
)
{
var
name
=
parseString
(
result
.
args
.
name
);
if
(
error
)
{
var
addr
=
new
BigNumber
(
result
.
args
.
addr
);
var
name_owner
=
new
BigNumber
(
result
.
args
.
owner
);
console
.
log
(
"
PrimaryChanged for
"
+
name_owner
.
toString
(
16
)
+
"
:
"
+
name
+
"
->
"
+
addr
.
toString
(
16
));
if
(
name
!=
req
.
params
.
name
||
addr
.
toString
(
16
)
!=
req
.
body
.
addr
.
toString
(
16
)
||
name_owner
.
toString
(
16
)
!=
req
.
body
.
owner
.
toString
(
16
)
||
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
return
;
}
}
else
{
var
name
=
parseString
(
result
.
args
.
name
);
var
name_addr
=
web3
.
toHex
(
new
BigNumber
(
result
.
args
.
addr
));
if
(
result
.
args
.
owner
!=
req
.
body
.
owner
)
{
console
.
log
(
"
Owner not matching
"
);
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
}
else
if
(
name
!=
req
.
params
.
name
)
{
console
.
log
(
"
Name not matching
"
);
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
}
else
if
(
name_addr
!=
addr
)
{
console
.
log
(
"
Address not matching
"
);
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
}));
}
else
{
console
.
log
(
result
);
console
.
log
(
result
);
http_res
.
end
(
JSON
.
stringify
({
"
success
"
:
true
}));
http_res
.
end
(
JSON
.
stringify
({
"
success
"
:
true
}));
}
}
...
@@ -189,12 +215,9 @@ function startServer() {
...
@@ -189,12 +215,9 @@ function startServer() {
}
}
});
});
}
else
{
}
else
{
console
.
log
(
owner
.
toString
(
16
)
+
"
/
"
+
req
.
body
.
owner
.
toString
(
16
));
if
(
owner
==
req
.
body
.
owner
)
{
if
(
owner
.
toString
(
16
)
==
req
.
body
.
owner
.
toString
(
16
))
{
reg
.
addr
(
req
.
params
.
name
,
function
(
err
,
reg_addr
)
{
reg
.
addr
(
req
.
params
.
name
,
function
(
err
,
addr
)
{
if
(
reg_addr
==
addr
)
{
addr
=
new
BigNumber
(
addr
);
console
.
log
(
addr
.
toString
(
16
)
+
"
/
"
+
req
.
body
.
addr
.
toString
(
16
));
if
(
addr
.
toString
(
16
)
==
req
.
body
.
addr
.
toString
(
16
))
{
http_res
.
end
(
JSON
.
stringify
({
"
success
"
:
true
}));
http_res
.
end
(
JSON
.
stringify
({
"
success
"
:
true
}));
}
else
{
}
else
{
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
,
"
owner
"
:
owner
,
"
addr
"
:
addr
}));
http_res
.
status
(
403
).
end
(
JSON
.
stringify
({
"
success
"
:
false
,
"
owner
"
:
owner
,
"
addr
"
:
addr
}));
...
...
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