-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,127 additions
and
62 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<!doctype> | ||
<html> | ||
|
||
<head> | ||
<script type="text/javascript" src="../dist/web3.js"></script> | ||
<script type="text/javascript"> | ||
|
||
var web3 = require('web3'); | ||
var BigNumber = require('bignumber.js'); | ||
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545")); | ||
var from = web3.eth.coinbase; | ||
web3.eth.defaultAccount = from; | ||
|
||
window.onload = function () { | ||
var abi = [{ | ||
"anonymous" : false, | ||
"inputs" : [ | ||
{ | ||
"indexed" : true, | ||
"name" : "_from", | ||
"type" : "address" | ||
}, | ||
{ | ||
"indexed" : false, | ||
"name" : "_id", | ||
"type" : "bytes32" | ||
}, | ||
{ | ||
"indexed" : false, | ||
"name" : "_value", | ||
"type" : "uint256" | ||
} | ||
], | ||
"name" : "Deposit", | ||
"type" : "event" | ||
}]; | ||
|
||
var ExchangeInterface = web3.eth.contract(abi).at(web3.eth.namereg.addr('XREG')); | ||
var filter = ExchangeInterface.Deposit({}, {fromBlock: 0}); | ||
filter.watch(function (err, event) { | ||
console.log(event); | ||
displayDeposit("block: " + event.blockNumber + " user: " + event.args._id + "\nvalue : " + event.args._value.toString(10)); | ||
}); | ||
}; | ||
|
||
function displayDeposit(text) { | ||
var node = document.createElement('li'); | ||
var textnode = document.createTextNode(text); | ||
node.appendChild(textnode); | ||
document.getElementById('deposits').appendChild(node); | ||
} | ||
|
||
function validateValue() { | ||
try { | ||
var value = document.getElementById('value').value; | ||
var bnValue = new BigNumber(value); | ||
document.getElementById('valueValidation').innerText = bnValue.toString(10); | ||
} catch (err) { | ||
document.getElementById('valueValidation').innerText = 'Value is incorrect, cannot parse'; | ||
} | ||
}; | ||
|
||
function validateIBAN() { | ||
var iban = document.getElementById('iban').value; | ||
if (!web3.isIBAN(iban)) { | ||
return document.getElementById('ibanValidation').innerText = 'IBAN number is incorrect'; | ||
} | ||
var institution = iban.substr(7, 4); | ||
var address = web3.eth.namereg.addr(institution); | ||
document.getElementById('ibanValidation').innerText = 'IBAN number correct, exchange address: ' + address; | ||
}; | ||
|
||
function transfer() { | ||
var value = new BigNumber(document.getElementById('value').value); | ||
var iban = document.getElementById('iban').value; | ||
web3.eth.icapTransfer(iban, from, value); | ||
}; | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<h1>ICAP</h1> | ||
<h3>Transfer</h3> | ||
<div> | ||
<text>Destination IBAN (eg. XE81ETHXREGGAVOFYORK): </text> | ||
<input type="text" id="iban" onkeyup='validateIBAN()'></input> | ||
<text id="ibanValidation"></text> | ||
</div> | ||
<div> | ||
<text>Value: </text> | ||
<input type="text" id="value" onkeyup='validateValue()'></input> | ||
<text id="valueValidation"></text> | ||
</div> | ||
<div> | ||
<button id="transfer" type="button" onClick="transfer()">Transfer!</button> | ||
</div> | ||
<h3>"XREG" Exchange deposits</h3> | ||
<ul id="deposits"></ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!doctype> | ||
<html> | ||
|
||
<head> | ||
<script type="text/javascript" src="../dist/web3.js"></script> | ||
<script type="text/javascript"> | ||
|
||
var web3 = require('web3'); | ||
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545")); | ||
var from = web3.eth.coinbase; | ||
web3.eth.defaultAccount = from; | ||
|
||
window.onload = function () { | ||
var filter = web3.eth.namereg.Changed(); | ||
filter.watch(function (err, event) { | ||
// live update all fields | ||
onAddressKeyUp(); | ||
onNameKeyUp(); | ||
onRegisterOwnerKeyUp(); | ||
}); | ||
}; | ||
|
||
function registerOwner() { | ||
var name = document.getElementById('registerOwner').value; | ||
web3.eth.namereg.reserve(name); | ||
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() { | ||
var address = document.getElementById('address').value; | ||
document.getElementById('nameOf').innerText = web3.eth.namereg.name(address); | ||
}; | ||
|
||
function onNameKeyUp() { | ||
var name = document.getElementById('name').value; | ||
document.getElementById('addressOf').innerText = web3.eth.namereg.addr(name); | ||
}; | ||
|
||
</script> | ||
</head> | ||
<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> | ||
<h3>Search for name</h3> | ||
<div> | ||
<text>Address: </text> | ||
<input type="text" id="address" onkeyup='onAddressKeyUp()'></input> | ||
<text>Name: </text> | ||
<text id="nameOf"></text> | ||
</div> | ||
<h3>Search for address</h3> | ||
<div> | ||
<text>Name: </text> | ||
<input type="text" id="name" onkeyup='onNameKeyUp()'></input> | ||
<text>Address: </text> | ||
<text id="addressOf"></text> | ||
</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> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
This file is part of ethereum.js. | ||
ethereum.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
ethereum.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
* @file icap.js | ||
* @author Marek Kotewicz <marek@ethdev.com> | ||
* @date 2015 | ||
*/ | ||
|
||
var utils = require('../utils/utils'); | ||
|
||
/** | ||
* This prototype should be used to extract necessary information from iban address | ||
* | ||
* @param {String} iban | ||
*/ | ||
var ICAP = function (iban) { | ||
this._iban = iban; | ||
}; | ||
|
||
/** | ||
* Should be called to check if icap is correct | ||
* | ||
* @method isValid | ||
* @returns {Boolean} true if it is, otherwise false | ||
*/ | ||
ICAP.prototype.isValid = function () { | ||
return utils.isIBAN(this._iban); | ||
}; | ||
|
||
/** | ||
* Should be called to check if iban number is direct | ||
* | ||
* @method isDirect | ||
* @returns {Boolean} true if it is, otherwise false | ||
*/ | ||
ICAP.prototype.isDirect = function () { | ||
return this._iban.length === 34; | ||
}; | ||
|
||
/** | ||
* Should be called to check if iban number if indirect | ||
* | ||
* @method isIndirect | ||
* @returns {Boolean} true if it is, otherwise false | ||
*/ | ||
ICAP.prototype.isIndirect = function () { | ||
return this._iban.length === 20; | ||
}; | ||
|
||
/** | ||
* Should be called to get iban checksum | ||
* Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) | ||
* | ||
* @method checksum | ||
* @returns {String} checksum | ||
*/ | ||
ICAP.prototype.checksum = function () { | ||
return this._iban.substr(2, 2); | ||
}; | ||
|
||
/** | ||
* Should be called to get institution identifier | ||
* eg. XREG | ||
* | ||
* @method institution | ||
* @returns {String} institution identifier | ||
*/ | ||
ICAP.prototype.institution = function () { | ||
return this.isIndirect() ? this._iban.substr(7, 4) : ''; | ||
}; | ||
|
||
/** | ||
* Should be called to get client identifier within institution | ||
* eg. GAVOFYORK | ||
* | ||
* @method client | ||
* @returns {String} client identifier | ||
*/ | ||
ICAP.prototype.client = function () { | ||
return this.isIndirect() ? this._iban.substr(11) : ''; | ||
}; | ||
|
||
/** | ||
* Should be called to get client direct address | ||
* | ||
* @method address | ||
* @returns {String} client direct address | ||
*/ | ||
ICAP.prototype.address = function () { | ||
return this.isDirect() ? this._iban.substr(4) : ''; | ||
}; | ||
|
||
module.exports = ICAP; | ||
|
Oops, something went wrong.