Browse Source

Merge commit '8d6d0f84c18542369a0cdc8e9618c7e2fbf0bf6b' into web3_5.0

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
753523cb70
  1. 2
      libjsqrc/ethereumjs/.jshintrc
  2. 7
      libjsqrc/ethereumjs/.versions
  3. 5
      libjsqrc/ethereumjs/bower.json
  4. 1915
      libjsqrc/ethereumjs/dist/web3-light.js
  5. 71
      libjsqrc/ethereumjs/dist/web3-light.js.map
  6. 4
      libjsqrc/ethereumjs/dist/web3-light.min.js
  7. 1917
      libjsqrc/ethereumjs/dist/web3.js
  8. 71
      libjsqrc/ethereumjs/dist/web3.js.map
  9. 4
      libjsqrc/ethereumjs/dist/web3.min.js
  10. 23
      libjsqrc/ethereumjs/example/contract.html
  11. 27
      libjsqrc/ethereumjs/example/event_inc.html
  12. 203
      libjsqrc/ethereumjs/example/icap.html
  13. 102
      libjsqrc/ethereumjs/example/namereg.html
  14. 76
      libjsqrc/ethereumjs/example/natspec_contract.html
  15. 2
      libjsqrc/ethereumjs/index.js
  16. 6
      libjsqrc/ethereumjs/lib/solidity/param.js
  17. 48
      libjsqrc/ethereumjs/lib/utils/config.js
  18. 39
      libjsqrc/ethereumjs/lib/utils/sha3.js
  19. 85
      libjsqrc/ethereumjs/lib/utils/utils.js
  20. 2
      libjsqrc/ethereumjs/lib/version.json
  21. 13
      libjsqrc/ethereumjs/lib/web3.js
  22. 3
      libjsqrc/ethereumjs/lib/web3/event.js
  23. 31
      libjsqrc/ethereumjs/lib/web3/function.js
  24. 108
      libjsqrc/ethereumjs/lib/web3/icap.js
  25. 46
      libjsqrc/ethereumjs/lib/web3/namereg.js
  26. 94
      libjsqrc/ethereumjs/lib/web3/transfer.js
  27. 2
      libjsqrc/ethereumjs/package.js
  28. 3
      libjsqrc/ethereumjs/package.json
  29. 4
      libjsqrc/ethereumjs/test/batch.js
  30. 2
      libjsqrc/ethereumjs/test/coder.decodeParam.js
  31. 2
      libjsqrc/ethereumjs/test/coder.encodeParam.js
  32. 308
      libjsqrc/ethereumjs/test/contract.js
  33. 17
      libjsqrc/ethereumjs/test/sha3.js
  34. 32
      libjsqrc/ethereumjs/test/utils.isIBAN.js
  35. 8
      libjsqrc/ethereumjs/test/utils.toWei.js
  36. 49
      libjsqrc/ethereumjs/test/web3.eth.sendIBANTransaction.js
  37. 16
      libjsqrc/ethereumjs/test/web3.sha3.js

2
libjsqrc/ethereumjs/.jshintrc

@ -9,7 +9,7 @@
"maxdepth": 3, "maxdepth": 3,
"maxerr": 50, "maxerr": 50,
/*"maxlen": 80*/ /*this should be our goal*/ /*"maxlen": 80*/ /*this should be our goal*/
"maxparams": 3, /*"maxparams": 3,*/
"nonew": true, "nonew": true,
"unused": true, "unused": true,
"undef": true, "undef": true,

7
libjsqrc/ethereumjs/.versions

@ -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

5
libjsqrc/ethereumjs/bower.json

@ -1,14 +1,15 @@
{ {
"name": "web3", "name": "web3",
"namespace": "ethereum", "namespace": "ethereum",
"version": "0.4.2", "version": "0.5.0",
"description": "Ethereum Compatible JavaScript API", "description": "Ethereum Compatible JavaScript API",
"main": [ "main": [
"./dist/web3.js", "./dist/web3.js",
"./dist/web3.min.js" "./dist/web3.min.js"
], ],
"dependencies": { "dependencies": {
"bignumber.js": ">=2.0.0" "bignumber.js": ">=2.0.0",
"crypto-js": "~3.1.4"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

1915
libjsqrc/ethereumjs/dist/web3-light.js

File diff suppressed because one or more lines are too long

71
libjsqrc/ethereumjs/dist/web3-light.js.map

File diff suppressed because one or more lines are too long

4
libjsqrc/ethereumjs/dist/web3-light.min.js

File diff suppressed because one or more lines are too long

1917
libjsqrc/ethereumjs/dist/web3.js

File diff suppressed because one or more lines are too long

71
libjsqrc/ethereumjs/dist/web3.js.map

File diff suppressed because one or more lines are too long

4
libjsqrc/ethereumjs/dist/web3.min.js

File diff suppressed because one or more lines are too long

23
libjsqrc/ethereumjs/example/contract.html

@ -16,23 +16,10 @@
" }\n" + " }\n" +
"}\n"; "}\n";
var code = web3.eth.compile.solidity(source).code; var compiled = web3.eth.compile.solidity(source);
/*var code = "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056";*/ var code = compiled.test.code;
// contract json abi, this is autogenerated using solc CLI
// contract description, this is autogenerated using solc CLI var abi = compiled.test.info.abiDefinition;
var desc = [{
"constant" : true,
"inputs" : [{
"name" : "a",
"type" : "uint256"
}],
"name" : "multiply",
"outputs" : [{
"name" : "d",
"type" : "uint256"
}],
"type" : "function"
}];
var myContract; var myContract;
@ -47,7 +34,7 @@
var watch = web3.eth.filter('latest'); var watch = web3.eth.filter('latest');
// create contract // create contract
myContract = web3.eth.contract(desc).new({data: code}); myContract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + myContract.address); console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation"; document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) { watch.watch(function (err, hash) {

27
libjsqrc/ethereumjs/example/event_inc.html

@ -18,29 +18,10 @@
" } " + " } " +
" uint x; " + " uint x; " +
"}"; "}";
var code = web3.eth.compile.solidity(source).code;
/*var code = "5b60456000600050819055505b608c8060196000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063371303c014602e57005b6034603a565b60006000f35b6000600081815054600101919050819055506001600260006000505406147f6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad600060006000505481526020016000a25b56";*/
var desc = [{ var compiled = web3.eth.compile.solidity(source);
"constant" : false, var code = compiled.Contract.code;
"inputs" : [], var abi = compiled.Contract.info.abiDefinition;
"name" : "inc",
"outputs" : [],
"type" : "function"
}, {
"anonymous" : false,
"inputs" : [{
"indexed" : true,
"name" : "odd",
"type" : "bool"
}, {
"indexed" : false,
"name" : "x",
"type" : "uint256"
}],
"name" : "Incremented",
"type" : "event"
}];
var address; var address;
var contract; var contract;
@ -55,7 +36,7 @@
var watch = web3.eth.filter('latest'); var watch = web3.eth.filter('latest');
contract = web3.eth.contract(desc).new({data: code}); contract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + contract.address); console.log('address: ' + contract.address);

203
libjsqrc/ethereumjs/example/icap.html

@ -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>&nbsp;</div>
<div>
<text>IBAN: </text>
<text id="iban"></text>
<text id="ibanValidation"></text>
</div>
<div>&nbsp;</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>

102
libjsqrc/ethereumjs/example/namereg.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>

76
libjsqrc/ethereumjs/example/natspec_contract.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>

2
libjsqrc/ethereumjs/index.js

@ -2,6 +2,8 @@ var web3 = require('./lib/web3');
web3.providers.HttpProvider = require('./lib/web3/httpprovider'); web3.providers.HttpProvider = require('./lib/web3/httpprovider');
web3.providers.QtSyncProvider = require('./lib/web3/qtsync'); web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
web3.eth.contract = require('./lib/web3/contract'); web3.eth.contract = require('./lib/web3/contract');
web3.eth.namereg = require('./lib/web3/namereg');
web3.eth.sendIBANTransaction = require('./lib/web3/transfer');
// dont override global variable // dont override global variable
if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') { if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {

6
libjsqrc/ethereumjs/lib/solidity/param.js

@ -72,7 +72,7 @@ SolidityParam.prototype.combine = function (param) {
* @returns {Boolean} * @returns {Boolean}
*/ */
SolidityParam.prototype.isDynamic = function () { SolidityParam.prototype.isDynamic = function () {
return this.value.length > 64; return this.value.length > 64 || this.offset !== undefined;
}; };
/** /**
@ -188,7 +188,7 @@ SolidityParam.decodeBytes = function (bytes, index) {
var offset = getOffset(bytes, index); var offset = getOffset(bytes, index);
// 2 * , cause we also parse length // 2 * , cause we also parse length
return new SolidityParam(bytes.substr(offset * 2, 2 * 64)); return new SolidityParam(bytes.substr(offset * 2, 2 * 64), 0);
}; };
/** /**
@ -203,7 +203,7 @@ SolidityParam.decodeArray = function (bytes, index) {
index = index || 0; index = index || 0;
var offset = getOffset(bytes, index); var offset = getOffset(bytes, index);
var length = parseInt('0x' + bytes.substr(offset * 2, 64)); var length = parseInt('0x' + bytes.substr(offset * 2, 64));
return new SolidityParam(bytes.substr(offset * 2, (length + 1) * 64)); return new SolidityParam(bytes.substr(offset * 2, (length + 1) * 64), 0);
}; };
module.exports = SolidityParam; module.exports = SolidityParam;

48
libjsqrc/ethereumjs/lib/utils/config.js

@ -36,26 +36,34 @@
/// required to define ETH_BIGNUMBER_ROUNDING_MODE /// required to define ETH_BIGNUMBER_ROUNDING_MODE
var BigNumber = require('bignumber.js'); var BigNumber = require('bignumber.js');
var ETH_UNITS = [ var ETH_UNITS = [
'wei', 'wei',
'Kwei', 'kwei',
'Mwei', 'Mwei',
'Gwei', 'Gwei',
'szabo', 'szabo',
'finney', 'finney',
'ether', 'femtoether',
'grand', 'picoether',
'Mether', 'nanoether',
'Gether', 'microether',
'Tether', 'milliether',
'Pether', 'nano',
'Eether', 'micro',
'Zether', 'milli',
'Yether', 'ether',
'Nether', 'grand',
'Dether', 'Mether',
'Vether', 'Gether',
'Uether' 'Tether',
'Pether',
'Eether',
'Zether',
'Yether',
'Nether',
'Dether',
'Vether',
'Uether'
]; ];
module.exports = { module.exports = {

39
libjsqrc/ethereumjs/lib/utils/sha3.js

@ -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();
};

85
libjsqrc/ethereumjs/lib/utils/utils.js

@ -36,22 +36,30 @@
var BigNumber = require('bignumber.js'); var BigNumber = require('bignumber.js');
var unitMap = { var unitMap = {
'wei': '1', 'wei': '1',
'kwei': '1000', 'kwei': '1000',
'ada': '1000', 'ada': '1000',
'mwei': '1000000', 'femtoether': '1000',
'babbage': '1000000', 'mwei': '1000000',
'gwei': '1000000000', 'babbage': '1000000',
'shannon': '1000000000', 'picoether': '1000000',
'szabo': '1000000000000', 'gwei': '1000000000',
'finney': '1000000000000000', 'shannon': '1000000000',
'ether': '1000000000000000000', 'nanoether': '1000000000',
'kether': '1000000000000000000000', 'nano': '1000000000',
'grand': '1000000000000000000000', 'szabo': '1000000000000',
'einstein': '1000000000000000000000', 'microether': '1000000000000',
'mether': '1000000000000000000000000', 'micro': '1000000000000',
'gether': '1000000000000000000000000000', 'finney': '1000000000000000',
'tether': '1000000000000000000000000000000' 'milliether': '1000000000000000',
'milli': '1000000000000000',
'ether': '1000000000000000000',
'kether': '1000000000000000000000',
'grand': '1000000000000000000000',
'einstein': '1000000000000000000000',
'mether': '1000000000000000000000000',
'gether': '1000000000000000000000000000',
'tether': '1000000000000000000000000000000'
}; };
/** /**
@ -239,13 +247,14 @@ var getValueOfUnit = function (unit) {
* Takes a number of wei and converts it to any other ether unit. * Takes a number of wei and converts it to any other ether unit.
* *
* Possible units are: * Possible units are:
* - kwei/ada * SI Short SI Full Effigy Other
* - mwei/babbage * - kwei femtoether ada
* - gwei/shannon * - mwei picoether babbage
* - szabo * - gwei nanoether shannon nano
* - finney * - -- microether szabo micro
* - ether * - -- milliether finney milli
* - kether/grand/einstein * - ether -- --
* - kether einstein grand
* - mether * - mether
* - gether * - gether
* - tether * - tether
@ -265,13 +274,14 @@ var fromWei = function(number, unit) {
* Takes a number of a unit and converts it to wei. * Takes a number of a unit and converts it to wei.
* *
* Possible units are: * Possible units are:
* - kwei/ada * SI Short SI Full Effigy Other
* - mwei/babbage * - kwei femtoether ada
* - gwei/shannon * - mwei picoether babbage
* - szabo * - gwei nanoether shannon nano
* - finney * - -- microether szabo micro
* - ether * - -- milliether finney milli
* - kether/grand/einstein * - ether -- --
* - kether einstein grand
* - mether * - mether
* - gether * - gether
* - tether * - tether
@ -447,6 +457,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 = { module.exports = {
padLeft: padLeft, padLeft: padLeft,
toHex: toHex, toHex: toHex,
@ -470,6 +492,7 @@ module.exports = {
isObject: isObject, isObject: isObject,
isBoolean: isBoolean, isBoolean: isBoolean,
isArray: isArray, isArray: isArray,
isJson: isJson isJson: isJson,
isIBAN: isIBAN
}; };

2
libjsqrc/ethereumjs/lib/version.json

@ -1,3 +1,3 @@
{ {
"version": "0.4.2" "version": "0.5.0"
} }

13
libjsqrc/ethereumjs/lib/web3.js

@ -35,17 +35,9 @@ var utils = require('./utils/utils');
var formatters = require('./web3/formatters'); var formatters = require('./web3/formatters');
var RequestManager = require('./web3/requestmanager'); var RequestManager = require('./web3/requestmanager');
var c = require('./utils/config'); var c = require('./utils/config');
var Method = require('./web3/method');
var Property = require('./web3/property'); var Property = require('./web3/property');
var Batch = require('./web3/batch'); var Batch = require('./web3/batch');
var sha3 = require('./utils/sha3');
var web3Methods = [
new Method({
name: 'sha3',
call: 'web3_sha3',
params: 1
})
];
var web3Properties = [ var web3Properties = [
new Property({ new Property({
@ -130,6 +122,8 @@ web3.toBigNumber = utils.toBigNumber;
web3.toWei = utils.toWei; web3.toWei = utils.toWei;
web3.fromWei = utils.fromWei; web3.fromWei = utils.fromWei;
web3.isAddress = utils.isAddress; web3.isAddress = utils.isAddress;
web3.isIBAN = utils.isIBAN;
web3.sha3 = sha3;
web3.createBatch = function () { web3.createBatch = function () {
return new Batch(); return new Batch();
}; };
@ -156,7 +150,6 @@ Object.defineProperty(web3.eth, 'defaultAccount', {
}); });
/// setups all api methods /// setups all api methods
setupMethods(web3, web3Methods);
setupProperties(web3, web3Properties); setupProperties(web3, web3Properties);
setupMethods(web3.net, net.methods); setupMethods(web3.net, net.methods);
setupProperties(web3.net, net.properties); setupProperties(web3.net, net.properties);

3
libjsqrc/ethereumjs/lib/web3/event.js

@ -24,6 +24,7 @@ var utils = require('../utils/utils');
var coder = require('../solidity/coder'); var coder = require('../solidity/coder');
var web3 = require('../web3'); var web3 = require('../web3');
var formatters = require('./formatters'); var formatters = require('./formatters');
var sha3 = require('../utils/sha3');
/** /**
* This prototype should be used to create event filters * This prototype should be used to create event filters
@ -77,7 +78,7 @@ SolidityEvent.prototype.typeName = function () {
* @return {String} event signature * @return {String} event signature
*/ */
SolidityEvent.prototype.signature = function () { SolidityEvent.prototype.signature = function () {
return web3.sha3(web3.fromAscii(this._name)).slice(2); return sha3(this._name);
}; };
/** /**

31
libjsqrc/ethereumjs/lib/web3/function.js

@ -23,6 +23,7 @@
var web3 = require('../web3'); var web3 = require('../web3');
var coder = require('../solidity/coder'); var coder = require('../solidity/coder');
var utils = require('../utils/utils'); var utils = require('../utils/utils');
var sha3 = require('../utils/sha3');
/** /**
* This prototype should be used to call/sendTransaction to solidity functions * This prototype should be used to call/sendTransaction to solidity functions
@ -69,12 +70,12 @@ SolidityFunction.prototype.toPayload = function (args) {
* @return {String} function signature * @return {String} function signature
*/ */
SolidityFunction.prototype.signature = function () { SolidityFunction.prototype.signature = function () {
return web3.sha3(web3.fromAscii(this._name)).slice(2, 10); return sha3(this._name).slice(0, 8);
}; };
SolidityFunction.prototype.unpackOutput = function (output) { SolidityFunction.prototype.unpackOutput = function (output) {
if (output === null) { if (!output) {
return; return;
} }
@ -94,7 +95,7 @@ SolidityFunction.prototype.unpackOutput = function (output) {
* @return {String} output bytes * @return {String} output bytes
*/ */
SolidityFunction.prototype.call = function () { 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 callback = this.extractCallback(args);
var payload = this.toPayload(args); var payload = this.toPayload(args);
@ -116,18 +117,35 @@ SolidityFunction.prototype.call = function () {
* @param {Object} options * @param {Object} options
*/ */
SolidityFunction.prototype.sendTransaction = function () { 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 callback = this.extractCallback(args);
var payload = this.toPayload(args); var payload = this.toPayload(args);
if (!callback) { if (!callback) {
web3.eth.sendTransaction(payload); return web3.eth.sendTransaction(payload);
return;
} }
web3.eth.sendTransaction(payload, callback); web3.eth.sendTransaction(payload, callback);
}; };
/**
* Should be used to estimateGas of solidity function
*
* @method estimateGas
* @param {Object} options
*/
SolidityFunction.prototype.estimateGas = function () {
var args = Array.prototype.slice.call(arguments);
var callback = this.extractCallback(args);
var payload = this.toPayload(args);
if (!callback) {
return web3.eth.estimateGas(payload);
}
web3.eth.estimateGas(payload, callback);
};
/** /**
* Should be used to get function display name * Should be used to get function display name
* *
@ -195,6 +213,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
execute.request = this.request.bind(this); execute.request = this.request.bind(this);
execute.call = this.call.bind(this); execute.call = this.call.bind(this);
execute.sendTransaction = this.sendTransaction.bind(this); execute.sendTransaction = this.sendTransaction.bind(this);
execute.estimateGas = this.estimateGas.bind(this);
var displayName = this.displayName(); var displayName = this.displayName();
if (!contract[displayName]) { if (!contract[displayName]) {
contract[displayName] = execute; contract[displayName] = execute;

108
libjsqrc/ethereumjs/lib/web3/icap.js

@ -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;

46
libjsqrc/ethereumjs/lib/web3/namereg.js

@ -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);

94
libjsqrc/ethereumjs/lib/web3/transfer.js

@ -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;

2
libjsqrc/ethereumjs/package.js

@ -1,7 +1,7 @@
/* jshint ignore:start */ /* jshint ignore:start */
Package.describe({ Package.describe({
name: 'ethereum:web3', name: 'ethereum:web3',
version: '0.4.2', version: '0.5.0',
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC', summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC',
git: 'https://github.com/ethereum/ethereum.js', git: 'https://github.com/ethereum/ethereum.js',
// By default, Meteor will default to using README.md for documentation. // By default, Meteor will default to using README.md for documentation.

3
libjsqrc/ethereumjs/package.json

@ -1,7 +1,7 @@
{ {
"name": "web3", "name": "web3",
"namespace": "ethereum", "namespace": "ethereum",
"version": "0.4.2", "version": "0.5.0",
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC", "description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
"main": "./index.js", "main": "./index.js",
"directories": { "directories": {
@ -9,6 +9,7 @@
}, },
"dependencies": { "dependencies": {
"bignumber.js": "debris/bignumber.js#master", "bignumber.js": "debris/bignumber.js#master",
"crypto-js": "^3.1.4",
"xmlhttprequest": "*" "xmlhttprequest": "*"
}, },
"browser": { "browser": {

4
libjsqrc/ethereumjs/test/batch.js

@ -58,10 +58,6 @@ describe('lib/web3/batch', function () {
var address = '0x0000000000000000000000000000000000000000'; var address = '0x0000000000000000000000000000000000000000';
var result = '0x126'; var result = '0x126';
var result2 = '0x0000000000000000000000000000000000000000000000000000000000000123'; var result2 = '0x0000000000000000000000000000000000000000000000000000000000000123';
var signature = '0x001122334455';
// TODO: fix this, maybe in browser sha3?
provider.injectResult(signature);
var counter = 0; var counter = 0;
var callback = function (err, r) { var callback = function (err, r) {

2
libjsqrc/ethereumjs/test/coder.decodeParam.js

@ -24,6 +24,8 @@ describe('lib/solidity/coder', function () {
test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' + test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' + '0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'}); '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'int[]', expected: [], value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000000'});
test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' + test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000003'}); '0000000000000000000000000000000000000000000000000000000000000003'});

2
libjsqrc/ethereumjs/test/coder.encodeParam.js

@ -24,6 +24,8 @@ describe('lib/solidity/coder', function () {
test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' + test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000009' + '0000000000000000000000000000000000000000000000000000000000000009' +
'6761766f66796f726b0000000000000000000000000000000000000000000000'}); '6761766f66796f726b0000000000000000000000000000000000000000000000'});
test({ type: 'int[]', value: [], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000000'});
test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' + test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000003'}); '0000000000000000000000000000000000000000000000000000000000000003'});

308
libjsqrc/ethereumjs/test/contract.js

@ -5,6 +5,7 @@ var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2'); var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2');
var utils = require('../lib/utils/utils'); var utils = require('../lib/utils/utils');
var BigNumber = require('bignumber.js'); var BigNumber = require('bignumber.js');
var sha3 = require('../lib/utils/sha3');
var desc = [{ var desc = [{
"name": "balance(address)", "name": "balance(address)",
@ -60,34 +61,28 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); // reset different polls web3.reset(); // reset different polls
var sha3 = '0x5131231231231231231231'; var signature = 'Changed(address,uint256,uint256,uint256)';
provider.injectResult(sha3);
var step = 0; var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { if (step === 0) {
step = 1; step = 1;
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'web3_sha3');
assert.equal(payload.params[0], web3.fromAscii('Changed(address,uint256,uint256,uint256)'));
} else if (step === 1) {
step = 2;
provider.injectResult(3); provider.injectResult(3);
assert.equal(payload.jsonrpc, '2.0'); assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_newFilter'); assert.equal(payload.method, 'eth_newFilter');
assert.deepEqual(payload.params[0], { assert.deepEqual(payload.params[0], {
topics: [ topics: [
sha3, '0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890', '0x0000000000000000000000001234567890123456789012345678901234567890',
null null
], ],
address: '0x1234567890123456789012345678901234567890' address: '0x1234567890123456789012345678901234567890'
}); });
} else if (step === 2) { } else if (step === 1) {
step = 3; step = 2;
provider.injectResult([{ provider.injectResult([{
address: address, address: address,
topics: [ topics: [
sha3, '0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890', '0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000000000000000000000000000000000000000000001' '0x0000000000000000000000000000000000000000000000000000000000000001'
], ],
@ -97,11 +92,11 @@ describe('web3.eth.contract', function () {
}]); }]);
assert.equal(payload.jsonrpc, '2.0'); assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_getFilterLogs'); assert.equal(payload.method, 'eth_getFilterLogs');
} else if (step === 3 && utils.isArray(payload)) { } else if (step === 2 && utils.isArray(payload)) {
provider.injectBatchResults([[{ provider.injectBatchResults([[{
address: address, address: address,
topics: [ topics: [
sha3, '0x' + sha3(signature),
'0x0000000000000000000000001234567890123456789012345678901234567890', '0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000000000000000000000000000000000000000000001' '0x0000000000000000000000000000000000000000000000000000000000000001'
], ],
@ -135,53 +130,37 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)'
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_call');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
assert.equal(payload.method, 'web3_sha3'); to: address
assert.equal(payload.params[0], web3.fromAscii('balance(address)')); }, 'latest']);
} else if (step === 1) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890',
to: address
}, 'latest']);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
contract.balance(address); var r = contract.balance(address);
assert.deepEqual(new BigNumber(0x32), r);
}); });
it('should sendTransaction to contract function', function () { it('should sendTransaction to contract function', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_sendTransaction');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) +
assert.equal(payload.method, 'web3_sha3'); '0000000000000000000000001234567890123456789012345678901234567890' +
assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); '0000000000000000000000000000000000000000000000000000000000000011' ,
} else if (step === 1) { to: address
assert.equal(payload.method, 'eth_sendTransaction'); }]);
assert.deepEqual(payload.params, [{
data: sha3.slice(0, 10) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address
}]);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
@ -194,30 +173,23 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_call');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
assert.equal(payload.method, 'web3_sha3'); to: address,
assert.equal(payload.params[0], web3.fromAscii('balance(address)')); from: address,
} else if (step === 1) { gas: '0xc350'
assert.equal(payload.method, 'eth_call'); }, 'latest']);
assert.deepEqual(payload.params, [{
data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890',
to: address,
from: address,
gas: '0xc350'
}, 'latest']);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
contract.balance(address, {from: address, gas: 50000}); var r = contract.balance(address, {from: address, gas: 50000});
assert.deepEqual(new BigNumber(0x32), r);
}); });
@ -226,30 +198,23 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032');
var signature = 'balance(address)';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_call');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890',
assert.equal(payload.method, 'web3_sha3'); to: address,
assert.equal(payload.params[0], web3.fromAscii('balance(address)')); from: address,
} else if (step === 1) { gas: '0xc350'
assert.equal(payload.method, 'eth_call'); }, 'latest']);
assert.deepEqual(payload.params, [{
data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890',
to: address,
from: address,
gas: '0xc350'
}, 'latest']);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
contract.balance.call(address, {from: address, gas: 50000}); var r = contract.balance.call(address, {from: address, gas: 50000});
assert.deepEqual(new BigNumber(0x32), r);
}); });
@ -257,29 +222,20 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_sendTransaction');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) +
assert.equal(payload.method, 'web3_sha3'); '0000000000000000000000001234567890123456789012345678901234567890' +
assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); '0000000000000000000000000000000000000000000000000000000000000011' ,
} else if (step === 1) { to: address,
assert.equal(payload.method, 'eth_sendTransaction'); from: address,
assert.deepEqual(payload.params, [{ gas: '0xc350',
data: sha3.slice(0, 10) + gasPrice: '0xbb8',
'0000000000000000000000001234567890123456789012345678901234567890' + value: '0x2710'
'0000000000000000000000000000000000000000000000000000000000000011' , }]);
to: address,
from: address,
gas: '0xc350',
gasPrice: '0xbb8',
value: '0x2710'
}]);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
@ -291,29 +247,20 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_sendTransaction');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) +
assert.equal(payload.method, 'web3_sha3'); '0000000000000000000000001234567890123456789012345678901234567890' +
assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); '0000000000000000000000000000000000000000000000000000000000000011' ,
} else if (step === 1) { to: address,
assert.equal(payload.method, 'eth_sendTransaction'); from: address,
assert.deepEqual(payload.params, [{ gas: '0xc350',
data: sha3.slice(0, 10) + gasPrice: '0xbb8',
'0000000000000000000000001234567890123456789012345678901234567890' + value: '0x2710'
'0000000000000000000000000000000000000000000000000000000000000011' , }]);
to: address,
from: address,
gas: '0xc350',
gasPrice: '0xbb8',
value: '0x2710'
}]);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
@ -325,29 +272,20 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider(); var provider = new FakeHttpProvider();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3); var signature = 'send(address,uint256)';
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 0) { assert.equal(payload.method, 'eth_sendTransaction');
step = 1; assert.deepEqual(payload.params, [{
assert.equal(payload.jsonrpc, '2.0'); data: '0x' + sha3(signature).slice(0, 8) +
assert.equal(payload.method, 'web3_sha3'); '0000000000000000000000001234567890123456789012345678901234567890' +
assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); '0000000000000000000000000000000000000000000000000000000000000011' ,
} else if (step === 1) { to: address,
assert.equal(payload.method, 'eth_sendTransaction'); from: address,
assert.deepEqual(payload.params, [{ gas: '0xc350',
data: sha3.slice(0, 10) + gasPrice: '0xbb8',
'0000000000000000000000001234567890123456789012345678901234567890' + value: '0x2710'
'0000000000000000000000000000000000000000000000000000000000000011' , }]);
to: address,
from: address,
gas: '0xc350',
gasPrice: '0xbb8',
value: '0x2710'
}]);
}
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
@ -358,32 +296,52 @@ describe('web3.eth.contract', function () {
}); });
}); });
it('should explicitly estimateGas with optional params', function () {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset();
var signature = 'send(address,uint256)';
var address = '0x1234567890123456789012345678901234567890';
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_estimateGas');
assert.deepEqual(payload.params, [{
data: '0x' + sha3(signature).slice(0, 8) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address,
from: address,
gas: '0xc350',
gasPrice: '0xbb8',
value: '0x2710'
}]);
});
var contract = web3.eth.contract(desc).at(address);
contract.send.estimateGas(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000});
});
it('should call testArr method and properly parse result', function () { it('should call testArr method and properly parse result', function () {
var provider = new FakeHttpProvider2(); var provider = new FakeHttpProvider2();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; var signature = 'testArr(int[])';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResultList([{ provider.injectResultList([{
result: sha3
}, {
result: '0x0000000000000000000000000000000000000000000000000000000000000005' result: '0x0000000000000000000000000000000000000000000000000000000000000005'
}]); }]);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 1) { // getting sha3 is first assert.equal(payload.method, 'eth_call');
assert.equal(payload.method, 'eth_call'); assert.deepEqual(payload.params, [{
assert.deepEqual(payload.params, [{ data: '0x' + sha3(signature).slice(0, 8) +
data: sha3.slice(0, 10) + '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003',
'0000000000000000000000000000000000000000000000000000000000000003', to: address
to: address },
}, 'latest'
'latest'
]); ]);
}
step++;
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);
@ -396,28 +354,22 @@ describe('web3.eth.contract', function () {
var provider = new FakeHttpProvider2(); var provider = new FakeHttpProvider2();
web3.setProvider(provider); web3.setProvider(provider);
web3.reset(); web3.reset();
var sha3 = '0x5131231231231231231231'; var signature = 'testArr(int[])';
var address = '0x1234567890123456789012345678901234567890'; var address = '0x1234567890123456789012345678901234567890';
provider.injectResultList([{ provider.injectResultList([{
result: sha3
}, {
result: '0x0000000000000000000000000000000000000000000000000000000000000005' result: '0x0000000000000000000000000000000000000000000000000000000000000005'
}]); }]);
var step = 0;
provider.injectValidation(function (payload) { provider.injectValidation(function (payload) {
if (step === 1) { // getting sha3 is first assert.equal(payload.method, 'eth_call');
assert.equal(payload.method, 'eth_call'); assert.deepEqual(payload.params, [{
assert.deepEqual(payload.params, [{ data: '0x' + sha3(signature).slice(0, 8) +
data: sha3.slice(0, 10) + '0000000000000000000000000000000000000000000000000000000000000020' +
'0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003',
'0000000000000000000000000000000000000000000000000000000000000003', to: address
to: address },
}, 'latest'
'latest' ]);
]);
}
step++;
}); });
var contract = web3.eth.contract(desc).at(address); var contract = web3.eth.contract(desc).at(address);

17
libjsqrc/ethereumjs/test/sha3.js

@ -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');
});

32
libjsqrc/ethereumjs/test/utils.isIBAN.js

@ -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);
});
});
});
});

8
libjsqrc/ethereumjs/test/utils.toWei.js

@ -19,6 +19,14 @@ describe('lib/utils/utils', function () {
assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000');
assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000');
assert.equal(utils.toWei(1, 'kwei'), utils.toWei(1, 'femtoether'));
assert.equal(utils.toWei(1, 'babbage'), utils.toWei(1, 'picoether'));
assert.equal(utils.toWei(1, 'shannon'), utils.toWei(1, 'nanoether'));
assert.equal(utils.toWei(1, 'szabo'), utils.toWei(1, 'microether'));
assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'milliether'));
assert.equal(utils.toWei(1, 'milli'), utils.toWei(1, 'milliether'));
assert.equal(utils.toWei(1, 'milli'), utils.toWei(1000, 'micro'));
assert.throws(function () {utils.toWei(1, 'wei1');}, Error); assert.throws(function () {utils.toWei(1, 'wei1');}, Error);
}); });
}); });

49
libjsqrc/ethereumjs/test/web3.eth.sendIBANTransaction.js

@ -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);
});
});

16
libjsqrc/ethereumjs/test/web3.sha3.js

@ -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…
Cancel
Save