Commit 65158d39 authored by obscuren's avatar obscuren

Filtering

parent b1870631
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
}]; }];
var address = web3.eth.transact({ var address = web3.eth.transact({
data: "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056", data: "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056",
gasprice: "1000000000000000", gasPrice: "1000000000000000",
gas: "10000", gas: "10000",
}); });
var contract = web3.eth.contract(address, desc); var contract = web3.eth.contract(address, desc);
......
...@@ -32,17 +32,19 @@ ...@@ -32,17 +32,19 @@
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
var desc = [{ var desc = [{
"name": "balance(address)", "name": "balance(address)",
"type": "function",
"inputs": [{ "inputs": [{
"name": "who", "name": "who",
"type": "address" "type": "address"
}], }],
"const": true, "constant": true,
"outputs": [{ "outputs": [{
"name": "value", "name": "value",
"type": "uint256" "type": "uint256"
}] }]
}, { }, {
"name": "send(address,uint256)", "name": "send(address,uint256)",
"type": "function",
"inputs": [{ "inputs": [{
"name": "to", "name": "to",
"type": "address" "type": "address"
...@@ -51,21 +53,31 @@ ...@@ -51,21 +53,31 @@
"type": "uint256" "type": "uint256"
}], }],
"outputs": [] "outputs": []
}, {
"name":"Changed",
"type":"event",
"inputs": [
{"name":"to","type":"address","indexed":false},
{"name":"amount","type":"uint256","indexed":true},
],
}]; }];
var address = web3.db.get("jevcoin", "address"); var address = "";//web3.db.get("jevcoin", "address");
if( address.length == 0 ) { if( address.length == 0 ) {
var code = "0x60056011565b60ae8060356000396000f35b64174876e800600033600160a060020a031660005260205260406000208190555056006001600060e060020a600035048063d0679d34146022578063e3d670d714603457005b602e6004356024356047565b60006000f35b603d600435608d565b8060005260206000f35b80600083600160a060020a0316600052602052604060002090815401908190555080600033600160a060020a031660005260205260406000209081540390819055505050565b6000600082600160a060020a0316600052602052604060002054905091905056"; var code = "0x60056011565b60b88060356000396000f35b64e8d4a51000600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a68146028578063d0679d34146034578063e3d670d714604657005b602e60b3565b60006000f35b60406004356024356059565b60006000f35b604f6004356091565b8060005260206000f35b8060005281600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660206000a25050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156";
address = web3.eth.transact({ address = web3.eth.transact({
data: code, data: code,
gasprice: "1000000000000000", gasPrice: "1000000000000000",
gas: "10000", gas: "10000",
}); });
web3.db.put("jevcoin", "address", address); web3.db.put("jevcoin", "address", address);
} }
var contract = web3.eth.contract(address, desc); var contract = web3.eth.contract(address, desc);
contract.Changed({to: "0xaabb"}).changed(function(e) {
console.log("e: " + JSON.stringify(e));
});
contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( "0xaa", 10000 );
function reflesh() { function reflesh() {
document.querySelector("#balance").innerHTML = contract.call().balance(eth.coinbase); document.querySelector("#balance").innerHTML = contract.call().balance(eth.coinbase);
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
<td id="accounts"></td> <td id="accounts"></td>
</tr> </tr>
<tr>
<td>Balance</td>
<td id="balance"></td>
<tr> <tr>
<td>Gas price</td> <td>Gas price</td>
<td id="gas_price"></td> <td id="gas_price"></td>
...@@ -63,6 +67,7 @@ ...@@ -63,6 +67,7 @@
document.querySelector("#peer_count").innerHTML = eth.peerCount; document.querySelector("#peer_count").innerHTML = eth.peerCount;
document.querySelector("#default_block").innerHTML = eth.defaultBlock; document.querySelector("#default_block").innerHTML = eth.defaultBlock;
document.querySelector("#accounts").innerHTML = eth.accounts; document.querySelector("#accounts").innerHTML = eth.accounts;
document.querySelector("#balance").innerHTML = web3.toEth(eth.balanceAt(eth.accounts[0]));
document.querySelector("#gas_price").innerHTML = eth.gasPrice; document.querySelector("#gas_price").innerHTML = eth.gasPrice;
document.querySelector("#mining").innerHTML = eth.mining; document.querySelector("#mining").innerHTML = eth.mining;
document.querySelector("#listening").innerHTML = eth.listening; document.querySelector("#listening").innerHTML = eth.listening;
......
...@@ -22,175 +22,57 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ ...@@ -22,175 +22,57 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
* @date 2014 * @date 2014
*/ */
// TODO: is these line is supposed to be here? var web3 = require('./web3');
if ("build" !== 'build') {/* var utils = require('./utils');
var BigNumber = require('bignumber.js'); // jshint ignore:line var types = require('./types');
*/} var c = require('./const');
var f = require('./formatters');
var web3 = require('./web3'); // jshint ignore:line
var displayTypeError = function (type) {
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN }); console.error('parser does not support type: ' + type);
var ETH_PADDING = 32;
/// method signature length in bytes
var ETH_METHOD_SIGNATURE_LENGTH = 4;
/// Finds first index of array element matching pattern
/// @param array
/// @param callback pattern
/// @returns index of element
var findIndex = function (array, callback) {
var end = false;
var i = 0;
for (; i < array.length && !end; i++) {
end = callback(array[i]);
}
return end ? i - 1 : -1;
};
/// @returns a function that is used as a pattern for 'findIndex'
var findMethodIndex = function (json, methodName) {
return findIndex(json, function (method) {
return method.name === methodName;
});
};
/// @returns method with given method name
var getMethodWithName = function (json, methodName) {
var index = findMethodIndex(json, methodName);
if (index === -1) {
console.error('method ' + methodName + ' not found in the abi');
return undefined;
}
return json[index];
};
/// @param string string to be padded
/// @param number of characters that result string should have
/// @param sign, by default 0
/// @returns right aligned string
var padLeft = function (string, chars, sign) {
return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
};
/// @param expected type prefix (string)
/// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false
var prefixedType = function (prefix) {
return function (type) {
return type.indexOf(prefix) === 0;
};
};
/// @param expected type name (string)
/// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false
var namedType = function (name) {
return function (type) {
return name === type;
};
}; };
/// This method should be called if we want to check if givent type is an array type
/// @returns true if it is, otherwise false
var arrayType = function (type) { var arrayType = function (type) {
return type.slice(-2) === '[]'; return type.slice(-2) === '[]';
}; };
/// Formats input value to byte representation of int
/// If value is negative, return it's two's complement
/// If the value is floating point, round it down
/// @returns right-aligned byte representation of int
var formatInputInt = function (value) {
var padding = ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number')
value = new BigNumber(value);
value = value.round();
if (value.lessThan(0))
value = new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(value).plus(1);
value = value.toString(16);
}
else if (value.indexOf('0x') === 0)
value = value.substr(2);
else if (typeof value === 'string')
value = formatInputInt(new BigNumber(value));
else
value = (+value).toString(16);
return padLeft(value, padding);
};
/// Formats input value to byte representation of string
/// @returns left-algined byte representation of string
var formatInputString = function (value) {
return web3.fromAscii(value, ETH_PADDING).substr(2);
};
/// Formats input value to byte representation of bool
/// @returns right-aligned byte representation bool
var formatInputBool = function (value) {
return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');
};
/// Formats input value to byte representation of real
/// Values are multiplied by 2^m and encoded as integers
/// @returns byte representation of real
var formatInputReal = function (value) {
return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128)));
};
var dynamicTypeBytes = function (type, value) { var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings // TODO: decide what to do with array of strings
if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length. if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return formatInputInt(value.length); return f.formatInputInt(value.length);
return ""; return "";
}; };
/// Setups input formatters for solidity types var inputTypes = types.inputTypes();
/// @returns an array of input formatters
var setupInputTypes = function () {
return [
{ type: prefixedType('uint'), format: formatInputInt },
{ type: prefixedType('int'), format: formatInputInt },
{ type: prefixedType('hash'), format: formatInputInt },
{ type: prefixedType('string'), format: formatInputString },
{ type: prefixedType('real'), format: formatInputReal },
{ type: prefixedType('ureal'), format: formatInputReal },
{ type: namedType('address'), format: formatInputInt },
{ type: namedType('bool'), format: formatInputBool }
];
};
var inputTypes = setupInputTypes();
/// Formats input params to bytes /// Formats input params to bytes
/// @param contract json abi /// @param abi contract method inputs
/// @param name of the method that we want to use
/// @param array of params that will be formatted to bytes /// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params /// @returns bytes representation of input params
var toAbiInput = function (json, methodName, params) { var formatInput = function (inputs, params) {
var bytes = ""; var bytes = "";
var padding = c.ETH_PADDING * 2;
var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
/// first we iterate in search for dynamic /// first we iterate in search for dynamic
method.inputs.forEach(function (input, index) { inputs.forEach(function (input, index) {
bytes += dynamicTypeBytes(input.type, params[index]); bytes += dynamicTypeBytes(input.type, params[index]);
}); });
method.inputs.forEach(function (input, i) { inputs.forEach(function (input, i) {
var typeMatch = false; var typeMatch = false;
for (var j = 0; j < inputTypes.length && !typeMatch; j++) { for (var j = 0; j < inputTypes.length && !typeMatch; j++) {
typeMatch = inputTypes[j].type(method.inputs[i].type, params[i]); typeMatch = inputTypes[j].type(inputs[i].type, params[i]);
} }
if (!typeMatch) { if (!typeMatch) {
console.error('input parser does not support type: ' + method.inputs[i].type); displayTypeError(inputs[i].type);
} }
var formatter = inputTypes[j - 1].format; var formatter = inputTypes[j - 1].format;
var toAppend = ""; var toAppend = "";
if (arrayType(method.inputs[i].type)) if (arrayType(inputs[i].type))
toAppend = params[i].reduce(function (acc, curr) { toAppend = params[i].reduce(function (acc, curr) {
return acc + formatter(curr); return acc + formatter(curr);
}, ""); }, "");
...@@ -202,118 +84,44 @@ var toAbiInput = function (json, methodName, params) { ...@@ -202,118 +84,44 @@ var toAbiInput = function (json, methodName, params) {
return bytes; return bytes;
}; };
/// Check if input value is negative
/// @param value is hex format
/// @returns true if it is negative, otherwise false
var signedIsNegative = function (value) {
return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';
};
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
var formatOutputInt = function (value) {
value = value || "0";
// check if it's negative number
// it it is, return two's complement
if (signedIsNegative(value)) {
return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
}
return new BigNumber(value, 16);
};
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to uint
var formatOutputUInt = function (value) {
value = value || "0";
return new BigNumber(value, 16);
};
/// @returns input bytes formatted to real
var formatOutputReal = function (value) {
return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128));
};
/// @returns input bytes formatted to ureal
var formatOutputUReal = function (value) {
return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128));
};
/// @returns right-aligned input bytes formatted to hex
var formatOutputHash = function (value) {
return "0x" + value;
};
/// @returns right-aligned input bytes formatted to bool
var formatOutputBool = function (value) {
return value === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;
};
/// @returns left-aligned input bytes formatted to ascii string
var formatOutputString = function (value) {
return web3.toAscii(value);
};
/// @returns right-aligned input bytes formatted to address
var formatOutputAddress = function (value) {
return "0x" + value.slice(value.length - 40, value.length);
};
var dynamicBytesLength = function (type) { var dynamicBytesLength = function (type) {
if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length. if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2; return c.ETH_PADDING * 2;
return 0; return 0;
}; };
/// Setups output formaters for solidity types var outputTypes = types.outputTypes();
/// @returns an array of output formatters
var setupOutputTypes = function () {
return [
{ type: prefixedType('uint'), format: formatOutputUInt },
{ type: prefixedType('int'), format: formatOutputInt },
{ type: prefixedType('hash'), format: formatOutputHash },
{ type: prefixedType('string'), format: formatOutputString },
{ type: prefixedType('real'), format: formatOutputReal },
{ type: prefixedType('ureal'), format: formatOutputUReal },
{ type: namedType('address'), format: formatOutputAddress },
{ type: namedType('bool'), format: formatOutputBool }
];
};
var outputTypes = setupOutputTypes();
/// Formats output bytes back to param list /// Formats output bytes back to param list
/// @param contract json abi /// @param contract abi method outputs
/// @param name of the method that we want to use
/// @param bytes representtion of output /// @param bytes representtion of output
/// @returns array of output params /// @returns array of output params
var fromAbiOutput = function (json, methodName, output) { var formatOutput = function (outs, output) {
output = output.slice(2); output = output.slice(2);
var result = []; var result = [];
var method = getMethodWithName(json, methodName); var padding = c.ETH_PADDING * 2;
var padding = ETH_PADDING * 2;
var dynamicPartLength = method.outputs.reduce(function (acc, curr) { var dynamicPartLength = outs.reduce(function (acc, curr) {
return acc + dynamicBytesLength(curr.type); return acc + dynamicBytesLength(curr.type);
}, 0); }, 0);
var dynamicPart = output.slice(0, dynamicPartLength); var dynamicPart = output.slice(0, dynamicPartLength);
output = output.slice(dynamicPartLength); output = output.slice(dynamicPartLength);
method.outputs.forEach(function (out, i) { outs.forEach(function (out, i) {
var typeMatch = false; var typeMatch = false;
for (var j = 0; j < outputTypes.length && !typeMatch; j++) { for (var j = 0; j < outputTypes.length && !typeMatch; j++) {
typeMatch = outputTypes[j].type(method.outputs[i].type); typeMatch = outputTypes[j].type(outs[i].type);
} }
if (!typeMatch) { if (!typeMatch) {
console.error('output parser does not support type: ' + method.outputs[i].type); displayTypeError(outs[i].type);
} }
var formatter = outputTypes[j - 1].format; var formatter = outputTypes[j - 1].format;
if (arrayType(method.outputs[i].type)) { if (arrayType(outs[i].type)) {
var size = formatOutputUInt(dynamicPart.slice(0, padding)); var size = f.formatOutputUInt(dynamicPart.slice(0, padding));
dynamicPart = dynamicPart.slice(padding); dynamicPart = dynamicPart.slice(padding);
var array = []; var array = [];
for (var k = 0; k < size; k++) { for (var k = 0; k < size; k++) {
...@@ -322,7 +130,7 @@ var fromAbiOutput = function (json, methodName, output) { ...@@ -322,7 +130,7 @@ var fromAbiOutput = function (json, methodName, output) {
} }
result.push(array); result.push(array);
} }
else if (prefixedType('string')(method.outputs[i].type)) { else if (types.prefixedType('string')(outs[i].type)) {
dynamicPart = dynamicPart.slice(padding); dynamicPart = dynamicPart.slice(padding);
result.push(formatter(output.slice(0, padding))); result.push(formatter(output.slice(0, padding)));
output = output.slice(padding); output = output.slice(padding);
...@@ -335,30 +143,18 @@ var fromAbiOutput = function (json, methodName, output) { ...@@ -335,30 +143,18 @@ var fromAbiOutput = function (json, methodName, output) {
return result; return result;
}; };
/// @returns display name for method eg. multiply(uint256) -> multiply
var methodDisplayName = function (method) {
var length = method.indexOf('(');
return length !== -1 ? method.substr(0, length) : method;
};
/// @returns overloaded part of method's name
var methodTypeName = function (method) {
/// TODO: make it not vulnerable
var length = method.indexOf('(');
return length !== -1 ? method.substr(length + 1, method.length - 1 - (length + 1)) : "";
};
/// @param json abi for contract /// @param json abi for contract
/// @returns input parser object for given json abi /// @returns input parser object for given json abi
/// TODO: refactor creating the parser, do not double logic from contract
var inputParser = function (json) { var inputParser = function (json) {
var parser = {}; var parser = {};
json.forEach(function (method) { json.forEach(function (method) {
var displayName = methodDisplayName(method.name); var displayName = utils.extractDisplayName(method.name);
var typeName = methodTypeName(method.name); var typeName = utils.extractTypeName(method.name);
var impl = function () { var impl = function () {
var params = Array.prototype.slice.call(arguments); var params = Array.prototype.slice.call(arguments);
return toAbiInput(json, method.name, params); return formatInput(method.inputs, params);
}; };
if (parser[displayName] === undefined) { if (parser[displayName] === undefined) {
...@@ -377,11 +173,11 @@ var outputParser = function (json) { ...@@ -377,11 +173,11 @@ var outputParser = function (json) {
var parser = {}; var parser = {};
json.forEach(function (method) { json.forEach(function (method) {
var displayName = methodDisplayName(method.name); var displayName = utils.extractDisplayName(method.name);
var typeName = methodTypeName(method.name); var typeName = utils.extractTypeName(method.name);
var impl = function (output) { var impl = function (output) {
return fromAbiOutput(json, method.name, output); return formatOutput(method.outputs, output);
}; };
if (parser[displayName] === undefined) { if (parser[displayName] === undefined) {
...@@ -394,23 +190,85 @@ var outputParser = function (json) { ...@@ -394,23 +190,85 @@ var outputParser = function (json) {
return parser; return parser;
}; };
/// @param method name for which we want to get method signature /// @param function/event name for which we want to get signature
/// @returns (promise) contract method signature for method with given name /// @returns signature of function/event with given name
var methodSignature = function (name) { var signatureFromAscii = function (name) {
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + ETH_METHOD_SIGNATURE_LENGTH * 2); return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);
};
var eventSignatureFromAscii = function (name) {
return web3.sha3(web3.fromAscii(name));
}; };
module.exports = { module.exports = {
inputParser: inputParser, inputParser: inputParser,
outputParser: outputParser, outputParser: outputParser,
methodSignature: methodSignature, formatInput: formatInput,
methodDisplayName: methodDisplayName, formatOutput: formatOutput,
methodTypeName: methodTypeName, signatureFromAscii: signatureFromAscii,
getMethodWithName: getMethodWithName eventSignatureFromAscii: eventSignatureFromAscii
};
},{"./const":2,"./formatters":6,"./types":11,"./utils":12,"./web3":13}],2:[function(require,module,exports){
/*
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 const.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
/// required to define ETH_BIGNUMBER_ROUNDING_MODE
if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); // jshint ignore:line
*/}
var ETH_UNITS = [
'wei',
'Kwei',
'Mwei',
'Gwei',
'szabo',
'finney',
'ether',
'grand',
'Mether',
'Gether',
'Tether',
'Pether',
'Eether',
'Zether',
'Yether',
'Nether',
'Dether',
'Vether',
'Uether'
];
module.exports = {
ETH_PADDING: 32,
ETH_SIGNATURE_LENGTH: 4,
ETH_UNITS: ETH_UNITS,
ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }
}; };
},{"./web3":7}],2:[function(require,module,exports){ },{}],3:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.
...@@ -433,98 +291,78 @@ module.exports = { ...@@ -433,98 +291,78 @@ module.exports = {
* @date 2014 * @date 2014
*/ */
var web3 = require('./web3'); // jshint ignore:line var web3 = require('./web3');
var abi = require('./abi'); var abi = require('./abi');
var utils = require('./utils');
var eventImpl = require('./event');
var exportNatspecGlobals = function (vars) {
// it's used byt natspec.js
// TODO: figure out better way to solve this
web3._currentContractAbi = vars.abi;
web3._currentContractAddress = vars.address;
web3._currentContractMethodName = vars.method;
web3._currentContractMethodParams = vars.params;
};
/** var addFunctionRelatedPropertiesToContract = function (contract) {
* This method should be called when we want to call / transact some solidity method from javascript
* it returns an object which has same methods available as solidity contract description contract.call = function (options) {
* usage example: contract._isTransact = false;
* contract._options = options;
* var abi = [{ return contract;
* name: 'myMethod', };
* inputs: [{ name: 'a', type: 'string' }],
* outputs: [{name: 'd', type: 'string' }]
* }]; // contract 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.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
* @param desc - abi json description of the contract, which is being created
* @returns contract object
*/
var contract = function (address, desc) { contract.transact = function (options) {
contract._isTransact = true;
contract._options = options;
return contract;
};
desc.forEach(function (method) { contract._options = {};
// workaround for invalid assumption that method.name is the full anonymous prototype of the method. ['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous contract[p] = function (v) {
// prototype, so we make it so as a workaround. contract._options[p] = v;
if (method.name.indexOf('(') === -1) { return contract;
var displayName = method.name; };
var typeName = method.inputs.map(function(i){return i.type; }).join();
method.name = displayName + '(' + typeName + ')';
}
}); });
};
var addFunctionsToContract = function (contract, desc, address) {
var inputParser = abi.inputParser(desc); var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc); var outputParser = abi.outputParser(desc);
var result = {}; // create contract functions
utils.filterFunctions(desc).forEach(function (method) {
result.call = function (options) {
result._isTransact = false;
result._options = options;
return result;
};
result.transact = function (options) {
result._isTransact = true;
result._options = options;
return result;
};
result._options = {};
['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {
result[p] = function (v) {
result._options[p] = v;
return result;
};
});
var displayName = utils.extractDisplayName(method.name);
desc.forEach(function (method) { var typeName = utils.extractTypeName(method.name);
var displayName = abi.methodDisplayName(method.name);
var typeName = abi.methodTypeName(method.name);
var impl = function () { var impl = function () {
var params = Array.prototype.slice.call(arguments); var params = Array.prototype.slice.call(arguments);
var signature = abi.methodSignature(method.name); var signature = abi.signatureFromAscii(method.name);
var parsed = inputParser[displayName][typeName].apply(null, params); var parsed = inputParser[displayName][typeName].apply(null, params);
var options = result._options || {}; var options = contract._options || {};
options.to = address; options.to = address;
options.data = signature + parsed; options.data = signature + parsed;
var isTransact = result._isTransact === true || (result._isTransact !== false && !method.constant); var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);
var collapse = options.collapse !== false; var collapse = options.collapse !== false;
// reset // reset
result._options = {}; contract._options = {};
result._isTransact = null; contract._isTransact = null;
if (isTransact) { if (isTransact) {
// it's used byt natspec.js
// TODO: figure out better way to solve this exportNatspecGlobals({
web3._currentContractAbi = desc; abi: desc,
web3._currentContractAddress = address; address: address,
web3._currentContractMethodName = method.name; method: method.name,
web3._currentContractMethodParams = params; params: params
});
// transactions do not have any output, cause we do not know, when they will be processed // transactions do not have any output, cause we do not know, when they will be processed
web3.eth.transact(options); web3.eth.transact(options);
...@@ -543,21 +381,509 @@ var contract = function (address, desc) { ...@@ -543,21 +381,509 @@ var contract = function (address, desc) {
return ret; return ret;
}; };
if (result[displayName] === undefined) { if (contract[displayName] === undefined) {
result[displayName] = impl; contract[displayName] = impl;
} }
result[displayName][typeName] = impl; contract[displayName][typeName] = impl;
});
};
var addEventRelatedPropertiesToContract = function (contract, desc, address) {
contract.address = address;
contract._onWatchEventResult = function (data) {
var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc));
var parser = eventImpl.outputParser(matchingEvent);
return parser(data);
};
Object.defineProperty(contract, 'topic', {
get: function() {
return utils.filterEvents(desc).map(function (e) {
return abi.eventSignatureFromAscii(e.name);
});
}
});
};
var addEventsToContract = function (contract, desc, address) {
// create contract events
utils.filterEvents(desc).forEach(function (e) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
var signature = abi.eventSignatureFromAscii(e.name);
var event = eventImpl.inputParser(address, signature, e);
var o = event.apply(null, params);
o._onWatchEventResult = function (data) {
var parser = eventImpl.outputParser(e);
return parser(data);
};
return web3.eth.watch(o);
};
// this property should be used by eth.filter to check if object is an event
impl._isEvent = true;
var displayName = utils.extractDisplayName(e.name);
var typeName = utils.extractTypeName(e.name);
if (contract[displayName] === undefined) {
contract[displayName] = impl;
}
contract[displayName][typeName] = impl;
});
};
/**
* This method should be called when we want to call / transact some solidity method from javascript
* it returns an object which has same methods available as solidity contract description
* usage example:
*
* var abi = [{
* name: 'myMethod',
* inputs: [{ name: 'a', type: 'string' }],
* outputs: [{name: 'd', type: 'string' }]
* }]; // contract 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.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
* @param desc - abi json description of the contract, which is being created
* @returns contract object
*/
var contract = function (address, desc) {
// 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.
// TODO: we may not want to modify input params, maybe use copy instead?
desc.forEach(function (method) {
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 result = {};
addFunctionRelatedPropertiesToContract(result);
addFunctionsToContract(result, desc, address);
addEventRelatedPropertiesToContract(result, desc, address);
addEventsToContract(result, desc, address);
return result; return result;
}; };
module.exports = contract; module.exports = contract;
},{"./abi":1,"./event":4,"./utils":12,"./web3":13}],4:[function(require,module,exports){
/*
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 event.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
var abi = require('./abi');
var utils = require('./utils');
/// filter inputs array && returns only indexed (or not) inputs
/// @param inputs array
/// @param bool if result should be an array of indexed params on not
/// @returns array of (not?) indexed params
var filterInputs = function (inputs, indexed) {
return inputs.filter(function (current) {
return current.indexed === indexed;
});
};
var inputWithName = function (inputs, name) {
var index = utils.findIndex(inputs, function (input) {
return input.name === name;
});
if (index === -1) {
console.error('indexed param with name ' + name + ' not found');
return undefined;
}
return inputs[index];
};
var indexedParamsToTopics = function (event, indexed) {
// sort keys?
return Object.keys(indexed).map(function (key) {
var inputs = [inputWithName(filterInputs(event.inputs, true), key)];
var value = indexed[key];
if (value instanceof Array) {
return value.map(function (v) {
return abi.formatInput(inputs, [v]);
});
}
return abi.formatInput(inputs, [value]);
});
};
var inputParser = function (address, signature, event) {
// valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'
return function (indexed, options) {
var o = options || {};
o.address = address;
o.topic = [];
o.topic.push(signature);
if (indexed) {
o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));
}
return o;
};
};
var getArgumentsObject = function (inputs, indexed, notIndexed) {
var indexedCopy = indexed.slice();
var notIndexedCopy = notIndexed.slice();
return inputs.reduce(function (acc, current) {
var value;
if (current.indexed)
value = indexed.splice(0, 1)[0];
else
value = notIndexed.splice(0, 1)[0];
acc[current.name] = value;
return acc;
}, {});
};
var outputParser = function (event) {
return function (output) {
var result = {
event: utils.extractDisplayName(event.name),
number: output.number,
args: {}
};
if (!output.topic) {
return result;
}
var indexedOutputs = filterInputs(event.inputs, true);
var indexedData = "0x" + output.topic.slice(1, output.topic.length).map(function (topic) { return topic.slice(2); }).join("");
var indexedRes = abi.formatOutput(indexedOutputs, indexedData);
var notIndexedOutputs = filterInputs(event.inputs, false);
var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data);
result.args = getArgumentsObject(event.inputs, indexedRes, notIndexedRes);
return result;
};
};
var getMatchingEvent = function (events, payload) {
for (var i = 0; i < events.length; i++) {
var signature = abi.eventSignatureFromAscii(events[i].name);
if (signature === payload.topic[0]) {
return events[i];
}
}
return undefined;
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser,
getMatchingEvent: getMatchingEvent
};
},{"./abi":1,"./utils":12}],5:[function(require,module,exports){
/*
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 filter.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Gav Wood <g@ethdev.com>
* @date 2014
*/
var web3 = require('./web3'); // jshint ignore:line
/// should be used when we want to watch something
/// it's using inner polling mechanism and is notified about changes
/// TODO: change 'options' name cause it may be not the best matching one, since we have events
var Filter = function(options, impl) {
if (typeof options !== "string") {
// topics property is deprecated, warn about it!
if (options.topics) {
console.warn('"topics" is deprecated, use "topic" instead');
}
this._onWatchResult = options._onWatchEventResult;
// evaluate lazy properties
options = {
to: options.to,
topic: options.topic,
earliest: options.earliest,
latest: options.latest,
max: options.max,
skip: options.skip,
address: options.address
};
}
this.impl = impl;
this.callbacks = [];
this.id = impl.newFilter(options);
web3.provider.startPolling({method: impl.changed, params: [this.id]}, this.id, this.trigger.bind(this));
};
/// alias for changed*
Filter.prototype.arrived = function(callback) {
this.changed(callback);
};
Filter.prototype.happened = function(callback) {
this.changed(callback);
};
/// gets called when there is new eth/shh message
Filter.prototype.changed = function(callback) {
this.callbacks.push(callback);
};
/// trigger calling new message from people
Filter.prototype.trigger = function(messages) {
for (var i = 0; i < this.callbacks.length; i++) {
for (var j = 0; j < messages.length; j++) {
var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j];
this.callbacks[i].call(this, message);
}
}
};
/// should be called to uninstall current filter
Filter.prototype.uninstall = function() {
this.impl.uninstallFilter(this.id);
web3.provider.stopPolling(this.id);
};
/// should be called to manually trigger getting latest messages from the client
Filter.prototype.messages = function() {
return this.impl.getMessages(this.id);
};
/// alias for messages
Filter.prototype.logs = function () {
return this.messages();
};
module.exports = Filter;
},{"./web3":13}],6:[function(require,module,exports){
/*
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 formatters.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); // jshint ignore:line
*/}
var utils = require('./utils');
var c = require('./const');
/// @param string string to be padded
/// @param number of characters that result string should have
/// @param sign, by default 0
/// @returns right aligned string
var padLeft = function (string, chars, sign) {
return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
};
/// Formats input value to byte representation of int
/// If value is negative, return it's two's complement
/// If the value is floating point, round it down
/// @returns right-aligned byte representation of int
var formatInputInt = function (value) {
var padding = c.ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number')
value = new BigNumber(value);
BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
value = value.round();
if (value.lessThan(0))
value = new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(value).plus(1);
value = value.toString(16);
}
else if (value.indexOf('0x') === 0)
value = value.substr(2);
else if (typeof value === 'string')
value = formatInputInt(new BigNumber(value));
else
value = (+value).toString(16);
return padLeft(value, padding);
};
/// Formats input value to byte representation of string
/// @returns left-algined byte representation of string
var formatInputString = function (value) {
return utils.fromAscii(value, c.ETH_PADDING).substr(2);
};
/// Formats input value to byte representation of bool
/// @returns right-aligned byte representation bool
var formatInputBool = function (value) {
return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');
};
/// Formats input value to byte representation of real
/// Values are multiplied by 2^m and encoded as integers
/// @returns byte representation of real
var formatInputReal = function (value) {
return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128)));
};
/// Check if input value is negative
/// @param value is hex format
/// @returns true if it is negative, otherwise false
var signedIsNegative = function (value) {
return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';
};
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
var formatOutputInt = function (value) {
value = value || "0";
// check if it's negative number
// it it is, return two's complement
if (signedIsNegative(value)) {
return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
}
return new BigNumber(value, 16);
};
/// Formats big right-aligned input bytes to uint
/// @returns right-aligned input bytes formatted to uint
var formatOutputUInt = function (value) {
value = value || "0";
return new BigNumber(value, 16);
};
/// @returns input bytes formatted to real
var formatOutputReal = function (value) {
return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128));
};
/// @returns input bytes formatted to ureal
var formatOutputUReal = function (value) {
return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128));
};
/// @returns right-aligned input bytes formatted to hex
var formatOutputHash = function (value) {
return "0x" + value;
};
/// @returns right-aligned input bytes formatted to bool
var formatOutputBool = function (value) {
return value === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;
};
/// @returns left-aligned input bytes formatted to ascii string
var formatOutputString = function (value) {
return utils.toAscii(value);
};
/// @returns right-aligned input bytes formatted to address
var formatOutputAddress = function (value) {
return "0x" + value.slice(value.length - 40, value.length);
};
module.exports = {
formatInputInt: formatInputInt,
formatInputString: formatInputString,
formatInputBool: formatInputBool,
formatInputReal: formatInputReal,
formatOutputInt: formatOutputInt,
formatOutputUInt: formatOutputUInt,
formatOutputReal: formatOutputReal,
formatOutputUReal: formatOutputUReal,
formatOutputHash: formatOutputHash,
formatOutputBool: formatOutputBool,
formatOutputString: formatOutputString,
formatOutputAddress: formatOutputAddress
};
},{"./abi":1,"./web3":7}],3:[function(require,module,exports){ },{"./const":2,"./utils":12}],7:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.
...@@ -574,65 +900,38 @@ module.exports = contract; ...@@ -574,65 +900,38 @@ module.exports = contract;
You should have received a copy of the GNU Lesser General Public License 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/>. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file filter.js /** @file httpsync.js
* @authors: * @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com> * Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com> * Marian Oancea <marian@ethdev.com>
* Gav Wood <g@ethdev.com>
* @date 2014 * @date 2014
*/ */
var web3 = require('./web3'); // jshint ignore:line if ("build" !== 'build') {/*
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
/// should be used when we want to watch something */}
/// it's using inner polling mechanism and is notified about changes
var Filter = function(options, impl) {
this.impl = impl;
this.callbacks = [];
this.id = impl.newFilter(options);
web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this));
};
/// alias for changed*
Filter.prototype.arrived = function(callback) {
this.changed(callback);
};
/// gets called when there is new eth/shh message
Filter.prototype.changed = function(callback) {
this.callbacks.push(callback);
};
/// trigger calling new message from people
Filter.prototype.trigger = function(messages) {
for (var i = 0; i < this.callbacks.length; i++) {
for (var j = 0; j < messages.length; j++) {
this.callbacks[i].call(this, messages[j]);
}
}
};
/// should be called to uninstall current filter var HttpSyncProvider = function (host) {
Filter.prototype.uninstall = function() { this.handlers = [];
this.impl.uninstallFilter(this.id); this.host = host || 'http://localhost:8080';
web3.provider.stopPolling(this.id);
}; };
/// should be called to manually trigger getting latest messages from the client HttpSyncProvider.prototype.send = function (payload) {
Filter.prototype.messages = function() { //var data = formatJsonRpcObject(payload);
return this.impl.getMessages(this.id);
var request = new XMLHttpRequest();
request.open('POST', this.host, false);
request.send(JSON.stringify(payload));
// check request.status
var result = request.responseText;
return JSON.parse(result);
}; };
/// alias for messages module.exports = HttpSyncProvider;
Filter.prototype.logs = function () {
return this.messages();
};
module.exports = Filter;
},{"./web3":7}],4:[function(require,module,exports){ },{}],8:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.
...@@ -649,62 +948,57 @@ module.exports = Filter; ...@@ -649,62 +948,57 @@ module.exports = Filter;
You should have received a copy of the GNU Lesser General Public License 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/>. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file httpsync.js /** @file jsonrpc.js
* @authors: * @authors:
* Marek Kotewicz <marek@ethdev.com> * Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com> * @date 2015
* @date 2014
*/ */
if ("build" !== 'build') {/* var messageId = 1;
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
*/}
var HttpSyncProvider = function (host) { /// Should be called to valid json create payload object
this.handlers = []; /// @param method of jsonrpc call, required
this.host = host || 'http://localhost:8080'; /// @param params, an array of method params, optional
}; /// @returns valid jsonrpc payload object
var toPayload = function (method, params) {
if (!method)
console.error('jsonrpc method should be specified!');
/// Transforms inner message to proper jsonrpc object
/// @param inner message object
/// @returns jsonrpc object
function formatJsonRpcObject(object) {
return { return {
jsonrpc: '2.0', jsonrpc: '2.0',
method: object.call, method: method,
params: object.args, params: params || [],
id: object._id id: messageId++
}; };
} };
/// Transforms jsonrpc object to inner message /// Should be called to check if jsonrpc response is valid
/// @param incoming jsonrpc message /// @returns true if response is valid, otherwise false
/// @returns inner message object var isValidResponse = function (response) {
function formatJsonRpcMessage(message) { return !!response &&
var object = JSON.parse(message); !response.error &&
response.jsonrpc === '2.0' &&
typeof response.id === 'number' &&
response.result !== undefined; // only undefined is not valid json object
};
return { /// Should be called to create batch payload object
_id: object.id, /// @param messages, an array of objects with method (required) and params (optional) fields
data: object.result, var toBatchPayload = function (messages) {
error: object.error return messages.map(function (message) {
}; return toPayload(message.method, message.params);
} });
};
HttpSyncProvider.prototype.send = function (payload) { module.exports = {
var data = formatJsonRpcObject(payload); toPayload: toPayload,
isValidResponse: isValidResponse,
var request = new XMLHttpRequest(); toBatchPayload: toBatchPayload
request.open('POST', this.host, false);
request.send(JSON.stringify(data));
// check request.status
return request.responseText;
}; };
module.exports = HttpSyncProvider;
},{}],5:[function(require,module,exports){ },{}],9:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.
...@@ -730,7 +1024,9 @@ module.exports = HttpSyncProvider; ...@@ -730,7 +1024,9 @@ module.exports = HttpSyncProvider;
* @date 2014 * @date 2014
*/ */
var web3 = require('./web3'); // jshint ignore:line var web3 = require('./web3');
var jsonrpc = require('./jsonrpc');
/** /**
* Provider manager object prototype * Provider manager object prototype
...@@ -744,25 +1040,35 @@ var web3 = require('./web3'); // jshint ignore:line ...@@ -744,25 +1040,35 @@ var web3 = require('./web3'); // jshint ignore:line
var ProviderManager = function() { var ProviderManager = function() {
this.polls = []; this.polls = [];
this.provider = undefined; this.provider = undefined;
this.id = 1;
var self = this; var self = this;
var poll = function () { var poll = function () {
if (self.provider) { if (self.provider) {
self.polls.forEach(function (data) { var pollsBatch = self.polls.map(function (data) {
data.data._id = self.id; return data.data;
self.id++; });
var result = self.provider.send(data.data);
var payload = jsonrpc.toBatchPayload(pollsBatch);
result = JSON.parse(result); var results = self.provider.send(payload);
self.polls.forEach(function (data, index) {
var result = results[index];
if (!jsonrpc.isValidResponse(result)) {
console.log(result);
return;
}
result = result.result;
// dont call the callback if result is not an array, or empty one // dont call the callback if result is not an array, or empty one
if (result.error || !(result.result instanceof Array) || result.result.length === 0) { if (!(result instanceof Array) || result.length === 0) {
return; return;
} }
data.callback(result.result); data.callback(result);
}); });
} }
setTimeout(poll, 1000); setTimeout(poll, 1000);
}; };
...@@ -770,22 +1076,19 @@ var ProviderManager = function() { ...@@ -770,22 +1076,19 @@ var ProviderManager = function() {
}; };
/// sends outgoing requests /// sends outgoing requests
/// @params data - an object with at least 'method' property
ProviderManager.prototype.send = function(data) { ProviderManager.prototype.send = function(data) {
var payload = jsonrpc.toPayload(data.method, data.params);
data.args = data.args || [];
data._id = this.id++;
if (this.provider === undefined) { if (this.provider === undefined) {
console.error('provider is not set'); console.error('provider is not set');
return null; return null;
} }
//TODO: handle error here? var result = this.provider.send(payload);
var result = this.provider.send(data);
result = JSON.parse(result);
if (result.error) { if (!jsonrpc.isValidResponse(result)) {
console.log(result.error); console.log(result);
return null; return null;
} }
...@@ -816,7 +1119,7 @@ ProviderManager.prototype.stopPolling = function (pollId) { ...@@ -816,7 +1119,7 @@ ProviderManager.prototype.stopPolling = function (pollId) {
module.exports = ProviderManager; module.exports = ProviderManager;
},{"./web3":7}],6:[function(require,module,exports){ },{"./jsonrpc":8,"./web3":13}],10:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.
...@@ -844,13 +1147,239 @@ var QtSyncProvider = function () { ...@@ -844,13 +1147,239 @@ var QtSyncProvider = function () {
}; };
QtSyncProvider.prototype.send = function (payload) { QtSyncProvider.prototype.send = function (payload) {
return navigator.qt.callMethod(JSON.stringify(payload)); var result = navigator.qt.callMethod(JSON.stringify(payload));
return JSON.parse(result);
}; };
module.exports = QtSyncProvider; module.exports = QtSyncProvider;
},{}],7:[function(require,module,exports){ },{}],11:[function(require,module,exports){
/*
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 types.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
var f = require('./formatters');
/// @param expected type prefix (string)
/// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false
var prefixedType = function (prefix) {
return function (type) {
return type.indexOf(prefix) === 0;
};
};
/// @param expected type name (string)
/// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false
var namedType = function (name) {
return function (type) {
return name === type;
};
};
/// Setups input formatters for solidity types
/// @returns an array of input formatters
var inputTypes = function () {
return [
{ type: prefixedType('uint'), format: f.formatInputInt },
{ type: prefixedType('int'), format: f.formatInputInt },
{ type: prefixedType('hash'), format: f.formatInputInt },
{ type: prefixedType('string'), format: f.formatInputString },
{ type: prefixedType('real'), format: f.formatInputReal },
{ type: prefixedType('ureal'), format: f.formatInputReal },
{ type: namedType('address'), format: f.formatInputInt },
{ type: namedType('bool'), format: f.formatInputBool }
];
};
/// Setups output formaters for solidity types
/// @returns an array of output formatters
var outputTypes = function () {
return [
{ type: prefixedType('uint'), format: f.formatOutputUInt },
{ type: prefixedType('int'), format: f.formatOutputInt },
{ type: prefixedType('hash'), format: f.formatOutputHash },
{ type: prefixedType('string'), format: f.formatOutputString },
{ type: prefixedType('real'), format: f.formatOutputReal },
{ type: prefixedType('ureal'), format: f.formatOutputUReal },
{ type: namedType('address'), format: f.formatOutputAddress },
{ type: namedType('bool'), format: f.formatOutputBool }
];
};
module.exports = {
prefixedType: prefixedType,
namedType: namedType,
inputTypes: inputTypes,
outputTypes: outputTypes
};
},{"./formatters":6}],12:[function(require,module,exports){
/*
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 utils.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
var c = require('./const');
/// Finds first index of array element matching pattern
/// @param array
/// @param callback pattern
/// @returns index of element
var findIndex = function (array, callback) {
var end = false;
var i = 0;
for (; i < array.length && !end; i++) {
end = callback(array[i]);
}
return end ? i - 1 : -1;
};
/// @returns ascii string representation of hex value prefixed with 0x
var toAscii = function(hex) {
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) === '0x') {
i = 2;
}
for (; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if (code === 0) {
break;
}
str += String.fromCharCode(code);
}
return str;
};
var toHex = function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
};
/// @returns hex representation (prefixed by 0x) of ascii string
var fromAscii = function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = toHex(str);
while (hex.length < pad*2)
hex += "00";
return "0x" + hex;
};
/// @returns display name for function/event eg. multiply(uint256) -> multiply
var extractDisplayName = function (name) {
var length = name.indexOf('(');
return length !== -1 ? name.substr(0, length) : name;
};
/// @returns overloaded part of function/event name
var extractTypeName = function (name) {
/// TODO: make it invulnerable
var length = name.indexOf('(');
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/// Filters all events form input abi
/// @returns abi array with filtered objects of type 'event'
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';
});
};
/// used to transform value/string to eth string
/// TODO: use BigNumber.js to parse int
/// TODO: add tests for it!
var toEth = function (str) {
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;
var unit = 0;
var units = c.ETH_UNITS;
while (val > 3000 && unit < units.length - 1)
{
val /= 1000;
unit++;
}
var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);
var replaceFunction = function($0, $1, $2) {
return $1 + ',' + $2;
};
while (true) {
var o = s;
s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction);
if (o === s)
break;
}
return s + ' ' + units[unit];
};
module.exports = {
findIndex: findIndex,
toAscii: toAscii,
fromAscii: fromAscii,
extractDisplayName: extractDisplayName,
extractTypeName: extractTypeName,
filterFunctions: filterFunctions,
filterEvents: filterEvents,
toEth: toEth
};
},{"./const":2}],13:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.
...@@ -880,27 +1409,7 @@ if ("build" !== 'build') {/* ...@@ -880,27 +1409,7 @@ if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); var BigNumber = require('bignumber.js');
*/} */}
var ETH_UNITS = [ var utils = require('./utils');
'wei',
'Kwei',
'Mwei',
'Gwei',
'szabo',
'finney',
'ether',
'grand',
'Mether',
'Gether',
'Tether',
'Pether',
'Eether',
'Zether',
'Yether',
'Nether',
'Dether',
'Vether',
'Uether'
];
/// @returns an array of objects describing web3 api methods /// @returns an array of objects describing web3 api methods
var web3Methods = function () { var web3Methods = function () {
...@@ -1009,8 +1518,8 @@ var setupMethods = function (obj, methods) { ...@@ -1009,8 +1518,8 @@ var setupMethods = function (obj, methods) {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
var call = typeof method.call === 'function' ? method.call(args) : method.call; var call = typeof method.call === 'function' ? method.call(args) : method.call;
return web3.provider.send({ return web3.provider.send({
call: call, method: call,
args: args params: args
}); });
}; };
}); });
...@@ -1023,15 +1532,15 @@ var setupProperties = function (obj, properties) { ...@@ -1023,15 +1532,15 @@ var setupProperties = function (obj, properties) {
var proto = {}; var proto = {};
proto.get = function () { proto.get = function () {
return web3.provider.send({ return web3.provider.send({
call: property.getter method: property.getter
}); });
}; };
if (property.setter) { if (property.setter) {
proto.set = function (val) { proto.set = function (val) {
return web3.provider.send({ return web3.provider.send({
call: property.setter, method: property.setter,
args: [val] params: [val]
}); });
}; };
} }
...@@ -1045,43 +1554,11 @@ var web3 = { ...@@ -1045,43 +1554,11 @@ var web3 = {
_events: {}, _events: {},
providers: {}, providers: {},
toHex: function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
},
/// @returns ascii string representation of hex value prefixed with 0x /// @returns ascii string representation of hex value prefixed with 0x
toAscii: function(hex) { toAscii: utils.toAscii,
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) === '0x')
i = 2;
for(; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if(code === 0) {
break;
}
str += String.fromCharCode(code);
}
return str;
},
/// @returns hex representation (prefixed by 0x) of ascii string /// @returns hex representation (prefixed by 0x) of ascii string
fromAscii: function(str, pad) { fromAscii: utils.fromAscii,
pad = pad === undefined ? 0 : pad;
var hex = this.toHex(str);
while(hex.length < pad*2)
hex += "00";
return "0x" + hex;
},
/// @returns decimal representaton of hex value prefixed by 0x /// @returns decimal representaton of hex value prefixed by 0x
toDecimal: function (val) { toDecimal: function (val) {
...@@ -1096,29 +1573,7 @@ var web3 = { ...@@ -1096,29 +1573,7 @@ var web3 = {
}, },
/// used to transform value/string to eth string /// used to transform value/string to eth string
/// TODO: use BigNumber.js to parse int toEth: utils.toEth,
toEth: function(str) {
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;
var unit = 0;
var units = ETH_UNITS;
while (val > 3000 && unit < units.length - 1)
{
val /= 1000;
unit++;
}
var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);
var replaceFunction = function($0, $1, $2) {
return $1 + ',' + $2;
};
while (true) {
var o = s;
s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction);
if (o === s)
break;
}
return s + ' ' + units[unit];
},
/// eth object prototype /// eth object prototype
eth: { eth: {
...@@ -1131,8 +1586,15 @@ var web3 = { ...@@ -1131,8 +1586,15 @@ var web3 = {
return ret; return ret;
}; };
}, },
watch: function (params) {
return new web3.filter(params, ethWatch); /// @param filter may be a string, object or event
/// @param indexed is optional, this is an object with optional event indexed params
/// @param options is optional, this is an object with optional event options ('max'...)
watch: function (filter, indexed, options) {
if (filter._isEvent) {
return filter(indexed, options);
}
return new web3.filter(filter, ethWatch);
} }
}, },
...@@ -1141,15 +1603,12 @@ var web3 = { ...@@ -1141,15 +1603,12 @@ var web3 = {
/// shh object prototype /// shh object prototype
shh: { shh: {
watch: function (params) {
return new web3.filter(params, shhWatch); /// @param filter may be a string, object or event
watch: function (filter, indexed) {
return new web3.filter(filter, shhWatch);
} }
}, },
/// @returns true if provider is installed
haveProvider: function() {
return !!web3.provider.provider;
}
}; };
/// setups all api methods /// setups all api methods
...@@ -1172,14 +1631,13 @@ var shhWatch = { ...@@ -1172,14 +1631,13 @@ var shhWatch = {
setupMethods(shhWatch, shhWatchMethods()); setupMethods(shhWatch, shhWatchMethods());
web3.setProvider = function(provider) { web3.setProvider = function(provider) {
//provider.onmessage = messageHandler; // there will be no async calls, to remove
web3.provider.set(provider); web3.provider.set(provider);
}; };
module.exports = web3; module.exports = web3;
},{}],"web3":[function(require,module,exports){ },{"./utils":12}],"web3":[function(require,module,exports){
var web3 = require('./lib/web3'); var web3 = require('./lib/web3');
var ProviderManager = require('./lib/providermanager'); var ProviderManager = require('./lib/providermanager');
web3.provider = new ProviderManager(); web3.provider = new ProviderManager();
...@@ -1192,7 +1650,7 @@ web3.abi = require('./lib/abi'); ...@@ -1192,7 +1650,7 @@ web3.abi = require('./lib/abi');
module.exports = web3; module.exports = web3;
},{"./lib/abi":1,"./lib/contract":2,"./lib/filter":3,"./lib/httpsync":4,"./lib/providermanager":5,"./lib/qtsync":6,"./lib/web3":7}]},{},["web3"]) },{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":9,"./lib/qtsync":10,"./lib/web3":13}]},{},["web3"])
//# sourceMappingURL=ethereum.js.map //# sourceMappingURL=ethereum.js.map
...@@ -110,6 +110,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, state ...@@ -110,6 +110,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, state
go self.eventMux.Post(TxPostEvent{tx}) go self.eventMux.Post(TxPostEvent{tx})
} }
go self.eventMux.Post(state.Logs())
return receipt, txGas, err return receipt, txGas, err
} }
...@@ -155,25 +157,25 @@ done: ...@@ -155,25 +157,25 @@ done:
return receipts, handled, unhandled, erroneous, err return receipts, handled, unhandled, erroneous, err
} }
func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, msgs state.Messages, err error) { func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, err error) {
// Processing a blocks may never happen simultaneously // Processing a blocks may never happen simultaneously
sm.mutex.Lock() sm.mutex.Lock()
defer sm.mutex.Unlock() defer sm.mutex.Unlock()
header := block.Header() header := block.Header()
if sm.bc.HasBlock(header.Hash()) { if sm.bc.HasBlock(header.Hash()) {
return nil, nil, &KnownBlockError{header.Number, header.Hash()} return nil, &KnownBlockError{header.Number, header.Hash()}
} }
if !sm.bc.HasBlock(header.ParentHash) { if !sm.bc.HasBlock(header.ParentHash) {
return nil, nil, ParentError(header.ParentHash) return nil, ParentError(header.ParentHash)
} }
parent := sm.bc.GetBlock(header.ParentHash) parent := sm.bc.GetBlock(header.ParentHash)
return sm.ProcessWithParent(block, parent) return sm.ProcessWithParent(block, parent)
} }
func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big.Int, messages state.Messages, err error) { func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big.Int, err error) {
sm.lastAttemptedBlock = block sm.lastAttemptedBlock = block
state := state.New(parent.Root(), sm.db) state := state.New(parent.Root(), sm.db)
...@@ -227,7 +229,6 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big ...@@ -227,7 +229,6 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
state.Sync() state.Sync()
// Set the block hashes for the current messages // Set the block hashes for the current messages
state.Manifest().SetHash(block.Hash()) state.Manifest().SetHash(block.Hash())
messages = state.Manifest().Messages
// Reset the manifest XXX We need this? // Reset the manifest XXX We need this?
state.Manifest().Reset() state.Manifest().Reset()
// Remove transactions from the pool // Remove transactions from the pool
...@@ -235,7 +236,7 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big ...@@ -235,7 +236,7 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash()[0:4]) chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash()[0:4])
return td, messages, nil return td, nil
} }
// Validates the current block. Returns an error if the block was invalid, // Validates the current block. Returns an error if the block was invalid,
......
...@@ -359,7 +359,7 @@ func (bc *ChainManager) Stop() { ...@@ -359,7 +359,7 @@ func (bc *ChainManager) Stop() {
func (self *ChainManager) InsertChain(chain types.Blocks) error { func (self *ChainManager) InsertChain(chain types.Blocks) error {
for _, block := range chain { for _, block := range chain {
td, messages, err := self.processor.Process(block) td, err := self.processor.Process(block)
if err != nil { if err != nil {
if IsKnownBlockErr(err) { if IsKnownBlockErr(err) {
continue continue
...@@ -391,7 +391,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { ...@@ -391,7 +391,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.mu.Unlock() self.mu.Unlock()
self.eventMux.Post(NewBlockEvent{block}) self.eventMux.Post(NewBlockEvent{block})
self.eventMux.Post(messages)
} }
return nil return nil
......
...@@ -2,6 +2,7 @@ package core ...@@ -2,6 +2,7 @@ package core
import ( import (
"bytes" "bytes"
"fmt"
"math" "math"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
...@@ -130,6 +131,7 @@ func (self *Filter) Find() state.Logs { ...@@ -130,6 +131,7 @@ func (self *Filter) Find() state.Logs {
func includes(addresses [][]byte, a []byte) (found bool) { func includes(addresses [][]byte, a []byte) (found bool) {
for _, addr := range addresses { for _, addr := range addresses {
fmt.Println("INCLUDES", addr, a)
if bytes.Compare(addr, a) == 0 { if bytes.Compare(addr, a) == 0 {
return true return true
} }
...@@ -139,20 +141,25 @@ func includes(addresses [][]byte, a []byte) (found bool) { ...@@ -139,20 +141,25 @@ func includes(addresses [][]byte, a []byte) (found bool) {
} }
func (self *Filter) FilterLogs(logs state.Logs) state.Logs { func (self *Filter) FilterLogs(logs state.Logs) state.Logs {
fmt.Println("FILTER LOGS", self.topics)
var ret state.Logs var ret state.Logs
// Filter the logs for interesting stuff // Filter the logs for interesting stuff
for _, log := range logs { for _, log := range logs {
fmt.Println(log)
if len(self.address) > 0 && !bytes.Equal(self.address, log.Address()) { if len(self.address) > 0 && !bytes.Equal(self.address, log.Address()) {
continue continue
} }
for _, topic := range self.topics { for _, topic := range self.topics {
fmt.Println("TOPIC:", topic)
if !includes(log.Topics(), topic) { if !includes(log.Topics(), topic) {
continue continue
} }
} }
fmt.Println("APPENDED")
ret = append(ret, log) ret = append(ret, log)
} }
......
package types package types
import ( import "math/big"
"math/big"
"github.com/ethereum/go-ethereum/state"
)
type BlockProcessor interface { type BlockProcessor interface {
Process(*Block) (*big.Int, state.Messages, error) Process(*Block) (*big.Int, error)
} }
...@@ -59,7 +59,7 @@ func (self *FilterManager) GetFilter(id int) *core.Filter { ...@@ -59,7 +59,7 @@ func (self *FilterManager) GetFilter(id int) *core.Filter {
func (self *FilterManager) filterLoop() { func (self *FilterManager) filterLoop() {
// Subscribe to events // Subscribe to events
events := self.eventMux.Subscribe(core.NewBlockEvent{}, state.Messages(nil)) events := self.eventMux.Subscribe(core.NewBlockEvent{}, state.Logs(nil))
out: out:
for { for {
......
...@@ -41,6 +41,10 @@ func env(block *types.Block, eth *eth.Ethereum) *environment { ...@@ -41,6 +41,10 @@ func env(block *types.Block, eth *eth.Ethereum) *environment {
return env return env
} }
type Agent interface {
Comms() chan<- *types.Block
}
type worker struct { type worker struct {
agents []chan<- *types.Block agents []chan<- *types.Block
mux *event.TypeMux mux *event.TypeMux
...@@ -68,11 +72,12 @@ out: ...@@ -68,11 +72,12 @@ out:
case event := <-events.Chan(): case event := <-events.Chan():
switch event := event.(type) { switch event := event.(type) {
case core.NewBlockEvent: case core.NewBlockEvent:
block := event.Block if self.eth.ChainManager().HasBlock(event.Block.Hash()) {
if self.eth.ChainManager().HasBlock(block.Hash()) { }
} else if true { case core.TxPreEvent:
if err := self.commitTransaction(event.Tx); err != nil {
self.commit()
} }
case core.TxPreEvent, *LocalTx:
} }
case <-self.quit: case <-self.quit:
break out break out
......
...@@ -87,7 +87,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler { ...@@ -87,7 +87,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) { fn := func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
rpchttplogger.Debugln("Handling request") rpchttplogger.DebugDetailln("Handling request")
reqParsed, reqerr := JSON.ParseRequestBody(req) reqParsed, reqerr := JSON.ParseRequestBody(req)
if reqerr != nil { if reqerr != nil {
...@@ -103,7 +103,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler { ...@@ -103,7 +103,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
return return
} }
rpchttplogger.Debugf("Generated response: %T %s", response, response) rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response}) JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
} }
......
...@@ -206,6 +206,7 @@ func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) { ...@@ -206,6 +206,7 @@ func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, NewErrorResponse(ErrorArguments)
} }
fmt.Println("filter params", req.Params)
args := new(FilterOptions) args := new(FilterOptions)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
......
...@@ -18,10 +18,11 @@ package rpc ...@@ -18,10 +18,11 @@ package rpc
import ( import (
"encoding/json" "encoding/json"
"github.com/ethereum/go-ethereum/logger"
"io" "io"
"net/http" "net/http"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
) )
...@@ -36,7 +37,7 @@ func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error) ...@@ -36,7 +37,7 @@ func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error)
rpclogger.Fatalln("Error marshalling JSON", err) rpclogger.Fatalln("Error marshalling JSON", err)
return 0, err return 0, err
} }
rpclogger.Infof("Sending payload: %s", payload) rpclogger.DebugDetailf("Sending payload: %s", payload)
return writer.Write(payload) return writer.Write(payload)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment