Browse Source

Squashed 'libjsqrc/ethereumjs/' changes from 81bbe8c..d223ac0

d223ac0 Additional work on the JS stuff to make it more similar to Solidity.
113a380 Fix string outputs. Auto collapse for < 2 returns.
fb34c6c Auto select call or transact depending on constness.
7869294 Fixes to ethereum.js and standard.js.
61a0158 Vanity addresses in AZ. Fixes to ethereum.js eth.flush()
c01f0ae Merge commit 'b1971f46cce7d21be5f6277c9f8c406a0d195f78' into natspec
29fa57e natspec.js updated to use sync api
13f39af Merge commit '93fa6855afad7a7eb86e49efe384372a6060da35' into natspec
6c4432d Merge commit 'b32dedc5b54f853cf63bb2663c8bca6aa4272b0b' into natspec
375ca54 Merge commit '8e3ba3a4285cc7e902a018196b3849df56944dd0' into natspec
d6a92b1 fixed natspec example
5e623f1 Merge commit 'cdd7af2a6e87363d0ff7d2528f9d9b521bf2ef20' into natspec
ad8e92e Merge commit 'eb4984c0d036c1420e782ca136810e851e33fb37' into natspec
81ff253 Merge commit 'c4638ba3edbd14677da5441d61f7845668df2b22' into natspec
e68f8e7 natspec changes
689630d Merge commit '53b4fda16d0b191be8ab986379a328aa38aaf916' into natspec
5c79ee4 fixed natspec_contract.html example
83505e6 Merge commit '2b4d38b9bf059014596e1ab00c99dc2ad4ab3761' into ethereumjs
2ce109e Merge commit '6a383d6ed3fb37cf6739f6ac441652adfdb70463' into ethereumjs
1c4d8f3 Merge commit '29333fc213b62b27ef826616cf77430947fb6eab' into ethereumjs
de4ea8e Merge commit 'd876522bc0614fea3180a54be57bcb61784b352e' into ethereumjs
6d02c0d Merge commit '1a6dbeff6e86d65cae6d7db366cbaa4182eaff7f' into ethereumjs
508f116 Merge pull request #798 from LefterisJP/natspec_OnContractCreation
a4049fb Cleaned up some unused functions
dac93ed Natspechandler: Get function hash from transaction data
f54c90a A first version of Natspec warning popup
b6c0e53 Auto-generated commits, too.
e95bb34 Fix for JS API formatting.

git-subtree-dir: libjsqrc/ethereumjs
git-subtree-split: d223ac0379c4c1f8c209e777ec9ed63384590157
cl-refactor
Marek Kotewicz 10 years ago
parent
commit
b1e00d6665
  1. 52
      dist/ethereum.js
  2. 8
      dist/ethereum.js.map
  3. 2
      dist/ethereum.min.js
  4. 78
      example/natspec_contract.html
  5. 4
      lib/abi.js
  6. 38
      lib/contract.js
  7. 10
      lib/web3.js

52
dist/ethereum.js

@ -129,7 +129,7 @@ var formatInputReal = function (value) {
var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings
if (arrayType(type) || prefixedType('string')(type))
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length.
return formatInputInt(value.length);
return "";
};
@ -252,7 +252,7 @@ var formatOutputAddress = function (value) {
};
var dynamicBytesLength = function (type) {
if (arrayType(type) || prefixedType('string')(type))
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2;
return 0;
};
@ -448,7 +448,7 @@ var abi = require('./abi');
* var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object
*
* myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)
* myContract.myMethod('this is test string param for call').call(); // myMethod call (explicit)
* myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)
* myContract.transact().myMethod('this is test string param for transact'); // myMethod transact
*
* @param address - address of the contract, which should be called
@ -457,6 +457,18 @@ var abi = require('./abi');
*/
var contract = function (address, desc) {
desc.forEach(function (method) {
// workaround for invalid assumption that method.name is the full anonymous prototype of the method.
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous
// prototype, so we make it so as a workaround.
if (method.name.indexOf('(') === -1) {
var displayName = method.name;
var typeName = method.inputs.map(function(i){return i.type}).join();
method.name = displayName + '(' + typeName + ')';
}
});
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
@ -474,6 +486,15 @@ var contract = function (address, desc) {
return result;
};
result._options = {};
['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {
result[p] = function (v) {
result._options[p] = v;
return result;
};
});
desc.forEach(function (method) {
var displayName = abi.methodDisplayName(method.name);
@ -488,11 +509,12 @@ var contract = function (address, desc) {
options.to = address;
options.data = signature + parsed;
var isTransact = result._isTransact;
var isTransact = result._isTransact === true || (result._isTransact !== false && !method.constant);
var collapse = options.collapse !== false;
// reset
result._options = {};
result._isTransact = false;
result._isTransact = null;
if (isTransact) {
// it's used byt natspec.js
@ -506,7 +528,15 @@ var contract = function (address, desc) {
}
var output = web3.eth.call(options);
return outputParser[displayName][typeName](output);
var ret = outputParser[displayName][typeName](output);
if (collapse)
{
if (ret.length == 1)
ret = ret[0];
else if (ret.length == 0)
ret = null;
}
return ret;
};
if (result[displayName] === undefined) {
@ -889,6 +919,7 @@ var ethMethods = function () {
{ name: 'transaction', call: transactionCall },
{ name: 'uncle', call: uncleCall },
{ name: 'compilers', call: 'eth_compilers' },
{ name: 'flush', call: 'eth_flush' },
{ name: 'lll', call: 'eth_lll' },
{ name: 'solidity', call: 'eth_solidity' },
{ name: 'serpent', call: 'eth_serpent' },
@ -1074,6 +1105,15 @@ var web3 = {
/// eth object prototype
eth: {
contractFromAbi: function (abi) {
return function(addr) {
// Default to address of Config. TODO: rremove prior to genesis.
addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
var ret = web3.eth.contract(addr, abi);
ret.address = addr;
return ret;
};
},
watch: function (params) {
return new web3.filter(params, ethWatch);
}

8
dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
dist/ethereum.min.js

File diff suppressed because one or more lines are too long

78
example/natspec_contract.html

@ -0,0 +1,78 @@
<!doctype>
<html>
<head>
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
<script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script>
<script type="text/javascript" src="../dist/ethereum.js"></script>
<script type="text/javascript" src="../../natspec.js"></script>
<script type="text/javascript">
var web3 = require('web3');
web3.setProvider(new web3.providers.QtSyncProvider());
// 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)",
"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.transact({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.transact().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>

4
lib/abi.js

@ -128,7 +128,7 @@ var formatInputReal = function (value) {
var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings
if (arrayType(type) || prefixedType('string')(type))
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length.
return formatInputInt(value.length);
return "";
};
@ -251,7 +251,7 @@ var formatOutputAddress = function (value) {
};
var dynamicBytesLength = function (type) {
if (arrayType(type) || prefixedType('string')(type))
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2;
return 0;
};

38
lib/contract.js

@ -37,7 +37,7 @@ var abi = require('./abi');
* var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object
*
* myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)
* myContract.myMethod('this is test string param for call').call(); // myMethod call (explicit)
* myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)
* myContract.transact().myMethod('this is test string param for transact'); // myMethod transact
*
* @param address - address of the contract, which should be called
@ -46,6 +46,18 @@ var abi = require('./abi');
*/
var contract = function (address, desc) {
desc.forEach(function (method) {
// workaround for invalid assumption that method.name is the full anonymous prototype of the method.
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous
// prototype, so we make it so as a workaround.
if (method.name.indexOf('(') === -1) {
var displayName = method.name;
var typeName = method.inputs.map(function(i){return i.type}).join();
method.name = displayName + '(' + typeName + ')';
}
});
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
@ -63,6 +75,15 @@ var contract = function (address, desc) {
return result;
};
result._options = {};
['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {
result[p] = function (v) {
result._options[p] = v;
return result;
};
});
desc.forEach(function (method) {
var displayName = abi.methodDisplayName(method.name);
@ -77,11 +98,12 @@ var contract = function (address, desc) {
options.to = address;
options.data = signature + parsed;
var isTransact = result._isTransact;
var isTransact = result._isTransact === true || (result._isTransact !== false && !method.constant);
var collapse = options.collapse !== false;
// reset
result._options = {};
result._isTransact = false;
result._isTransact = null;
if (isTransact) {
// it's used byt natspec.js
@ -95,7 +117,15 @@ var contract = function (address, desc) {
}
var output = web3.eth.call(options);
return outputParser[displayName][typeName](output);
var ret = outputParser[displayName][typeName](output);
if (collapse)
{
if (ret.length == 1)
ret = ret[0];
else if (ret.length == 0)
ret = null;
}
return ret;
};
if (result[displayName] === undefined) {

10
lib/web3.js

@ -82,6 +82,7 @@ var ethMethods = function () {
{ name: 'transaction', call: transactionCall },
{ name: 'uncle', call: uncleCall },
{ name: 'compilers', call: 'eth_compilers' },
{ name: 'flush', call: 'eth_flush' },
{ name: 'lll', call: 'eth_lll' },
{ name: 'solidity', call: 'eth_solidity' },
{ name: 'serpent', call: 'eth_serpent' },
@ -267,6 +268,15 @@ var web3 = {
/// eth object prototype
eth: {
contractFromAbi: function (abi) {
return function(addr) {
// Default to address of Config. TODO: rremove prior to genesis.
addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
var ret = web3.eth.contract(addr, abi);
ret.address = addr;
return ret;
};
},
watch: function (params) {
return new web3.filter(params, ethWatch);
}

Loading…
Cancel
Save