mirror of https://github.com/status-im/web3.js.git
use "official" namereg, updated examples
This commit is contained in:
parent
d8ad2b7a98
commit
dfd5060a6a
|
@ -3403,17 +3403,24 @@ module.exports = Method;
|
||||||
|
|
||||||
var contract = require('./contract');
|
var contract = require('./contract');
|
||||||
|
|
||||||
var address = '0xb9b5002e4d93944eb47050a16512bc576c7508c0';
|
var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
||||||
//var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
|
||||||
var abi = [
|
var abi = [
|
||||||
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"getName","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
|
||||||
{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"register","outputs":[],"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":"addressOf","outputs":[{"name":"addr","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":"getAddress","outputs":[{"name":"o_owner","type":"address"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},
|
||||||
{"constant":false,"inputs":[],"name":"unregister","outputs":[],"type":"function"},
|
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"},
|
||||||
{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"nameOf","outputs":[{"name":"name","type":"bytes32"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"},
|
||||||
{"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"AddressRegistered","type":"event"},
|
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"},
|
||||||
{"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"AddressDeregistered","type":"event"}
|
{"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"}],"name":"PrimaryChanged","type":"event"}
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = contract(abi).at(address);
|
module.exports = contract(abi).at(address);
|
||||||
|
@ -3992,11 +3999,11 @@ var transfer = function (iban, from, value, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
var address = namereg.addressOf(icap.institution());
|
var address = namereg.addr(icap.institution());
|
||||||
return deposit(address, from, value, icap.client());
|
return deposit(address, from, value, icap.client());
|
||||||
}
|
}
|
||||||
|
|
||||||
namereg.addressOf(icap.insitution(), function (err, address) {
|
namereg.addr(icap.insitution(), function (err, address) {
|
||||||
return deposit(address, from, value, icap.client(), callback);
|
return deposit(address, from, value, icap.client(), callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -3403,17 +3403,24 @@ module.exports = Method;
|
||||||
|
|
||||||
var contract = require('./contract');
|
var contract = require('./contract');
|
||||||
|
|
||||||
var address = '0xb9b5002e4d93944eb47050a16512bc576c7508c0';
|
var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
||||||
//var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
|
||||||
var abi = [
|
var abi = [
|
||||||
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"getName","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
|
||||||
{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"register","outputs":[],"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":"addressOf","outputs":[{"name":"addr","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":"getAddress","outputs":[{"name":"o_owner","type":"address"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},
|
||||||
{"constant":false,"inputs":[],"name":"unregister","outputs":[],"type":"function"},
|
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"},
|
||||||
{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"nameOf","outputs":[{"name":"name","type":"bytes32"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"},
|
||||||
{"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"AddressRegistered","type":"event"},
|
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"},
|
||||||
{"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"AddressDeregistered","type":"event"}
|
{"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"}],"name":"PrimaryChanged","type":"event"}
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = contract(abi).at(address);
|
module.exports = contract(abi).at(address);
|
||||||
|
@ -3992,11 +3999,11 @@ var transfer = function (iban, from, value, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
var address = namereg.addressOf(icap.institution());
|
var address = namereg.addr(icap.institution());
|
||||||
return deposit(address, from, value, icap.client());
|
return deposit(address, from, value, icap.client());
|
||||||
}
|
}
|
||||||
|
|
||||||
namereg.addressOf(icap.insitution(), function (err, address) {
|
namereg.addr(icap.insitution(), function (err, address) {
|
||||||
return deposit(address, from, value, icap.client(), callback);
|
return deposit(address, from, value, icap.client(), callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -35,7 +35,7 @@
|
||||||
"type" : "event"
|
"type" : "event"
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var ExchangeInterface = web3.eth.contract(abi).at(web3.eth.namereg.addressOf('XREG'));
|
var ExchangeInterface = web3.eth.contract(abi).at(web3.eth.namereg.addr('XREG'));
|
||||||
var filter = ExchangeInterface.Deposit({}, {fromBlock: 0});
|
var filter = ExchangeInterface.Deposit({}, {fromBlock: 0});
|
||||||
filter.watch(function (err, event) {
|
filter.watch(function (err, event) {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
return document.getElementById('ibanValidation').innerText = 'IBAN number is incorrect';
|
return document.getElementById('ibanValidation').innerText = 'IBAN number is incorrect';
|
||||||
}
|
}
|
||||||
var institution = iban.substr(7, 4);
|
var institution = iban.substr(7, 4);
|
||||||
var address = web3.eth.namereg.addressOf(institution);
|
var address = web3.eth.namereg.addr(institution);
|
||||||
document.getElementById('ibanValidation').innerText = 'IBAN number correct, exchange address: ' + address;
|
document.getElementById('ibanValidation').innerText = 'IBAN number correct, exchange address: ' + address;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,54 +11,59 @@
|
||||||
web3.eth.defaultAccount = from;
|
web3.eth.defaultAccount = from;
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
document.getElementById('yourName').innerText = web3.eth.namereg.nameOf(web3.eth.coinbase);
|
var filter = web3.eth.namereg.Changed();
|
||||||
var filter = web3.eth.namereg.AddressRegistered();
|
|
||||||
filter.watch(function (err, event) {
|
filter.watch(function (err, event) {
|
||||||
// live update all fields
|
// live update all fields
|
||||||
document.getElementById('yourName').innerText = web3.eth.namereg.nameOf(web3.eth.coinbase);
|
onAddressKeyUp();
|
||||||
if (from === event.args.account) {
|
onNameKeyUp();
|
||||||
document.getElementById('progress').innerText = 'name changed!';
|
onRegisterOwnerKeyUp();
|
||||||
}
|
|
||||||
|
|
||||||
var name = document.getElementById('name').value;
|
|
||||||
var address = document.getElementById('address').value;
|
|
||||||
document.getElementById('addressOf').innerText = web3.eth.namereg.addressOf(name);
|
|
||||||
document.getElementById('nameOf').innerText = web3.eth.namereg.nameOf(address);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function changeName() {
|
function registerOwner() {
|
||||||
var name = document.getElementById('newName').value;
|
var name = document.getElementById('registerOwner').value;
|
||||||
web3.eth.namereg.register(name);
|
web3.eth.namereg.reserve(name);
|
||||||
document.getElementById('progress').innerText = 'changing name in progress, please wait...';
|
document.getElementById('nameAvailability').innerText += ' Registering name in progress, please wait...';
|
||||||
|
};
|
||||||
|
|
||||||
|
function changeAddress() {
|
||||||
|
var name = document.getElementById('registerOwner').value;
|
||||||
|
var address = document.getElementById('newAddress').value;
|
||||||
|
web3.eth.namereg.setAddress(name, address, true);
|
||||||
|
document.getElementById('currentAddress').innerText += ' Changing address in progress. Please wait.';
|
||||||
|
};
|
||||||
|
|
||||||
|
function onRegisterOwnerKeyUp() {
|
||||||
|
var name = document.getElementById('registerOwner').value;
|
||||||
|
var owner = web3.eth.namereg.owner(name)
|
||||||
|
document.getElementById('currentAddress').innerText = web3.eth.namereg.addr(name);
|
||||||
|
if (owner !== '0x0000000000000000000000000000000000000000') {
|
||||||
|
if (owner === from) {
|
||||||
|
document.getElementById('nameAvailability').innerText = "This name is already owned by you " + owner;
|
||||||
|
} else {
|
||||||
|
document.getElementById('nameAvailability').innerText = "This name is not available. It's already registered by " + owner;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
document.getElementById('nameAvailability').innerText = "This name is available. You can register it.";
|
||||||
};
|
};
|
||||||
|
|
||||||
function onAddressKeyUp() {
|
function onAddressKeyUp() {
|
||||||
var address = document.getElementById('address').value;
|
var address = document.getElementById('address').value;
|
||||||
document.getElementById('nameOf').innerText = web3.eth.namereg.nameOf(address);
|
document.getElementById('nameOf').innerText = web3.eth.namereg.name(address);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onNameKeyUp() {
|
function onNameKeyUp() {
|
||||||
var name = document.getElementById('name').value;
|
var name = document.getElementById('name').value;
|
||||||
document.getElementById('addressOf').innerText = web3.eth.namereg.addressOf(name);
|
document.getElementById('addressOf').innerText = web3.eth.namereg.addr(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<i>This example shows only part of namereg functionalities. Namereg contract is available <a href="https://github.com/ethereum/dapp-bin/blob/master/GlobalRegistrar/contract.sol">here</a>
|
||||||
|
</i>
|
||||||
<h1>Namereg</h1>
|
<h1>Namereg</h1>
|
||||||
<h3>Register name</h3>
|
|
||||||
<div>
|
|
||||||
<text>Your current name is: </text>
|
|
||||||
<text id="yourName"></text>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<text>Change name: </text>
|
|
||||||
<input type="text" id="newName"></input>
|
|
||||||
<button id="changeName" type="button" onClick="changeName()">Change!</button>
|
|
||||||
<text id="progress"></text>
|
|
||||||
</div>
|
|
||||||
<h3>Search for name</h3>
|
<h3>Search for name</h3>
|
||||||
<div>
|
<div>
|
||||||
<text>Address: </text>
|
<text>Address: </text>
|
||||||
|
@ -73,6 +78,25 @@
|
||||||
<text>Address: </text>
|
<text>Address: </text>
|
||||||
<text id="addressOf"></text>
|
<text id="addressOf"></text>
|
||||||
</div>
|
</div>
|
||||||
|
<h3>Register name</h3>
|
||||||
|
<div>
|
||||||
|
<text>Check if name is available: </text>
|
||||||
|
<input type="text" id="registerOwner" onkeyup='onRegisterOwnerKeyUp()'></input>
|
||||||
|
<text id='nameAvailability'></text>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button id="registerOwnerButton" type="button" onClick="registerOwner()">Register!</button>
|
||||||
|
</div>
|
||||||
|
<h3></h3>
|
||||||
|
<i>If you own the name, you can also change the address it points to</i>
|
||||||
|
<div>
|
||||||
|
<text>Address: </text>
|
||||||
|
<input type="text" id="newAddress"></input>
|
||||||
|
<button id="changeAddress" type="button" onClick="changeAddress()">Change address!</button>
|
||||||
|
<text>Current address :</text>
|
||||||
|
<text id="currentAddress"></text>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -22,17 +22,24 @@
|
||||||
|
|
||||||
var contract = require('./contract');
|
var contract = require('./contract');
|
||||||
|
|
||||||
var address = '0xb9b5002e4d93944eb47050a16512bc576c7508c0';
|
var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
||||||
//var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
|
||||||
var abi = [
|
var abi = [
|
||||||
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"getName","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
|
||||||
{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"register","outputs":[],"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":"addressOf","outputs":[{"name":"addr","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":"getAddress","outputs":[{"name":"o_owner","type":"address"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},
|
||||||
{"constant":false,"inputs":[],"name":"unregister","outputs":[],"type":"function"},
|
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"},
|
||||||
{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"nameOf","outputs":[{"name":"name","type":"bytes32"}],"type":"function"},
|
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"},
|
||||||
{"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"AddressRegistered","type":"event"},
|
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"},
|
||||||
{"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"AddressDeregistered","type":"event"}
|
{"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"}],"name":"PrimaryChanged","type":"event"}
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = contract(abi).at(address);
|
module.exports = contract(abi).at(address);
|
||||||
|
|
|
@ -49,11 +49,11 @@ var transfer = function (iban, from, value, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
var address = namereg.addressOf(icap.institution());
|
var address = namereg.addr(icap.institution());
|
||||||
return deposit(address, from, value, icap.client());
|
return deposit(address, from, value, icap.client());
|
||||||
}
|
}
|
||||||
|
|
||||||
namereg.addressOf(icap.insitution(), function (err, address) {
|
namereg.addr(icap.insitution(), function (err, address) {
|
||||||
return deposit(address, from, value, icap.client(), callback);
|
return deposit(address, from, value, icap.client(), callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue