mirror of https://github.com/status-im/web3.js.git
icap.html example
This commit is contained in:
parent
6fb04d8816
commit
e9483a6404
|
@ -1279,6 +1279,18 @@ var isJson = function (str) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This method should be called to check if string is valid ethereum IBAN number
|
||||
* Supports direct and indirect IBANs
|
||||
*
|
||||
* @method isIBAN
|
||||
* @param {String}
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isIBAN = function (iban) {
|
||||
return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30})$/.test(iban);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
padLeft: padLeft,
|
||||
toHex: toHex,
|
||||
|
@ -1302,7 +1314,8 @@ module.exports = {
|
|||
isObject: isObject,
|
||||
isBoolean: isBoolean,
|
||||
isArray: isArray,
|
||||
isJson: isJson
|
||||
isJson: isJson,
|
||||
isIBAN: isIBAN
|
||||
};
|
||||
|
||||
|
||||
|
@ -1436,6 +1449,7 @@ web3.toBigNumber = utils.toBigNumber;
|
|||
web3.toWei = utils.toWei;
|
||||
web3.fromWei = utils.fromWei;
|
||||
web3.isAddress = utils.isAddress;
|
||||
web3.isIBAN = utils.isIBAN;
|
||||
web3.sha3 = sha3;
|
||||
web3.createBatch = function () {
|
||||
return new Batch();
|
||||
|
@ -2766,7 +2780,7 @@ SolidityFunction.prototype.unpackOutput = function (output) {
|
|||
* @return {String} output bytes
|
||||
*/
|
||||
SolidityFunction.prototype.call = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
|
||||
var callback = this.extractCallback(args);
|
||||
var payload = this.toPayload(args);
|
||||
|
||||
|
@ -2788,7 +2802,7 @@ SolidityFunction.prototype.call = function () {
|
|||
* @param {Object} options
|
||||
*/
|
||||
SolidityFunction.prototype.sendTransaction = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
|
||||
var callback = this.extractCallback(args);
|
||||
var payload = this.toPayload(args);
|
||||
|
||||
|
@ -2992,6 +3006,8 @@ module.exports = HttpProvider;
|
|||
* @date 2015
|
||||
*/
|
||||
|
||||
var utils = require('../utils/utils');
|
||||
|
||||
/**
|
||||
* This prototype should be used to extract necessary information from iban address
|
||||
*
|
||||
|
@ -3008,7 +3024,7 @@ var ICAP = function (iban) {
|
|||
* @returns {Boolean} true if it is, otherwise false
|
||||
*/
|
||||
ICAP.prototype.isValid = function () {
|
||||
return true;
|
||||
return utils.isIBAN(this._iban);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3031,17 +3047,6 @@ ICAP.prototype.isIndirect = function () {
|
|||
return this._iban.length === 20;
|
||||
};
|
||||
|
||||
/**
|
||||
* Should return iban country code
|
||||
* For ethereum it should always XE
|
||||
*
|
||||
* @method countryCode
|
||||
* @returns {String} countryCode
|
||||
*/
|
||||
ICAP.prototype.countryCode = function () {
|
||||
return this._iban.substr(0, 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get iban checksum
|
||||
* Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
|
||||
|
@ -3053,17 +3058,6 @@ ICAP.prototype.checksum = function () {
|
|||
return this._iban.substr(2, 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Asset identifier
|
||||
* For ethereum based contracts ETH is the only valid identifier
|
||||
*
|
||||
* @method asset
|
||||
* @returns {String} asset indetifier
|
||||
*/
|
||||
ICAP.prototype.asset = function () {
|
||||
return this.isIndirect() ? this._iban.substr(4, 3) : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get institution identifier
|
||||
* eg. XREG
|
||||
|
@ -3099,7 +3093,7 @@ ICAP.prototype.address = function () {
|
|||
module.exports = ICAP;
|
||||
|
||||
|
||||
},{}],21:[function(require,module,exports){
|
||||
},{"../utils/utils":7}],21:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -3980,7 +3974,7 @@ var transfer = function (iban, from, value, callback) {
|
|||
}
|
||||
|
||||
if (!callback) {
|
||||
var address = namereg.addressOf(icap.insitution());
|
||||
var address = namereg.addressOf(icap.institution());
|
||||
return deposit(address, from, value, icap.client());
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1279,6 +1279,18 @@ var isJson = function (str) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This method should be called to check if string is valid ethereum IBAN number
|
||||
* Supports direct and indirect IBANs
|
||||
*
|
||||
* @method isIBAN
|
||||
* @param {String}
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isIBAN = function (iban) {
|
||||
return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30})$/.test(iban);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
padLeft: padLeft,
|
||||
toHex: toHex,
|
||||
|
@ -1302,7 +1314,8 @@ module.exports = {
|
|||
isObject: isObject,
|
||||
isBoolean: isBoolean,
|
||||
isArray: isArray,
|
||||
isJson: isJson
|
||||
isJson: isJson,
|
||||
isIBAN: isIBAN
|
||||
};
|
||||
|
||||
|
||||
|
@ -1436,6 +1449,7 @@ web3.toBigNumber = utils.toBigNumber;
|
|||
web3.toWei = utils.toWei;
|
||||
web3.fromWei = utils.fromWei;
|
||||
web3.isAddress = utils.isAddress;
|
||||
web3.isIBAN = utils.isIBAN;
|
||||
web3.sha3 = sha3;
|
||||
web3.createBatch = function () {
|
||||
return new Batch();
|
||||
|
@ -2766,7 +2780,7 @@ SolidityFunction.prototype.unpackOutput = function (output) {
|
|||
* @return {String} output bytes
|
||||
*/
|
||||
SolidityFunction.prototype.call = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
|
||||
var callback = this.extractCallback(args);
|
||||
var payload = this.toPayload(args);
|
||||
|
||||
|
@ -2788,7 +2802,7 @@ SolidityFunction.prototype.call = function () {
|
|||
* @param {Object} options
|
||||
*/
|
||||
SolidityFunction.prototype.sendTransaction = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
|
||||
var callback = this.extractCallback(args);
|
||||
var payload = this.toPayload(args);
|
||||
|
||||
|
@ -2992,6 +3006,8 @@ module.exports = HttpProvider;
|
|||
* @date 2015
|
||||
*/
|
||||
|
||||
var utils = require('../utils/utils');
|
||||
|
||||
/**
|
||||
* This prototype should be used to extract necessary information from iban address
|
||||
*
|
||||
|
@ -3008,7 +3024,7 @@ var ICAP = function (iban) {
|
|||
* @returns {Boolean} true if it is, otherwise false
|
||||
*/
|
||||
ICAP.prototype.isValid = function () {
|
||||
return true;
|
||||
return utils.isIBAN(this._iban);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3031,17 +3047,6 @@ ICAP.prototype.isIndirect = function () {
|
|||
return this._iban.length === 20;
|
||||
};
|
||||
|
||||
/**
|
||||
* Should return iban country code
|
||||
* For ethereum it should always XE
|
||||
*
|
||||
* @method countryCode
|
||||
* @returns {String} countryCode
|
||||
*/
|
||||
ICAP.prototype.countryCode = function () {
|
||||
return this._iban.substr(0, 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get iban checksum
|
||||
* Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
|
||||
|
@ -3053,17 +3058,6 @@ ICAP.prototype.checksum = function () {
|
|||
return this._iban.substr(2, 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Asset identifier
|
||||
* For ethereum based contracts ETH is the only valid identifier
|
||||
*
|
||||
* @method asset
|
||||
* @returns {String} asset indetifier
|
||||
*/
|
||||
ICAP.prototype.asset = function () {
|
||||
return this.isIndirect() ? this._iban.substr(4, 3) : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get institution identifier
|
||||
* eg. XREG
|
||||
|
@ -3099,7 +3093,7 @@ ICAP.prototype.address = function () {
|
|||
module.exports = ICAP;
|
||||
|
||||
|
||||
},{}],21:[function(require,module,exports){
|
||||
},{"../utils/utils":7}],21:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -3980,7 +3974,7 @@ var transfer = function (iban, from, value, callback) {
|
|||
}
|
||||
|
||||
if (!callback) {
|
||||
var address = namereg.addressOf(icap.insitution());
|
||||
var address = namereg.addressOf(icap.institution());
|
||||
return deposit(address, from, value, icap.client());
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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.addressOf('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.addressOf(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>
|
|
@ -447,6 +447,18 @@ var isJson = function (str) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This method should be called to check if string is valid ethereum IBAN number
|
||||
* Supports direct and indirect IBANs
|
||||
*
|
||||
* @method isIBAN
|
||||
* @param {String}
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isIBAN = function (iban) {
|
||||
return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30})$/.test(iban);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
padLeft: padLeft,
|
||||
toHex: toHex,
|
||||
|
@ -470,6 +482,7 @@ module.exports = {
|
|||
isObject: isObject,
|
||||
isBoolean: isBoolean,
|
||||
isArray: isArray,
|
||||
isJson: isJson
|
||||
isJson: isJson,
|
||||
isIBAN: isIBAN
|
||||
};
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ web3.toBigNumber = utils.toBigNumber;
|
|||
web3.toWei = utils.toWei;
|
||||
web3.fromWei = utils.fromWei;
|
||||
web3.isAddress = utils.isAddress;
|
||||
web3.isIBAN = utils.isIBAN;
|
||||
web3.sha3 = sha3;
|
||||
web3.createBatch = function () {
|
||||
return new Batch();
|
||||
|
|
|
@ -95,7 +95,7 @@ SolidityFunction.prototype.unpackOutput = function (output) {
|
|||
* @return {String} output bytes
|
||||
*/
|
||||
SolidityFunction.prototype.call = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
|
||||
var callback = this.extractCallback(args);
|
||||
var payload = this.toPayload(args);
|
||||
|
||||
|
@ -117,7 +117,7 @@ SolidityFunction.prototype.call = function () {
|
|||
* @param {Object} options
|
||||
*/
|
||||
SolidityFunction.prototype.sendTransaction = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
|
||||
var callback = this.extractCallback(args);
|
||||
var payload = this.toPayload(args);
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
* @date 2015
|
||||
*/
|
||||
|
||||
var utils = require('../utils/utils');
|
||||
|
||||
/**
|
||||
* This prototype should be used to extract necessary information from iban address
|
||||
*
|
||||
|
@ -36,7 +38,7 @@ var ICAP = function (iban) {
|
|||
* @returns {Boolean} true if it is, otherwise false
|
||||
*/
|
||||
ICAP.prototype.isValid = function () {
|
||||
return true;
|
||||
return utils.isIBAN(this._iban);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -59,17 +61,6 @@ ICAP.prototype.isIndirect = function () {
|
|||
return this._iban.length === 20;
|
||||
};
|
||||
|
||||
/**
|
||||
* Should return iban country code
|
||||
* For ethereum it should always XE
|
||||
*
|
||||
* @method countryCode
|
||||
* @returns {String} countryCode
|
||||
*/
|
||||
ICAP.prototype.countryCode = function () {
|
||||
return this._iban.substr(0, 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get iban checksum
|
||||
* Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
|
||||
|
@ -81,17 +72,6 @@ ICAP.prototype.checksum = function () {
|
|||
return this._iban.substr(2, 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* Asset identifier
|
||||
* For ethereum based contracts ETH is the only valid identifier
|
||||
*
|
||||
* @method asset
|
||||
* @returns {String} asset indetifier
|
||||
*/
|
||||
ICAP.prototype.asset = function () {
|
||||
return this.isIndirect() ? this._iban.substr(4, 3) : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Should be called to get institution identifier
|
||||
* eg. XREG
|
||||
|
|
|
@ -49,7 +49,7 @@ var transfer = function (iban, from, value, callback) {
|
|||
}
|
||||
|
||||
if (!callback) {
|
||||
var address = namereg.addressOf(icap.insitution());
|
||||
var address = namereg.addressOf(icap.institution());
|
||||
return deposit(address, from, value, icap.client());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue