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
02ba6d72
Commit
02ba6d72
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
nameservice: save contract ABI on disk, fix loading code
Change-Id: If171f72edc9847628cf6ee8d9f406fbab222299a
parent
544854d3
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
index.js
+35
-24
35 additions, 24 deletions
index.js
with
35 additions
and
24 deletions
index.js
+
35
−
24
View file @
02ba6d72
...
@@ -32,8 +32,9 @@ var balance = web3.eth.getBalance(coinbase);
...
@@ -32,8 +32,9 @@ var balance = web3.eth.getBalance(coinbase);
console
.
log
(
balance
.
toString
(
10
));
console
.
log
(
balance
.
toString
(
10
));
var
REG_ADDR_FILE
=
"
contractAddress.txt
"
;
var
REG_ADDR_FILE
=
"
contractAddress.txt
"
;
var
REG_ADDR
=
"
0x1b364554e859d3277d3477ef6bf21113464e2392
"
;
var
REG_ABI_FILE
=
"
contractABI.json
"
;
var
REG_ABI
=
[{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
name
"
,
"
outputs
"
:[{
"
name
"
:
"
o_name
"
,
"
type
"
:
"
bytes32
"
}],
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
owner
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
address
"
}],
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
content
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
bytes32
"
}],
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
addr
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
address
"
}],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
reserve
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
subRegistrar
"
,
"
outputs
"
:[{
"
name
"
:
"
o_subRegistrar
"
,
"
type
"
:
"
address
"
}],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_owner
"
,
"
type
"
:
"
address
"
},{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
reserveFor
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_newOwner
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
transfer
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_registrar
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
setSubRegistrar
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[],
"
name
"
:
"
Registrar
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
},{
"
name
"
:
"
_primary
"
,
"
type
"
:
"
bool
"
}],
"
name
"
:
"
setAddress
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_content
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
setContent
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
disown
"
,
"
outputs
"
:[],
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
register
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
address
"
}],
"
type
"
:
"
function
"
},{
"
anonymous
"
:
false
,
"
inputs
"
:[{
"
indexed
"
:
true
,
"
name
"
:
"
name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
Changed
"
,
"
type
"
:
"
event
"
},{
"
anonymous
"
:
false
,
"
inputs
"
:[{
"
indexed
"
:
true
,
"
name
"
:
"
name
"
,
"
type
"
:
"
bytes32
"
},{
"
indexed
"
:
true
,
"
name
"
:
"
addr
"
,
"
type
"
:
"
address
"
},{
"
indexed
"
:
false
,
"
name
"
:
"
owner
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
PrimaryChanged
"
,
"
type
"
:
"
event
"
}];
var
REG_ADDR
=
"
0xe53cb2ace8707526a5050bec7bcf979c57f8b44f
"
;
var
REG_ABI
=
[{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
name
"
,
"
outputs
"
:[{
"
name
"
:
"
o_name
"
,
"
type
"
:
"
bytes32
"
}],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
owner
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
address
"
}],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
content
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
bytes32
"
}],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
addr
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
address
"
}],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
subRegistrar
"
,
"
outputs
"
:[{
"
name
"
:
"
o_subRegistrar
"
,
"
type
"
:
"
address
"
}],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
reserve
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_owner
"
,
"
type
"
:
"
address
"
},{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
reserveFor
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_newOwner
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
transfer
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_registrar
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
setSubRegistrar
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[],
"
name
"
:
"
Registrar
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_a
"
,
"
type
"
:
"
address
"
},{
"
name
"
:
"
_primary
"
,
"
type
"
:
"
bool
"
}],
"
name
"
:
"
setAddress
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
},{
"
name
"
:
"
_content
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
setContent
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
false
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
disown
"
,
"
outputs
"
:[],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
constant
"
:
true
,
"
inputs
"
:[{
"
name
"
:
"
_name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
register
"
,
"
outputs
"
:[{
"
name
"
:
""
,
"
type
"
:
"
address
"
}],
"
payable
"
:
false
,
"
type
"
:
"
function
"
},{
"
anonymous
"
:
false
,
"
inputs
"
:[{
"
indexed
"
:
true
,
"
name
"
:
"
name
"
,
"
type
"
:
"
bytes32
"
}],
"
name
"
:
"
Changed
"
,
"
type
"
:
"
event
"
},{
"
anonymous
"
:
false
,
"
inputs
"
:[{
"
indexed
"
:
true
,
"
name
"
:
"
name
"
,
"
type
"
:
"
bytes32
"
},{
"
indexed
"
:
true
,
"
name
"
:
"
addr
"
,
"
type
"
:
"
address
"
},{
"
indexed
"
:
false
,
"
name
"
:
"
owner
"
,
"
type
"
:
"
address
"
}],
"
name
"
:
"
PrimaryChanged
"
,
"
type
"
:
"
event
"
}];
var
account
;
var
account
;
var
regContract
;
var
regContract
;
...
@@ -69,30 +70,39 @@ function waitForGaz(want, cb) {
...
@@ -69,30 +70,39 @@ function waitForGaz(want, cb) {
function
loadContract
()
{
function
loadContract
()
{
fs
.
readFile
(
REG_ADDR_FILE
,
function
(
err
,
content
)
{
fs
.
readFile
(
REG_ADDR_FILE
,
function
(
err
,
content
)
{
if
(
!
err
)
{
if
(
err
)
{
REG_ADDR
=
content
;
}
else
{
console
.
log
(
"
Can't read contract address:
"
+
err
);
console
.
log
(
"
Can't read contract address:
"
+
err
);
}
else
{
REG_ADDR
=
String
(
content
);
}
}
console
.
log
(
"
Loading name contract from blockchain at
"
+
REG_ADDR
);
fs
.
readFile
(
REG_ABI_FILE
,
function
(
err
,
abi_str
){
web3
.
eth
.
getCode
(
REG_ADDR
,
function
(
error
,
result
)
{
if
(
err
)
//console.log("Contract code at " + REG_ADDR + ": " + result);
console
.
log
(
"
Can't read contract ABI:
"
+
err
);
if
(
result
==
"
0x
"
)
{
else
console
.
log
(
"
Contract not found at
"
+
REG_ADDR
);
REG_ABI
=
JSON
.
parse
(
abi_str
);
initContract
();
console
.
log
(
"
Loading name contract from blockchain at
"
+
REG_ADDR
);
}
else
{
web3
.
eth
.
getCode
(
REG_ADDR
,
function
(
error
,
result
)
{
regContract
=
web3
.
eth
.
contract
(
REG_ABI
);
if
(
error
)
regContract
.
at
(
REG_ADDR
,
function
(
err
,
result
)
{
console
.
log
(
"
Error getting contract code:
"
+
error
);
console
.
log
(
"
Contract found and loaded from
"
+
REG_ADDR
);
/*else
if
(
!
err
)
{
console.log("Contract code at " + REG_ADDR + ": " + result);*/
reg
=
result
;
if
(
!
result
||
result
==
"
0x
"
)
{
startServer
();
console
.
log
(
"
Contract not found at
"
+
REG_ADDR
);
}
initContract
();
else
{
}
else
{
console
.
error
(
"
err:
"
+
err
);
regContract
=
web3
.
eth
.
contract
(
REG_ABI
);
}
regContract
.
at
(
REG_ADDR
,
function
(
err
,
result
)
{
});
console
.
log
(
"
Contract found and loaded from
"
+
REG_ADDR
);
}
if
(
!
err
)
{
reg
=
result
;
startServer
();
}
else
{
console
.
error
(
"
err:
"
+
err
);
}
});
}
});
});
});
});
});
}
}
...
@@ -108,6 +118,7 @@ function initContract() {
...
@@ -108,6 +118,7 @@ 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
;
fs
.
writeFile
(
REG_ABI_FILE
,
JSON
.
stringify
(
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
){
...
...
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