changed most of the function names
Missing is still: - eth.watch - eth.contract (has different behaviour now) - shh methods correct return values need to be checked
This commit is contained in:
parent
c4c3b126a3
commit
5c994ff817
|
@ -38,7 +38,7 @@ There you go, now you can use it:
|
||||||
|
|
||||||
```
|
```
|
||||||
var coinbase = web3.eth.coinbase;
|
var coinbase = web3.eth.coinbase;
|
||||||
var balance = web3.eth.balanceAt(coinbase);
|
var balance = web3.eth.getBalance(coinbase);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -549,53 +549,67 @@ module.exports = {
|
||||||
* @date 2015
|
* @date 2015
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// @returns an array of objects describing web3.eth api methods
|
var blockCall = function (args) {
|
||||||
var methods = function () {
|
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber";
|
||||||
var blockCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber";
|
|
||||||
};
|
|
||||||
|
|
||||||
var transactionCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var uncleCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var transactionCountCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_transactionCountByHash' : 'eth_transactionCountByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var uncleCountCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_uncleCountByHash' : 'eth_uncleCountByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
return [
|
|
||||||
{ name: 'balanceAt', call: 'eth_balanceAt' },
|
|
||||||
{ name: 'stateAt', call: 'eth_stateAt' },
|
|
||||||
{ name: 'storageAt', call: 'eth_storageAt' },
|
|
||||||
{ name: 'countAt', call: 'eth_countAt'},
|
|
||||||
{ name: 'codeAt', call: 'eth_codeAt' },
|
|
||||||
{ name: 'transact', call: 'eth_transact' },
|
|
||||||
{ name: 'call', call: 'eth_call' },
|
|
||||||
{ name: 'block', call: blockCall },
|
|
||||||
{ 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' },
|
|
||||||
{ name: 'logs', call: 'eth_logs' },
|
|
||||||
{ name: 'transactionCount', call: transactionCountCall },
|
|
||||||
{ name: 'uncleCount', call: uncleCountCall }
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var transactionCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
var uncleCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
var transactionCountCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_transactionCountByHash' : 'eth_transactionCountByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
var uncleCountCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_uncleCountByHash' : 'eth_uncleCountByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @returns an array of objects describing web3.eth api methods
|
||||||
|
var methods = [
|
||||||
|
{ name: 'getBalance', call: 'eth_balanceAt' },
|
||||||
|
{ name: 'getState', call: 'eth_stateAt' },
|
||||||
|
{ name: 'getStorage', call: 'eth_storageAt' },
|
||||||
|
{ name: 'getTransactionCount', call: 'eth_countAt'},
|
||||||
|
{ name: 'getCode', call: 'eth_codeAt' },
|
||||||
|
{ name: 'sendTransaction', call: 'eth_transact' },
|
||||||
|
{ name: 'call', call: 'eth_call' },
|
||||||
|
{ name: 'getBlock', call: blockCall },
|
||||||
|
{ name: 'getTransaction', call: transactionCall },
|
||||||
|
{ name: 'getUncle', call: uncleCall },
|
||||||
|
{ name: 'getCompilers', call: 'eth_compilers' },
|
||||||
|
{ name: 'flush', call: 'eth_flush' },
|
||||||
|
{ name: 'compile.solidity', call: 'eth_solidity' },
|
||||||
|
{ name: 'compile.lll', call: 'eth_lll' },
|
||||||
|
{ name: 'compile.serpent', call: 'eth_serpent' },
|
||||||
|
{ name: 'logs', call: 'eth_logs' },
|
||||||
|
{ name: 'getBlockTransactionCount', call: transactionCountCall },
|
||||||
|
{ name: 'getBlockUncleCount', call: uncleCountCall },
|
||||||
|
|
||||||
|
// deprecated methods
|
||||||
|
{ name: 'balanceAt', call: 'eth_balanceAt', newMethod: 'getBalance' },
|
||||||
|
{ name: 'stateAt', call: 'eth_stateAt', newMethod: 'getState' },
|
||||||
|
{ name: 'storageAt', call: 'eth_storageAt', newMethod: 'getStorage' },
|
||||||
|
{ name: 'countAt', call: 'eth_countAt', newMethod: 'getTransactionCount' },
|
||||||
|
{ name: 'codeAt', call: 'eth_codeAt', newMethod: 'getCode' },
|
||||||
|
{ name: 'transact', call: 'eth_transact', newMethod: 'sendTransaction' },
|
||||||
|
{ name: 'block', call: blockCall, newMethod: 'getBlock' },
|
||||||
|
{ name: 'transaction', call: transactionCall, newMethod: 'getTransaction' },
|
||||||
|
{ name: 'uncle', call: uncleCall, newMethod: 'getUncle' },
|
||||||
|
{ name: 'compilers', call: 'eth_compilers', newMethod: 'getCompilers' },
|
||||||
|
{ name: 'solidity', call: 'eth_solidity', newMethod: 'compile.solidity' },
|
||||||
|
{ name: 'lll', call: 'eth_lll', newMethod: 'compile.lll' },
|
||||||
|
{ name: 'serpent', call: 'eth_serpent', newMethod: 'compile.serpent' },
|
||||||
|
{ name: 'transactionCount', call: transactionCountCall, newMethod: 'getBlockTransactionCount' },
|
||||||
|
{ name: 'uncleCount', call: uncleCountCall, newMethod: 'getBlockUncleCount' }
|
||||||
|
];
|
||||||
|
|
||||||
/// @returns an array of objects describing web3.eth api properties
|
/// @returns an array of objects describing web3.eth api properties
|
||||||
var properties = function () {
|
var properties = [
|
||||||
return [
|
|
||||||
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },
|
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },
|
||||||
{ name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },
|
{ name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },
|
||||||
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },
|
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },
|
||||||
|
@ -603,9 +617,12 @@ var properties = function () {
|
||||||
{ name: 'accounts', getter: 'eth_accounts' },
|
{ name: 'accounts', getter: 'eth_accounts' },
|
||||||
{ name: 'peerCount', getter: 'eth_peerCount' },
|
{ name: 'peerCount', getter: 'eth_peerCount' },
|
||||||
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },
|
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },
|
||||||
{ name: 'number', getter: 'eth_number'}
|
{ name: 'blockNumber', getter: 'eth_number'},
|
||||||
];
|
|
||||||
};
|
// deprecated properties
|
||||||
|
{ name: 'number', call: 'eth_number', newProperty: 'blockNumber'}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
methods: methods,
|
methods: methods,
|
||||||
|
@ -1643,14 +1660,30 @@ var web3Methods = function () {
|
||||||
/// setups api calls for these methods
|
/// setups api calls for these methods
|
||||||
var setupMethods = function (obj, methods) {
|
var setupMethods = function (obj, methods) {
|
||||||
methods.forEach(function (method) {
|
methods.forEach(function (method) {
|
||||||
obj[method.name] = function () {
|
// allow for object methods 'myObject.method'
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var objectMethods = method.name.split('.'),
|
||||||
var call = typeof method.call === 'function' ? method.call(args) : method.call;
|
callFunction = function () {
|
||||||
return web3.manager.send({
|
var args = Array.prototype.slice.call(arguments);
|
||||||
method: call,
|
var call = typeof method.call === 'function' ? method.call(args) : method.call;
|
||||||
params: args
|
|
||||||
});
|
// show deprecated warning
|
||||||
};
|
if(method.newMethod)
|
||||||
|
console.warn('This method is deprecated please use eth.'+ method.newMethod +'() instead.');
|
||||||
|
|
||||||
|
return web3.manager.send({
|
||||||
|
method: call,
|
||||||
|
params: args
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if(objectMethods.length > 1) {
|
||||||
|
if(!obj[objectMethods[0]])
|
||||||
|
obj[objectMethods[0]] = {};
|
||||||
|
|
||||||
|
obj[objectMethods[0]][objectMethods[1]] = callFunction;
|
||||||
|
} else
|
||||||
|
obj[method.name] = callFunction;
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1660,6 +1693,12 @@ var setupProperties = function (obj, properties) {
|
||||||
properties.forEach(function (property) {
|
properties.forEach(function (property) {
|
||||||
var proto = {};
|
var proto = {};
|
||||||
proto.get = function () {
|
proto.get = function () {
|
||||||
|
|
||||||
|
// show deprecated warning
|
||||||
|
if(property.newProperty)
|
||||||
|
console.warn('This property is deprecated please use eth.'+ property.newProperty +' instead.');
|
||||||
|
|
||||||
|
|
||||||
return web3.manager.send({
|
return web3.manager.send({
|
||||||
method: property.getter
|
method: property.getter
|
||||||
});
|
});
|
||||||
|
@ -1667,6 +1706,11 @@ var setupProperties = function (obj, properties) {
|
||||||
|
|
||||||
if (property.setter) {
|
if (property.setter) {
|
||||||
proto.set = function (val) {
|
proto.set = function (val) {
|
||||||
|
|
||||||
|
// show deprecated warning
|
||||||
|
if(property.newProperty)
|
||||||
|
console.warn('This property is deprecated please use eth.'+ property.newProperty +' instead.');
|
||||||
|
|
||||||
return web3.manager.send({
|
return web3.manager.send({
|
||||||
method: property.setter,
|
method: property.setter,
|
||||||
params: [val]
|
params: [val]
|
||||||
|
@ -1771,8 +1815,8 @@ var web3 = {
|
||||||
|
|
||||||
/// setups all api methods
|
/// setups all api methods
|
||||||
setupMethods(web3, web3Methods());
|
setupMethods(web3, web3Methods());
|
||||||
setupMethods(web3.eth, eth.methods());
|
setupMethods(web3.eth, eth.methods);
|
||||||
setupProperties(web3.eth, eth.properties());
|
setupProperties(web3.eth, eth.properties);
|
||||||
setupMethods(web3.db, db.methods());
|
setupMethods(web3.db, db.methods());
|
||||||
setupMethods(web3.shh, shh.methods());
|
setupMethods(web3.shh, shh.methods());
|
||||||
setupMethods(ethWatch, watches.eth());
|
setupMethods(ethWatch, watches.eth());
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -13,12 +13,12 @@
|
||||||
var coinbase = web3.eth.coinbase;
|
var coinbase = web3.eth.coinbase;
|
||||||
var originalBalance = 0;
|
var originalBalance = 0;
|
||||||
|
|
||||||
var balance = web3.eth.balanceAt(coinbase);
|
var balance = web3.eth.getBalance(coinbase);
|
||||||
var originalBalance = web3.toDecimal(balance);
|
var originalBalance = web3.toDecimal(balance);
|
||||||
document.getElementById('original').innerText = 'original balance: ' + originalBalance + ' watching...';
|
document.getElementById('original').innerText = 'original balance: ' + originalBalance + ' watching...';
|
||||||
|
|
||||||
web3.eth.watch('pending').changed(function() {
|
web3.eth.watch('pending').changed(function() {
|
||||||
balance = web3.eth.balanceAt(coinbase)
|
balance = web3.eth.getBalance(coinbase)
|
||||||
var currentBalance = web3.toDecimal(balance);
|
var currentBalance = web3.toDecimal(balance);
|
||||||
document.getElementById("current").innerText = 'current: ' + currentBalance;
|
document.getElementById("current").innerText = 'current: ' + currentBalance;
|
||||||
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);
|
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
document.getElementById('source').innerText = source;
|
document.getElementById('source').innerText = source;
|
||||||
|
|
||||||
// create contract
|
// create contract
|
||||||
var address = web3.eth.transact({code: web3.eth.solidity(source)});
|
var address = web3.eth.sendTransaction({data: web3.eth.compile.solidity(source)});
|
||||||
contract = web3.eth.contract(address, desc);
|
contract = web3.eth.contract(address, desc);
|
||||||
document.getElementById('call').style.visibility = 'visible';
|
document.getElementById('call').style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
document.getElementById('source').innerText = source;
|
document.getElementById('source').innerText = source;
|
||||||
|
|
||||||
// create contract
|
// create contract
|
||||||
var address = web3.eth.transact({code: web3.eth.solidity(source)});
|
var address = web3.eth.sendTransaction({data: web3.eth.compile.solidity(source)});
|
||||||
contract = web3.eth.contract(address, desc);
|
contract = web3.eth.contract(address, desc);
|
||||||
document.getElementById('call').style.visibility = 'visible';
|
document.getElementById('call').style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var createContract = function () {
|
var createContract = function () {
|
||||||
address = web3.eth.transact({code: web3.eth.solidity(source)});
|
address = web3.eth.sendTransaction({data: web3.eth.compile.solidity(source)});
|
||||||
contract = web3.eth.contract(address, desc);
|
contract = web3.eth.contract(address, desc);
|
||||||
contract.Incremented({odd: true}).changed(update);
|
contract.Incremented({odd: true}).changed(update);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
document.getElementById('source').innerText = source;
|
document.getElementById('source').innerText = source;
|
||||||
|
|
||||||
// create contract
|
// create contract
|
||||||
var address = web3.eth.transact({code: web3.eth.solidity(source)});
|
var address = web3.eth.sendTransaction({code: web3.eth.solidity(source)});
|
||||||
contract = web3.eth.contract(address, desc);
|
contract = web3.eth.contract(address, desc);
|
||||||
document.getElementById('call').style.visibility = 'visible';
|
document.getElementById('call').style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
|
|
||||||
// transaction does not return any result, cause it's not synchronous and we don't know,
|
// transaction does not return any result, cause it's not synchronous and we don't know,
|
||||||
// when it will be processed
|
// when it will be processed
|
||||||
contract.transact().multiply(param);
|
contract.sendTransaction().multiply(param);
|
||||||
document.getElementById('result').innerText = 'transaction made';
|
document.getElementById('result').innerText = 'transaction made';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,6 @@ web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
|
||||||
var coinbase = web3.eth.coinbase;
|
var coinbase = web3.eth.coinbase;
|
||||||
console.log(coinbase);
|
console.log(coinbase);
|
||||||
|
|
||||||
var balance = web3.eth.balanceAt(coinbase);
|
var balance = web3.eth.getBalance(coinbase);
|
||||||
console.log(balance);
|
console.log(balance);
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ var addFunctionsToContract = function (contract, desc, address) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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.sendTransaction(options);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
112
lib/eth.js
112
lib/eth.js
|
@ -20,53 +20,68 @@
|
||||||
* @date 2015
|
* @date 2015
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// @returns an array of objects describing web3.eth api methods
|
var blockCall = function (args) {
|
||||||
var methods = function () {
|
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber";
|
||||||
var blockCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber";
|
|
||||||
};
|
|
||||||
|
|
||||||
var transactionCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var uncleCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var transactionCountCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_transactionCountByHash' : 'eth_transactionCountByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var uncleCountCall = function (args) {
|
|
||||||
return typeof args[0] === "string" ? 'eth_uncleCountByHash' : 'eth_uncleCountByNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
return [
|
|
||||||
{ name: 'balanceAt', call: 'eth_balanceAt' },
|
|
||||||
{ name: 'stateAt', call: 'eth_stateAt' },
|
|
||||||
{ name: 'storageAt', call: 'eth_storageAt' },
|
|
||||||
{ name: 'countAt', call: 'eth_countAt'},
|
|
||||||
{ name: 'codeAt', call: 'eth_codeAt' },
|
|
||||||
{ name: 'transact', call: 'eth_transact' },
|
|
||||||
{ name: 'call', call: 'eth_call' },
|
|
||||||
{ name: 'block', call: blockCall },
|
|
||||||
{ 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' },
|
|
||||||
{ name: 'logs', call: 'eth_logs' },
|
|
||||||
{ name: 'transactionCount', call: transactionCountCall },
|
|
||||||
{ name: 'uncleCount', call: uncleCountCall }
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var transactionCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
var uncleCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
var transactionCountCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_transactionCountByHash' : 'eth_transactionCountByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
var uncleCountCall = function (args) {
|
||||||
|
return typeof args[0] === "string" ? 'eth_uncleCountByHash' : 'eth_uncleCountByNumber';
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @returns an array of objects describing web3.eth api methods
|
||||||
|
var methods = [
|
||||||
|
{ name: 'getBalance', call: 'eth_balanceAt' },
|
||||||
|
{ name: 'getState', call: 'eth_stateAt' },
|
||||||
|
{ name: 'getStorage', call: 'eth_storageAt' },
|
||||||
|
{ name: 'getTransactionCount', call: 'eth_countAt'},
|
||||||
|
{ name: 'getCode', call: 'eth_codeAt' },
|
||||||
|
{ name: 'sendTransaction', call: 'eth_transact' },
|
||||||
|
{ name: 'call', call: 'eth_call' },
|
||||||
|
{ name: 'getBlock', call: blockCall },
|
||||||
|
{ name: 'getTransaction', call: transactionCall },
|
||||||
|
{ name: 'getUncle', call: uncleCall },
|
||||||
|
{ name: 'getCompilers', call: 'eth_compilers' },
|
||||||
|
{ name: 'flush', call: 'eth_flush' },
|
||||||
|
{ name: 'compile.solidity', call: 'eth_solidity' },
|
||||||
|
{ name: 'compile.lll', call: 'eth_lll' },
|
||||||
|
{ name: 'compile.serpent', call: 'eth_serpent' },
|
||||||
|
{ name: 'logs', call: 'eth_logs' },
|
||||||
|
{ name: 'getBlockTransactionCount', call: transactionCountCall },
|
||||||
|
{ name: 'getBlockUncleCount', call: uncleCountCall },
|
||||||
|
|
||||||
|
// deprecated methods
|
||||||
|
{ name: 'balanceAt', call: 'eth_balanceAt', newMethod: 'getBalance' },
|
||||||
|
{ name: 'stateAt', call: 'eth_stateAt', newMethod: 'getState' },
|
||||||
|
{ name: 'storageAt', call: 'eth_storageAt', newMethod: 'getStorage' },
|
||||||
|
{ name: 'countAt', call: 'eth_countAt', newMethod: 'getTransactionCount' },
|
||||||
|
{ name: 'codeAt', call: 'eth_codeAt', newMethod: 'getCode' },
|
||||||
|
{ name: 'transact', call: 'eth_transact', newMethod: 'sendTransaction' },
|
||||||
|
{ name: 'block', call: blockCall, newMethod: 'getBlock' },
|
||||||
|
{ name: 'transaction', call: transactionCall, newMethod: 'getTransaction' },
|
||||||
|
{ name: 'uncle', call: uncleCall, newMethod: 'getUncle' },
|
||||||
|
{ name: 'compilers', call: 'eth_compilers', newMethod: 'getCompilers' },
|
||||||
|
{ name: 'solidity', call: 'eth_solidity', newMethod: 'compile.solidity' },
|
||||||
|
{ name: 'lll', call: 'eth_lll', newMethod: 'compile.lll' },
|
||||||
|
{ name: 'serpent', call: 'eth_serpent', newMethod: 'compile.serpent' },
|
||||||
|
{ name: 'transactionCount', call: transactionCountCall, newMethod: 'getBlockTransactionCount' },
|
||||||
|
{ name: 'uncleCount', call: uncleCountCall, newMethod: 'getBlockUncleCount' },
|
||||||
|
{ name: 'logs', call: 'eth_logs' }
|
||||||
|
];
|
||||||
|
|
||||||
/// @returns an array of objects describing web3.eth api properties
|
/// @returns an array of objects describing web3.eth api properties
|
||||||
var properties = function () {
|
var properties = [
|
||||||
return [
|
|
||||||
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },
|
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },
|
||||||
{ name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },
|
{ name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },
|
||||||
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },
|
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },
|
||||||
|
@ -74,9 +89,12 @@ var properties = function () {
|
||||||
{ name: 'accounts', getter: 'eth_accounts' },
|
{ name: 'accounts', getter: 'eth_accounts' },
|
||||||
{ name: 'peerCount', getter: 'eth_peerCount' },
|
{ name: 'peerCount', getter: 'eth_peerCount' },
|
||||||
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },
|
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },
|
||||||
{ name: 'number', getter: 'eth_number'}
|
{ name: 'blockNumber', getter: 'eth_number'},
|
||||||
];
|
|
||||||
};
|
// deprecated properties
|
||||||
|
{ name: 'number', call: 'eth_number', newProperty: 'blockNumber'}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
methods: methods,
|
methods: methods,
|
||||||
|
|
47
lib/web3.js
47
lib/web3.js
|
@ -46,14 +46,30 @@ var web3Methods = function () {
|
||||||
/// setups api calls for these methods
|
/// setups api calls for these methods
|
||||||
var setupMethods = function (obj, methods) {
|
var setupMethods = function (obj, methods) {
|
||||||
methods.forEach(function (method) {
|
methods.forEach(function (method) {
|
||||||
obj[method.name] = function () {
|
// allow for object methods 'myObject.method'
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var objectMethods = method.name.split('.'),
|
||||||
var call = typeof method.call === 'function' ? method.call(args) : method.call;
|
callFunction = function () {
|
||||||
return web3.manager.send({
|
var args = Array.prototype.slice.call(arguments);
|
||||||
method: call,
|
var call = typeof method.call === 'function' ? method.call(args) : method.call;
|
||||||
params: args
|
|
||||||
});
|
// show deprecated warning
|
||||||
};
|
if(method.newMethod)
|
||||||
|
console.warn('This method is deprecated please use eth.'+ method.newMethod +'() instead.');
|
||||||
|
|
||||||
|
return web3.manager.send({
|
||||||
|
method: call,
|
||||||
|
params: args
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if(objectMethods.length > 1) {
|
||||||
|
if(!obj[objectMethods[0]])
|
||||||
|
obj[objectMethods[0]] = {};
|
||||||
|
|
||||||
|
obj[objectMethods[0]][objectMethods[1]] = callFunction;
|
||||||
|
} else
|
||||||
|
obj[method.name] = callFunction;
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,6 +79,12 @@ var setupProperties = function (obj, properties) {
|
||||||
properties.forEach(function (property) {
|
properties.forEach(function (property) {
|
||||||
var proto = {};
|
var proto = {};
|
||||||
proto.get = function () {
|
proto.get = function () {
|
||||||
|
|
||||||
|
// show deprecated warning
|
||||||
|
if(property.newProperty)
|
||||||
|
console.warn('This property is deprecated please use eth.'+ property.newProperty +' instead.');
|
||||||
|
|
||||||
|
|
||||||
return web3.manager.send({
|
return web3.manager.send({
|
||||||
method: property.getter
|
method: property.getter
|
||||||
});
|
});
|
||||||
|
@ -70,6 +92,11 @@ var setupProperties = function (obj, properties) {
|
||||||
|
|
||||||
if (property.setter) {
|
if (property.setter) {
|
||||||
proto.set = function (val) {
|
proto.set = function (val) {
|
||||||
|
|
||||||
|
// show deprecated warning
|
||||||
|
if(property.newProperty)
|
||||||
|
console.warn('This property is deprecated please use eth.'+ property.newProperty +' instead.');
|
||||||
|
|
||||||
return web3.manager.send({
|
return web3.manager.send({
|
||||||
method: property.setter,
|
method: property.setter,
|
||||||
params: [val]
|
params: [val]
|
||||||
|
@ -174,8 +201,8 @@ var web3 = {
|
||||||
|
|
||||||
/// setups all api methods
|
/// setups all api methods
|
||||||
setupMethods(web3, web3Methods());
|
setupMethods(web3, web3Methods());
|
||||||
setupMethods(web3.eth, eth.methods());
|
setupMethods(web3.eth, eth.methods);
|
||||||
setupProperties(web3.eth, eth.properties());
|
setupProperties(web3.eth, eth.properties);
|
||||||
setupMethods(web3.db, db.methods());
|
setupMethods(web3.db, db.methods());
|
||||||
setupMethods(web3.shh, shh.methods());
|
setupMethods(web3.shh, shh.methods());
|
||||||
setupMethods(ethWatch, watches.eth());
|
setupMethods(ethWatch, watches.eth());
|
||||||
|
|
Loading…
Reference in New Issue