Marek Kotewicz
10 years ago
37 changed files with 4600 additions and 747 deletions
@ -1,4 +1,3 @@ |
|||||
3stack:bignumber@2.0.0 |
ethereum:web3@0.5.0 |
||||
ethereum:js@0.0.15-rc12 |
meteor@1.1.6 |
||||
meteor@1.1.4 |
underscore@1.0.3 |
||||
underscore@1.0.2 |
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
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,203 @@ |
|||||
|
<!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; |
||||
|
|
||||
|
var nameregAbi = [ |
||||
|
{"constant":true,"inputs":[{"name":"_owner","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":"_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"}],"name":"PrimaryChanged","type":"event"} |
||||
|
]; |
||||
|
|
||||
|
var depositAbi = [{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"deposit","outputs":[],"type":"function"}]; |
||||
|
|
||||
|
var Namereg = web3.eth.contract(nameregAbi); |
||||
|
var Deposit = web3.eth.contract(depositAbi); |
||||
|
|
||||
|
var namereg = web3.eth.namereg; |
||||
|
var deposit; |
||||
|
var iban; |
||||
|
|
||||
|
function validateNamereg() { |
||||
|
var address = document.getElementById('namereg').value; |
||||
|
var ok = /^(0x)?[0-9a-f]{40}$/.test(address) || address === 'default'; |
||||
|
if (ok) { |
||||
|
namereg = address === 'default' ? web3.eth.namereg : Namereg.at(address); |
||||
|
document.getElementById('nameregValidation').innerText = 'ok!'; |
||||
|
} else { |
||||
|
document.getElementById('nameregValidation').innerText = 'namereg address is incorrect!'; |
||||
|
} |
||||
|
return ok; |
||||
|
}; |
||||
|
|
||||
|
function onNameregKeyUp() { |
||||
|
updateIBAN(validateNamereg()); |
||||
|
onExchangeKeyUp(); |
||||
|
}; |
||||
|
|
||||
|
function validateExchange() { |
||||
|
var exchange = document.getElementById('exchange').value; |
||||
|
var ok = /^[0-9A-Z]{4}$/.test(exchange); |
||||
|
if (ok) { |
||||
|
var address = namereg.addr(exchange); |
||||
|
deposit = Deposit.at(address); |
||||
|
document.getElementById('exchangeValidation').innerText = 'ok! address of exchange: ' + address; |
||||
|
} else { |
||||
|
document.getElementById('exchangeValidation').innerText = 'exchange id is incorrect'; |
||||
|
} |
||||
|
return ok; |
||||
|
}; |
||||
|
|
||||
|
function onExchangeKeyUp() { |
||||
|
updateIBAN(validateExchange()); |
||||
|
}; |
||||
|
|
||||
|
function validateClient() { |
||||
|
var client = document.getElementById('client').value; |
||||
|
var ok = /^[0-9A-Z]{9}$/.test(client); |
||||
|
if (ok) { |
||||
|
document.getElementById('clientValidation').innerText = 'ok!'; |
||||
|
} else { |
||||
|
document.getElementById('clientValidation').innerText = 'client id is incorrect'; |
||||
|
} |
||||
|
return ok; |
||||
|
}; |
||||
|
|
||||
|
function onClientKeyUp() { |
||||
|
updateIBAN(validateClient()); |
||||
|
}; |
||||
|
|
||||
|
function validateValue() { |
||||
|
try { |
||||
|
var value = document.getElementById('value').value; |
||||
|
var bnValue = new BigNumber(value); |
||||
|
document.getElementById('valueValidation').innerText = bnValue.toString(10); |
||||
|
return true; |
||||
|
} catch (err) { |
||||
|
document.getElementById('valueValidation').innerText = 'Value is incorrect, cannot parse'; |
||||
|
return false; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
function onValueKeyUp() { |
||||
|
validateValue(); |
||||
|
}; |
||||
|
|
||||
|
function validateIBAN() { |
||||
|
if (!web3.isIBAN(iban)) { |
||||
|
return document.getElementById('ibanValidation').innerText = ' - IBAN number is incorrect'; |
||||
|
} |
||||
|
document.getElementById('ibanValidation').innerText = ' - IBAN number correct'; |
||||
|
}; |
||||
|
|
||||
|
function updateIBAN(ok) { |
||||
|
var exchangeId = document.getElementById('exchange').value; |
||||
|
var clientId = document.getElementById('client').value; |
||||
|
iban = 'XE' + '00' + 'ETH' + exchangeId + clientId; |
||||
|
document.getElementById('iban').innerText = iban; |
||||
|
validateIBAN(); |
||||
|
}; |
||||
|
|
||||
|
function transfer() { |
||||
|
var value = new BigNumber(document.getElementById('value').value); |
||||
|
var exchange = document.getElementById('exchange').value; |
||||
|
var client = document.getElementById('client').value; |
||||
|
deposit.deposit(client, {value: value}); |
||||
|
displayTransfer("deposited client's " + client + " funds " + value.toString(10) + " to exchange " + exchange); |
||||
|
}; |
||||
|
|
||||
|
function displayTransfer(text) { |
||||
|
var node = document.createElement('li'); |
||||
|
var textnode = document.createTextNode(text); |
||||
|
node.appendChild(textnode); |
||||
|
document.getElementById('transfers').appendChild(node); |
||||
|
} |
||||
|
|
||||
|
</script> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>ICAP transfer</h1> |
||||
|
<div> |
||||
|
<h4>namereg address</h4> |
||||
|
</div> |
||||
|
<div> |
||||
|
<text>eg. 0x436474facc88948696b371052a1befb801f003ca or 'default')</text> |
||||
|
</div> |
||||
|
<div> |
||||
|
<input type="text" id="namereg" onkeyup='onNameregKeyUp()' value="default"></input> |
||||
|
<text id="nameregValidation"></text> |
||||
|
</div> |
||||
|
|
||||
|
<div> |
||||
|
<h4>exchange identifier</h4> |
||||
|
</div> |
||||
|
<div> |
||||
|
<text>eg. WYWY</text> |
||||
|
</div> |
||||
|
<div> |
||||
|
<input type="text" id="exchange" onkeyup='onExchangeKeyUp()'></input> |
||||
|
<text id="exchangeValidation"></text> |
||||
|
</div> |
||||
|
|
||||
|
<div> |
||||
|
<h4>client identifier</h4> |
||||
|
</div> |
||||
|
<div> |
||||
|
<text>eg. GAVOFYORK</text> |
||||
|
</div> |
||||
|
<div> |
||||
|
<input type="text" id="client" onkeyup='onClientKeyUp()'></input> |
||||
|
<text id="clientValidation"></text> |
||||
|
</div> |
||||
|
|
||||
|
<div> |
||||
|
<h4>value</h4> |
||||
|
</div> |
||||
|
<div> |
||||
|
<text>eg. 100</text> |
||||
|
</div> |
||||
|
<div> |
||||
|
<input type="text" id="value" onkeyup='onValueKeyUp()'></input> |
||||
|
<text id="valueValidation"></text> |
||||
|
</div> |
||||
|
|
||||
|
<div> </div> |
||||
|
<div> |
||||
|
<text>IBAN: </text> |
||||
|
<text id="iban"></text> |
||||
|
<text id="ibanValidation"></text> |
||||
|
</div> |
||||
|
<div> </div> |
||||
|
<div> |
||||
|
<button id="transfer" type="button" onClick="transfer()">Transfer!</button> |
||||
|
<text id="transferValidation"></text> |
||||
|
</div> |
||||
|
|
||||
|
<div> |
||||
|
<h4>transfers</h4> |
||||
|
</div> |
||||
|
<div> |
||||
|
<ul id='transfers'></ul> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -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> |
||||
|
|
@ -1,76 +0,0 @@ |
|||||
<!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()); |
|
||||
|
|
||||
// solidity source code |
|
||||
var source = "" + |
|
||||
"contract test {\n" + |
|
||||
" /// @notice Will multiply `a` by 7. \n" + |
|
||||
" function multiply(uint a) returns(uint d) {\n" + |
|
||||
" return a * 7;\n" + |
|
||||
" }\n" + |
|
||||
"}\n"; |
|
||||
|
|
||||
// contract description, this will be autogenerated somehow |
|
||||
var desc = [{ |
|
||||
"name": "multiply(uint256)", |
|
||||
"type": "function", |
|
||||
"inputs": [ |
|
||||
{ |
|
||||
"name": "a", |
|
||||
"type": "uint256" |
|
||||
} |
|
||||
], |
|
||||
"outputs": [ |
|
||||
{ |
|
||||
"name": "d", |
|
||||
"type": "uint256" |
|
||||
} |
|
||||
] |
|
||||
}]; |
|
||||
|
|
||||
var contract; |
|
||||
|
|
||||
function createExampleContract() { |
|
||||
// hide create button |
|
||||
document.getElementById('create').style.visibility = 'hidden'; |
|
||||
document.getElementById('source').innerText = source; |
|
||||
|
|
||||
// create contract |
|
||||
var address = web3.eth.sendTransaction({code: web3.eth.solidity(source)}); |
|
||||
contract = web3.eth.contract(address, desc); |
|
||||
document.getElementById('call').style.visibility = 'visible'; |
|
||||
} |
|
||||
|
|
||||
function callExampleContract() { |
|
||||
// this should be generated by ethereum |
|
||||
var param = parseInt(document.getElementById('value').value); |
|
||||
|
|
||||
// transaction does not return any result, cause it's not synchronous and we don't know, |
|
||||
// when it will be processed |
|
||||
contract.sendTransaction().multiply(param); |
|
||||
document.getElementById('result').innerText = 'transaction made'; |
|
||||
} |
|
||||
|
|
||||
</script> |
|
||||
</head> |
|
||||
<body> |
|
||||
<h1>contract</h1> |
|
||||
<div id="source"></div> |
|
||||
<div id='create'> |
|
||||
<button type="button" onClick="createExampleContract();">create example contract</button> |
|
||||
</div> |
|
||||
<div id='call' style='visibility: hidden;'> |
|
||||
<input type="number" id="value"></input> |
|
||||
<button type="button" onClick="callExampleContract()">Call Contract</button> |
|
||||
</div> |
|
||||
<div id="result"></div> |
|
||||
</body> |
|
||||
</html> |
|
||||
|
|
@ -0,0 +1,39 @@ |
|||||
|
/* |
||||
|
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 sha3.js |
||||
|
* @author Marek Kotewicz <marek@ethdev.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
var utils = require('./utils'); |
||||
|
var sha3 = require('crypto-js/sha3'); |
||||
|
|
||||
|
module.exports = function (str, isNew) { |
||||
|
if (str.substr(0, 2) === '0x' && !isNew) { |
||||
|
console.warn('requirement of using web3.fromAscii before sha3 is deprecated'); |
||||
|
console.warn('new usage: \'web3.sha3("hello")\''); |
||||
|
console.warn('see https://github.com/ethereum/web3.js/pull/205'); |
||||
|
console.warn('if you need to hash hex value, you can do \'sha3("0xfff", true)\''); |
||||
|
str = utils.toAscii(str); |
||||
|
} |
||||
|
|
||||
|
return sha3(str, { |
||||
|
outputLength: 256 |
||||
|
}).toString(); |
||||
|
}; |
||||
|
|
@ -1,3 +1,3 @@ |
|||||
{ |
{ |
||||
"version": "0.4.2" |
"version": "0.5.0" |
||||
} |
} |
||||
|
@ -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; |
||||
|
|
@ -0,0 +1,46 @@ |
|||||
|
/* |
||||
|
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 namereg.js |
||||
|
* @author Marek Kotewicz <marek@ethdev.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
var contract = require('./contract'); |
||||
|
|
||||
|
var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; |
||||
|
|
||||
|
var abi = [ |
||||
|
{"constant":true,"inputs":[{"name":"_owner","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":"_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"}],"name":"PrimaryChanged","type":"event"} |
||||
|
]; |
||||
|
|
||||
|
module.exports = contract(abi).at(address); |
||||
|
|
@ -0,0 +1,94 @@ |
|||||
|
/* |
||||
|
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 transfer.js |
||||
|
* @author Marek Kotewicz <marek@ethdev.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
var web3 = require('../web3'); |
||||
|
var ICAP = require('./icap'); |
||||
|
var namereg = require('./namereg'); |
||||
|
var contract = require('./contract'); |
||||
|
|
||||
|
/** |
||||
|
* Should be used to make ICAP transfer |
||||
|
* |
||||
|
* @method transfer |
||||
|
* @param {String} iban number |
||||
|
* @param {String} from (address) |
||||
|
* @param {Value} value to be tranfered |
||||
|
* @param {Function} callback, callback |
||||
|
*/ |
||||
|
var transfer = function (from, iban, value, callback) { |
||||
|
var icap = new ICAP(iban); |
||||
|
if (!icap.isValid()) { |
||||
|
throw new Error('invalid iban address'); |
||||
|
} |
||||
|
|
||||
|
if (icap.isDirect()) { |
||||
|
return transferToAddress(from, icap.address(), value, callback); |
||||
|
} |
||||
|
|
||||
|
if (!callback) { |
||||
|
var address = namereg.addr(icap.institution()); |
||||
|
return deposit(from, address, value, icap.client()); |
||||
|
} |
||||
|
|
||||
|
namereg.addr(icap.insitution(), function (err, address) { |
||||
|
return deposit(from, address, value, icap.client(), callback); |
||||
|
}); |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Should be used to transfer funds to certain address |
||||
|
* |
||||
|
* @method transferToAddress |
||||
|
* @param {String} address |
||||
|
* @param {String} from (address) |
||||
|
* @param {Value} value to be tranfered |
||||
|
* @param {Function} callback, callback |
||||
|
*/ |
||||
|
var transferToAddress = function (from, address, value, callback) { |
||||
|
return web3.eth.sendTransaction({ |
||||
|
address: address, |
||||
|
from: from, |
||||
|
value: value |
||||
|
}, callback); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) |
||||
|
* |
||||
|
* @method deposit |
||||
|
* @param {String} address |
||||
|
* @param {String} from (address) |
||||
|
* @param {Value} value to be tranfered |
||||
|
* @param {String} client unique identifier |
||||
|
* @param {Function} callback, callback |
||||
|
*/ |
||||
|
var deposit = function (from, address, value, client, callback) { |
||||
|
var abi = [{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"deposit","outputs":[],"type":"function"}]; |
||||
|
return contract(abi).at(address).deposit(client, { |
||||
|
from: from, |
||||
|
value: value |
||||
|
}, callback); |
||||
|
}; |
||||
|
|
||||
|
module.exports = transfer; |
||||
|
|
@ -0,0 +1,17 @@ |
|||||
|
var chai = require('chai'); |
||||
|
var assert = chai.assert; |
||||
|
var sha3 = require('../lib/utils/sha3'); |
||||
|
var web3 = require('../index'); |
||||
|
|
||||
|
describe('lib/utils/sha3', function () { |
||||
|
var test = function (v, e) { |
||||
|
it('should encode ' + v + ' to ' + e, function () { |
||||
|
assert.equal(sha3(v), e); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad'); |
||||
|
test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1'); |
||||
|
test(web3.fromAscii('test123'), 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad'); |
||||
|
}); |
||||
|
|
@ -0,0 +1,32 @@ |
|||||
|
var chai = require('chai'); |
||||
|
var utils = require('../lib/utils/utils.js'); |
||||
|
var assert = chai.assert; |
||||
|
|
||||
|
var tests = [ |
||||
|
{ obj: function () {}, is: false}, |
||||
|
{ obj: new Function(), is: false}, |
||||
|
{ obj: 'function', is: false}, |
||||
|
{ obj: {}, is: false}, |
||||
|
{ obj: '[]', is: false}, |
||||
|
{ obj: '[1, 2]', is: false}, |
||||
|
{ obj: '{}', is: false}, |
||||
|
{ obj: '{"a": 123, "b" :3,}', is: false}, |
||||
|
{ obj: '{"c" : 2}', is: false}, |
||||
|
{ obj: 'XE81ETHXREGGAVOFYORK', is: true}, |
||||
|
{ obj: 'XE81ETCXREGGAVOFYORK', is: false}, |
||||
|
{ obj: 'XE81ETHXREGGAVOFYORKD', is: false}, |
||||
|
{ obj: 'XE81ETHXREGGaVOFYORK', is: false}, |
||||
|
{ obj: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: true}, |
||||
|
{ obj: 'XD7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false} |
||||
|
]; |
||||
|
|
||||
|
describe('lib/utils/utils', function () { |
||||
|
describe('isIBAN', function () { |
||||
|
tests.forEach(function (test) { |
||||
|
it('shoud test if value ' + test.obj + ' is iban: ' + test.is, function () { |
||||
|
assert.equal(utils.isIBAN(test.obj), test.is); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
|
@ -0,0 +1,49 @@ |
|||||
|
var chai = require('chai'); |
||||
|
var assert = chai.assert; |
||||
|
var web3 = require('../index'); |
||||
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider'); |
||||
|
var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2'); |
||||
|
|
||||
|
describe('web3.eth.sendIBANTransaction', function () { |
||||
|
it('should send transaction', function () { |
||||
|
|
||||
|
var iban = 'XE81ETHXREGGAVOFYORK'; |
||||
|
var address = '0x1234567890123456789012345678901234500000'; |
||||
|
var exAddress = '0x1234567890123456789012345678901234567890' |
||||
|
|
||||
|
var provider = new FakeHttpProvider2(); |
||||
|
web3.setProvider(provider); |
||||
|
web3.reset(); |
||||
|
|
||||
|
provider.injectResultList([{ |
||||
|
result: exAddress |
||||
|
}, { |
||||
|
result: '' |
||||
|
}]); |
||||
|
|
||||
|
var step = 0; |
||||
|
provider.injectValidation(function (payload) { |
||||
|
if (step === 0) { |
||||
|
step++; |
||||
|
assert.equal(payload.method, 'eth_call'); |
||||
|
assert.deepEqual(payload.params, [{ |
||||
|
data: '0x3b3b57de5852454700000000000000000000000000000000000000000000000000000000', |
||||
|
to: web3.eth.namereg.address |
||||
|
}, "latest"]); |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
assert.equal(payload.method, 'eth_sendTransaction'); |
||||
|
assert.deepEqual(payload.params, [{ |
||||
|
data: '0xb214faa54741564f46594f524b0000000000000000000000000000000000000000000000', |
||||
|
from: address, |
||||
|
to: exAddress, |
||||
|
value: payload.params[0].value // don't check this
|
||||
|
}]); |
||||
|
}); |
||||
|
|
||||
|
web3.eth.sendIBANTransaction(address, iban, 10000); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
|
@ -1,16 +0,0 @@ |
|||||
var BigNumber = require('bignumber.js'); |
|
||||
var web3 = require('../index'); |
|
||||
var testMethod = require('./helpers/test.method.js'); |
|
||||
|
|
||||
var method = 'sha3'; |
|
||||
|
|
||||
var tests = [{ |
|
||||
args: ['myString'], |
|
||||
formattedArgs: ['myString'], |
|
||||
result: '0x319319f831983198319881', |
|
||||
formattedResult: '0x319319f831983198319881', |
|
||||
call: 'web3_'+ method |
|
||||
}]; |
|
||||
|
|
||||
testMethod.runTests(null, method, tests); |
|
||||
|
|
Loading…
Reference in new issue