mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-22 11:08:33 +00:00
Modularize web3.js (#541)
* added sub packages * added lerna monopackage management * check for package is instance * added method, subscription and utils package * moved almost all packages * moved all packages, no umbrella package yet * added extend to packages * made contract pass * made batch tests pass * expose providers * fixed test async * fixed test errors * fixed test event encode decode * fixed test formatter tests * fixed method tests * fixed method utils * fixed some eth methods * fixed some eth methods 2 * bumped version 0.18.3 to republish meteor package * fixed get* tests * fixed subscribe tests * added newBlockHeaders subscription * remove unpublished package from package.json * added sendTransaction test * fixed call test * moved files to done * changed extend * added iban tests * Fixed ALL tests * Fixed lint tests * Fixed contract tests * added method tests * added more method tests to test promiEvents extensively * added confirmation event * improved method confirmation checking
This commit is contained in:
parent
0720bf3293
commit
bbfefb091c
18
.gitignore
vendored
18
.gitignore
vendored
@ -1,21 +1,13 @@
|
|||||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
.DS_Store
|
||||||
#
|
|
||||||
# If you find yourself ignoring temporary files generated by your text editor
|
|
||||||
# or operating system, you probably want to add a global ignore instead:
|
|
||||||
# git config --global core.excludesfile ~/.gitignore_global
|
|
||||||
|
|
||||||
*.swp
|
*.swp
|
||||||
/coverage
|
|
||||||
/tmp
|
|
||||||
*/**/*un~
|
*/**/*un~
|
||||||
*un~
|
*un~
|
||||||
.DS_Store
|
|
||||||
*/**/.DS_Store
|
*/**/.DS_Store
|
||||||
ethereum/ethereum
|
npm-debug.log
|
||||||
ethereal/ethereal
|
.npm/
|
||||||
|
/coverage
|
||||||
|
/tmp
|
||||||
example/js
|
example/js
|
||||||
node_modules
|
node_modules
|
||||||
bower_components
|
bower_components
|
||||||
npm-debug.log
|
|
||||||
/bower
|
/bower
|
||||||
.npm/
|
|
||||||
|
2
.jshintignore
Normal file
2
.jshintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
packages/**/node_modules/
|
@ -5,7 +5,7 @@
|
|||||||
"eqeqeq": true,
|
"eqeqeq": true,
|
||||||
"freeze": true,
|
"freeze": true,
|
||||||
"funcscope": false,
|
"funcscope": false,
|
||||||
"maxcomplexity": 9,
|
"maxcomplexity": 8,
|
||||||
"maxdepth": 3,
|
"maxdepth": 3,
|
||||||
"maxerr": 50,
|
"maxerr": 50,
|
||||||
/*"maxlen": 80*/ /*this should be our goal*/
|
/*"maxlen": 80*/ /*this should be our goal*/
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
example/js
|
|
||||||
node_modules
|
|
||||||
test
|
test
|
||||||
.gitignore
|
.gitignore
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.travis.yml
|
.travis.yml
|
||||||
.npmignore
|
.npmignore
|
||||||
component.json
|
|
||||||
testling.html
|
|
4
dist/web3-light.js
vendored
4
dist/web3-light.js
vendored
@ -2475,7 +2475,11 @@ module.exports = {
|
|||||||
|
|
||||||
},{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":86}],21:[function(require,module,exports){
|
},{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":86}],21:[function(require,module,exports){
|
||||||
module.exports={
|
module.exports={
|
||||||
|
<<<<<<< HEAD
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
|
=======
|
||||||
|
"version": "0.18.3"
|
||||||
|
>>>>>>> develop
|
||||||
}
|
}
|
||||||
|
|
||||||
},{}],22:[function(require,module,exports){
|
},{}],22:[function(require,module,exports){
|
||||||
|
9
dist/web3-light.min.js
vendored
9
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
4
dist/web3.js
vendored
4
dist/web3.js
vendored
@ -2475,7 +2475,11 @@ module.exports = {
|
|||||||
|
|
||||||
},{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":86}],21:[function(require,module,exports){
|
},{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":86}],21:[function(require,module,exports){
|
||||||
module.exports={
|
module.exports={
|
||||||
|
<<<<<<< HEAD
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
|
=======
|
||||||
|
"version": "0.18.3"
|
||||||
|
>>>>>>> develop
|
||||||
}
|
}
|
||||||
|
|
||||||
},{}],22:[function(require,module,exports){
|
},{}],22:[function(require,module,exports){
|
||||||
|
7
dist/web3.js.map
vendored
7
dist/web3.js.map
vendored
File diff suppressed because one or more lines are too long
10
dist/web3.min.js
vendored
10
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -254,6 +254,7 @@ Example
|
|||||||
.on('receipt', function(receipt){
|
.on('receipt', function(receipt){
|
||||||
// same as when the promise gets resolved, see below
|
// same as when the promise gets resolved, see below
|
||||||
})
|
})
|
||||||
|
.on('confirmation', function(confirmationNumber, receipt){ ... })
|
||||||
.then(function(receipt){
|
.then(function(receipt){
|
||||||
console.log(myContract.options.address) // gives the new contract address
|
console.log(myContract.options.address) // gives the new contract address
|
||||||
});
|
});
|
||||||
@ -351,7 +352,7 @@ Example
|
|||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
// or sending a transaction to a method
|
// or sending and using the events
|
||||||
|
|
||||||
myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'})
|
myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'})
|
||||||
.on('transactionHash', function(hash){
|
.on('transactionHash', function(hash){
|
||||||
@ -360,6 +361,7 @@ Example
|
|||||||
.on('receipt', function(receipt){
|
.on('receipt', function(receipt){
|
||||||
...
|
...
|
||||||
})
|
})
|
||||||
|
.on('confirmation', function(confirmationNumber, receipt){ ... })
|
||||||
.on('error', console.error);
|
.on('error', console.error);
|
||||||
|
|
||||||
|
|
||||||
@ -435,7 +437,7 @@ Parameters
|
|||||||
* ``String`` - **from**: The address the transaction should be send from.
|
* ``String`` - **from**: The address the transaction should be send from.
|
||||||
* ``String`` - **gasPrice** (optional): The gas price in wei to use for this transaction.
|
* ``String`` - **gasPrice** (optional): The gas price in wei to use for this transaction.
|
||||||
* ``Number`` - **gas** (optional): The maximum gas provided for this transaction (gas limit).
|
* ``Number`` - **gas** (optional): The maximum gas provided for this transaction (gas limit).
|
||||||
2. ``Function`` - **callback** (optional): This callback will be fired first with the "transactionHash" and later for the "receipt" as second argument, or with an error object as the first argument.
|
2. ``Function`` - **callback** (optional): This callback will be fired first with the "transactionHash", or with an error object as the first argument.
|
||||||
|
|
||||||
-------
|
-------
|
||||||
Returns
|
Returns
|
||||||
@ -444,7 +446,8 @@ Returns
|
|||||||
``PromiEvent``: A promise combined event emitter. Will be resolved when the transaction *receipt* is available. Additionally the following events are available:
|
``PromiEvent``: A promise combined event emitter. Will be resolved when the transaction *receipt* is available. Additionally the following events are available:
|
||||||
|
|
||||||
- ``"transactionHash"`` returns ``String``: is fired right after the transaction is send and a transaction hash is available.
|
- ``"transactionHash"`` returns ``String``: is fired right after the transaction is send and a transaction hash is available.
|
||||||
- ``"receipt"`` returns ``String``: is fired when the transaction receipt with the contract address is available.
|
- ``"receipt"`` returns ``Object``: is fired when the transaction receipt is available.
|
||||||
|
- ``"confirmation"`` returns ``Number``, ``Object``: is fired for every confirmation up to the 12th confirmation. Receives the confirmation number as the first and the receipt as the second argument.
|
||||||
- ``"error"`` returns ``Error``: is fired if an error occurs during deployment.
|
- ``"error"`` returns ``Error``: is fired if an error occurs during deployment.
|
||||||
|
|
||||||
|
|
||||||
@ -474,6 +477,7 @@ Example
|
|||||||
.on('receipt', function(receipt){
|
.on('receipt', function(receipt){
|
||||||
...
|
...
|
||||||
})
|
})
|
||||||
|
.on('confirmation', function(confirmationNumber, receipt){ ... })
|
||||||
.on('error', console.error);
|
.on('error', console.error);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var version = require('./lib/version.json');
|
var version = require('./lerna.json');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
var del = require('del');
|
var del = require('del');
|
||||||
|
8
index.js
8
index.js
@ -1,8 +0,0 @@
|
|||||||
var Web3 = require('./lib/web3');
|
|
||||||
|
|
||||||
// dont override global variable
|
|
||||||
if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') {
|
|
||||||
window.Web3 = Web3;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Web3;
|
|
7
lerna.json
Normal file
7
lerna.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lerna": "2.0.0-beta.32",
|
||||||
|
"packages": [
|
||||||
|
"packages/*"
|
||||||
|
]
|
||||||
|
}
|
@ -1,254 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_owner",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "name",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "o_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "owner",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "content",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "addr",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "reserve",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "subRegistrar",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_newOwner",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "transfer",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_registrar",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "setSubRegistrar",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [],
|
|
||||||
"name": "Registrar",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_a",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_primary",
|
|
||||||
"type": "bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "setAddress",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_content",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "setContent",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "disown",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "_winner",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "AuctionEnded",
|
|
||||||
"type": "event"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "_bidder",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "_value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "NewBid",
|
|
||||||
"type": "event"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "Changed",
|
|
||||||
"type": "event"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "addr",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "PrimaryChanged",
|
|
||||||
"type": "event"
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,108 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "owner",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_refund",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "disown",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "addr",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "reserve",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_newOwner",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "transfer",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "_name",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "_a",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "setAddr",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "name",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "Changed",
|
|
||||||
"type": "event"
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,147 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "from",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "to",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "transfer",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "from",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "to",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "indirectId",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "icapTransfer",
|
|
||||||
"outputs": [],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"constant": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "to",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "deposit",
|
|
||||||
"outputs": [],
|
|
||||||
"payable": true,
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "from",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "AnonymousDeposit",
|
|
||||||
"type": "event"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "from",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "to",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "Deposit",
|
|
||||||
"type": "event"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "from",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "to",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "Transfer",
|
|
||||||
"type": "event"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous": false,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "from",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": true,
|
|
||||||
"name": "to",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "indirectId",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"indexed": false,
|
|
||||||
"name": "value",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "IcapTransfer",
|
|
||||||
"type": "event"
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,4 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = BigNumber; // jshint ignore:line
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/** @file config.js
|
|
||||||
* @authors:
|
|
||||||
* Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @date 2015
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utils
|
|
||||||
*
|
|
||||||
* @module utils
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility functions
|
|
||||||
*
|
|
||||||
* @class [utils] config
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/// required to define ETH_BIGNUMBER_ROUNDING_MODE
|
|
||||||
var BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
var ETH_UNITS = [
|
|
||||||
'wei',
|
|
||||||
'kwei',
|
|
||||||
'Mwei',
|
|
||||||
'Gwei',
|
|
||||||
'szabo',
|
|
||||||
'finney',
|
|
||||||
'femtoether',
|
|
||||||
'picoether',
|
|
||||||
'nanoether',
|
|
||||||
'microether',
|
|
||||||
'milliether',
|
|
||||||
'nano',
|
|
||||||
'micro',
|
|
||||||
'milli',
|
|
||||||
'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 },
|
|
||||||
ETH_POLLING_TIMEOUT: 1000/2,
|
|
||||||
defaultBlock: 'latest',
|
|
||||||
defaultAccount: undefined
|
|
||||||
};
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0"
|
|
||||||
}
|
|
153
lib/web3.js
153
lib/web3.js
@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @file web3.js
|
|
||||||
* @authors:
|
|
||||||
* Jeffrey Wilcke <jeff@ethdev.com>
|
|
||||||
* Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* Marian Oancea <marian@ethdev.com>
|
|
||||||
* Fabian Vogelsteller <fabian@ethdev.com>
|
|
||||||
* Gav Wood <g@ethdev.com>
|
|
||||||
* @date 2016
|
|
||||||
*/
|
|
||||||
|
|
||||||
var RequestManager = require('./web3/requestmanager');
|
|
||||||
var Iban = require('./web3/iban');
|
|
||||||
var Eth = require('./web3/methods/eth');
|
|
||||||
var DB = require('./web3/methods/db');
|
|
||||||
var Shh = require('./web3/methods/shh');
|
|
||||||
var Net = require('./web3/methods/net');
|
|
||||||
var Personal = require('./web3/methods/personal');
|
|
||||||
var Swarm = require('./web3/methods/swarm');
|
|
||||||
var Settings = require('./web3/settings');
|
|
||||||
var version = require('./version.json');
|
|
||||||
var utils = require('./utils/utils');
|
|
||||||
var sha3 = require('./utils/sha3');
|
|
||||||
var extend = require('./web3/extend');
|
|
||||||
var Batch = require('./web3/batch');
|
|
||||||
var Property = require('./web3/property');
|
|
||||||
var HttpProvider = require('./web3/providers/httpprovider');
|
|
||||||
var IpcProvider = require('./web3/providers/ipcprovider');
|
|
||||||
var WebsocketProvider = require('./web3/providers/websocketprovider');
|
|
||||||
var BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Web3 (provider) {
|
|
||||||
this._requestManager = new RequestManager(provider);
|
|
||||||
this.currentProvider = provider;
|
|
||||||
this.eth = new Eth(this);
|
|
||||||
this.db = new DB(this);
|
|
||||||
this.shh = new Shh(this);
|
|
||||||
this.net = new Net(this);
|
|
||||||
this.personal = new Personal(this);
|
|
||||||
this.bzz = new Swarm(this);
|
|
||||||
this.settings = new Settings();
|
|
||||||
this.version = {
|
|
||||||
api: version.version
|
|
||||||
};
|
|
||||||
this.providers = {
|
|
||||||
HttpProvider: HttpProvider,
|
|
||||||
IpcProvider: IpcProvider,
|
|
||||||
WebsocketProvider: WebsocketProvider
|
|
||||||
};
|
|
||||||
this._extend = extend(this);
|
|
||||||
this._extend({
|
|
||||||
properties: properties()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// expose providers on the class
|
|
||||||
Web3.providers = {
|
|
||||||
HttpProvider: HttpProvider,
|
|
||||||
IpcProvider: IpcProvider,
|
|
||||||
WebsocketProvider: WebsocketProvider
|
|
||||||
};
|
|
||||||
|
|
||||||
Web3.prototype.setProvider = function (provider) {
|
|
||||||
this._requestManager.setProvider(provider);
|
|
||||||
this.currentProvider = provider;
|
|
||||||
};
|
|
||||||
|
|
||||||
Web3.prototype.reset = function (keepIsSyncing) {
|
|
||||||
this._requestManager.reset(keepIsSyncing);
|
|
||||||
this.settings = new Settings();
|
|
||||||
};
|
|
||||||
|
|
||||||
Web3.prototype.BigNumber = BigNumber;
|
|
||||||
Web3.prototype.toHex = utils.toHex;
|
|
||||||
Web3.prototype.toAscii = utils.toAscii;
|
|
||||||
Web3.prototype.toUtf8 = utils.toUtf8;
|
|
||||||
Web3.prototype.fromAscii = utils.fromAscii;
|
|
||||||
Web3.prototype.fromUtf8 = utils.fromUtf8;
|
|
||||||
Web3.prototype.toDecimal = utils.toDecimal;
|
|
||||||
Web3.prototype.fromDecimal = utils.fromDecimal;
|
|
||||||
Web3.prototype.toBigNumber = utils.toBigNumber;
|
|
||||||
Web3.prototype.toWei = utils.toWei;
|
|
||||||
Web3.prototype.fromWei = utils.fromWei;
|
|
||||||
Web3.prototype.isAddress = utils.isAddress;
|
|
||||||
Web3.prototype.isChecksumAddress = utils.isChecksumAddress;
|
|
||||||
Web3.prototype.toChecksumAddress = utils.toChecksumAddress;
|
|
||||||
Web3.prototype.isIBAN = utils.isIBAN;
|
|
||||||
|
|
||||||
|
|
||||||
Web3.prototype.sha3 = function(string, options) {
|
|
||||||
return '0x' + sha3(string, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms direct icap to address
|
|
||||||
*/
|
|
||||||
Web3.prototype.fromICAP = function (icap) {
|
|
||||||
var iban = new Iban(icap);
|
|
||||||
return iban.address();
|
|
||||||
};
|
|
||||||
|
|
||||||
var properties = function () {
|
|
||||||
return [
|
|
||||||
new Property({
|
|
||||||
name: 'version.node',
|
|
||||||
getter: 'web3_clientVersion'
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'version.network',
|
|
||||||
getter: 'net_version',
|
|
||||||
inputFormatter: utils.toDecimal
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'version.ethereum',
|
|
||||||
getter: 'eth_protocolVersion',
|
|
||||||
inputFormatter: utils.toDecimal
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'version.whisper',
|
|
||||||
getter: 'shh_version',
|
|
||||||
inputFormatter: utils.toDecimal
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
Web3.prototype.isConnected = function(){
|
|
||||||
return (this.currentProvider && this.currentProvider.isConnected());
|
|
||||||
};
|
|
||||||
|
|
||||||
Web3.prototype.createBatch = function () {
|
|
||||||
return new Batch(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Web3;
|
|
||||||
|
|
@ -1,315 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @file event.js
|
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @author Fabian Vogelsteller <fabian@frozeman.de>
|
|
||||||
* @date 2016
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('../utils/utils');
|
|
||||||
var coder = require('../solidity/coder');
|
|
||||||
var formatters = require('./formatters');
|
|
||||||
var sha3 = require('../utils/sha3');
|
|
||||||
var Subscription = require('./subscription');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This prototype should be used to create event filters
|
|
||||||
*/
|
|
||||||
var ContractEvent = function (requestManager, json, address, allEvents) {
|
|
||||||
this._requestManager = requestManager;
|
|
||||||
this._address = address;
|
|
||||||
this._json = json;
|
|
||||||
this._name = json.inputs ? utils.transformToFullName(json) : null;
|
|
||||||
this._params = json.inputs;
|
|
||||||
this._anonymous = json.anonymous;
|
|
||||||
this._allEvents = !!allEvents;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to get filtered param types
|
|
||||||
*
|
|
||||||
* @method types
|
|
||||||
* @param {Bool} decide if returned typed should be indexed
|
|
||||||
* @param {Object} params the parameters of the event
|
|
||||||
* @return {Array} array of types
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.types = function (indexed, params) {
|
|
||||||
return params.filter(function (i) {
|
|
||||||
return i.indexed === indexed;
|
|
||||||
}).map(function (i) {
|
|
||||||
return i.type;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to get event display name
|
|
||||||
*
|
|
||||||
* @method displayName
|
|
||||||
* @param {String} name (optional) the events name
|
|
||||||
* @return {String} event display name
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.displayName = function (name) {
|
|
||||||
return utils.extractDisplayName(name || this._name);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to get event type name
|
|
||||||
*
|
|
||||||
* @method typeName
|
|
||||||
* @return {String} event type name
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.typeName = function () {
|
|
||||||
return utils.extractTypeName(this._name);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to get event signature
|
|
||||||
*
|
|
||||||
* @method signature
|
|
||||||
* @return {String} event signature
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.signature = function () {
|
|
||||||
return sha3(this._name);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to encode indexed params and options to one final object
|
|
||||||
*
|
|
||||||
* @method encode
|
|
||||||
* @param {Object} options
|
|
||||||
* @return {Object} everything combined together and encoded
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.encode = function (options) {
|
|
||||||
options = options || {};
|
|
||||||
var indexed = options.filter || {},
|
|
||||||
result = {};
|
|
||||||
|
|
||||||
|
|
||||||
['fromBlock', 'toBlock'].filter(function (f) {
|
|
||||||
return options[f] !== undefined;
|
|
||||||
}).forEach(function (f) {
|
|
||||||
result[f] = formatters.inputBlockNumberFormatter(options[f]);
|
|
||||||
});
|
|
||||||
|
|
||||||
result.topics = [];
|
|
||||||
|
|
||||||
// single events
|
|
||||||
if(!this._allEvents) {
|
|
||||||
|
|
||||||
if (!this._anonymous) {
|
|
||||||
result.topics.push('0x' + this.signature());
|
|
||||||
}
|
|
||||||
|
|
||||||
var indexedTopics = this._params.filter(function (i) {
|
|
||||||
return i.indexed === true;
|
|
||||||
}).map(function (i) {
|
|
||||||
var value = indexed[i.name];
|
|
||||||
if (value === undefined || value === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (utils.isArray(value)) {
|
|
||||||
return value.map(function (v) {
|
|
||||||
return '0x' + coder.encodeParam(i.type, v);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return '0x' + coder.encodeParam(i.type, value);
|
|
||||||
});
|
|
||||||
|
|
||||||
result.topics = result.topics.concat(indexedTopics);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.address = this._address;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to decode indexed params and options
|
|
||||||
*
|
|
||||||
* @method decode
|
|
||||||
* @param {Object} data
|
|
||||||
* @return {Object} result object with decoded indexed && not indexed params
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.decode = function (data) {
|
|
||||||
var name = null,
|
|
||||||
params = null,
|
|
||||||
anonymous = null;
|
|
||||||
data.data = data.data || '';
|
|
||||||
data.topics = data.topics || [];
|
|
||||||
|
|
||||||
// all events
|
|
||||||
if(this._allEvents) {
|
|
||||||
|
|
||||||
var eventTopic = data.topics[0].slice(2);
|
|
||||||
var match = this._json.filter(function (j) {
|
|
||||||
return eventTopic === sha3(utils.transformToFullName(j));
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (!match) { // cannot find matching event?
|
|
||||||
console.warn('Can\'t find event for log');
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = utils.transformToFullName(match);
|
|
||||||
params = match.inputs;
|
|
||||||
anonymous = match.anonymous;
|
|
||||||
|
|
||||||
// single event
|
|
||||||
} else {
|
|
||||||
name = this._name;
|
|
||||||
params = this._params;
|
|
||||||
anonymous = this._anonymous;
|
|
||||||
}
|
|
||||||
|
|
||||||
var argTopics = anonymous ? data.topics : data.topics.slice(1);
|
|
||||||
var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
|
|
||||||
var indexedParams = coder.decodeParams(this.types(true, params), indexedData);
|
|
||||||
|
|
||||||
var notIndexedData = data.data.slice(2);
|
|
||||||
var notIndexedParams = coder.decodeParams(this.types(false, params), notIndexedData);
|
|
||||||
|
|
||||||
var result = formatters.outputLogFormatter(data);
|
|
||||||
result.event = this.displayName(name);
|
|
||||||
result.address = data.address;
|
|
||||||
|
|
||||||
result.returnValues = params.reduce(function (acc, current) {
|
|
||||||
acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift();
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
delete result.data;
|
|
||||||
delete result.topics;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the arguments of the function call
|
|
||||||
*
|
|
||||||
* @method getArgs
|
|
||||||
* @param {Object} options
|
|
||||||
* @param {Function} callback
|
|
||||||
* @return {Object} filter object
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.getArgs = function (options, callback) {
|
|
||||||
if (utils.isFunction(arguments[arguments.length - 1])) {
|
|
||||||
callback = arguments[arguments.length - 1];
|
|
||||||
|
|
||||||
if(arguments.length === 1) {
|
|
||||||
options = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: this.encode(options),
|
|
||||||
formatter: this.decode.bind(this),
|
|
||||||
callback: callback
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to create new filter object from event
|
|
||||||
*
|
|
||||||
* @method execute
|
|
||||||
* @param {Object} options
|
|
||||||
* @param {Function} callback
|
|
||||||
* @return {Object} filter object
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.execute = function () {
|
|
||||||
|
|
||||||
var args = this.getArgs.apply(this, arguments);
|
|
||||||
var subscription = new Subscription({
|
|
||||||
subscription: {
|
|
||||||
params: 1,
|
|
||||||
inputFormatter: [formatters.inputLogFormatter],
|
|
||||||
outputFormatter: args.formatter
|
|
||||||
},
|
|
||||||
subscribeMethod: 'eth_subscribe',
|
|
||||||
unsubscribeMethod: 'eth_unsubscribe',
|
|
||||||
requestManager: this._requestManager
|
|
||||||
});
|
|
||||||
|
|
||||||
return subscription.subscribe.apply(subscription, ['logs', args.options, args.callback]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: put indexed args into the options object
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get past logs for this event
|
|
||||||
*
|
|
||||||
* @method getPastEvents
|
|
||||||
* @param {Object} options
|
|
||||||
* @param {Function} callback
|
|
||||||
* @param {Contract}
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.getPastEvents = function(){
|
|
||||||
|
|
||||||
var args = this.getArgs.apply(this, arguments);
|
|
||||||
|
|
||||||
// TODO remove send sync and return promise
|
|
||||||
|
|
||||||
if (utils.isFunction(args.callback)) {
|
|
||||||
return this._requestManager.send({
|
|
||||||
method: 'eth_getLogs',
|
|
||||||
params: [args.options]
|
|
||||||
}, function(error, logs){
|
|
||||||
if(!error) {
|
|
||||||
args.callback(null, logs.map(args.formatter));
|
|
||||||
} else {
|
|
||||||
args.callback(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._requestManager.sendSync({
|
|
||||||
method: 'eth_getLogs',
|
|
||||||
params: [args.options]
|
|
||||||
}).map(args.formatter);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to attach event to contract object
|
|
||||||
*
|
|
||||||
* @method attachToContract
|
|
||||||
* @param {Contract}
|
|
||||||
*/
|
|
||||||
ContractEvent.prototype.attachToContract = function (contract) {
|
|
||||||
var execute = this.execute.bind(this);
|
|
||||||
|
|
||||||
// attach past logs
|
|
||||||
execute.getPastEvents = this.getPastEvents.bind(this);
|
|
||||||
|
|
||||||
// all events
|
|
||||||
if(this._allEvents) {
|
|
||||||
contract.allEvents = execute;
|
|
||||||
|
|
||||||
// single event
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var displayName = this.displayName();
|
|
||||||
if (!contract[displayName]) {
|
|
||||||
contract[displayName] = execute;
|
|
||||||
}
|
|
||||||
contract[displayName][this.typeName()] = this.execute.bind(this, contract);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = ContractEvent;
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
var formatters = require('./formatters');
|
|
||||||
var utils = require('./../utils/utils');
|
|
||||||
var Method = require('./method');
|
|
||||||
var Property = require('./property');
|
|
||||||
|
|
||||||
// TODO: refactor, so the input params are not altered.
|
|
||||||
// it's necessary to make same 'extension' work with multiple providers
|
|
||||||
var extend = function (web3) {
|
|
||||||
/* jshint maxcomplexity:5 */
|
|
||||||
var ex = function (extension) {
|
|
||||||
|
|
||||||
var extendedObject;
|
|
||||||
if (extension.property) {
|
|
||||||
if (!web3[extension.property]) {
|
|
||||||
web3[extension.property] = {};
|
|
||||||
}
|
|
||||||
extendedObject = web3[extension.property];
|
|
||||||
} else {
|
|
||||||
extendedObject = web3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extension.methods) {
|
|
||||||
extension.methods.forEach(function (method) {
|
|
||||||
method.attachToObject(extendedObject);
|
|
||||||
method.setRequestManager(web3._requestManager);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extension.properties) {
|
|
||||||
extension.properties.forEach(function (property) {
|
|
||||||
property.attachToObject(extendedObject);
|
|
||||||
property.setRequestManager(web3._requestManager);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ex.formatters = formatters;
|
|
||||||
ex.utils = utils;
|
|
||||||
ex.Method = Method;
|
|
||||||
ex.Property = Property;
|
|
||||||
|
|
||||||
return ex;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = extend;
|
|
||||||
|
|
@ -1,235 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.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>
|
|
||||||
* Fabian Vogelsteller <fabian@ethdev.com>
|
|
||||||
* Gav Wood <g@ethdev.com>
|
|
||||||
* @date 2014
|
|
||||||
*/
|
|
||||||
|
|
||||||
var formatters = require('./formatters');
|
|
||||||
var utils = require('../utils/utils');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a given topic to a hex string, but also allows null values.
|
|
||||||
*
|
|
||||||
* @param {Mixed} value
|
|
||||||
* @return {String}
|
|
||||||
*/
|
|
||||||
var toTopic = function(value){
|
|
||||||
|
|
||||||
if(value === null || typeof value === 'undefined')
|
|
||||||
return null;
|
|
||||||
|
|
||||||
value = String(value);
|
|
||||||
|
|
||||||
if(value.indexOf('0x') === 0)
|
|
||||||
return value;
|
|
||||||
else
|
|
||||||
return utils.fromUtf8(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
/// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
|
|
||||||
/// @param should be string or object
|
|
||||||
/// @returns options string or object
|
|
||||||
var getOptions = function (options) {
|
|
||||||
|
|
||||||
if (utils.isString(options)) {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
// make sure topics, get converted to hex
|
|
||||||
options.topics = options.topics || [];
|
|
||||||
options.topics = options.topics.map(function(topic){
|
|
||||||
return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic);
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
topics: options.topics,
|
|
||||||
from: options.from,
|
|
||||||
to: options.to,
|
|
||||||
address: options.address,
|
|
||||||
fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
|
|
||||||
toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Adds the callback and sets up the methods, to iterate over the results.
|
|
||||||
|
|
||||||
@method getLogsAtStart
|
|
||||||
@param {Object} self
|
|
||||||
@param {funciton}
|
|
||||||
*/
|
|
||||||
var getLogsAtStart = function(self, callback){
|
|
||||||
// call getFilterLogs for the first watch callback start
|
|
||||||
if (!utils.isString(self.options)) {
|
|
||||||
self.get(function (err, messages) {
|
|
||||||
// don't send all the responses to all the watches again... just to self one
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(utils.isArray(messages)) {
|
|
||||||
messages.forEach(function (message) {
|
|
||||||
callback(null, message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Adds the callback and sets up the methods, to iterate over the results.
|
|
||||||
|
|
||||||
@method pollFilter
|
|
||||||
@param {Object} self
|
|
||||||
*/
|
|
||||||
var pollFilter = function(self) {
|
|
||||||
|
|
||||||
var onMessage = function (error, messages) {
|
|
||||||
if (error) {
|
|
||||||
return self.callbacks.forEach(function (callback) {
|
|
||||||
callback(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(utils.isArray(messages)) {
|
|
||||||
messages.forEach(function (message) {
|
|
||||||
message = self.formatter ? self.formatter(message) : message;
|
|
||||||
self.callbacks.forEach(function (callback) {
|
|
||||||
callback(null, message);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
self.requestManager.startPolling({
|
|
||||||
method: self.implementation.poll.call,
|
|
||||||
params: [self.filterId],
|
|
||||||
}, self.filterId, onMessage, self.stopWatching.bind(self));
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var Filter = function (requestManager, options, methods, formatter, callback, filterCreationErrorCallback) {
|
|
||||||
var self = this;
|
|
||||||
var implementation = {};
|
|
||||||
methods.forEach(function (method) {
|
|
||||||
method.setRequestManager(requestManager);
|
|
||||||
method.attachToObject(implementation);
|
|
||||||
});
|
|
||||||
this.requestManager = requestManager;
|
|
||||||
this.options = getOptions(options);
|
|
||||||
this.implementation = implementation;
|
|
||||||
this.filterId = null;
|
|
||||||
this.callbacks = [];
|
|
||||||
this.getLogsCallbacks = [];
|
|
||||||
this.pollFilters = [];
|
|
||||||
this.formatter = formatter;
|
|
||||||
this.implementation.newFilter(this.options, function(error, id){
|
|
||||||
if(error) {
|
|
||||||
self.callbacks.forEach(function(cb){
|
|
||||||
cb(error);
|
|
||||||
});
|
|
||||||
filterCreationErrorCallback(error);
|
|
||||||
} else {
|
|
||||||
self.filterId = id;
|
|
||||||
|
|
||||||
// check if there are get pending callbacks as a consequence
|
|
||||||
// of calling get() with filterId unassigned.
|
|
||||||
self.getLogsCallbacks.forEach(function (cb){
|
|
||||||
self.get(cb);
|
|
||||||
});
|
|
||||||
self.getLogsCallbacks = [];
|
|
||||||
|
|
||||||
// get filter logs for the already existing watch calls
|
|
||||||
self.callbacks.forEach(function(cb){
|
|
||||||
getLogsAtStart(self, cb);
|
|
||||||
});
|
|
||||||
if(self.callbacks.length > 0)
|
|
||||||
pollFilter(self);
|
|
||||||
|
|
||||||
// start to watch immediately
|
|
||||||
if(typeof callback === 'function') {
|
|
||||||
return self.watch(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
Filter.prototype.watch = function (callback) {
|
|
||||||
this.callbacks.push(callback);
|
|
||||||
|
|
||||||
if(this.filterId) {
|
|
||||||
getLogsAtStart(this, callback);
|
|
||||||
pollFilter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
Filter.prototype.stopWatching = function (callback) {
|
|
||||||
this.requestManager.stopPolling(this.filterId);
|
|
||||||
this.callbacks = [];
|
|
||||||
// remove filter async
|
|
||||||
if (callback) {
|
|
||||||
this.implementation.uninstallFilter(this.filterId, callback);
|
|
||||||
} else {
|
|
||||||
return this.implementation.uninstallFilter(this.filterId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Filter.prototype.get = function (callback) {
|
|
||||||
var self = this;
|
|
||||||
if (utils.isFunction(callback)) {
|
|
||||||
if (this.filterId === null) {
|
|
||||||
// If filterId is not set yet, call it back
|
|
||||||
// when newFilter() assigns it.
|
|
||||||
this.getLogsCallbacks.push(callback);
|
|
||||||
} else {
|
|
||||||
this.implementation.getLogs(this.filterId, function(err, res){
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
} else {
|
|
||||||
callback(null, res.map(function (log) {
|
|
||||||
return self.formatter ? self.formatter(log) : log;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.filterId === null) {
|
|
||||||
throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
|
|
||||||
}
|
|
||||||
var logs = this.implementation.getLogs(this.filterId);
|
|
||||||
return logs.map(function (log) {
|
|
||||||
return self.formatter ? self.formatter(log) : log;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Filter;
|
|
||||||
|
|
@ -1,199 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @file method.js
|
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @date 2015
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('../utils/utils');
|
|
||||||
var errors = require('./errors');
|
|
||||||
var Promise = require("bluebird");
|
|
||||||
// var eventifiedPromise = require('./eventifiedPromise.js');
|
|
||||||
|
|
||||||
var Method = function (options) {
|
|
||||||
this.name = options.name;
|
|
||||||
this.call = options.call;
|
|
||||||
this.params = options.params || 0;
|
|
||||||
this.inputFormatter = options.inputFormatter;
|
|
||||||
this.outputFormatter = options.outputFormatter;
|
|
||||||
// this.parent = parent;
|
|
||||||
this.requestManager = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
Method.prototype.setRequestManager = function (rm) {
|
|
||||||
this.requestManager = rm;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to determine name of the jsonrpc method based on arguments
|
|
||||||
*
|
|
||||||
* @method getCall
|
|
||||||
* @param {Array} arguments
|
|
||||||
* @return {String} name of jsonrpc method
|
|
||||||
*/
|
|
||||||
Method.prototype.getCall = function (args) {
|
|
||||||
return utils.isFunction(this.call) ? this.call(args) : this.call;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to extract callback from array of arguments. Modifies input param
|
|
||||||
*
|
|
||||||
* @method extractCallback
|
|
||||||
* @param {Array} arguments
|
|
||||||
* @return {Function|Null} callback, if exists
|
|
||||||
*/
|
|
||||||
Method.prototype.extractCallback = function (args) {
|
|
||||||
if (utils.isFunction(args[args.length - 1])) {
|
|
||||||
return args.pop(); // modify the args array!
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to check if the number of arguments is correct
|
|
||||||
*
|
|
||||||
* @method validateArgs
|
|
||||||
* @param {Array} arguments
|
|
||||||
* @throws {Error} if it is not
|
|
||||||
*/
|
|
||||||
Method.prototype.validateArgs = function (args) {
|
|
||||||
if (args.length !== this.params) {
|
|
||||||
throw errors.InvalidNumberOfParams();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to format input args of method
|
|
||||||
*
|
|
||||||
* @method formatInput
|
|
||||||
* @param {Array}
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
Method.prototype.formatInput = function (args) {
|
|
||||||
if (!this.inputFormatter) {
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.inputFormatter.map(function (formatter, index) {
|
|
||||||
return formatter ? formatter(args[index]) : args[index];
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to format output(result) of method
|
|
||||||
*
|
|
||||||
* @method formatOutput
|
|
||||||
* @param {Object}
|
|
||||||
* @return {Object}
|
|
||||||
*/
|
|
||||||
Method.prototype.formatOutput = function (result) {
|
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
if(utils.isArray(result)) {
|
|
||||||
return result.map(function(res){
|
|
||||||
return _this.outputFormatter && res ? _this.outputFormatter(res) : res;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return this.outputFormatter && result ? this.outputFormatter(result) : result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should create payload from given input args
|
|
||||||
*
|
|
||||||
* @method toPayload
|
|
||||||
* @param {Array} args
|
|
||||||
* @return {Object}
|
|
||||||
*/
|
|
||||||
Method.prototype.toPayload = function (args) {
|
|
||||||
var call = this.getCall(args);
|
|
||||||
var callback = this.extractCallback(args);
|
|
||||||
var params = this.formatInput(args);
|
|
||||||
this.validateArgs(params);
|
|
||||||
|
|
||||||
return {
|
|
||||||
method: call,
|
|
||||||
params: params,
|
|
||||||
callback: callback
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Method.prototype.attachToObject = function (obj) {
|
|
||||||
var func = this.buildCall();
|
|
||||||
func.call = this.call; // TODO!!! that's ugly. filter.js uses it
|
|
||||||
var name = this.name.split('.');
|
|
||||||
if (name.length > 1) {
|
|
||||||
obj[name[0]] = obj[name[0]] || {};
|
|
||||||
obj[name[0]][name[1]] = func;
|
|
||||||
} else {
|
|
||||||
obj[name[0]] = func;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Method.prototype.buildCall = function() {
|
|
||||||
var method = this;
|
|
||||||
var send = function () {
|
|
||||||
var resolve, reject,
|
|
||||||
promise = new Promise(function() {
|
|
||||||
resolve = arguments[0];
|
|
||||||
reject = arguments[1];
|
|
||||||
}),//eventifiedPromise(),
|
|
||||||
payload = method.toPayload(Array.prototype.slice.call(arguments));
|
|
||||||
|
|
||||||
|
|
||||||
method.requestManager.send(payload, function (err, result) {
|
|
||||||
result = method.formatOutput(result);
|
|
||||||
|
|
||||||
// TODO? if afterProcess is available
|
|
||||||
// if(method.afterProcessor)
|
|
||||||
// method.afterProcessor(defer, err, result);
|
|
||||||
|
|
||||||
// TODO send transaction uses PromiEvent
|
|
||||||
|
|
||||||
if(!err) {
|
|
||||||
if(payload.callback) {
|
|
||||||
payload.callback(null, result);
|
|
||||||
}
|
|
||||||
// defer.promise.emit('data', result);
|
|
||||||
resolve(result);
|
|
||||||
//defer.promise.removeAllListeners();
|
|
||||||
} else {
|
|
||||||
return utils._fireError(err, null, reject, payload.callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
send.request = this.request.bind(this);
|
|
||||||
return send;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to create pure JSONRPC request which can be used in batch request
|
|
||||||
*
|
|
||||||
* @method request
|
|
||||||
* @param {...} params
|
|
||||||
* @return {Object} jsonrpc request
|
|
||||||
*/
|
|
||||||
Method.prototype.request = function () {
|
|
||||||
var payload = this.toPayload(Array.prototype.slice.call(arguments));
|
|
||||||
payload.format = this.formatOutput.bind(this);
|
|
||||||
return payload;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Method;
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/** @file db.js
|
|
||||||
* @authors:
|
|
||||||
* Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @date 2015
|
|
||||||
*/
|
|
||||||
|
|
||||||
var Method = require('../method');
|
|
||||||
|
|
||||||
var DB = function (web3) {
|
|
||||||
this._requestManager = web3._requestManager;
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
methods().forEach(function(method) {
|
|
||||||
method.attachToObject(self);
|
|
||||||
method.setRequestManager(web3._requestManager);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var methods = function () {
|
|
||||||
var putString = new Method({
|
|
||||||
name: 'putString',
|
|
||||||
call: 'db_putString',
|
|
||||||
params: 3
|
|
||||||
});
|
|
||||||
|
|
||||||
var getString = new Method({
|
|
||||||
name: 'getString',
|
|
||||||
call: 'db_getString',
|
|
||||||
params: 2
|
|
||||||
});
|
|
||||||
|
|
||||||
var putHex = new Method({
|
|
||||||
name: 'putHex',
|
|
||||||
call: 'db_putHex',
|
|
||||||
params: 3
|
|
||||||
});
|
|
||||||
|
|
||||||
var getHex = new Method({
|
|
||||||
name: 'getHex',
|
|
||||||
call: 'db_getHex',
|
|
||||||
params: 2
|
|
||||||
});
|
|
||||||
|
|
||||||
return [
|
|
||||||
putString, getString, putHex, getHex
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = DB;
|
|
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/** @file eth.js
|
|
||||||
* @authors:
|
|
||||||
* Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @date 2015
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('../../utils/utils');
|
|
||||||
var Property = require('../property');
|
|
||||||
|
|
||||||
var Net = function (web3) {
|
|
||||||
this._requestManager = web3._requestManager;
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
properties().forEach(function(p) {
|
|
||||||
p.attachToObject(self);
|
|
||||||
p.setRequestManager(web3._requestManager);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @returns an array of objects describing web3.eth api properties
|
|
||||||
var properties = function () {
|
|
||||||
return [
|
|
||||||
new Property({
|
|
||||||
name: 'listening',
|
|
||||||
getter: 'net_listening'
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'peerCount',
|
|
||||||
getter: 'net_peerCount',
|
|
||||||
outputFormatter: utils.toDecimal
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Net;
|
|
@ -1,144 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @file property.js
|
|
||||||
* @author Fabian Vogelsteller <fabian@frozeman.de>
|
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @date 2015
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('../utils/utils');
|
|
||||||
|
|
||||||
var Property = function (options) {
|
|
||||||
this.name = options.name;
|
|
||||||
this.getter = options.getter;
|
|
||||||
this.setter = options.setter;
|
|
||||||
this.outputFormatter = options.outputFormatter;
|
|
||||||
this.inputFormatter = options.inputFormatter;
|
|
||||||
this.requestManager = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
Property.prototype.setRequestManager = function (rm) {
|
|
||||||
this.requestManager = rm;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to format input args of method
|
|
||||||
*
|
|
||||||
* @method formatInput
|
|
||||||
* @param {Array}
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
Property.prototype.formatInput = function (arg) {
|
|
||||||
return this.inputFormatter ? this.inputFormatter(arg) : arg;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to format output(result) of method
|
|
||||||
*
|
|
||||||
* @method formatOutput
|
|
||||||
* @param {Object}
|
|
||||||
* @return {Object}
|
|
||||||
*/
|
|
||||||
Property.prototype.formatOutput = function (result) {
|
|
||||||
return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to extract callback from array of arguments. Modifies input param
|
|
||||||
*
|
|
||||||
* @method extractCallback
|
|
||||||
* @param {Array} arguments
|
|
||||||
* @return {Function|Null} callback, if exists
|
|
||||||
*/
|
|
||||||
Property.prototype.extractCallback = function (args) {
|
|
||||||
if (utils.isFunction(args[args.length - 1])) {
|
|
||||||
return args.pop(); // modify the args array!
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should attach function to method
|
|
||||||
*
|
|
||||||
* @method attachToObject
|
|
||||||
* @param {Object}
|
|
||||||
* @param {Function}
|
|
||||||
*/
|
|
||||||
Property.prototype.attachToObject = function (obj) {
|
|
||||||
var proto = {
|
|
||||||
get: this.buildGet(),
|
|
||||||
enumerable: true
|
|
||||||
};
|
|
||||||
|
|
||||||
var names = this.name.split('.');
|
|
||||||
var name = names[0];
|
|
||||||
if (names.length > 1) {
|
|
||||||
obj[names[0]] = obj[names[0]] || {};
|
|
||||||
obj = obj[names[0]];
|
|
||||||
name = names[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.defineProperty(obj, name, proto);
|
|
||||||
obj[asyncGetterName(name)] = this.buildAsyncGet();
|
|
||||||
};
|
|
||||||
|
|
||||||
var asyncGetterName = function (name) {
|
|
||||||
return 'get' + name.charAt(0).toUpperCase() + name.slice(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
Property.prototype.buildGet = function () {
|
|
||||||
var property = this;
|
|
||||||
return function get() {
|
|
||||||
return property.formatOutput(property.requestManager.sendSync({
|
|
||||||
method: property.getter
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Property.prototype.buildAsyncGet = function () {
|
|
||||||
var property = this;
|
|
||||||
var get = function (callback) {
|
|
||||||
property.requestManager.send({
|
|
||||||
method: property.getter
|
|
||||||
}, function (err, result) {
|
|
||||||
callback(err, property.formatOutput(result));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
get.request = this.request.bind(this);
|
|
||||||
return get;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be called to create pure JSONRPC request which can be used in batch request
|
|
||||||
*
|
|
||||||
* @method request
|
|
||||||
* @param {...} params
|
|
||||||
* @return {Object} jsonrpc request
|
|
||||||
*/
|
|
||||||
Property.prototype.request = function () {
|
|
||||||
var payload = {
|
|
||||||
method: this.getter,
|
|
||||||
params: [],
|
|
||||||
callback: this.extractCallback(Array.prototype.slice.call(arguments))
|
|
||||||
};
|
|
||||||
payload.format = this.formatOutput.bind(this);
|
|
||||||
return payload;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Property;
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
var Settings = function () {
|
|
||||||
this.defaultBlock = 'latest';
|
|
||||||
this.defaultAccount = undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Settings;
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of web3.js.
|
|
||||||
|
|
||||||
web3.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.
|
|
||||||
|
|
||||||
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @file transfer.js
|
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
|
||||||
* @date 2015
|
|
||||||
*/
|
|
||||||
|
|
||||||
var Iban = require('./iban');
|
|
||||||
var exchangeAbi = require('../contracts/SmartExchange.json');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to make Iban transfer
|
|
||||||
*
|
|
||||||
* @method transfer
|
|
||||||
* @param {String} from
|
|
||||||
* @param {String} to iban
|
|
||||||
* @param {Value} value to be tranfered
|
|
||||||
* @param {Function} callback, callback
|
|
||||||
*/
|
|
||||||
var transfer = function (eth, from, to, value, callback) {
|
|
||||||
var iban = new Iban(to);
|
|
||||||
if (!iban.isValid()) {
|
|
||||||
throw new Error('invalid iban address');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iban.isDirect()) {
|
|
||||||
return transferToAddress(eth, from, iban.address(), value, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!callback) {
|
|
||||||
var address = eth.icapNamereg().addr(iban.institution());
|
|
||||||
return deposit(eth, from, address, value, iban.client());
|
|
||||||
}
|
|
||||||
|
|
||||||
eth.icapNamereg().addr(iban.institution(), function (err, address) {
|
|
||||||
return deposit(eth, from, address, value, iban.client(), callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to transfer funds to certain address
|
|
||||||
*
|
|
||||||
* @method transferToAddress
|
|
||||||
* @param {String} from
|
|
||||||
* @param {String} to
|
|
||||||
* @param {Value} value to be tranfered
|
|
||||||
* @param {Function} callback, callback
|
|
||||||
*/
|
|
||||||
var transferToAddress = function (eth, from, to, value, callback) {
|
|
||||||
return eth.sendTransaction({
|
|
||||||
address: to,
|
|
||||||
from: from,
|
|
||||||
value: value
|
|
||||||
}, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!)
|
|
||||||
*
|
|
||||||
* @method deposit
|
|
||||||
* @param {String} from
|
|
||||||
* @param {String} to
|
|
||||||
* @param {Value} value to be transfered
|
|
||||||
* @param {String} client unique identifier
|
|
||||||
* @param {Function} callback, callback
|
|
||||||
*/
|
|
||||||
var deposit = function (eth, from, to, value, client, callback) {
|
|
||||||
var abi = exchangeAbi;
|
|
||||||
return eth.contract(abi).at(to).deposit(client, {
|
|
||||||
from: from,
|
|
||||||
value: value
|
|
||||||
}, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = transfer;
|
|
||||||
|
|
168
package.json
168
package.json
@ -1,93 +1,87 @@
|
|||||||
{
|
{
|
||||||
"name": "web3",
|
"name": "web3",
|
||||||
"namespace": "ethereum",
|
"namespace": "ethereum",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
|
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
|
||||||
"license": "LGPL-3.0",
|
"license": "LGPL-3.0",
|
||||||
"main": "./index.js",
|
"main": "./src/index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "./lib"
|
"src": "./src",
|
||||||
},
|
"doc": "./doc"
|
||||||
"browser": {
|
|
||||||
"xmlhttprequest": "./lib/utils/browser-xhr.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"bignumber.js": "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2",
|
|
||||||
"bluebird": "^3.3.1",
|
|
||||||
"crypto-js": "^3.1.4",
|
|
||||||
"eventemitter3": "^1.1.1",
|
|
||||||
"global": "^4.3.1",
|
|
||||||
"lodash": "^4.17.4",
|
|
||||||
"utf8": "^2.1.1",
|
|
||||||
"websocket": "^1.0.23",
|
|
||||||
"xhr2": "*",
|
|
||||||
"xmlhttprequest": "*"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"bower": ">=1.4.1",
|
|
||||||
"browserify": ">=10.0",
|
|
||||||
"chai": "^3.0.0",
|
|
||||||
"coveralls": "^2.11.2",
|
|
||||||
"del": ">=2.0.2",
|
|
||||||
"exorcist": "^0.4.0",
|
|
||||||
"gulp": ">=3.9.0",
|
|
||||||
"gulp-jshint": ">=1.5.0",
|
|
||||||
"gulp-rename": ">=1.2.0",
|
|
||||||
"gulp-replace": "^0.5.3",
|
|
||||||
"gulp-streamify": "0.0.5",
|
|
||||||
"gulp-uglify": ">=1.2.0",
|
|
||||||
"istanbul": "^0.4.4",
|
|
||||||
"jshint": ">=2.5.0",
|
|
||||||
"mocha": ">=2.3.3",
|
|
||||||
"sandboxed-module": "^2.0.2",
|
|
||||||
"vinyl-source-stream": "^1.1.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "gulp",
|
|
||||||
"watch": "gulp watch",
|
|
||||||
"lint": "jshint *.js lib",
|
|
||||||
"test": "mocha; jshint *.js lib",
|
|
||||||
"test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/ethereum/web3.js.git"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/ethereum/web3.js",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/ethereum/web3.js/issues"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"ethereum",
|
|
||||||
"javascript",
|
|
||||||
"API"
|
|
||||||
],
|
|
||||||
"author": "ethdev.com",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Fabian Vogelsteller",
|
|
||||||
"email": "fabian@ethereum.org",
|
|
||||||
"homepage": "http://frozeman.de"
|
|
||||||
},
|
},
|
||||||
{
|
"dependencies": {
|
||||||
"name": "Marek Kotewicz",
|
|
||||||
"email": "marek@ethcore.io",
|
|
||||||
"url": "https://github.com/debris"
|
|
||||||
},
|
},
|
||||||
{
|
"devDependencies": {
|
||||||
"name": "Marian Oancea",
|
"bower": ">=1.4.1",
|
||||||
"email": "marian@ethereum.org",
|
"browserify": ">=10.0",
|
||||||
"url": "https://github.com/cubedro"
|
"chai": "^3.0.0",
|
||||||
|
"coveralls": "^2.11.2",
|
||||||
|
"del": ">=2.0.2",
|
||||||
|
"exorcist": "^0.4.0",
|
||||||
|
"gulp": ">=3.9.0",
|
||||||
|
"gulp-jshint": ">=1.5.0",
|
||||||
|
"gulp-rename": ">=1.2.0",
|
||||||
|
"gulp-replace": "^0.5.3",
|
||||||
|
"gulp-streamify": "0.0.5",
|
||||||
|
"gulp-uglify": ">=1.2.0",
|
||||||
|
"istanbul": "^0.4.4",
|
||||||
|
"jshint": ">=2.5.0",
|
||||||
|
"mocha": ">=2.3.3",
|
||||||
|
"sandboxed-module": "^2.0.2",
|
||||||
|
"vinyl-source-stream": "^1.1.0",
|
||||||
|
"lerna": "2.0.0-beta.32",
|
||||||
|
"crypto-js": "^3.1.4",
|
||||||
|
"underscore": "^1.8.3",
|
||||||
|
"bignumber.js": "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2"
|
||||||
},
|
},
|
||||||
{
|
"scripts": {
|
||||||
"name": "Gav Wood",
|
"postinstall": "lerna bootstrap",
|
||||||
"email": "g@ethcore.io",
|
"build": "gulp",
|
||||||
"homepage": "http://gavwood.com"
|
"watch": "gulp watch",
|
||||||
|
"lint": "jshint *.js packages",
|
||||||
|
"test": "mocha; jshint *.js packages",
|
||||||
|
"test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose"
|
||||||
},
|
},
|
||||||
{
|
"repository": {
|
||||||
"name": "Jeffery Wilcke",
|
"type": "git",
|
||||||
"email": "jeffrey.wilcke@ethereum.org",
|
"url": "https://github.com/ethereum/web3.js.git"
|
||||||
"url": "https://github.com/obscuren"
|
},
|
||||||
}
|
"homepage": "https://github.com/ethereum/web3.js",
|
||||||
]
|
"bugs": {
|
||||||
|
"url ": "https://github.com/ethereum/web3.js/issues"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"Ethereum",
|
||||||
|
"JavaScript",
|
||||||
|
"API"
|
||||||
|
],
|
||||||
|
"author": "ethereum.org",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabian Vogelsteller",
|
||||||
|
"email": "fabian@ethereum.org",
|
||||||
|
"homepage": "http://frozeman.de"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Marek Kotewicz",
|
||||||
|
"email": "marek@ethcore.io",
|
||||||
|
"url": "https://github.com/debris"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Marian Oancea",
|
||||||
|
"email": "marian@ethereum.org",
|
||||||
|
"url": "https://github.com/cubedro"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gav Wood",
|
||||||
|
"email": "g@ethcore.io",
|
||||||
|
"homepage": "http://gavwood.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jeffery Wilcke",
|
||||||
|
"email": "jeffrey.wilcke@ethereum.org",
|
||||||
|
"url": "https://github.com/obscuren"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
12
packages/web3-bzz/package.json
Normal file
12
packages/web3-bzz/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-bzz",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 module to interact with the Swarm network.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-bzz",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core": "^1.0.0",
|
||||||
|
"web3-core-method": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
@ -15,34 +15,34 @@
|
|||||||
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file bzz.js
|
* @file index.js
|
||||||
* @author Alex Beregszaszi <alex@rtfs.hu>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @date 2016
|
* @date 2017
|
||||||
*
|
|
||||||
* Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Method = require('../method');
|
var core = require('web3-core');
|
||||||
var Property = require('../property');
|
var Method = require('web3-core-method');
|
||||||
|
|
||||||
function Swarm(web3) {
|
|
||||||
this._requestManager = web3._requestManager;
|
|
||||||
|
|
||||||
var self = this;
|
function Swarm() {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// sets _requestmanager
|
||||||
|
core.packageInit(this, arguments);
|
||||||
|
|
||||||
|
|
||||||
methods().forEach(function(method) {
|
methods().forEach(function(method) {
|
||||||
method.attachToObject(self);
|
method.attachToObject(_this);
|
||||||
method.setRequestManager(self._requestManager);
|
method.setRequestManager(_this._requestManager);
|
||||||
});
|
|
||||||
|
|
||||||
properties().forEach(function(p) {
|
|
||||||
p.attachToObject(self);
|
|
||||||
p.setRequestManager(self._requestManager);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.addProviders(Swarm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var methods = function () {
|
var methods = function () {
|
||||||
var blockNetworkRead = new Method({
|
var blockNetworkRead = new Method({
|
||||||
name: 'blockNetworkRead',
|
name: 'blockNetworkRead',
|
||||||
@ -114,6 +114,20 @@ var methods = function () {
|
|||||||
inputFormatter: [null, null, null, null]
|
inputFormatter: [null, null, null, null]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var getHive = new Method({
|
||||||
|
name: 'getHive',
|
||||||
|
call: 'bzz_hive',
|
||||||
|
params: 0,
|
||||||
|
inputFormatter: []
|
||||||
|
});
|
||||||
|
|
||||||
|
var getInfo = new Method({
|
||||||
|
name: 'getInfo',
|
||||||
|
call: 'bzz_info',
|
||||||
|
params: 0,
|
||||||
|
inputFormatter: []
|
||||||
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
blockNetworkRead,
|
blockNetworkRead,
|
||||||
syncEnabled,
|
syncEnabled,
|
||||||
@ -124,22 +138,12 @@ var methods = function () {
|
|||||||
store,
|
store,
|
||||||
get,
|
get,
|
||||||
put,
|
put,
|
||||||
modify
|
modify,
|
||||||
];
|
getHive,
|
||||||
};
|
getInfo
|
||||||
|
|
||||||
var properties = function () {
|
|
||||||
return [
|
|
||||||
new Property({
|
|
||||||
name: 'hive',
|
|
||||||
getter: 'bzz_hive'
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'info',
|
|
||||||
getter: 'bzz_info'
|
|
||||||
})
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = Swarm;
|
module.exports = Swarm;
|
||||||
|
|
12
packages/web3-core-helpers/package.json
Normal file
12
packages/web3-core-helpers/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-core-helpers",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 core tools helper for sub packages. This is an internal package.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-helpers",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-utils": "^1.0.0",
|
||||||
|
"web3-core-iban": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
64
packages/web3-core-helpers/src/config.js
Normal file
64
packages/web3-core-helpers/src/config.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
This file is part of web3.js.
|
||||||
|
|
||||||
|
web3.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.
|
||||||
|
|
||||||
|
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file index.js
|
||||||
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
|
* @date 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
// var BigNumber = require('bignumber.js');
|
||||||
|
|
||||||
|
var ETH_UNITS = [
|
||||||
|
'wei',
|
||||||
|
'kwei',
|
||||||
|
'Mwei',
|
||||||
|
'Gwei',
|
||||||
|
'szabo',
|
||||||
|
'finney',
|
||||||
|
'femtoether',
|
||||||
|
'picoether',
|
||||||
|
'nanoether',
|
||||||
|
'microether',
|
||||||
|
'milliether',
|
||||||
|
'nano',
|
||||||
|
'micro',
|
||||||
|
'milli',
|
||||||
|
'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 },
|
||||||
|
// ETH_POLLING_TIMEOUT: 1000/2,
|
||||||
|
defaultBlock: 'latest',
|
||||||
|
defaultAccount: null
|
||||||
|
};
|
||||||
|
|
@ -14,15 +14,16 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file errors.js
|
* @file errors.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @date 2015
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
|
* @date 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
InvalidNumberOfParams: function () {
|
InvalidNumberOfParams: function (got, expected, method) {
|
||||||
return new Error('Invalid number of input parameters');
|
return new Error('Invalid number of parameters for "'+ method +'". Got '+ got +' expected '+ expected +'!');
|
||||||
},
|
},
|
||||||
InvalidConnection: function (host){
|
InvalidConnection: function (host){
|
||||||
return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
|
return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
|
@ -16,15 +16,15 @@
|
|||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file formatters.js
|
* @file formatters.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @author Fabian Vogelsteller <fabian@ethdev.com>
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
* @date 2015
|
* @date 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var utils = require('../utils/utils');
|
var utils = require('web3-utils');
|
||||||
var config = require('../utils/config');
|
var Iban = require('web3-core-iban');
|
||||||
var Iban = require('./iban');
|
|
||||||
var sha3 = require('../utils/sha3');
|
var config = require('./config');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should the format output to a big number
|
* Should the format output to a big number
|
||||||
@ -34,7 +34,7 @@ var sha3 = require('../utils/sha3');
|
|||||||
* @returns {BigNumber} object
|
* @returns {BigNumber} object
|
||||||
*/
|
*/
|
||||||
var outputBigNumberFormatter = function (number) {
|
var outputBigNumberFormatter = function (number) {
|
||||||
return utils.toBigNumber(number);
|
return utils.toBigNumber(number).toFixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
var isPredefinedBlockNumber = function (blockNumber) {
|
var isPredefinedBlockNumber = function (blockNumber) {
|
||||||
@ -42,7 +42,7 @@ var isPredefinedBlockNumber = function (blockNumber) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var inputDefaultBlockNumberFormatter = function (blockNumber) {
|
var inputDefaultBlockNumberFormatter = function (blockNumber) {
|
||||||
if (!blockNumber) {
|
if (blockNumber === undefined || blockNumber === null) {
|
||||||
return config.defaultBlock;
|
return config.defaultBlock;
|
||||||
}
|
}
|
||||||
return inputBlockNumberFormatter(blockNumber);
|
return inputBlockNumberFormatter(blockNumber);
|
||||||
@ -66,10 +66,10 @@ var inputBlockNumberFormatter = function (blockNumber) {
|
|||||||
*/
|
*/
|
||||||
var inputCallFormatter = function (options){
|
var inputCallFormatter = function (options){
|
||||||
|
|
||||||
options.from = options.from || config.defaultAccount;
|
var from = options.from || config.defaultAccount;
|
||||||
|
|
||||||
if (options.from) {
|
if (from) {
|
||||||
options.from = inputAddressFormatter(options.from);
|
options.from = inputAddressFormatter(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.to) { // it might be contract creation
|
if (options.to) { // it might be contract creation
|
||||||
@ -128,8 +128,16 @@ var outputTransactionFormatter = function (tx){
|
|||||||
tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
|
tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
|
||||||
tx.nonce = utils.toDecimal(tx.nonce);
|
tx.nonce = utils.toDecimal(tx.nonce);
|
||||||
tx.gas = utils.toDecimal(tx.gas);
|
tx.gas = utils.toDecimal(tx.gas);
|
||||||
tx.gasPrice = utils.toBigNumber(tx.gasPrice);
|
tx.gasPrice = outputBigNumberFormatter(tx.gasPrice);
|
||||||
tx.value = utils.toBigNumber(tx.value);
|
tx.value = outputBigNumberFormatter(tx.value);
|
||||||
|
|
||||||
|
if(tx.to) {
|
||||||
|
tx.to = utils.toChecksumAddress(tx.to);
|
||||||
|
}
|
||||||
|
if(tx.from) {
|
||||||
|
tx.from = utils.toChecksumAddress(tx.from);
|
||||||
|
}
|
||||||
|
|
||||||
return tx;
|
return tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -149,9 +157,11 @@ var outputTransactionReceiptFormatter = function (receipt){
|
|||||||
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
|
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
|
||||||
|
|
||||||
if(utils.isArray(receipt.logs)) {
|
if(utils.isArray(receipt.logs)) {
|
||||||
receipt.logs = receipt.logs.map(function(log){
|
receipt.logs = receipt.logs.map(outputLogFormatter);
|
||||||
return outputLogFormatter(log);
|
}
|
||||||
});
|
|
||||||
|
if(receipt.contractAddress) {
|
||||||
|
receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return receipt;
|
return receipt;
|
||||||
@ -171,11 +181,11 @@ var outputBlockFormatter = function(block) {
|
|||||||
block.gasUsed = utils.toDecimal(block.gasUsed);
|
block.gasUsed = utils.toDecimal(block.gasUsed);
|
||||||
block.size = utils.toDecimal(block.size);
|
block.size = utils.toDecimal(block.size);
|
||||||
block.timestamp = utils.toDecimal(block.timestamp);
|
block.timestamp = utils.toDecimal(block.timestamp);
|
||||||
if(block.number !== null)
|
if (block.number !== null)
|
||||||
block.number = utils.toDecimal(block.number);
|
block.number = utils.toDecimal(block.number);
|
||||||
|
|
||||||
block.difficulty = utils.toBigNumber(block.difficulty);
|
block.difficulty = outputBigNumberFormatter(block.difficulty);
|
||||||
block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
|
block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty);
|
||||||
|
|
||||||
if (utils.isArray(block.transactions)) {
|
if (utils.isArray(block.transactions)) {
|
||||||
block.transactions.forEach(function(item){
|
block.transactions.forEach(function(item){
|
||||||
@ -184,6 +194,9 @@ var outputBlockFormatter = function(block) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (block.miner)
|
||||||
|
block.miner = utils.toChecksumAddress(block.miner);
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -216,11 +229,8 @@ var inputLogFormatter = function(options) {
|
|||||||
|
|
||||||
toTopic = null;
|
toTopic = null;
|
||||||
|
|
||||||
if(options.address && !utils.isAddress(options.address))
|
if(options.address)
|
||||||
throw new Error('The given address is not valid!');
|
options.address = inputAddressFormatter(options.address);
|
||||||
|
|
||||||
// if(options.address)
|
|
||||||
// options.address = options.address.toLowerCase();
|
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
@ -235,15 +245,25 @@ var inputLogFormatter = function(options) {
|
|||||||
var outputLogFormatter = function(log) {
|
var outputLogFormatter = function(log) {
|
||||||
|
|
||||||
// generate a custom log id
|
// generate a custom log id
|
||||||
log.id = 'log_'+ sha3(log.blockHash.replace('0x','') + log.transactionHash.replace('0x','') + log.logIndex.replace('0x','')).substr(0,8);
|
if(typeof log.blockHash === 'string' &&
|
||||||
|
typeof log.transactionHash === 'string' &&
|
||||||
|
typeof log.logIndex === 'string') {
|
||||||
|
var shaId = utils.sha3(log.blockHash.replace('0x','') + log.transactionHash.replace('0x','') + log.logIndex.replace('0x',''));
|
||||||
|
log.id = 'log_'+ shaId.replace('0x','').substr(0,8);
|
||||||
|
} else {
|
||||||
|
log.id = null;
|
||||||
|
}
|
||||||
|
|
||||||
if(log.blockNumber !== null)
|
if (log.blockNumber !== null)
|
||||||
log.blockNumber = utils.toDecimal(log.blockNumber);
|
log.blockNumber = utils.toDecimal(log.blockNumber);
|
||||||
if(log.transactionIndex !== null)
|
if (log.transactionIndex !== null)
|
||||||
log.transactionIndex = utils.toDecimal(log.transactionIndex);
|
log.transactionIndex = utils.toDecimal(log.transactionIndex);
|
||||||
if(log.logIndex !== null)
|
if (log.logIndex !== null)
|
||||||
log.logIndex = utils.toDecimal(log.logIndex);
|
log.logIndex = utils.toDecimal(log.logIndex);
|
||||||
|
|
||||||
|
if (log.address)
|
||||||
|
log.address = utils.toChecksumAddress(log.address);
|
||||||
|
|
||||||
return log;
|
return log;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -257,9 +277,13 @@ var outputLogFormatter = function(log) {
|
|||||||
var inputPostFormatter = function(post) {
|
var inputPostFormatter = function(post) {
|
||||||
|
|
||||||
// post.payload = utils.toHex(post.payload);
|
// post.payload = utils.toHex(post.payload);
|
||||||
post.ttl = utils.fromDecimal(post.ttl);
|
|
||||||
post.workToProve = utils.fromDecimal(post.workToProve);
|
if (post.ttl)
|
||||||
post.priority = utils.fromDecimal(post.priority);
|
post.ttl = utils.fromDecimal(post.ttl);
|
||||||
|
if (post.workToProve)
|
||||||
|
post.workToProve = utils.fromDecimal(post.workToProve);
|
||||||
|
if (post.priority)
|
||||||
|
post.priority = utils.fromDecimal(post.priority);
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
if (!utils.isArray(post.topics)) {
|
if (!utils.isArray(post.topics)) {
|
||||||
@ -300,7 +324,7 @@ var outputPostFormatter = function(post){
|
|||||||
post.topics = [];
|
post.topics = [];
|
||||||
}
|
}
|
||||||
post.topics = post.topics.map(function(topic){
|
post.topics = post.topics.map(function(topic){
|
||||||
return utils.toAscii(topic);
|
return utils.toUtf8(topic);
|
||||||
});
|
});
|
||||||
|
|
||||||
return post;
|
return post;
|
||||||
@ -309,13 +333,11 @@ var outputPostFormatter = function(post){
|
|||||||
var inputAddressFormatter = function (address) {
|
var inputAddressFormatter = function (address) {
|
||||||
var iban = new Iban(address);
|
var iban = new Iban(address);
|
||||||
if (iban.isValid() && iban.isDirect()) {
|
if (iban.isValid() && iban.isDirect()) {
|
||||||
return '0x' + iban.address();
|
return iban.address().toLowerCase();
|
||||||
} else if (utils.isStrictAddress(address)) {
|
|
||||||
return address;
|
|
||||||
} else if (utils.isAddress(address)) {
|
} else if (utils.isAddress(address)) {
|
||||||
return '0x' + address;
|
return '0x' + address.toLowerCase().replace('0x','');
|
||||||
}
|
}
|
||||||
throw new Error('invalid address');
|
throw new Error('Provided address "'+ address +'" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can\'t be converted.');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -14,26 +14,21 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file namereg.js
|
* @file index.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @date 2015
|
* @date 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json');
|
"use strict";
|
||||||
var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json');
|
|
||||||
|
|
||||||
var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
|
var errors = require('./errors');
|
||||||
var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00';
|
var formatters = require('./formatters');
|
||||||
|
var config = require('./config');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
global: {
|
errors: errors,
|
||||||
abi: globalRegistrarAbi,
|
formatters: formatters,
|
||||||
address: globalNameregAddress
|
config: config
|
||||||
},
|
|
||||||
icap: {
|
|
||||||
abi: icapRegistrarAbi,
|
|
||||||
address: icapNameregAddress
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
12
packages/web3-core-iban/package.json
Normal file
12
packages/web3-core-iban/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-core-iban",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "This package converts Ethereum addresses to IBAN adresses a vice versa.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-iban",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-utils": "^1.0.0",
|
||||||
|
"bignumber.js": "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2"
|
||||||
|
}
|
||||||
|
}
|
@ -14,14 +14,20 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file iban.js
|
* @file iban.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
*
|
||||||
|
* Details: https://github.com/ethereum/wiki/wiki/ICAP:-Inter-exchange-Client-Address-Protocol
|
||||||
|
*
|
||||||
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
* @date 2015
|
* @date 2015
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var utils = require('web3-utils');
|
||||||
|
|
||||||
var BigNumber = require('bignumber.js');
|
var BigNumber = require('bignumber.js');
|
||||||
|
|
||||||
|
|
||||||
var padLeft = function (string, bytes) {
|
var padLeft = function (string, bytes) {
|
||||||
var result = string;
|
var result = string;
|
||||||
while (result.length < bytes * 2) {
|
while (result.length < bytes * 2) {
|
||||||
@ -92,6 +98,10 @@ var Iban = function (iban) {
|
|||||||
* @return {Iban} the IBAN object
|
* @return {Iban} the IBAN object
|
||||||
*/
|
*/
|
||||||
Iban.fromAddress = function (address) {
|
Iban.fromAddress = function (address) {
|
||||||
|
if(!utils.isAddress(address)){
|
||||||
|
throw new Error('Provided address is not a valid address: '+ address);
|
||||||
|
}
|
||||||
|
|
||||||
var asBn = new BigNumber(address, 16);
|
var asBn = new BigNumber(address, 16);
|
||||||
var base36 = asBn.toString(36);
|
var base36 = asBn.toString(36);
|
||||||
var padded = padLeft(base36, 15);
|
var padded = padLeft(base36, 15);
|
||||||
@ -128,7 +138,7 @@ Iban.createIndirect = function (options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thos method should be used to check if given string is valid iban object
|
* This method should be used to check if given string is valid iban object
|
||||||
*
|
*
|
||||||
* @method isValid
|
* @method isValid
|
||||||
* @param {String} iban string
|
* @param {String} iban string
|
||||||
@ -213,8 +223,8 @@ Iban.prototype.address = function () {
|
|||||||
if (this.isDirect()) {
|
if (this.isDirect()) {
|
||||||
var base36 = this._iban.substr(4);
|
var base36 = this._iban.substr(4);
|
||||||
var asBn = new BigNumber(base36, 36);
|
var asBn = new BigNumber(base36, 36);
|
||||||
return padLeft(asBn.toString(16), 20);
|
return utils.toChecksumAddress(padLeft(asBn.toString(16), 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
@ -224,4 +234,3 @@ Iban.prototype.toString = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Iban;
|
module.exports = Iban;
|
||||||
|
|
14
packages/web3-core-method/package.json
Normal file
14
packages/web3-core-method/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-core-method",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Creates the methods on the web3 modules. This is an internal package.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-method",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"web3-utils": "^1.0.0",
|
||||||
|
"web3-core-promiEvent": "^1.0.0",
|
||||||
|
"underscore": "^1.8.3"
|
||||||
|
}
|
||||||
|
}
|
351
packages/web3-core-method/src/index.js
Normal file
351
packages/web3-core-method/src/index.js
Normal file
@ -0,0 +1,351 @@
|
|||||||
|
/*
|
||||||
|
This file is part of web3.js.
|
||||||
|
|
||||||
|
web3.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.
|
||||||
|
|
||||||
|
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file index.js
|
||||||
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
|
* @date 2017
|
||||||
|
*/
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
var errors = require('web3-core-helpers').errors;
|
||||||
|
var utils = require('web3-utils');
|
||||||
|
var promiEvent = require('web3-core-promiEvent');
|
||||||
|
|
||||||
|
var TIMEOUTBLOCK = 50;
|
||||||
|
var CONFIRMATIONBLOCKS = 12;
|
||||||
|
|
||||||
|
var Method = function (options) {
|
||||||
|
|
||||||
|
if(!options.call || !options.name) {
|
||||||
|
throw new Error('When creating a method you need to provide at least the "name" and "call" property.');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.name = options.name;
|
||||||
|
this.call = options.call;
|
||||||
|
this.params = options.params || 0;
|
||||||
|
this.inputFormatter = options.inputFormatter;
|
||||||
|
this.outputFormatter = options.outputFormatter;
|
||||||
|
this.requestManager = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
Method.prototype.setRequestManager = function (rm, eth) {
|
||||||
|
this.requestManager = rm;
|
||||||
|
|
||||||
|
if (eth) {
|
||||||
|
this.eth = eth;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be used to determine name of the jsonrpc method based on arguments
|
||||||
|
*
|
||||||
|
* @method getCall
|
||||||
|
* @param {Array} arguments
|
||||||
|
* @return {String} name of jsonrpc method
|
||||||
|
*/
|
||||||
|
Method.prototype.getCall = function (args) {
|
||||||
|
return utils.isFunction(this.call) ? this.call(args) : this.call;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be used to extract callback from array of arguments. Modifies input param
|
||||||
|
*
|
||||||
|
* @method extractCallback
|
||||||
|
* @param {Array} arguments
|
||||||
|
* @return {Function|Null} callback, if exists
|
||||||
|
*/
|
||||||
|
Method.prototype.extractCallback = function (args) {
|
||||||
|
if (utils.isFunction(args[args.length - 1])) {
|
||||||
|
return args.pop(); // modify the args array!
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to check if the number of arguments is correct
|
||||||
|
*
|
||||||
|
* @method validateArgs
|
||||||
|
* @param {Array} arguments
|
||||||
|
* @throws {Error} if it is not
|
||||||
|
*/
|
||||||
|
Method.prototype.validateArgs = function (args) {
|
||||||
|
if (args.length !== this.params) {
|
||||||
|
throw errors.InvalidNumberOfParams(args.length, this.params, this.name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to format input args of method
|
||||||
|
*
|
||||||
|
* @method formatInput
|
||||||
|
* @param {Array}
|
||||||
|
* @return {Array}
|
||||||
|
*/
|
||||||
|
Method.prototype.formatInput = function (args) {
|
||||||
|
if (!this.inputFormatter) {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.inputFormatter.map(function (formatter, index) {
|
||||||
|
return formatter ? formatter(args[index]) : args[index];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to format output(result) of method
|
||||||
|
*
|
||||||
|
* @method formatOutput
|
||||||
|
* @param {Object}
|
||||||
|
* @return {Object}
|
||||||
|
*/
|
||||||
|
Method.prototype.formatOutput = function (result) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
if(utils.isArray(result)) {
|
||||||
|
return result.map(function(res){
|
||||||
|
return _this.outputFormatter && res ? _this.outputFormatter(res) : res;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return this.outputFormatter && result ? this.outputFormatter(result) : result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should create payload from given input args
|
||||||
|
*
|
||||||
|
* @method toPayload
|
||||||
|
* @param {Array} args
|
||||||
|
* @return {Object}
|
||||||
|
*/
|
||||||
|
Method.prototype.toPayload = function (args) {
|
||||||
|
var call = this.getCall(args);
|
||||||
|
var callback = this.extractCallback(args);
|
||||||
|
var params = this.formatInput(args);
|
||||||
|
this.validateArgs(params);
|
||||||
|
|
||||||
|
return {
|
||||||
|
method: call,
|
||||||
|
params: params,
|
||||||
|
callback: callback
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Method.prototype.attachToObject = function (obj) {
|
||||||
|
var func = this.buildCall();
|
||||||
|
func.call = this.call; // TODO!!! that's ugly. filter.js uses it
|
||||||
|
var name = this.name.split('.');
|
||||||
|
if (name.length > 1) {
|
||||||
|
obj[name[0]] = obj[name[0]] || {};
|
||||||
|
obj[name[0]][name[1]] = func;
|
||||||
|
} else {
|
||||||
|
obj[name[0]] = func;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Method.prototype._confirmTransaction = function (defer, result, payload) {
|
||||||
|
var method = this,
|
||||||
|
promiseResolved = false,
|
||||||
|
canUnsubscribe = true,
|
||||||
|
timeoutCount = 0,
|
||||||
|
confirmationCount = 0,
|
||||||
|
isContractDeployment = _.isObject(payload.params[0]) &&
|
||||||
|
payload.params[0].data &&
|
||||||
|
payload.params[0].from &&
|
||||||
|
!payload.params[0].to,
|
||||||
|
receiptError = new Error('Failed to check for transaction receipt.');
|
||||||
|
|
||||||
|
|
||||||
|
// fire "receipt" and confirmation events and resolve after
|
||||||
|
method.eth.subscribe('newBlockHeaders', function (err, block, sub) {
|
||||||
|
if(!err) {
|
||||||
|
|
||||||
|
method.eth.getTransactionReceipt(result)
|
||||||
|
// catch error from requesting receipt
|
||||||
|
.catch(function () {
|
||||||
|
sub.unsubscribe();
|
||||||
|
promiseResolved = true;
|
||||||
|
utils._fireError(receiptError, defer.eventEmitter, defer.reject);
|
||||||
|
})
|
||||||
|
// if CONFIRMATION listener exists check for confirmations
|
||||||
|
.then(function(receipt) {
|
||||||
|
|
||||||
|
if (!receipt) {
|
||||||
|
throw new Error('Receipt is null');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defer.eventEmitter.listeners('confirmation').length > 0) {
|
||||||
|
|
||||||
|
defer.eventEmitter.emit('confirmation', confirmationCount, receipt);
|
||||||
|
|
||||||
|
canUnsubscribe = false;
|
||||||
|
confirmationCount++;
|
||||||
|
|
||||||
|
if (confirmationCount === CONFIRMATIONBLOCKS + 1) { // add 1 so we account for conf 0
|
||||||
|
sub.unsubscribe();
|
||||||
|
defer.eventEmitter.removeAllListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return receipt;
|
||||||
|
})
|
||||||
|
// CHECK for CONTRACT DEPLOYMENT
|
||||||
|
.then(function(receipt) {
|
||||||
|
|
||||||
|
if (isContractDeployment && !promiseResolved) {
|
||||||
|
|
||||||
|
if (!receipt.contractAddress) {
|
||||||
|
promiseResolved = true;
|
||||||
|
utils._fireError(new Error('The transaction receipt didn\'t contain a contract address.'), defer.eventEmitter, defer.reject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
method.eth.getCode(receipt.contractAddress, function (e, code) {
|
||||||
|
|
||||||
|
if (!code) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (code.length > 2) {
|
||||||
|
defer.eventEmitter.emit('receipt', receipt);
|
||||||
|
defer.resolve(receipt);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
utils._fireError(new Error('The contract code couldn\'t be stored, please check your gas limit.'), defer.eventEmitter, defer.reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canUnsubscribe) {
|
||||||
|
sub.unsubscribe();
|
||||||
|
defer.eventEmitter.removeAllListeners();
|
||||||
|
}
|
||||||
|
promiseResolved = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return receipt;
|
||||||
|
})
|
||||||
|
// CHECK for normal tx check for receipt only
|
||||||
|
.then(function(receipt) {
|
||||||
|
|
||||||
|
if (!isContractDeployment && !promiseResolved) {
|
||||||
|
|
||||||
|
if(!receipt.outOfGas) {
|
||||||
|
defer.eventEmitter.emit('receipt', receipt);
|
||||||
|
defer.resolve(receipt);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
utils._fireError(new Error('Transaction ran out of gas.'), defer.eventEmitter, defer.reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canUnsubscribe) {
|
||||||
|
sub.unsubscribe();
|
||||||
|
defer.eventEmitter.removeAllListeners();
|
||||||
|
}
|
||||||
|
promiseResolved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
// time out the transaction if not mined after 50 blocks
|
||||||
|
.catch(function () {
|
||||||
|
if (timeoutCount >= TIMEOUTBLOCK) {
|
||||||
|
sub.unsubscribe();
|
||||||
|
promiseResolved = true;
|
||||||
|
utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
timeoutCount++;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sub.unsubscribe();
|
||||||
|
promiseResolved = true;
|
||||||
|
utils._fireError(receiptError, defer.eventEmitter, defer.reject);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Method.prototype.buildCall = function() {
|
||||||
|
var method = this,
|
||||||
|
isSendTx = (method.call === 'eth_sendTransaction' || method.call === 'eth_sendRawTransaction');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// actual send function
|
||||||
|
var send = function () {
|
||||||
|
var defer = promiEvent(!isSendTx),
|
||||||
|
payload = method.toPayload(Array.prototype.slice.call(arguments));
|
||||||
|
|
||||||
|
|
||||||
|
method.requestManager.send(payload, function (err, result) {
|
||||||
|
result = method.formatOutput(result);
|
||||||
|
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
if (payload.callback) {
|
||||||
|
payload.callback(null, result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(err.error) {
|
||||||
|
err = err.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils._fireError(err, defer.eventEmitter, defer.reject, payload.callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return PROMISE
|
||||||
|
if (!isSendTx) {
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
defer.resolve(result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// return PROMIEVENT
|
||||||
|
} else if (method.eth) {
|
||||||
|
|
||||||
|
defer.eventEmitter.emit('transactionHash', result);
|
||||||
|
|
||||||
|
|
||||||
|
method._confirmTransaction(defer, result, payload);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return defer.eventEmitter;
|
||||||
|
};
|
||||||
|
|
||||||
|
send.request = this.request.bind(this);
|
||||||
|
return send;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to create the pure JSONRPC request which can be used in a batch request
|
||||||
|
*
|
||||||
|
* @method request
|
||||||
|
* @return {Object} jsonrpc request
|
||||||
|
*/
|
||||||
|
Method.prototype.request = function () {
|
||||||
|
var payload = this.toPayload(Array.prototype.slice.call(arguments));
|
||||||
|
payload.format = this.formatOutput.bind(this);
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Method;
|
12
packages/web3-core-promiEvent/package.json
Normal file
12
packages/web3-core-promiEvent/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-core-promiEvent",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "This package extends eventEmitters with promises to allow chaining as well as multiple final states of a function.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-promiEvent",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"bluebird": "^3.3.1",
|
||||||
|
"eventemitter3": "^1.1.1"
|
||||||
|
}
|
||||||
|
}
|
@ -15,8 +15,8 @@
|
|||||||
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file eventifiedPromise.js
|
* @file index.js
|
||||||
* @author Fabian Vogelsteller <fabian@frozeman.de>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @date 2016
|
* @date 2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -28,9 +28,9 @@ var Promise = require("bluebird");
|
|||||||
*
|
*
|
||||||
* @method eventifiedPromise
|
* @method eventifiedPromise
|
||||||
*/
|
*/
|
||||||
var eventifiedPromise = function(justPromise) {
|
var promiEvent = function(justPromise) {
|
||||||
var resolve, reject,
|
var resolve, reject,
|
||||||
promise = new Promise(function() {
|
eventEmitter = new Promise(function() {
|
||||||
resolve = arguments[0];
|
resolve = arguments[0];
|
||||||
reject = arguments[1];
|
reject = arguments[1];
|
||||||
});
|
});
|
||||||
@ -39,7 +39,7 @@ var eventifiedPromise = function(justPromise) {
|
|||||||
return {
|
return {
|
||||||
resolve: resolve,
|
resolve: resolve,
|
||||||
reject: reject,
|
reject: reject,
|
||||||
promise: promise
|
eventEmitter: eventEmitter
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,20 +47,20 @@ var eventifiedPromise = function(justPromise) {
|
|||||||
var emitter = new EventEmitter();
|
var emitter = new EventEmitter();
|
||||||
|
|
||||||
// add eventEmitter to the promise
|
// add eventEmitter to the promise
|
||||||
promise.emit = emitter.emit;
|
eventEmitter.emit = emitter.emit;
|
||||||
promise.on = emitter.on;
|
eventEmitter.on = emitter.on;
|
||||||
promise.once = emitter.once;
|
eventEmitter.once = emitter.once;
|
||||||
promise.off = emitter.off;
|
eventEmitter.off = emitter.off;
|
||||||
promise.listeners = emitter.listeners;
|
eventEmitter.listeners = emitter.listeners;
|
||||||
promise.addListener = emitter.addListener;
|
eventEmitter.addListener = emitter.addListener;
|
||||||
promise.removeListener = emitter.removeListener;
|
eventEmitter.removeListener = emitter.removeListener;
|
||||||
promise.removeAllListeners = emitter.removeAllListeners;
|
eventEmitter.removeAllListeners = emitter.removeAllListeners;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
resolve: resolve,
|
resolve: resolve,
|
||||||
reject: reject,
|
reject: reject,
|
||||||
promise: promise
|
eventEmitter: eventEmitter
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = eventifiedPromise;
|
module.exports = promiEvent;
|
17
packages/web3-core-requestManager/package.json
Normal file
17
packages/web3-core-requestManager/package.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-requestManager",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 module to handle requests to external providers. Contains also the providers.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-requestManager",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"underscore": "^1.8.3",
|
||||||
|
"xmlhttprequest": "*",
|
||||||
|
"xhr2": "*"
|
||||||
|
},
|
||||||
|
"browser": {
|
||||||
|
"xmlhttprequest": "./src/browser-xhr.js"
|
||||||
|
}
|
||||||
|
}
|
@ -14,14 +14,14 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file batch.js
|
* @file batch.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Marek Kotewicz <marek@ethdev.com>
|
||||||
* @date 2015
|
* @date 2015
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Jsonrpc = require('./jsonrpc');
|
var Jsonrpc = require('./jsonrpc');
|
||||||
var errors = require('./errors');
|
var errors = require('web3-core-helpers').errors;
|
||||||
|
|
||||||
var Batch = function (web3) {
|
var Batch = function (web3) {
|
||||||
this.requestManager = web3._requestManager;
|
this.requestManager = web3._requestManager;
|
||||||
@ -59,7 +59,7 @@ Batch.prototype.execute = function () {
|
|||||||
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
|
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Batch;
|
module.exports = Batch;
|
@ -15,18 +15,28 @@
|
|||||||
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file requestmanager.js
|
* @file index.js
|
||||||
* @author Jeffrey Wilcke <jeff@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @date 2017
|
||||||
* @author Marian Oancea <marian@ethdev.com>
|
|
||||||
* @author Fabian Vogelsteller <fabian@ethdev.com>
|
|
||||||
* @author Gav Wood <g@ethdev.com>
|
|
||||||
* @date 2014
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
var Jsonrpc = require('./jsonrpc');
|
var Jsonrpc = require('./jsonrpc');
|
||||||
var utils = require('../utils/utils');
|
var errors = require('web3-core-helpers').errors;
|
||||||
var errors = require('./errors');
|
var BatchManager = require('./batch');
|
||||||
|
|
||||||
|
var HttpProvider = require('./providers/httpprovider');
|
||||||
|
var IpcProvider = require('./providers/ipcprovider');
|
||||||
|
var WebsocketProvider = require('./providers/websocketprovider');
|
||||||
|
|
||||||
|
var providers = {
|
||||||
|
HttpProvider: HttpProvider,
|
||||||
|
IpcProvider: IpcProvider,
|
||||||
|
WebsocketProvider: WebsocketProvider
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It's responsible for passing messages to providers
|
* It's responsible for passing messages to providers
|
||||||
@ -37,8 +47,13 @@ var errors = require('./errors');
|
|||||||
var RequestManager = function (provider) {
|
var RequestManager = function (provider) {
|
||||||
this.setProvider(provider);
|
this.setProvider(provider);
|
||||||
this.subscriptions = {};
|
this.subscriptions = {};
|
||||||
|
|
||||||
|
this.providers = providers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// expose providers
|
||||||
|
RequestManager.providers = providers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to synchronously send request
|
* Should be used to synchronously send request
|
||||||
*
|
*
|
||||||
@ -110,7 +125,7 @@ RequestManager.prototype.sendBatch = function (data, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!utils.isArray(results)) {
|
if (!_.isArray(results)) {
|
||||||
return callback(errors.InvalidResponse(results));
|
return callback(errors.InvalidResponse(results));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,4 +231,8 @@ RequestManager.prototype.reset = function (keepIsSyncing) {
|
|||||||
this.provider.reset();
|
this.provider.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = RequestManager;
|
module.exports = {
|
||||||
|
Manager: RequestManager,
|
||||||
|
BatchManager: BatchManager
|
||||||
|
};
|
||||||
|
|
@ -36,8 +36,9 @@ var Jsonrpc = {
|
|||||||
* @returns {Object} valid jsonrpc payload object
|
* @returns {Object} valid jsonrpc payload object
|
||||||
*/
|
*/
|
||||||
Jsonrpc.toPayload = function (method, params) {
|
Jsonrpc.toPayload = function (method, params) {
|
||||||
if (!method)
|
if (!method) {
|
||||||
console.error('jsonrpc method should be specified!');
|
throw new Error('JSONRPC method should be specified for params: "'+ JSON.stringify(params) +'"!');
|
||||||
|
}
|
||||||
|
|
||||||
// advance message ID
|
// advance message ID
|
||||||
Jsonrpc.messageId++;
|
Jsonrpc.messageId++;
|
@ -23,7 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var errors = require('../errors');
|
var errors = require('web3-core-helpers').errors;
|
||||||
|
|
||||||
|
|
||||||
// workaround to use httpprovider in different envs
|
// workaround to use httpprovider in different envs
|
||||||
|
|
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var utils = require('../../utils/utils');
|
var _ = require('underscore');
|
||||||
var errors = require('../errors');
|
var errors = require('web3-core-helpers').errors;
|
||||||
|
|
||||||
|
|
||||||
var IpcProvider = function (path, net) {
|
var IpcProvider = function (path, net) {
|
||||||
@ -46,7 +46,7 @@ var IpcProvider = function (path, net) {
|
|||||||
var id = null;
|
var id = null;
|
||||||
|
|
||||||
// get the id which matches the returned id
|
// get the id which matches the returned id
|
||||||
if(utils.isArray(result)) {
|
if(_.isArray(result)) {
|
||||||
result.forEach(function(load){
|
result.forEach(function(load){
|
||||||
if(_this.responseCallbacks[load.id])
|
if(_this.responseCallbacks[load.id])
|
||||||
id = load.id;
|
id = load.id;
|
||||||
@ -58,7 +58,7 @@ var IpcProvider = function (path, net) {
|
|||||||
// notification
|
// notification
|
||||||
if(!id && result.method === 'eth_subscription') {
|
if(!id && result.method === 'eth_subscription') {
|
||||||
_this.notificationCallbacks.forEach(function(callback){
|
_this.notificationCallbacks.forEach(function(callback){
|
||||||
if(utils.isFunction(callback))
|
if(_.isFunction(callback))
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ IpcProvider.prototype.addDefaultEvents = function(){
|
|||||||
|
|
||||||
// inform notifications
|
// inform notifications
|
||||||
_this.notificationCallbacks.forEach(function (callback) {
|
_this.notificationCallbacks.forEach(function (callback) {
|
||||||
if (utils.isFunction(callback))
|
if (_.isFunction(callback))
|
||||||
callback(new Error('IPC socket connection closed'));
|
callback(new Error('IPC socket connection closed'));
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var utils = require('../../utils/utils');
|
var _ = require('underscore');
|
||||||
var errors = require('../errors');
|
var errors = require('web3-core-helpers').errors;
|
||||||
// var W3CWebSocket = require('websocket').w3cwebsocket;
|
// var W3CWebSocket = require('websocket').w3cwebsocket;
|
||||||
// Default connection ws://localhost:8546
|
// Default connection ws://localhost:8546
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ var WebsocketProvider = function (path) {
|
|||||||
var id = null;
|
var id = null;
|
||||||
|
|
||||||
// get the id which matches the returned id
|
// get the id which matches the returned id
|
||||||
if(utils.isArray(result)) {
|
if(_.isArray(result)) {
|
||||||
result.forEach(function(load){
|
result.forEach(function(load){
|
||||||
if(_this.responseCallbacks[load.id])
|
if(_this.responseCallbacks[load.id])
|
||||||
id = load.id;
|
id = load.id;
|
||||||
@ -61,7 +61,7 @@ var WebsocketProvider = function (path) {
|
|||||||
// notification
|
// notification
|
||||||
if(!id && result.method === 'eth_subscription') {
|
if(!id && result.method === 'eth_subscription') {
|
||||||
_this.notificationCallbacks.forEach(function(callback){
|
_this.notificationCallbacks.forEach(function(callback){
|
||||||
if(utils.isFunction(callback))
|
if(_.isFunction(callback))
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ WebsocketProvider.prototype.addDefaultEvents = function(){
|
|||||||
|
|
||||||
// cancel subscriptions
|
// cancel subscriptions
|
||||||
noteCb.forEach(function (callback) {
|
noteCb.forEach(function (callback) {
|
||||||
if (utils.isFunction(callback))
|
if (_.isFunction(callback))
|
||||||
callback(e);
|
callback(e);
|
||||||
});
|
});
|
||||||
};
|
};
|
13
packages/web3-core-subscriptions/package.json
Normal file
13
packages/web3-core-subscriptions/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-core-subscriptions",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Manages web3 subscriptions. This is an internal package.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core-subscriptions",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"underscore": "^1.8.3",
|
||||||
|
"eventemitter3": "^1.1.1"
|
||||||
|
}
|
||||||
|
}
|
@ -14,11 +14,10 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/** @file subscriptions.js
|
/**
|
||||||
*
|
* @file index.js
|
||||||
* @authors:
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* Fabian Vogelsteller <fabian@ethereum.org>
|
* @date 2017
|
||||||
* @date 2016
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Subscription = require('./subscription.js');
|
var Subscription = require('./subscription.js');
|
||||||
@ -55,6 +54,10 @@ Subscriptions.prototype.buildCall = function() {
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
return function(){
|
return function(){
|
||||||
|
if(!_this.subscriptions[arguments[0]]) {
|
||||||
|
console.warn('Subscription "'+ JSON.stringify(arguments[0]) +'" doesn\'t exist. Subscribing anyway.');
|
||||||
|
}
|
||||||
|
|
||||||
var subscription = new Subscription({
|
var subscription = new Subscription({
|
||||||
subscription: _this.subscriptions[arguments[0]],
|
subscription: _this.subscriptions[arguments[0]],
|
||||||
subscribeMethod: _this.subscribe,
|
subscribeMethod: _this.subscribe,
|
||||||
@ -66,4 +69,8 @@ Subscriptions.prototype.buildCall = function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Subscriptions;
|
|
||||||
|
module.exports = {
|
||||||
|
subscriptions: Subscriptions,
|
||||||
|
subscription: Subscription
|
||||||
|
};
|
@ -14,15 +14,14 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/** @file subscription.js
|
/**
|
||||||
*
|
* @file subscription.js
|
||||||
* @authors:
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* Fabian Vogelsteller <fabian@ethereum.org>
|
* @date 2017
|
||||||
* @date 2016
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var utils = require('../utils/utils');
|
var _ = require('underscore');
|
||||||
var errors = require('./errors');
|
var errors = require('web3-core-helpers').errors;
|
||||||
var EventEmitter = require('eventemitter3');
|
var EventEmitter = require('eventemitter3');
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ var Subscription = function (options) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Subscription.prototype._extractCallback = function (args) {
|
Subscription.prototype._extractCallback = function (args) {
|
||||||
if (utils.isFunction(args[args.length - 1])) {
|
if (_.isFunction(args[args.length - 1])) {
|
||||||
return args.pop(); // modify the args array!
|
return args.pop(); // modify the args array!
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -87,7 +86,7 @@ Subscription.prototype._validateArgs = function (args) {
|
|||||||
subscription.params = 0;
|
subscription.params = 0;
|
||||||
|
|
||||||
if (args.length !== subscription.params + 1) {
|
if (args.length !== subscription.params + 1) {
|
||||||
throw errors.InvalidNumberOfParams();
|
throw errors.InvalidNumberOfParams(args.length, subscription.params + 1, args[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,7 +101,16 @@ Subscription.prototype._validateArgs = function (args) {
|
|||||||
Subscription.prototype._formatInput = function (args) {
|
Subscription.prototype._formatInput = function (args) {
|
||||||
var subscription = this.options.subscription;
|
var subscription = this.options.subscription;
|
||||||
|
|
||||||
if (!subscription || !subscription.inputFormatter) {
|
if (!subscription) {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace subscription with given name
|
||||||
|
if (subscription.subscriptionName) {
|
||||||
|
args[0] = subscription.subscriptionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subscription.inputFormatter) {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +188,7 @@ Subscription.prototype.subscribe = function() {
|
|||||||
this.options.params = payload.params[1];
|
this.options.params = payload.params[1];
|
||||||
|
|
||||||
// get past logs, if fromBlock is available
|
// get past logs, if fromBlock is available
|
||||||
if(payload.params[0] === 'logs' && utils.isObject(payload.params[1]) && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) {
|
if(payload.params[0] === 'logs' && _.isObject(payload.params[1]) && payload.params[1].hasOwnProperty('fromBlock') && isFinite(payload.params[1].fromBlock)) {
|
||||||
// send the subscription request
|
// send the subscription request
|
||||||
this.options.requestManager.send({
|
this.options.requestManager.send({
|
||||||
method: 'eth_getLogs',
|
method: 'eth_getLogs',
|
||||||
@ -213,12 +221,13 @@ Subscription.prototype.subscribe = function() {
|
|||||||
_this.options.requestManager.addSubscription(_this.id, payload.params[0] ,'eth', function(err, result) {
|
_this.options.requestManager.addSubscription(_this.id, payload.params[0] ,'eth', function(err, result) {
|
||||||
|
|
||||||
// TODO remove once its fixed in geth
|
// TODO remove once its fixed in geth
|
||||||
if(utils.isArray(result))
|
if(_.isArray(result))
|
||||||
result = result[0];
|
result = result[0];
|
||||||
|
|
||||||
var output = _this._formatOutput(result);
|
var output = _this._formatOutput(result);
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
// TODO remove eventEmitter??
|
||||||
if(output.removed)
|
if(output.removed)
|
||||||
_this.emit('changed', output);
|
_this.emit('changed', output);
|
||||||
else
|
else
|
14
packages/web3-core/package.json
Normal file
14
packages/web3-core/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-core",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 core tools for sub packages. This is an internal package.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-core",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"web3-core-method": "^1.0.0",
|
||||||
|
"web3-utils": "^1.0.0",
|
||||||
|
"web3-requestManager": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
65
packages/web3-core/src/extend.js
Normal file
65
packages/web3-core/src/extend.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
This file is part of web3.js.
|
||||||
|
|
||||||
|
web3.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.
|
||||||
|
|
||||||
|
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file extend.js
|
||||||
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
|
* @date 2017
|
||||||
|
*/
|
||||||
|
|
||||||
|
var formatters = require('web3-core-helpers').formatters;
|
||||||
|
var Method = require('web3-core-method');
|
||||||
|
var utils = require('web3-utils');
|
||||||
|
|
||||||
|
|
||||||
|
var extend = function (pckg) {
|
||||||
|
/* jshint maxcomplexity:5 */
|
||||||
|
var ex = function (extension) {
|
||||||
|
|
||||||
|
var extendedObject;
|
||||||
|
if (extension.property) {
|
||||||
|
if (!pckg[extension.property]) {
|
||||||
|
pckg[extension.property] = {};
|
||||||
|
}
|
||||||
|
extendedObject = pckg[extension.property];
|
||||||
|
} else {
|
||||||
|
extendedObject = pckg;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extension.methods) {
|
||||||
|
extension.methods.forEach(function (method) {
|
||||||
|
if(!(method instanceof Method)) {
|
||||||
|
method = new Method(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
method.attachToObject(extendedObject);
|
||||||
|
method.setRequestManager(pckg._requestManager);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
ex.formatters = formatters;
|
||||||
|
ex.utils = utils;
|
||||||
|
ex.Method = Method;
|
||||||
|
|
||||||
|
return ex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = extend;
|
||||||
|
|
89
packages/web3-core/src/index.js
Normal file
89
packages/web3-core/src/index.js
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
This file is part of web3.js.
|
||||||
|
|
||||||
|
web3.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.
|
||||||
|
|
||||||
|
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file index.js
|
||||||
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
|
* @date 2017
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var requestManager = require('web3-requestManager');
|
||||||
|
var extend = require('./extend.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
packageInit: function (pkg, args) {
|
||||||
|
args = Array.prototype.slice.call(args);
|
||||||
|
|
||||||
|
if (!pkg) {
|
||||||
|
throw new Error('You need to instantiate using the "new" keyword.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (!args[0]) {
|
||||||
|
// throw new Error('You must pass in a provider as argument!');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// make write only property of pkg.provider
|
||||||
|
Object.defineProperty(pkg, 'currentProvider', {
|
||||||
|
get: function () {
|
||||||
|
return pkg._provider;
|
||||||
|
},
|
||||||
|
set: function () {
|
||||||
|
return pkg._provider;
|
||||||
|
},
|
||||||
|
enumerable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// inherit from web3 umbrella package
|
||||||
|
if (args[0] && args[0]._requestManager) {
|
||||||
|
pkg._requestManager = args[0]._requestManager;
|
||||||
|
pkg._provider = args[0].provider;
|
||||||
|
|
||||||
|
// set requestmanager on package
|
||||||
|
} else {
|
||||||
|
pkg._requestManager = new requestManager.Manager(args[0]);
|
||||||
|
pkg._provider = args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// add providers
|
||||||
|
pkg.providers = requestManager.Manager.providers;
|
||||||
|
|
||||||
|
// add set Provider function
|
||||||
|
pkg.setProvider = function (provider) {
|
||||||
|
pkg._requestManager.setProvider(provider);
|
||||||
|
pkg._provider = provider;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// add reset function
|
||||||
|
pkg.reset = function (keepIsSyncing) {
|
||||||
|
pkg._requestManager.reset(keepIsSyncing);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// attach batch request creation
|
||||||
|
pkg.createBatchRequest = function () {
|
||||||
|
return new requestManager.BatchManager(pkg);
|
||||||
|
};
|
||||||
|
|
||||||
|
// attach extend function
|
||||||
|
pkg.extend = extend(pkg);
|
||||||
|
},
|
||||||
|
addProviders: function (pkg) {
|
||||||
|
pkg.providers = requestManager.Manager.providers;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
20
packages/web3-eth/package.json
Normal file
20
packages/web3-eth/package.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-eth",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 module to interact with the Ethereum blockchain and smart contracts.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core": "^1.0.0",
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"web3-core-iban": "^1.0.0",
|
||||||
|
"web3-core-subscriptions": "^1.0.0",
|
||||||
|
"web3-core-method": "^1.0.0",
|
||||||
|
"web3-utils": "^1.0.0",
|
||||||
|
"underscore": "^1.8.3",
|
||||||
|
"web3-core-promiEvent": "^1.0.0",
|
||||||
|
|
||||||
|
"bignumber.js": "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2"
|
||||||
|
}
|
||||||
|
}
|
@ -20,14 +20,15 @@
|
|||||||
* @date 2016
|
* @date 2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('underscore');
|
||||||
var utils = require('../utils/utils');
|
var Method = require('web3-core-method');
|
||||||
var eventifiedPromise = require('./eventifiedPromise.js');
|
var utils = require('web3-utils');
|
||||||
var Method = require('./method.js');
|
var Subscription = require('web3-core-subscriptions').subscription;
|
||||||
var coder = require('../solidity/coder');
|
var formatters = require('web3-core-helpers').formatters;
|
||||||
var formatters = require('./formatters');
|
var promiEvent = require('web3-core-promiEvent');
|
||||||
var sha3 = require('../utils/sha3');
|
|
||||||
var Subscription = require('./subscription.js');
|
|
||||||
|
var coder = require('./solidity/coder');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,10 +68,9 @@ var Contract = function(jsonInterface, address, options) {
|
|||||||
// set address
|
// set address
|
||||||
Object.defineProperty(this.options, 'address', {
|
Object.defineProperty(this.options, 'address', {
|
||||||
set: function(value){
|
set: function(value){
|
||||||
if(utils.isAddress(value))
|
if(value) {
|
||||||
this._address = value.toLowerCase();
|
this._address = formatters.inputAddressFormatter(value);
|
||||||
else if(value)
|
}
|
||||||
throw new Error('The provided contract address is not a valid address.');
|
|
||||||
},
|
},
|
||||||
get: function(){
|
get: function(){
|
||||||
return this._address;
|
return this._address;
|
||||||
@ -95,7 +95,7 @@ var Contract = function(jsonInterface, address, options) {
|
|||||||
|
|
||||||
// function
|
// function
|
||||||
if (method.type === 'function') {
|
if (method.type === 'function') {
|
||||||
method.signature = '0x'+ sha3(utils.transformToFullName(method)).slice(0, 8);
|
method.signature = utils.sha3(utils.transformToFullName(method)).slice(0, 10);
|
||||||
func = _this._createTxObject.bind({
|
func = _this._createTxObject.bind({
|
||||||
method: method,
|
method: method,
|
||||||
parent: _this
|
parent: _this
|
||||||
@ -112,14 +112,10 @@ var Contract = function(jsonInterface, address, options) {
|
|||||||
// add method by name
|
// add method by name
|
||||||
_this.methods[funcName] = func;
|
_this.methods[funcName] = func;
|
||||||
|
|
||||||
// also add to the main contract object
|
|
||||||
// if(!_this[method.name] || _this[method.name].name === 'bound _createTxObject')
|
|
||||||
// _this[method.name] = _this.methods[method.name];
|
|
||||||
// _this[method.signature] = _this.methods[method.signature];
|
|
||||||
|
|
||||||
// event
|
// event
|
||||||
} else if (method.type === 'event') {
|
} else if (method.type === 'event') {
|
||||||
method.signature = '0x'+ sha3(utils.transformToFullName(method));
|
method.signature = utils.sha3(utils.transformToFullName(method));
|
||||||
var event = _this._on.bind(_this, method.signature);
|
var event = _this._on.bind(_this, method.signature);
|
||||||
|
|
||||||
// add method only if not already exists
|
// add method only if not already exists
|
||||||
@ -161,7 +157,7 @@ var Contract = function(jsonInterface, address, options) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Contract.prototype._web3 = {}; // web3 is attached here in eth.js
|
Contract.prototype._eth = {}; // eth is attached here in web3-eth/src/index.js
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -333,8 +329,6 @@ Contract.prototype._decodeEventABI = function (data) {
|
|||||||
|
|
||||||
result.event = event.name;
|
result.event = event.name;
|
||||||
|
|
||||||
//delete result.data;
|
|
||||||
//delete result.topics;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -354,7 +348,7 @@ Contract.prototype._encodeMethodABI = function _encodeMethodABI() {
|
|||||||
var signature = false,
|
var signature = false,
|
||||||
paramsABI = this._parent.options.jsonInterface.filter(function (json) {
|
paramsABI = this._parent.options.jsonInterface.filter(function (json) {
|
||||||
return ((methodSignature === 'constructor' && json.type === methodSignature) ||
|
return ((methodSignature === 'constructor' && json.type === methodSignature) ||
|
||||||
((json.signature === methodSignature || json.signature === '0x'+ methodSignature.replace('0x','') || json.name === methodSignature) && json.type === 'function'));
|
((json.signature === methodSignature || json.signature === methodSignature.replace('0x','') || json.name === methodSignature) && json.type === 'function'));
|
||||||
}).map(function (json) {
|
}).map(function (json) {
|
||||||
if(json.inputs.length !== args.length) {
|
if(json.inputs.length !== args.length) {
|
||||||
throw new Error('The number of arguments is not matching the methods required number. You need to pass '+ json.inputs.length +' arguments.');
|
throw new Error('The number of arguments is not matching the methods required number. You need to pass '+ json.inputs.length +' arguments.');
|
||||||
@ -436,10 +430,9 @@ Contract.prototype.deploy = function(options, callback){
|
|||||||
|
|
||||||
// return error, if no "data" is specified
|
// return error, if no "data" is specified
|
||||||
if(!options.data) {
|
if(!options.data) {
|
||||||
return utils._fireError(new Error('No "data" specified in neither the given options, nor the default options.'), defer.promise, defer.reject, callback);
|
return utils._fireError(new Error('No "data" specified in neither the given options, nor the default options.'), null, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return defer.promise;
|
|
||||||
var constructor = _.find(this.options.jsonInterface, function (method) {
|
var constructor = _.find(this.options.jsonInterface, function (method) {
|
||||||
return (method.type === 'constructor');
|
return (method.type === 'constructor');
|
||||||
}) || {};
|
}) || {};
|
||||||
@ -550,7 +543,7 @@ Contract.prototype._on = function(){
|
|||||||
},
|
},
|
||||||
subscribeMethod: 'eth_subscribe',
|
subscribeMethod: 'eth_subscribe',
|
||||||
unsubscribeMethod: 'eth_unsubscribe',
|
unsubscribeMethod: 'eth_unsubscribe',
|
||||||
requestManager: this._web3._requestManager
|
requestManager: this._eth._requestManager
|
||||||
});
|
});
|
||||||
subscription.subscribe('logs', subOptions.params, subOptions.callback || function () {});
|
subscription.subscribe('logs', subOptions.params, subOptions.callback || function () {});
|
||||||
|
|
||||||
@ -576,7 +569,7 @@ Contract.prototype.getPastEvents = function(){
|
|||||||
inputFormatter: [formatters.inputLogFormatter],
|
inputFormatter: [formatters.inputLogFormatter],
|
||||||
outputFormatter: this._decodeEventABI.bind(subOptions.event)
|
outputFormatter: this._decodeEventABI.bind(subOptions.event)
|
||||||
});
|
});
|
||||||
getPastLogs.setRequestManager(this._web3._requestManager);
|
getPastLogs.setRequestManager(this._eth._requestManager);
|
||||||
var call = getPastLogs.buildCall();
|
var call = getPastLogs.buildCall();
|
||||||
|
|
||||||
getPastLogs = null;
|
getPastLogs = null;
|
||||||
@ -617,112 +610,6 @@ Contract.prototype._createTxObject = function _createTxObject(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The callback called when executing a method
|
|
||||||
*
|
|
||||||
* @method _methodReturnCallback
|
|
||||||
* @param {Object} err
|
|
||||||
* @param {Mixed} returnValue
|
|
||||||
*/
|
|
||||||
Contract.prototype._methodReturnCallback = function methodReturnCallback(defer, callback, type, err, returnValue) {
|
|
||||||
var _this = this,
|
|
||||||
error = new Error('Failed to check for transaction receipt.'),
|
|
||||||
callbackFired = false;
|
|
||||||
|
|
||||||
if(type === 'call') {
|
|
||||||
returnValue = _this._parent._decodeMethodReturn(_this._method.outputs, returnValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
return utils._fireError(err, defer.promise, defer.reject, callback);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// send immediate returnValue (see end of the function for resolve event of call and estimateGas)
|
|
||||||
if(callback) {
|
|
||||||
callback(null, returnValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for receipt on send
|
|
||||||
if(type === 'send') {
|
|
||||||
|
|
||||||
defer.promise.emit('transactionHash', returnValue);
|
|
||||||
|
|
||||||
// fire "receipt" event and resolve after
|
|
||||||
_this._parent._web3.eth.subscribe('newBlocks', {}, function (err, block, sub) {
|
|
||||||
if(!err) {
|
|
||||||
|
|
||||||
_this._parent._web3.eth.getTransactionReceipt(returnValue, function (err, receipt) {
|
|
||||||
if(!err) {
|
|
||||||
if(!callbackFired && receipt) {
|
|
||||||
|
|
||||||
// CHECK for contract deployment
|
|
||||||
if(_this._deployData) {
|
|
||||||
|
|
||||||
if(!receipt.contractAddress) {
|
|
||||||
callbackFired = true;
|
|
||||||
return utils._fireError(new Error('The transaction receipt didn\'t contain a contract address.'), defer.promise, defer.reject);
|
|
||||||
}
|
|
||||||
|
|
||||||
_this._parent._web3.eth.getCode(receipt.contractAddress, function(e, code){
|
|
||||||
|
|
||||||
if(!code)
|
|
||||||
return;
|
|
||||||
|
|
||||||
sub.unsubscribe();
|
|
||||||
callbackFired = true;
|
|
||||||
|
|
||||||
if(code.length > 2) {
|
|
||||||
defer.promise.emit('receipt', receipt);
|
|
||||||
defer.resolve(receipt);
|
|
||||||
defer.promise.removeAllListeners();
|
|
||||||
} else {
|
|
||||||
return utils._fireError(new Error('The contract code couldn\'t be stored, please check your gas limit.'), defer.promise, defer.reject);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CHECK for normal tx check for receipt only
|
|
||||||
} else {
|
|
||||||
sub.unsubscribe();
|
|
||||||
callbackFired = true;
|
|
||||||
|
|
||||||
if(!receipt.outOfGas) {
|
|
||||||
defer.promise.emit('receipt', receipt);
|
|
||||||
defer.resolve(receipt);
|
|
||||||
defer.promise.removeAllListeners();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return utils._fireError(new Error('Transaction ran out of gas.'), defer.promise, defer.reject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sub.unsubscribe();
|
|
||||||
callbackFired = true;
|
|
||||||
return utils._fireError(error, defer.promise, defer.reject);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sub.unsubscribe();
|
|
||||||
callbackFired = true;
|
|
||||||
return utils._fireError(error, defer.promise, defer.reject);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// remove all listeners on the end, as no event will ever fire again
|
|
||||||
defer.resolve(returnValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the options for the execute call
|
* Generates the options for the execute call
|
||||||
*
|
*
|
||||||
@ -745,7 +632,7 @@ Contract.prototype._processExecuteArguments = function _processExecuteArguments(
|
|||||||
// get the options
|
// get the options
|
||||||
processedArgs.options = (utils.isObject(args[args.length - 1])) ? args.pop() : {};
|
processedArgs.options = (utils.isObject(args[args.length - 1])) ? args.pop() : {};
|
||||||
|
|
||||||
// get the generateRequest argument
|
// get the generateRequest argument for batch requests
|
||||||
processedArgs.generateRequest = (args[args.length - 1] === true)? args.pop() : false;
|
processedArgs.generateRequest = (args[args.length - 1] === true)? args.pop() : false;
|
||||||
|
|
||||||
processedArgs.options = this._parent._fillWithDefaultOptions(processedArgs.options);
|
processedArgs.options = this._parent._fillWithDefaultOptions(processedArgs.options);
|
||||||
@ -760,7 +647,7 @@ Contract.prototype._processExecuteArguments = function _processExecuteArguments(
|
|||||||
|
|
||||||
// return error, if no "data" is specified
|
// return error, if no "data" is specified
|
||||||
if(!processedArgs.options.data)
|
if(!processedArgs.options.data)
|
||||||
return utils._fireError(new Error('Couldn\'t find a matching contract method, or the number of parameters is wrong.'), defer.promise, defer.reject, processedArgs.callback);
|
return utils._fireError(new Error('Couldn\'t find a matching contract method, or the number of parameters is wrong.'), defer.eventEmitter, defer.reject, processedArgs.callback);
|
||||||
|
|
||||||
return processedArgs;
|
return processedArgs;
|
||||||
};
|
};
|
||||||
@ -773,11 +660,12 @@ Contract.prototype._processExecuteArguments = function _processExecuteArguments(
|
|||||||
* @param {Boolean} makeRequest if true, it simply returns the request parameters, rather than executing it
|
* @param {Boolean} makeRequest if true, it simply returns the request parameters, rather than executing it
|
||||||
*/
|
*/
|
||||||
Contract.prototype._executeMethod = function _executeMethod(){
|
Contract.prototype._executeMethod = function _executeMethod(){
|
||||||
var args = this._parent._processExecuteArguments.call(this, Array.prototype.slice.call(arguments), defer),
|
var _this = this,
|
||||||
defer = eventifiedPromise((args.type !== 'send'));
|
args = this._parent._processExecuteArguments.call(this, Array.prototype.slice.call(arguments), defer),
|
||||||
|
defer = promiEvent((args.type !== 'send'));
|
||||||
|
|
||||||
|
|
||||||
// simple return request
|
// simple return request for batch requests
|
||||||
if(args.generateRequest) {
|
if(args.generateRequest) {
|
||||||
|
|
||||||
var payload = {
|
var payload = {
|
||||||
@ -796,40 +684,52 @@ Contract.prototype._executeMethod = function _executeMethod(){
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var methodReturnCallback = this._parent._methodReturnCallback.bind(this, defer, args.callback, args.type);
|
|
||||||
|
|
||||||
switch (args.type) {
|
switch (args.type) {
|
||||||
case 'estimate':
|
case 'estimate':
|
||||||
|
|
||||||
this._parent._web3.eth.estimateGas(args.options, methodReturnCallback);
|
return this._parent._eth.estimateGas(args.options, args.callback);
|
||||||
|
|
||||||
break;
|
|
||||||
case 'call':
|
case 'call':
|
||||||
|
|
||||||
// TODO check errors: missing "from" should give error on deploy and send, call ?
|
// TODO check errors: missing "from" should give error on deploy and send, call ?
|
||||||
|
|
||||||
this._parent._web3.eth.call(args.options, args.defaultBlock, methodReturnCallback);
|
this._parent._eth.call(args.options, args.defaultBlock, function (err, result) {
|
||||||
|
|
||||||
|
// decode result
|
||||||
|
if(result) {
|
||||||
|
result = _this._parent._decodeMethodReturn(_this._method.outputs, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// throw error
|
||||||
|
if(err) {
|
||||||
|
return utils._fireError(err, null, defer.reject, args.callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_.isFunction(args.callback)) {
|
||||||
|
args.callback(null, result);
|
||||||
|
}
|
||||||
|
defer.resolve(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
return defer.eventEmitter;
|
||||||
|
|
||||||
break;
|
|
||||||
case 'send':
|
case 'send':
|
||||||
|
|
||||||
// return error, if no "from" is specified
|
// return error, if no "from" is specified
|
||||||
if(!utils.isAddress(args.options.from)) {
|
if(!utils.isAddress(args.options.from)) {
|
||||||
return utils._fireError(new Error('No "from" address specified in neither the given options, nor the default options.'), defer.promise, defer.reject, args.callback);
|
return utils._fireError(new Error('No "from" address specified in neither the given options, nor the default options.'), defer.eventEmitter, defer.reject, args.callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isBoolean(this._method.payable) && !this._method.payable && args.options.value && args.options.value > 0) {
|
if (_.isBoolean(this._method.payable) && !this._method.payable && args.options.value && args.options.value > 0) {
|
||||||
return utils._fireError(new Error('Can not send value to non-payable contract method or constructor'), defer.promise, defer.reject, args.callback);
|
return utils._fireError(new Error('Can not send value to non-payable contract method or constructor'), defer.eventEmitter, defer.reject, args.callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._parent._web3.eth.sendTransaction(args.options, methodReturnCallback);
|
return this._parent._eth.sendTransaction(args.options, args.callback);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return defer.promise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Contract;
|
module.exports = Contract;
|
@ -15,98 +15,162 @@
|
|||||||
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file eth.js
|
* @file index.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @author Fabian Vogelsteller <fabian@ethdev.com>
|
* @date 2017
|
||||||
* @date 2015
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var formatters = require('../formatters');
|
var _ = require('underscore');
|
||||||
var utils = require('../../utils/utils');
|
var core = require('web3-core');
|
||||||
var c = require('../../utils/config');
|
var helpers = require('web3-core-helpers');
|
||||||
var Method = require('../method');
|
var Subscriptions = require('web3-core-subscriptions').subscriptions;
|
||||||
var Property = require('../property');
|
var utils = require('web3-utils');
|
||||||
var Subscriptions = require('../subscriptions');
|
var Method = require('web3-core-method');
|
||||||
var Contract = require('../contract');
|
var Contract = require('./contract');
|
||||||
var namereg = require('../namereg');
|
var Iban = require('web3-core-iban');
|
||||||
var Iban = require('../iban');
|
|
||||||
var transfer = require('../transfer');
|
var formatters = helpers.formatters;
|
||||||
|
|
||||||
|
|
||||||
var blockCall = function (args) {
|
var blockCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
|
return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
|
||||||
};
|
};
|
||||||
|
|
||||||
var transactionFromBlockCall = function (args) {
|
var transactionFromBlockCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
|
return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
|
||||||
};
|
};
|
||||||
|
|
||||||
var uncleCall = function (args) {
|
var uncleCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
|
return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
|
||||||
};
|
};
|
||||||
|
|
||||||
var getBlockTransactionCountCall = function (args) {
|
var getBlockTransactionCountCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
|
return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
|
||||||
};
|
};
|
||||||
|
|
||||||
var uncleCountCall = function (args) {
|
var uncleCountCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
|
return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
|
||||||
};
|
};
|
||||||
|
|
||||||
function Eth(web3) {
|
|
||||||
this._requestManager = web3._requestManager;
|
|
||||||
|
|
||||||
var self = this;
|
function Eth() {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// sets _requestmanager
|
||||||
|
core.packageInit(this, arguments);
|
||||||
|
|
||||||
|
|
||||||
methods().forEach(function(method) {
|
methods().forEach(function(method) {
|
||||||
method.attachToObject(self);
|
method.attachToObject(_this);
|
||||||
method.setRequestManager(self._requestManager);
|
method.setRequestManager(_this._requestManager, _this); // second param means is Eth (necessary for promiEvent)
|
||||||
});
|
});
|
||||||
|
|
||||||
properties().forEach(function(p) {
|
|
||||||
p.attachToObject(self);
|
|
||||||
p.setRequestManager(self._requestManager);
|
|
||||||
});
|
|
||||||
|
|
||||||
// add contract
|
// add contract
|
||||||
this.contract = Contract;
|
this.contract = Contract;
|
||||||
this.contract.prototype._web3 = web3;
|
this.contract.prototype._eth = this;
|
||||||
|
|
||||||
this.iban = Iban;
|
// add IBAN
|
||||||
this.sendIBANTransaction = transfer.bind(null, this);
|
this.iban = {
|
||||||
|
_Iban: Iban,
|
||||||
|
toAddress: function (ib) {
|
||||||
|
ib = new Iban(ib);
|
||||||
|
|
||||||
this.namereg = function () {
|
if(!ib.isDirect()) {
|
||||||
return this.contract(namereg.global.abi).at(namereg.global.address);
|
throw new Error('IBAN is indirect and can\'t be converted');
|
||||||
|
}
|
||||||
|
|
||||||
|
return ib.address();
|
||||||
|
},
|
||||||
|
toIBAN: function (address) {
|
||||||
|
return Iban.fromAddress(address).toString();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.icapNamereg = function () {
|
|
||||||
return this.contract(namereg.icap.abi).at(namereg.icap.address);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.addProviders(Eth);
|
||||||
|
|
||||||
|
|
||||||
Object.defineProperty(Eth.prototype, 'defaultBlock', {
|
Object.defineProperty(Eth.prototype, 'defaultBlock', {
|
||||||
get: function () {
|
get: function () {
|
||||||
return c.defaultBlock;
|
return helpers.config.defaultBlock;
|
||||||
},
|
},
|
||||||
set: function (val) {
|
set: function (val) {
|
||||||
c.defaultBlock = val;
|
helpers.config.defaultBlock = val;
|
||||||
return val;
|
return val;
|
||||||
}
|
},
|
||||||
|
enumerable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(Eth.prototype, 'defaultAccount', {
|
Object.defineProperty(Eth.prototype, 'defaultAccount', {
|
||||||
get: function () {
|
get: function () {
|
||||||
return c.defaultAccount;
|
return helpers.config.defaultAccount;
|
||||||
},
|
},
|
||||||
set: function (val) {
|
set: function (val) {
|
||||||
c.defaultAccount = val;
|
helpers.config.defaultAccount = val;
|
||||||
return val;
|
return val;
|
||||||
}
|
},
|
||||||
|
enumerable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var methods = function () {
|
var methods = function () {
|
||||||
|
|
||||||
|
var getVersion = new Method({
|
||||||
|
name: 'getProtocolVersion',
|
||||||
|
call: 'eth_protocolVersion',
|
||||||
|
params: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var getCoinbase = new Method({
|
||||||
|
name: 'getCoinbase',
|
||||||
|
call: 'eth_coinbase',
|
||||||
|
params: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var getMining = new Method({
|
||||||
|
name: 'isMining',
|
||||||
|
call: 'eth_mining',
|
||||||
|
params: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var getHashrate = new Method({
|
||||||
|
name: 'getHashrate',
|
||||||
|
call: 'eth_hashrate',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: utils.toDecimal
|
||||||
|
});
|
||||||
|
|
||||||
|
var getSyncing = new Method({
|
||||||
|
name: 'getSyncing',
|
||||||
|
call: 'eth_syncing',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: formatters.outputSyncingFormatter
|
||||||
|
});
|
||||||
|
|
||||||
|
var getGasPrice = new Method({
|
||||||
|
name: 'getGasPrice',
|
||||||
|
call: 'eth_gasPrice',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: formatters.outputBigNumberFormatter
|
||||||
|
});
|
||||||
|
|
||||||
|
var getAccounts = new Method({
|
||||||
|
name: 'getAccounts',
|
||||||
|
call: 'eth_accounts',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: utils.toChecksumAddress
|
||||||
|
});
|
||||||
|
|
||||||
|
var getBlockNumber = new Method({
|
||||||
|
name: 'getBlockNumber',
|
||||||
|
call: 'eth_blockNumber',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: utils.toDecimal
|
||||||
|
});
|
||||||
|
|
||||||
var getBalance = new Method({
|
var getBalance = new Method({
|
||||||
name: 'getBalance',
|
name: 'getBalance',
|
||||||
call: 'eth_getBalance',
|
call: 'eth_getBalance',
|
||||||
@ -119,7 +183,7 @@ var methods = function () {
|
|||||||
name: 'getStorageAt',
|
name: 'getStorageAt',
|
||||||
call: 'eth_getStorageAt',
|
call: 'eth_getStorageAt',
|
||||||
params: 3,
|
params: 3,
|
||||||
inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
|
inputFormatter: [formatters.inputAddressFormatter, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
|
||||||
});
|
});
|
||||||
|
|
||||||
var getCode = new Method({
|
var getCode = new Method({
|
||||||
@ -166,6 +230,7 @@ var methods = function () {
|
|||||||
name: 'getTransaction',
|
name: 'getTransaction',
|
||||||
call: 'eth_getTransactionByHash',
|
call: 'eth_getTransactionByHash',
|
||||||
params: 1,
|
params: 1,
|
||||||
|
inputFormatter: [formatters.inputAddressFormatter],
|
||||||
outputFormatter: formatters.outputTransactionFormatter
|
outputFormatter: formatters.outputTransactionFormatter
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,6 +246,7 @@ var methods = function () {
|
|||||||
name: 'getTransactionReceipt',
|
name: 'getTransactionReceipt',
|
||||||
call: 'eth_getTransactionReceipt',
|
call: 'eth_getTransactionReceipt',
|
||||||
params: 1,
|
params: 1,
|
||||||
|
inputFormatter: [null],
|
||||||
outputFormatter: formatters.outputTransactionReceiptFormatter
|
outputFormatter: formatters.outputTransactionReceiptFormatter
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -192,8 +258,8 @@ var methods = function () {
|
|||||||
outputFormatter: utils.toDecimal
|
outputFormatter: utils.toDecimal
|
||||||
});
|
});
|
||||||
|
|
||||||
var sendRawTransaction = new Method({
|
var sendSignedTransaction = new Method({
|
||||||
name: 'sendRawTransaction',
|
name: 'sendSignedTransaction',
|
||||||
call: 'eth_sendRawTransaction',
|
call: 'eth_sendRawTransaction',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: [null]
|
inputFormatter: [null]
|
||||||
@ -279,8 +345,10 @@ var methods = function () {
|
|||||||
subscribe: 'eth_subscribe',
|
subscribe: 'eth_subscribe',
|
||||||
unsubscribe: 'eth_unsubscribe',
|
unsubscribe: 'eth_unsubscribe',
|
||||||
subscriptions: {
|
subscriptions: {
|
||||||
'newBlocks': {
|
'newBlockHeaders': {
|
||||||
params: 1,
|
// TODO change name on RPC side?
|
||||||
|
subscriptionName: 'newHeads', // replace subscription with this name
|
||||||
|
params: 0,
|
||||||
outputFormatter: formatters.outputBlockFormatter
|
outputFormatter: formatters.outputBlockFormatter
|
||||||
},
|
},
|
||||||
'pendingTransactions': {
|
'pendingTransactions': {
|
||||||
@ -301,6 +369,14 @@ var methods = function () {
|
|||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
getVersion,
|
||||||
|
getCoinbase,
|
||||||
|
getMining,
|
||||||
|
getHashrate,
|
||||||
|
getSyncing,
|
||||||
|
getGasPrice,
|
||||||
|
getAccounts,
|
||||||
|
getBlockNumber,
|
||||||
getBalance,
|
getBalance,
|
||||||
getStorageAt,
|
getStorageAt,
|
||||||
getCode,
|
getCode,
|
||||||
@ -315,7 +391,7 @@ var methods = function () {
|
|||||||
getTransactionCount,
|
getTransactionCount,
|
||||||
call,
|
call,
|
||||||
estimateGas,
|
estimateGas,
|
||||||
sendRawTransaction,
|
sendSignedTransaction,
|
||||||
sendTransaction,
|
sendTransaction,
|
||||||
sign,
|
sign,
|
||||||
compileSolidity,
|
compileSolidity,
|
||||||
@ -323,50 +399,8 @@ var methods = function () {
|
|||||||
compileSerpent,
|
compileSerpent,
|
||||||
submitWork,
|
submitWork,
|
||||||
getWork,
|
getWork,
|
||||||
subscribe,
|
getPastLogs,
|
||||||
getPastLogs
|
subscribe
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var properties = function () {
|
|
||||||
return [
|
|
||||||
new Property({
|
|
||||||
name: 'coinbase',
|
|
||||||
getter: 'eth_coinbase'
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'mining',
|
|
||||||
getter: 'eth_mining'
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'hashrate',
|
|
||||||
getter: 'eth_hashrate',
|
|
||||||
outputFormatter: utils.toDecimal
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'syncing',
|
|
||||||
getter: 'eth_syncing',
|
|
||||||
outputFormatter: formatters.outputSyncingFormatter
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'gasPrice',
|
|
||||||
getter: 'eth_gasPrice',
|
|
||||||
outputFormatter: formatters.outputBigNumberFormatter
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'accounts',
|
|
||||||
getter: 'eth_accounts'
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'blockNumber',
|
|
||||||
getter: 'eth_blockNumber',
|
|
||||||
outputFormatter: utils.toDecimal
|
|
||||||
}),
|
|
||||||
new Property({
|
|
||||||
name: 'protocolVersion',
|
|
||||||
getter: 'eth_protocolVersion'
|
|
||||||
})
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
@ -21,8 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var BigNumber = require('bignumber.js');
|
var BigNumber = require('bignumber.js');
|
||||||
var utils = require('../utils/utils');
|
var utils = require('web3-utils');
|
||||||
var c = require('../utils/config');
|
var c = require('web3-core-helpers').config;
|
||||||
var SolidityParam = require('./param');
|
var SolidityParam = require('./param');
|
||||||
|
|
||||||
|
|
||||||
@ -133,9 +133,9 @@ var formatOutputInt = function (param) {
|
|||||||
// check if it's negative number
|
// check if it's negative number
|
||||||
// it it is, return two's complement
|
// it it is, return two's complement
|
||||||
if (signedIsNegative(value)) {
|
if (signedIsNegative(value)) {
|
||||||
return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
|
return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1).toFixed();
|
||||||
}
|
}
|
||||||
return new BigNumber(value, 16);
|
return new BigNumber(value, 16).toFixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,11 +143,11 @@ var formatOutputInt = function (param) {
|
|||||||
*
|
*
|
||||||
* @method formatOutputUInt
|
* @method formatOutputUInt
|
||||||
* @param {SolidityParam}
|
* @param {SolidityParam}
|
||||||
* @returns {BigNumeber} right-aligned output bytes formatted to uint
|
* @returns {BigNumber} right-aligned output bytes formatted to uint
|
||||||
*/
|
*/
|
||||||
var formatOutputUInt = function (param) {
|
var formatOutputUInt = function (param) {
|
||||||
var value = param.staticPart() || "0";
|
var value = param.staticPart() || "0";
|
||||||
return new BigNumber(value, 16);
|
return new BigNumber(value, 16).toFixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -158,7 +158,7 @@ var formatOutputUInt = function (param) {
|
|||||||
* @returns {BigNumber} input bytes formatted to real
|
* @returns {BigNumber} input bytes formatted to real
|
||||||
*/
|
*/
|
||||||
var formatOutputReal = function (param) {
|
var formatOutputReal = function (param) {
|
||||||
return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128));
|
return new BigNumber(formatOutputInt(param)).dividedBy(new BigNumber(2).pow(128)).toFixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,7 +169,7 @@ var formatOutputReal = function (param) {
|
|||||||
* @returns {BigNumber} input bytes formatted to ureal
|
* @returns {BigNumber} input bytes formatted to ureal
|
||||||
*/
|
*/
|
||||||
var formatOutputUReal = function (param) {
|
var formatOutputUReal = function (param) {
|
||||||
return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128));
|
return new BigNumber(formatOutputUInt(param)).dividedBy(new BigNumber(2).pow(128)).toFixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
@ -14,13 +14,13 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file param.js
|
* @file param.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Marek Kotewicz <marek@ethdev.com>
|
||||||
* @date 2015
|
* @date 2015
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var utils = require('../utils/utils');
|
var utils = require('web3-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SolidityParam object prototype.
|
* SolidityParam object prototype.
|
||||||
@ -33,7 +33,7 @@ var SolidityParam = function (value, offset) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method should be used to get length of params's dynamic part
|
* This method should be used to get length of params's dynamic part
|
||||||
*
|
*
|
||||||
* @method dynamicPartLength
|
* @method dynamicPartLength
|
||||||
* @returns {Number} length of dynamic part (in bytes)
|
* @returns {Number} length of dynamic part (in bytes)
|
||||||
*/
|
*/
|
||||||
@ -61,7 +61,7 @@ SolidityParam.prototype.withOffset = function (offset) {
|
|||||||
* @param {SolidityParam} result of combination
|
* @param {SolidityParam} result of combination
|
||||||
*/
|
*/
|
||||||
SolidityParam.prototype.combine = function (param) {
|
SolidityParam.prototype.combine = function (param) {
|
||||||
return new SolidityParam(this.value + param.value);
|
return new SolidityParam(this.value + param.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,8 +93,8 @@ SolidityParam.prototype.offsetAsBytes = function () {
|
|||||||
*/
|
*/
|
||||||
SolidityParam.prototype.staticPart = function () {
|
SolidityParam.prototype.staticPart = function () {
|
||||||
if (!this.isDynamic()) {
|
if (!this.isDynamic()) {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
return this.offsetAsBytes();
|
return this.offsetAsBytes();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ SolidityParam.prototype.encode = function () {
|
|||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
SolidityParam.encodeList = function (params) {
|
SolidityParam.encodeList = function (params) {
|
||||||
|
|
||||||
// updating offsets
|
// updating offsets
|
||||||
var totalOffset = params.length * 32;
|
var totalOffset = params.length * 32;
|
||||||
var offsetParams = params.map(function (param) {
|
var offsetParams = params.map(function (param) {
|
13
packages/web3-net/package.json
Normal file
13
packages/web3-net/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-net",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 module to interact with the Ethereum nodes networking properties.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-net",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core": "^1.0.0",
|
||||||
|
"web3-core-method": "^1.0.0",
|
||||||
|
"web3-utils": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
72
packages/web3-net/src/index.js
Normal file
72
packages/web3-net/src/index.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
This file is part of web3.js.
|
||||||
|
|
||||||
|
web3.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.
|
||||||
|
|
||||||
|
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file index.js
|
||||||
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
|
* @date 2017
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var core = require('web3-core');
|
||||||
|
var Method = require('web3-core-method');
|
||||||
|
var utils = require('web3-utils');
|
||||||
|
|
||||||
|
|
||||||
|
var Net = function () {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// sets _requestmanager
|
||||||
|
core.packageInit(this, arguments);
|
||||||
|
|
||||||
|
|
||||||
|
methods().forEach(function(method) {
|
||||||
|
method.attachToObject(_this);
|
||||||
|
method.setRequestManager(_this._requestManager);
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
core.addProviders(Net);
|
||||||
|
|
||||||
|
|
||||||
|
var methods = function () {
|
||||||
|
|
||||||
|
var getListening = new Method({
|
||||||
|
name: 'isListening',
|
||||||
|
call: 'net_listening',
|
||||||
|
params: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var getPeerCount = new Method({
|
||||||
|
name: 'getPeerCount',
|
||||||
|
call: 'net_peerCount',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: utils.toDecimal
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
getListening,
|
||||||
|
getPeerCount
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = Net;
|
||||||
|
|
||||||
|
|
14
packages/web3-personal/package.json
Normal file
14
packages/web3-personal/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-personal",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-personal",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core": "^1.0.0",
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"web3-core-method": "^1.0.0",
|
||||||
|
"web3-utils": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
@ -15,40 +15,51 @@
|
|||||||
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file eth.js
|
* @file index.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @author Fabian Vogelsteller <fabian@ethdev.com>
|
* @date 2017
|
||||||
* @date 2015
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Method = require('../method');
|
var core = require('web3-core');
|
||||||
var Property = require('../property');
|
var Method = require('web3-core-method');
|
||||||
var formatters = require('../formatters');
|
var utils = require('web3-utils');
|
||||||
|
|
||||||
function Personal(web3) {
|
var formatters = require('web3-core-helpers').formatters;
|
||||||
this._requestManager = web3._requestManager;
|
|
||||||
|
|
||||||
|
function Personal() {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// sets _requestmanager
|
||||||
|
core.packageInit(this, arguments);
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
methods().forEach(function(method) {
|
methods().forEach(function(method) {
|
||||||
method.attachToObject(self);
|
method.attachToObject(_this);
|
||||||
method.setRequestManager(self._requestManager);
|
method.setRequestManager(_this._requestManager);
|
||||||
});
|
|
||||||
|
|
||||||
properties().forEach(function(p) {
|
|
||||||
p.attachToObject(self);
|
|
||||||
p.setRequestManager(self._requestManager);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.addProviders(Personal);
|
||||||
|
|
||||||
|
|
||||||
var methods = function () {
|
var methods = function () {
|
||||||
|
|
||||||
|
var getAccounts = new Method({
|
||||||
|
name: 'getAccounts',
|
||||||
|
call: 'personal_listAccounts',
|
||||||
|
params: 0,
|
||||||
|
outputFormatter: utils.toChecksumAddress
|
||||||
|
});
|
||||||
|
|
||||||
var newAccount = new Method({
|
var newAccount = new Method({
|
||||||
name: 'newAccount',
|
name: 'newAccount',
|
||||||
call: 'personal_newAccount',
|
call: 'personal_newAccount',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: [null]
|
inputFormatter: [null],
|
||||||
|
outputFormatter: utils.toChecksumAddress
|
||||||
});
|
});
|
||||||
|
|
||||||
var unlockAccount = new Method({
|
var unlockAccount = new Method({
|
||||||
@ -72,7 +83,9 @@ var methods = function () {
|
|||||||
inputFormatter: [formatters.inputAddressFormatter]
|
inputFormatter: [formatters.inputAddressFormatter]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
getAccounts,
|
||||||
newAccount,
|
newAccount,
|
||||||
unlockAccount,
|
unlockAccount,
|
||||||
sendTransaction,
|
sendTransaction,
|
||||||
@ -80,14 +93,7 @@ var methods = function () {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
var properties = function () {
|
|
||||||
return [
|
|
||||||
new Property({
|
|
||||||
name: 'listAccounts',
|
|
||||||
getter: 'personal_listAccounts'
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = Personal;
|
module.exports = Personal;
|
||||||
|
|
||||||
|
|
14
packages/web3-shh/package.json
Normal file
14
packages/web3-shh/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-shh",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Web3 module to interact with the Whisper messaging protocol.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-shh",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"web3-core": "^1.0.0",
|
||||||
|
"web3-core-helpers": "^1.0.0",
|
||||||
|
"web3-core-method": "^1.0.0",
|
||||||
|
"web3-core-subscriptions": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
@ -14,34 +14,42 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/** @file shh.js
|
/**
|
||||||
* @authors:
|
* @file index.js
|
||||||
* Marek Kotewicz <marek@ethdev.com>
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
* @date 2015
|
* @date 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Method = require('../method');
|
"use strict";
|
||||||
var formatters = require('../formatters');
|
|
||||||
var Subscriptions = require('../subscriptions');
|
var core = require('web3-core');
|
||||||
|
var Subscriptions = require('web3-core-subscriptions').subscriptions;
|
||||||
|
var Method = require('web3-core-method');
|
||||||
|
|
||||||
|
var formatters = require('web3-core-helpers').formatters;
|
||||||
|
|
||||||
|
|
||||||
var Shh = function (web3) {
|
var Shh = function () {
|
||||||
this._requestManager = web3._requestManager;
|
var _this = this;
|
||||||
|
|
||||||
var self = this;
|
// sets _requestmanager
|
||||||
|
core.packageInit(this, arguments);
|
||||||
|
|
||||||
methods().forEach(function(method) {
|
|
||||||
method.attachToObject(self);
|
methods().forEach(function(method) {
|
||||||
method.setRequestManager(self._requestManager);
|
method.attachToObject(_this);
|
||||||
|
method.setRequestManager(_this._requestManager);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
core.addProviders(Shh);
|
||||||
|
|
||||||
var methods = function () {
|
|
||||||
|
var methods = function () {
|
||||||
|
|
||||||
var post = new Method({
|
var post = new Method({
|
||||||
name: 'post',
|
name: 'post',
|
||||||
call: 'shh_post',
|
call: 'shh_post',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: [formatters.inputPostFormatter]
|
inputFormatter: [formatters.inputPostFormatter]
|
||||||
});
|
});
|
||||||
@ -74,7 +82,7 @@ var methods = function () {
|
|||||||
name: 'getPastMessages',
|
name: 'getPastMessages',
|
||||||
call: 'shh_getMessages',
|
call: 'shh_getMessages',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: [formatters.inputLogFormatter],
|
inputFormatter: [formatters.inputPostFormatter],
|
||||||
outputFormatter: formatters.outputPostFormatter
|
outputFormatter: formatters.outputPostFormatter
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -86,7 +94,7 @@ var methods = function () {
|
|||||||
subscriptions: {
|
subscriptions: {
|
||||||
'messages': {
|
'messages': {
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: [formatters.inputLogFormatter],
|
inputFormatter: [formatters.inputPostFormatter],
|
||||||
outputFormatter: formatters.outputPostFormatter
|
outputFormatter: formatters.outputPostFormatter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,3 +113,4 @@ var methods = function () {
|
|||||||
|
|
||||||
module.exports = Shh;
|
module.exports = Shh;
|
||||||
|
|
||||||
|
|
14
packages/web3-utils/package.json
Normal file
14
packages/web3-utils/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "web3-utils",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Collection of utility functions used in web3.js.",
|
||||||
|
"repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-utils",
|
||||||
|
"license": "LGPL-3.0",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"utf8": "^2.1.1",
|
||||||
|
"crypto-js": "^3.1.4",
|
||||||
|
|
||||||
|
"bignumber.js": "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2"
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of web3.js.
|
This file is part of web3.js.
|
||||||
|
|
||||||
web3.js is free software: you can redistribute it and/or modify
|
web3.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
|
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
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
web3.js is distributed in the hope that it will be useful,
|
web3.js is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Lesser General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file utils.js
|
* @file utils.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
* @date 2015
|
* @author Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
*/
|
* @date 2017
|
||||||
|
|
||||||
/**
|
|
||||||
* Utils
|
|
||||||
*
|
|
||||||
* @module utils
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility functions
|
|
||||||
*
|
|
||||||
* @class [utils] utils
|
|
||||||
* @constructor
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var BigNumber = require('bignumber.js');
|
var BigNumber = require('bignumber.js');
|
||||||
var sha3 = require('./sha3.js');
|
|
||||||
var utf8 = require('utf8');
|
var utf8 = require('utf8');
|
||||||
|
|
||||||
|
// var iban = require('web3-core-iban');
|
||||||
|
var sha3 = require('./sha3.js');
|
||||||
|
|
||||||
var unitMap = {
|
var unitMap = {
|
||||||
'noether': '0',
|
'noether': '0',
|
||||||
'wei': '1',
|
'wei': '1',
|
||||||
@ -79,18 +69,25 @@ var unitMap = {
|
|||||||
* @return {Object} the emitter
|
* @return {Object} the emitter
|
||||||
*/
|
*/
|
||||||
var _fireError = function (error, emitter, reject, callback) {
|
var _fireError = function (error, emitter, reject, callback) {
|
||||||
setTimeout(function(){
|
if(isFunction(callback)) {
|
||||||
if(isFunction(callback)) {
|
callback(error);
|
||||||
callback(error);
|
}
|
||||||
|
if(isFunction(reject)) {
|
||||||
|
// suppress uncatched error if an error listener is present
|
||||||
|
if(emitter &&
|
||||||
|
isFunction(emitter.listeners) &&
|
||||||
|
emitter.listeners('error').length &&
|
||||||
|
isFunction(emitter.suppressUnhandledRejections)) {
|
||||||
|
emitter.suppressUnhandledRejections();
|
||||||
}
|
}
|
||||||
if(isFunction(reject)) {
|
reject(error);
|
||||||
reject(error);
|
}
|
||||||
}
|
|
||||||
if(emitter && isFunction(emitter.emit)) {
|
if(emitter && isFunction(emitter.emit)) {
|
||||||
emitter.emit('error', error);
|
emitter.emit('error', error);
|
||||||
emitter.removeAllListeners();
|
emitter.removeAllListeners();
|
||||||
}
|
}
|
||||||
}, 0);
|
|
||||||
return emitter;
|
return emitter;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -338,7 +335,7 @@ var getValueOfUnit = function (unit) {
|
|||||||
* @param {Number|String} number can be a number, number string or a HEX of a decimal
|
* @param {Number|String} number can be a number, number string or a HEX of a decimal
|
||||||
* @param {String} unit the unit to convert to, default ether
|
* @param {String} unit the unit to convert to, default ether
|
||||||
* @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
|
* @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
|
||||||
*/
|
*/
|
||||||
var fromWei = function(number, unit) {
|
var fromWei = function(number, unit) {
|
||||||
var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
|
var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
|
||||||
|
|
||||||
@ -366,7 +363,7 @@ var fromWei = function(number, unit) {
|
|||||||
* @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal
|
* @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal
|
||||||
* @param {String} unit the unit to convert from, default ether
|
* @param {String} unit the unit to convert from, default ether
|
||||||
* @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
|
* @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
|
||||||
*/
|
*/
|
||||||
var toWei = function(number, unit) {
|
var toWei = function(number, unit) {
|
||||||
var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
|
var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
|
||||||
|
|
||||||
@ -379,7 +376,7 @@ var toWei = function(number, unit) {
|
|||||||
* @method toBigNumber
|
* @method toBigNumber
|
||||||
* @param {Number|String|BigNumber} a number, string, HEX string or BigNumber
|
* @param {Number|String|BigNumber} a number, string, HEX string or BigNumber
|
||||||
* @return {BigNumber} BigNumber
|
* @return {BigNumber} BigNumber
|
||||||
*/
|
*/
|
||||||
var toBigNumber = function(number) {
|
var toBigNumber = function(number) {
|
||||||
/*jshint maxcomplexity:5 */
|
/*jshint maxcomplexity:5 */
|
||||||
number = number || 0;
|
number = number || 0;
|
||||||
@ -408,16 +405,6 @@ var toTwosComplement = function (number) {
|
|||||||
return bigNumber;
|
return bigNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given string is strictly an address
|
|
||||||
*
|
|
||||||
* @method isStrictAddress
|
|
||||||
* @param {String} address the given HEX adress
|
|
||||||
* @return {Boolean}
|
|
||||||
*/
|
|
||||||
var isStrictAddress = function (address) {
|
|
||||||
return /^0x[0-9a-f]{40}$/i.test(address);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given string is an address
|
* Checks if the given string is an address
|
||||||
@ -425,12 +412,12 @@ var isStrictAddress = function (address) {
|
|||||||
* @method isAddress
|
* @method isAddress
|
||||||
* @param {String} address the given HEX adress
|
* @param {String} address the given HEX adress
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
var isAddress = function (address) {
|
var isAddress = function (address) {
|
||||||
if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
|
if (!/^(0x|0X)?[0-9a-f]{40}$/i.test(address)) {
|
||||||
// check if it has the basic requirements of an address
|
// check if it has the basic requirements of an address
|
||||||
return false;
|
return false;
|
||||||
} else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
|
} else if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) {
|
||||||
// If it's all small caps or all all caps, return true
|
// If it's all small caps or all all caps, return true
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -447,11 +434,11 @@ var isAddress = function (address) {
|
|||||||
* @method isChecksumAddress
|
* @method isChecksumAddress
|
||||||
* @param {String} address the given HEX adress
|
* @param {String} address the given HEX adress
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
var isChecksumAddress = function (address) {
|
var isChecksumAddress = function (address) {
|
||||||
// Check each case
|
// Check each case
|
||||||
address = address.replace('0x','');
|
address = address.replace('0x','');
|
||||||
var addressHash = sha3(address.toLowerCase());
|
var addressHash = sha3(address.toLowerCase()).replace('0x','');
|
||||||
|
|
||||||
for (var i = 0; i < 40; i++ ) {
|
for (var i = 0; i < 40; i++ ) {
|
||||||
// the nth letter should be uppercase if the nth digit of casemap is 1
|
// the nth letter should be uppercase if the nth digit of casemap is 1
|
||||||
@ -470,18 +457,18 @@ var isChecksumAddress = function (address) {
|
|||||||
* @method toChecksumAddress
|
* @method toChecksumAddress
|
||||||
* @param {String} address the given HEX adress
|
* @param {String} address the given HEX adress
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
var toChecksumAddress = function (address) {
|
var toChecksumAddress = function (address) {
|
||||||
if (typeof address === 'undefined') return '';
|
if (typeof address === 'undefined') return '';
|
||||||
|
|
||||||
address = address.toLowerCase().replace('0x','');
|
address = address.toLowerCase().replace('0x','');
|
||||||
var addressHash = sha3(address);
|
var addressHash = sha3(address).replace('0x','');
|
||||||
var checksumAddress = '0x';
|
var checksumAddress = '0x';
|
||||||
|
|
||||||
for (var i = 0; i < address.length; i++ ) {
|
for (var i = 0; i < address.length; i++ ) {
|
||||||
// If ith character is 9 to f then make it uppercase
|
// If ith character is 9 to f then make it uppercase
|
||||||
if (parseInt(addressHash[i], 16) > 7) {
|
if (parseInt(addressHash[i], 16) > 7) {
|
||||||
checksumAddress += address[i].toUpperCase();
|
checksumAddress += address[i].toUpperCase();
|
||||||
} else {
|
} else {
|
||||||
checksumAddress += address[i];
|
checksumAddress += address[i];
|
||||||
}
|
}
|
||||||
@ -497,8 +484,8 @@ var toChecksumAddress = function (address) {
|
|||||||
* @return {String} formatted address
|
* @return {String} formatted address
|
||||||
*/
|
*/
|
||||||
var toAddress = function (address) {
|
var toAddress = function (address) {
|
||||||
if (isStrictAddress(address)) {
|
if (isAddress(address)) {
|
||||||
return address;
|
return '0x'+ address.toLowerCase().replace('0x','');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/^[0-9a-f]{40}$/.test(address)) {
|
if (/^[0-9a-f]{40}$/.test(address)) {
|
||||||
@ -611,7 +598,6 @@ module.exports = {
|
|||||||
toTwosComplement: toTwosComplement,
|
toTwosComplement: toTwosComplement,
|
||||||
toAddress: toAddress,
|
toAddress: toAddress,
|
||||||
isBigNumber: isBigNumber,
|
isBigNumber: isBigNumber,
|
||||||
isStrictAddress: isStrictAddress,
|
|
||||||
isAddress: isAddress,
|
isAddress: isAddress,
|
||||||
isChecksumAddress: isChecksumAddress,
|
isChecksumAddress: isChecksumAddress,
|
||||||
toChecksumAddress: toChecksumAddress,
|
toChecksumAddress: toChecksumAddress,
|
||||||
@ -620,5 +606,8 @@ module.exports = {
|
|||||||
isObject: isObject,
|
isObject: isObject,
|
||||||
isBoolean: isBoolean,
|
isBoolean: isBoolean,
|
||||||
isArray: isArray,
|
isArray: isArray,
|
||||||
isJson: isJson
|
isJson: isJson,
|
||||||
|
sha3: sha3,
|
||||||
|
// iban: iban
|
||||||
};
|
};
|
||||||
|
|
@ -14,9 +14,9 @@
|
|||||||
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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file sha3.js
|
* @file sha3.js
|
||||||
* @author Marek Kotewicz <marek@ethdev.com>
|
* @author Marek Kotewicz <marek@ethcore.io>
|
||||||
* @date 2015
|
* @date 2015
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ module.exports = function (value, options) {
|
|||||||
value = CryptoJS.enc.Hex.parse(value);
|
value = CryptoJS.enc.Hex.parse(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sha3(value, {
|
return '0x'+ sha3(value, {
|
||||||
outputLength: 256
|
outputLength: 256
|
||||||
}).toString();
|
}).toString();
|
||||||
};
|
};
|
60
src/index.js
Normal file
60
src/index.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
This file is part of web3.js.
|
||||||
|
|
||||||
|
web3.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.
|
||||||
|
|
||||||
|
web3.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 web3.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file index.js
|
||||||
|
* @authors:
|
||||||
|
* Fabian Vogelsteller <fabian@ethereum.org>
|
||||||
|
* Gav Wood <gav@ethcore.io>
|
||||||
|
* Jeffrey Wilcke <jeffrey.wilcke@ethereum.org>
|
||||||
|
* Marek Kotewicz <marek@ethcore.io>
|
||||||
|
* Marian Oancea <marian@ethereum.org>
|
||||||
|
* @date 2017
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var core = require('../packages/web3-core');
|
||||||
|
|
||||||
|
var Eth = require('../packages/web3-eth');
|
||||||
|
var Net = require('../packages/web3-net');
|
||||||
|
var Shh = require('../packages/web3-shh');
|
||||||
|
var Personal = require('../packages/web3-personal');
|
||||||
|
|
||||||
|
var utils = require('../packages/web3-utils');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var Web3 = function () {
|
||||||
|
|
||||||
|
// sets _requestmanager etc
|
||||||
|
core.packageInit(this, arguments);
|
||||||
|
|
||||||
|
|
||||||
|
this.net = new Net(this);
|
||||||
|
this.eth = new Eth(this);
|
||||||
|
this.personal = new Personal(this); // move to -> web3.eth.accounts
|
||||||
|
this.shh = new Shh(this);
|
||||||
|
|
||||||
|
this.utils = utils;
|
||||||
|
};
|
||||||
|
|
||||||
|
core.addProviders(Web3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = Web3;
|
||||||
|
|
@ -1,21 +1,22 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var Web3 = require('../index');
|
var Web3 = require('../src/index');
|
||||||
var web3 = new Web3();
|
|
||||||
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||||
|
|
||||||
|
var web3 = new Web3();
|
||||||
|
|
||||||
// use sendTransaction as dummy
|
// use sendTransaction as dummy
|
||||||
var method = 'sendTransaction';
|
var method = 'call';
|
||||||
|
|
||||||
var tests = [{
|
var tests = [{
|
||||||
input: {
|
input: {
|
||||||
'from': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
'from': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
||||||
'to': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'
|
'to': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'
|
||||||
},
|
},
|
||||||
formattedInput: {
|
formattedInput: [{
|
||||||
'from': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
'from': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
||||||
'to': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'
|
'to': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'
|
||||||
},
|
}, 'latest'],
|
||||||
result: '0xb',
|
result: '0xb',
|
||||||
formattedResult: '0xb',
|
formattedResult: '0xb',
|
||||||
call: 'eth_'+ method
|
call: 'eth_'+ method
|
||||||
@ -23,8 +24,8 @@ var tests = [{
|
|||||||
|
|
||||||
describe('async', function () {
|
describe('async', function () {
|
||||||
tests.forEach(function (test, index) {
|
tests.forEach(function (test, index) {
|
||||||
it('test: ' + index, function (done) {
|
it('test callback: ' + index, function (done) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var provider = new FakeHttpProvider();
|
var provider = new FakeHttpProvider();
|
||||||
web3.setProvider(provider);
|
web3.setProvider(provider);
|
||||||
@ -32,23 +33,47 @@ describe('async', function () {
|
|||||||
provider.injectValidation(function (payload) {
|
provider.injectValidation(function (payload) {
|
||||||
assert.equal(payload.jsonrpc, '2.0');
|
assert.equal(payload.jsonrpc, '2.0');
|
||||||
assert.equal(payload.method, test.call);
|
assert.equal(payload.method, test.call);
|
||||||
assert.deepEqual(payload.params, [test.formattedInput]);
|
assert.deepEqual(payload.params, test.formattedInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
web3.eth[method](test.input, function(error, result){
|
web3.eth[method](test.input, function(error, result){
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assert.isNull(error);
|
assert.isNull(error);
|
||||||
assert.strictEqual(test.formattedResult, result);
|
assert.strictEqual(test.formattedResult, result);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('error test: ' + index, function (done) {
|
it('test promise: ' + index, function (done) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var provider = new FakeHttpProvider();
|
||||||
|
web3.setProvider(provider);
|
||||||
|
provider.injectResult(test.result);
|
||||||
|
provider.injectValidation(function (payload) {
|
||||||
|
assert.equal(payload.jsonrpc, '2.0');
|
||||||
|
assert.equal(payload.method, test.call);
|
||||||
|
assert.deepEqual(payload.params, test.formattedInput);
|
||||||
|
});
|
||||||
|
|
||||||
|
// when
|
||||||
|
web3.eth[method](test.input)
|
||||||
|
.then(function(result){
|
||||||
|
|
||||||
|
// then
|
||||||
|
assert.strictEqual(test.formattedResult, result);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('error test callback: ' + index, function (done) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var provider = new FakeHttpProvider();
|
var provider = new FakeHttpProvider();
|
||||||
web3.setProvider(provider);
|
web3.setProvider(provider);
|
||||||
@ -59,10 +84,10 @@ describe('async', function () {
|
|||||||
provider.injectValidation(function (payload) {
|
provider.injectValidation(function (payload) {
|
||||||
assert.equal(payload.jsonrpc, '2.0');
|
assert.equal(payload.jsonrpc, '2.0');
|
||||||
assert.equal(payload.method, test.call);
|
assert.equal(payload.method, test.call);
|
||||||
assert.deepEqual(payload.params, [test.formattedInput]);
|
assert.deepEqual(payload.params, test.formattedInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
web3.eth[method](test.input, function(error, result){
|
web3.eth[method](test.input, function(error, result){
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -70,8 +95,37 @@ describe('async', function () {
|
|||||||
assert.strictEqual(test.formattedResult, error.message);
|
assert.strictEqual(test.formattedResult, error.message);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
}).catch(function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('error test promise: ' + index, function (done) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var provider = new FakeHttpProvider();
|
||||||
|
web3.setProvider(provider);
|
||||||
|
provider.injectError({
|
||||||
|
message: test.result,
|
||||||
|
code: -32603
|
||||||
|
});
|
||||||
|
provider.injectValidation(function (payload) {
|
||||||
|
assert.equal(payload.jsonrpc, '2.0');
|
||||||
|
assert.equal(payload.method, test.call);
|
||||||
|
assert.deepEqual(payload.params, test.formattedInput);
|
||||||
|
});
|
||||||
|
|
||||||
|
// when
|
||||||
|
web3.eth[method](test.input)
|
||||||
|
.catch(function(error){
|
||||||
|
|
||||||
|
// then
|
||||||
|
assert.strictEqual(test.formattedResult, error.message);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var Web3 = require('../index');
|
var Web3 = require('../src/index');
|
||||||
var web3 = new Web3();
|
|
||||||
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||||
var bn = require('bignumber.js');
|
|
||||||
|
|
||||||
|
|
||||||
describe('lib/web3/batch', function () {
|
describe('lib/web3/batch', function () {
|
||||||
describe('execute', function () {
|
describe('execute', function () {
|
||||||
it('should execute batch request', function (done) {
|
it('should execute batch request', function (done) {
|
||||||
|
|
||||||
var provider = new FakeHttpProvider();
|
var provider = new FakeHttpProvider();
|
||||||
web3.setProvider(provider);
|
var web3 = new Web3(provider);
|
||||||
web3.reset();
|
|
||||||
|
|
||||||
var result = '0x126';
|
var result = '0x126';
|
||||||
|
var resultVal = '294';
|
||||||
var result2 = '0x127';
|
var result2 = '0x127';
|
||||||
|
var result2Val = '295';
|
||||||
provider.injectBatchResults([result, result2]);
|
provider.injectBatchResults([result, result2]);
|
||||||
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var callback = function (err, r) {
|
var callback = function (err, r) {
|
||||||
counter++;
|
counter++;
|
||||||
assert.deepEqual(new bn(result), r);
|
assert.deepEqual(r, resultVal);
|
||||||
};
|
};
|
||||||
|
|
||||||
var callback2 = function (err, r) {
|
var callback2 = function (err, r) {
|
||||||
assert.equal(counter, 1);
|
assert.equal(counter, 1);
|
||||||
assert.deepEqual(new bn(result2), r);
|
assert.deepEqual(r, result2Val);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ describe('lib/web3/batch', function () {
|
|||||||
assert.deepEqual(second.params, ['0x0000000000000000000000000000000000000005', 'latest']);
|
assert.deepEqual(second.params, ['0x0000000000000000000000000000000000000005', 'latest']);
|
||||||
});
|
});
|
||||||
|
|
||||||
var batch = web3.createBatch();
|
var batch = web3.createBatchRequest();
|
||||||
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
|
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
|
||||||
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000005', 'latest', callback2));
|
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000005', 'latest', callback2));
|
||||||
batch.execute();
|
batch.execute();
|
||||||
@ -48,8 +49,7 @@ describe('lib/web3/batch', function () {
|
|||||||
it('should execute batch request for async properties', function (done) {
|
it('should execute batch request for async properties', function (done) {
|
||||||
|
|
||||||
var provider = new FakeHttpProvider();
|
var provider = new FakeHttpProvider();
|
||||||
web3.setProvider(provider);
|
var web3 = new Web3(provider);
|
||||||
web3.reset();
|
|
||||||
|
|
||||||
var result = [];
|
var result = [];
|
||||||
var result2 = '0xb';
|
var result2 = '0xb';
|
||||||
@ -77,7 +77,7 @@ describe('lib/web3/batch', function () {
|
|||||||
assert.deepEqual(second.params, []);
|
assert.deepEqual(second.params, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
var batch = web3.createBatch();
|
var batch = web3.createBatchRequest();
|
||||||
batch.add(web3.eth.getAccounts.request(callback));
|
batch.add(web3.eth.getAccounts.request(callback));
|
||||||
batch.add(web3.net.getPeerCount.request(callback2));
|
batch.add(web3.net.getPeerCount.request(callback2));
|
||||||
batch.execute();
|
batch.execute();
|
||||||
@ -86,8 +86,7 @@ describe('lib/web3/batch', function () {
|
|||||||
it('should execute batch request with contract', function (done) {
|
it('should execute batch request with contract', function (done) {
|
||||||
|
|
||||||
var provider = new FakeHttpProvider();
|
var provider = new FakeHttpProvider();
|
||||||
web3.setProvider(provider);
|
var web3 = new Web3(provider);
|
||||||
web3.reset();
|
|
||||||
|
|
||||||
var abi = [{
|
var abi = [{
|
||||||
"name": "balance",
|
"name": "balance",
|
||||||
@ -106,23 +105,25 @@ describe('lib/web3/batch', function () {
|
|||||||
|
|
||||||
var address = '0x1000000000000000000000000000000000000001';
|
var address = '0x1000000000000000000000000000000000000001';
|
||||||
var result = '0x126';
|
var result = '0x126';
|
||||||
|
var resultVal = '294';
|
||||||
var result2 = '0x0000000000000000000000000000000000000000000000000000000000000123';
|
var result2 = '0x0000000000000000000000000000000000000000000000000000000000000123';
|
||||||
|
var result2Val = '291';
|
||||||
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var callback = function (err, r) {
|
var callback = function (err, r) {
|
||||||
counter++;
|
counter++;
|
||||||
assert.deepEqual(new bn(result), r);
|
assert.deepEqual(r, resultVal);
|
||||||
};
|
};
|
||||||
|
|
||||||
var callback2 = function (err, r) {
|
var callback2 = function (err, r) {
|
||||||
assert.equal(counter, 1);
|
assert.equal(counter, 1);
|
||||||
assert.deepEqual(new bn(result2), r);
|
assert.deepEqual(r, result2Val);
|
||||||
};
|
};
|
||||||
|
|
||||||
var callback3 = function (err, r) {
|
var callback3 = function (err, r) {
|
||||||
counter++;
|
counter++;
|
||||||
assert.equal(counter, 2);
|
assert.equal(counter, 2);
|
||||||
assert.deepEqual(new bn(result2), r);
|
assert.deepEqual(r, result2Val);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,7 +169,7 @@ describe('lib/web3/batch', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var batch = web3.createBatch();
|
var batch = web3.createBatchRequest();
|
||||||
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000022', 'latest', callback));
|
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000022', 'latest', callback));
|
||||||
batch.add(new web3.eth.contract(abi, address).methods.balance(address).call.request(callback2));
|
batch.add(new web3.eth.contract(abi, address).methods.balance(address).call.request(callback2));
|
||||||
batch.add(new web3.eth.contract(abi, address).methods.balance(address).call.request({from: '0x1000000000000000000000000000000000000002'}, callback2));
|
batch.add(new web3.eth.contract(abi, address).methods.balance(address).call.request({from: '0x1000000000000000000000000000000000000002'}, callback2));
|
||||||
@ -181,8 +182,7 @@ describe('lib/web3/batch', function () {
|
|||||||
it('should execute batch requests and receive errors', function (done) {
|
it('should execute batch requests and receive errors', function (done) {
|
||||||
|
|
||||||
var provider = new FakeHttpProvider();
|
var provider = new FakeHttpProvider();
|
||||||
web3.setProvider(provider);
|
var web3 = new Web3(provider);
|
||||||
web3.reset();
|
|
||||||
|
|
||||||
var abi = [{
|
var abi = [{
|
||||||
"name": "balance",
|
"name": "balance",
|
||||||
@ -231,7 +231,7 @@ describe('lib/web3/batch', function () {
|
|||||||
'0xa']);
|
'0xa']);
|
||||||
});
|
});
|
||||||
|
|
||||||
var batch = web3.createBatch();
|
var batch = web3.createBatchRequest();
|
||||||
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
|
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
|
||||||
batch.add(new web3.eth.contract(abi, address).methods.balance(address).call.request({from: '0x0000000000000000000000000000000000000000'},10, callback2));
|
batch.add(new web3.eth.contract(abi, address).methods.balance(address).call.request({from: '0x0000000000000000000000000000000000000000'},10, callback2));
|
||||||
provider.injectBatchResults([result, result2], true); // injects error
|
provider.injectBatchResults([result, result2], true); // injects error
|
||||||
|
355
test/contract.js
355
test/contract.js
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,14 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var errors = require('../lib/web3/errors');
|
|
||||||
|
var errors = require('../packages/web3-core-helpers/src/errors.js');
|
||||||
|
|
||||||
describe('lib/web3/method', function () {
|
describe('lib/web3/method', function () {
|
||||||
describe('getCall', function () {
|
describe('getCall', function () {
|
||||||
|
|
||||||
for(var key in errors) {
|
for(var key in errors) {
|
||||||
it('should return and error', function () {
|
it('should return and error', function () {
|
||||||
|
|
||||||
assert.instanceOf(errors[key](), Error);
|
assert.instanceOf(errors[key](), Error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var BigNumber = require('bignumber.js');
|
var Eth = require('../packages/web3-eth/');
|
||||||
var SolidityEvent = require('../lib/web3/events');
|
|
||||||
var Web3 = require('../index');
|
|
||||||
|
|
||||||
|
|
||||||
var name = 'event1';
|
var name = 'event1';
|
||||||
var address = '0x1234567890123456789012345678901234567890';
|
var address = '0xffddb67890123456789012345678901234567890';
|
||||||
|
var resultAddress = '0xffdDb67890123456789012345678901234567890';
|
||||||
|
|
||||||
var tests = [{
|
var tests = [{
|
||||||
abi: {
|
abi: {
|
||||||
name: name,
|
name: name,
|
||||||
|
type: 'event',
|
||||||
inputs: []
|
inputs: []
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
@ -27,9 +27,12 @@ var tests = [{
|
|||||||
logIndex: 1,
|
logIndex: 1,
|
||||||
transactionIndex: 16,
|
transactionIndex: 16,
|
||||||
transactionHash: '0x1234567890',
|
transactionHash: '0x1234567890',
|
||||||
address: address,
|
address: resultAddress,
|
||||||
blockHash: '0x1234567890',
|
blockHash: '0x1234567890',
|
||||||
blockNumber: 1
|
blockNumber: 1,
|
||||||
|
id: "log_c71f2e84",
|
||||||
|
data: '',
|
||||||
|
topics: []
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
abi: {
|
abi: {
|
||||||
@ -52,14 +55,17 @@ var tests = [{
|
|||||||
expected: {
|
expected: {
|
||||||
event: name,
|
event: name,
|
||||||
returnValues: {
|
returnValues: {
|
||||||
a: new BigNumber(1)
|
a: '1'
|
||||||
},
|
},
|
||||||
logIndex: 1,
|
logIndex: 1,
|
||||||
transactionIndex: 16,
|
transactionIndex: 16,
|
||||||
transactionHash: '0x1234567890',
|
transactionHash: '0x1234567890',
|
||||||
address: address,
|
address: resultAddress,
|
||||||
blockHash: '0x1234567890',
|
blockHash: '0x1234567890',
|
||||||
blockNumber: 1
|
blockNumber: 1,
|
||||||
|
topics: [],
|
||||||
|
data: "0x0000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
id: "log_c71f2e84"
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
abi: {
|
abi: {
|
||||||
@ -89,11 +95,11 @@ var tests = [{
|
|||||||
address: address,
|
address: address,
|
||||||
blockHash: '0x1234567890',
|
blockHash: '0x1234567890',
|
||||||
blockNumber: '0x1',
|
blockNumber: '0x1',
|
||||||
data: '0x' +
|
data: '0x' +
|
||||||
'0000000000000000000000000000000000000000000000000000000000000001' +
|
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||||
'0000000000000000000000000000000000000000000000000000000000000004',
|
'0000000000000000000000000000000000000000000000000000000000000004',
|
||||||
topics: [
|
topics: [
|
||||||
address,
|
address,
|
||||||
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
||||||
'0x0000000000000000000000000000000000000000000000000000000000000010'
|
'0x0000000000000000000000000000000000000000000000000000000000000010'
|
||||||
]
|
]
|
||||||
@ -101,17 +107,26 @@ var tests = [{
|
|||||||
expected: {
|
expected: {
|
||||||
event: name,
|
event: name,
|
||||||
returnValues: {
|
returnValues: {
|
||||||
a: new BigNumber(1),
|
a: '1',
|
||||||
b: new BigNumber(10),
|
b: '10',
|
||||||
c: new BigNumber(4),
|
c: '4',
|
||||||
d: new BigNumber(16)
|
d: '16'
|
||||||
},
|
},
|
||||||
logIndex: 1,
|
logIndex: 1,
|
||||||
transactionIndex: 16,
|
transactionIndex: 16,
|
||||||
transactionHash: '0x1234567890',
|
transactionHash: '0x1234567890',
|
||||||
address: address,
|
address: resultAddress,
|
||||||
blockHash: '0x1234567890',
|
blockHash: '0x1234567890',
|
||||||
blockNumber: 1
|
blockNumber: 1,
|
||||||
|
id: "log_c71f2e84",
|
||||||
|
data: '0x' +
|
||||||
|
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||||
|
'0000000000000000000000000000000000000000000000000000000000000004',
|
||||||
|
topics: [
|
||||||
|
address,
|
||||||
|
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
||||||
|
'0x0000000000000000000000000000000000000000000000000000000000000010'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
abi: {
|
abi: {
|
||||||
@ -139,11 +154,11 @@ var tests = [{
|
|||||||
logIndex: '0x1',
|
logIndex: '0x1',
|
||||||
transactionIndex: '0x10',
|
transactionIndex: '0x10',
|
||||||
transactionHash: '0x1234567890',
|
transactionHash: '0x1234567890',
|
||||||
address: address,
|
address: resultAddress,
|
||||||
blockHash: '0x1234567890',
|
blockHash: '0x1234567890',
|
||||||
blockNumber: '0x1',
|
blockNumber: '0x1',
|
||||||
data: '0x' +
|
data: '0x' +
|
||||||
'0000000000000000000000000000000000000000000000000000000000000001' +
|
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||||
'0000000000000000000000000000000000000000000000000000000000000004',
|
'0000000000000000000000000000000000000000000000000000000000000004',
|
||||||
topics: [
|
topics: [
|
||||||
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
||||||
@ -153,17 +168,25 @@ var tests = [{
|
|||||||
expected: {
|
expected: {
|
||||||
event: name,
|
event: name,
|
||||||
returnValues: {
|
returnValues: {
|
||||||
a: new BigNumber(1),
|
a: '1',
|
||||||
b: new BigNumber(10),
|
b: '10',
|
||||||
c: new BigNumber(4),
|
c: '4',
|
||||||
d: new BigNumber(16)
|
d: '16'
|
||||||
},
|
},
|
||||||
logIndex: 1,
|
logIndex: 1,
|
||||||
transactionIndex: 16,
|
transactionIndex: 16,
|
||||||
transactionHash: '0x1234567890',
|
transactionHash: '0x1234567890',
|
||||||
address: address,
|
address: resultAddress,
|
||||||
blockHash: '0x1234567890',
|
blockHash: '0x1234567890',
|
||||||
blockNumber: 1
|
blockNumber: 1,
|
||||||
|
id: "log_c71f2e84",
|
||||||
|
data: '0x' +
|
||||||
|
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||||
|
'0000000000000000000000000000000000000000000000000000000000000004',
|
||||||
|
topics: [
|
||||||
|
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
||||||
|
'0x0000000000000000000000000000000000000000000000000000000000000010'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@ -171,10 +194,10 @@ describe('lib/web3/event', function () {
|
|||||||
describe('decode', function () {
|
describe('decode', function () {
|
||||||
tests.forEach(function (test, index) {
|
tests.forEach(function (test, index) {
|
||||||
it('test no: ' + index, function () {
|
it('test no: ' + index, function () {
|
||||||
var web3 = new Web3();
|
var eth = new Eth();
|
||||||
var event = new SolidityEvent(web3, test.abi, address);
|
var contract = new eth.contract([test.abi], address);
|
||||||
|
|
||||||
var result = event.decode(test.data);
|
var result = contract._decodeEventABI.call(test.abi, test.data);
|
||||||
assert.deepEqual(result, test.expected);
|
assert.deepEqual(result, test.expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var SolidityEvent = require('../lib/web3/events');
|
var Eth = require('../packages/web3-eth');
|
||||||
var Web3 = require('../index');
|
|
||||||
|
|
||||||
|
|
||||||
var address = '0x1234567890123456789012345678901234567890';
|
var address = '0x1234567890123456789012345678901234567890';
|
||||||
@ -10,7 +9,8 @@ var signature = '0xffff';
|
|||||||
var tests = [{
|
var tests = [{
|
||||||
abi: {
|
abi: {
|
||||||
name: 'event1',
|
name: 'event1',
|
||||||
inputs: []
|
inputs: [],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {},
|
options: {},
|
||||||
expected: {
|
expected: {
|
||||||
@ -26,7 +26,8 @@ var tests = [{
|
|||||||
type: 'int',
|
type: 'int',
|
||||||
name: 'a',
|
name: 'a',
|
||||||
indexed: true
|
indexed: true
|
||||||
}]
|
}],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -59,7 +60,8 @@ var tests = [{
|
|||||||
type: 'int',
|
type: 'int',
|
||||||
name: 'd',
|
name: 'd',
|
||||||
indexed: true
|
indexed: true
|
||||||
}]
|
}],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -86,7 +88,8 @@ var tests = [{
|
|||||||
type: 'int',
|
type: 'int',
|
||||||
name: 'b',
|
name: 'b',
|
||||||
indexed: true
|
indexed: true
|
||||||
}]
|
}],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -109,7 +112,8 @@ var tests = [{
|
|||||||
type: 'int',
|
type: 'int',
|
||||||
name: 'a',
|
name: 'a',
|
||||||
indexed: true
|
indexed: true
|
||||||
}]
|
}],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -130,7 +134,8 @@ var tests = [{
|
|||||||
type: 'int',
|
type: 'int',
|
||||||
name: 'a',
|
name: 'a',
|
||||||
indexed: true
|
indexed: true
|
||||||
}]
|
}],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -156,7 +161,8 @@ var tests = [{
|
|||||||
type: 'int',
|
type: 'int',
|
||||||
name: 'a',
|
name: 'a',
|
||||||
indexed: true
|
indexed: true
|
||||||
}]
|
}],
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -182,7 +188,8 @@ var tests = [{
|
|||||||
name: 'a',
|
name: 'a',
|
||||||
indexed: true
|
indexed: true
|
||||||
}],
|
}],
|
||||||
anonymous: true
|
anonymous: true,
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -207,7 +214,8 @@ var tests = [{
|
|||||||
name: 'b',
|
name: 'b',
|
||||||
indexed: true
|
indexed: true
|
||||||
}],
|
}],
|
||||||
anonymous: true
|
anonymous: true,
|
||||||
|
signature: signature
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
filter: {
|
filter: {
|
||||||
@ -227,13 +235,11 @@ describe('lib/web3/event', function () {
|
|||||||
describe('encode', function () {
|
describe('encode', function () {
|
||||||
tests.forEach(function (test, index) {
|
tests.forEach(function (test, index) {
|
||||||
it('test no: ' + index, function () {
|
it('test no: ' + index, function () {
|
||||||
var web3 = new Web3();
|
var eth = new Eth();
|
||||||
var event = new SolidityEvent(web3, test.abi, address);
|
var contract = new eth.contract([test.abi], address);
|
||||||
event.signature = function () { // inject signature
|
|
||||||
return signature.slice(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = event.encode(test.options);
|
|
||||||
|
var result = contract._encodeEventABI(test.abi, test.options);
|
||||||
assert.deepEqual(result, test.expected);
|
assert.deepEqual(result, test.expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
var BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
{ input: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8' },
|
{ input: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8' },
|
||||||
{ input: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'},
|
{ input: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'},
|
||||||
{ input: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'},
|
{ input: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'},
|
||||||
{ input: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', result: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae' }
|
{ input: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', result: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae' },
|
||||||
|
{ input: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', result: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae' }
|
||||||
];
|
];
|
||||||
|
|
||||||
var errorTests = [
|
var errorTests = [
|
||||||
@ -15,11 +15,12 @@ var errorTests = [
|
|||||||
'0x0c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
'0x0c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
||||||
'00c5496aee77c1ba1f0854206a26dda82a81d6d',
|
'00c5496aee77c1ba1f0854206a26dda82a81d6d',
|
||||||
'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZE',
|
'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZE',
|
||||||
'0x'
|
'0x',
|
||||||
|
'0x11f4d0a3c12e86B4b5F39b213f7E19D048276DAe'
|
||||||
]
|
]
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('inputAddressFormatter', function () {
|
describe('inputAddressFormatter correct addresses', function () {
|
||||||
tests.forEach(function(test){
|
tests.forEach(function(test){
|
||||||
it('should return the correct value', function () {
|
it('should return the correct value', function () {
|
||||||
assert.deepEqual(formatters.inputAddressFormatter(test.input), test.result);
|
assert.deepEqual(formatters.inputAddressFormatter(test.input), test.result);
|
||||||
@ -30,12 +31,12 @@ describe('formatters', function () {
|
|||||||
|
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('inputAddressFormatter', function () {
|
describe('inputAddressFormatter wrong addresses', function () {
|
||||||
errorTests.forEach(function(test){
|
errorTests.forEach(function(test){
|
||||||
it('should throw an exception', function () {
|
it('should throw an exception', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
formatters.inputAddressFormatter(test);
|
formatters.inputAddressFormatter(test);
|
||||||
});
|
}, null, null, 'Should throw:'+ test);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var formatters = require('../lib/web3/formatters');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
{ value: 'latest', expected: 'latest' },
|
{ value: 'latest', expected: 'latest' },
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('inputPostFormatter', function () {
|
describe('inputPostFormatter', function () {
|
||||||
@ -13,7 +13,8 @@ describe('formatters', function () {
|
|||||||
payload: '0x7b2274657374223a2274657374227d',//{test: 'test'},
|
payload: '0x7b2274657374223a2274657374227d',//{test: 'test'},
|
||||||
ttl: 200,
|
ttl: 200,
|
||||||
priority: 1000,
|
priority: 1000,
|
||||||
topics: ['hello','mytopics']
|
topics: ['hello','mytopics'],
|
||||||
|
"workToProve": 1
|
||||||
}), {
|
}), {
|
||||||
from: '0x00000',
|
from: '0x00000',
|
||||||
to: '0x00000',
|
to: '0x00000',
|
||||||
@ -21,7 +22,7 @@ describe('formatters', function () {
|
|||||||
ttl: '0xc8',
|
ttl: '0xc8',
|
||||||
priority: '0x3e8',
|
priority: '0x3e8',
|
||||||
topics: ['0x68656c6c6f','0x6d79746f70696373'],
|
topics: ['0x68656c6c6f','0x6d79746f70696373'],
|
||||||
workToProve: '0x0'
|
workToProve: '0x1'
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
var BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
var tests = [{
|
var tests = [{
|
||||||
input: {
|
input: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: new BigNumber(100),
|
value: '100',
|
||||||
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', // checksum address
|
||||||
to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
to: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae',
|
||||||
nonce: 1000,
|
nonce: 1000,
|
||||||
gas: 1000,
|
gas: 1000,
|
||||||
gasPrice: new BigNumber(1000)
|
gasPrice: '1000'
|
||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: '0x64',
|
value: '0x64',
|
||||||
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
from: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae',
|
||||||
to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
to: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae',
|
||||||
nonce: '0x3e8',
|
nonce: '0x3e8',
|
||||||
gas: '0x3e8',
|
gas: '0x3e8',
|
||||||
gasPrice: '0x3e8'
|
gasPrice: '0x3e8'
|
||||||
@ -25,24 +24,24 @@ var tests = [{
|
|||||||
},{
|
},{
|
||||||
input: {
|
input: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: new BigNumber(100),
|
value: '100',
|
||||||
from: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
from: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
||||||
to: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe' // checksum address
|
||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: '0x64',
|
value: '0x64',
|
||||||
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
||||||
to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
to: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae'
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
input: {
|
input: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: new BigNumber(100),
|
value: '100',
|
||||||
from: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
from: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
||||||
to: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
to: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',
|
||||||
gas: '1000',
|
gas: '1000',
|
||||||
gasPrice: new BigNumber(1000)
|
gasPrice: '1000'
|
||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
@ -55,11 +54,11 @@ var tests = [{
|
|||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: new BigNumber(100),
|
value: '100',
|
||||||
from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
||||||
to: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
to: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
||||||
gas: '1000',
|
gas: '1000',
|
||||||
gasPrice: new BigNumber(1000)
|
gasPrice: '1000'
|
||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
@ -72,10 +71,10 @@ var tests = [{
|
|||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
value: new BigNumber(100),
|
value: '100',
|
||||||
from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
|
||||||
gas: '1000',
|
gas: '1000',
|
||||||
gasPrice: new BigNumber(1000)
|
gasPrice: '1000'
|
||||||
},
|
},
|
||||||
result: {
|
result: {
|
||||||
data: '0x34234bf23bf4234',
|
data: '0x34234bf23bf4234',
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
var BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('outputBlockFormatter', function () {
|
describe('outputBlockFormatter', function () {
|
||||||
it('should return the correct value', function () {
|
it('should return the correct value', function () {
|
||||||
|
|
||||||
assert.deepEqual(formatters.outputBlockFormatter({
|
assert.deepEqual(formatters.outputBlockFormatter({
|
||||||
hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||||
@ -26,12 +26,12 @@ describe('formatters', function () {
|
|||||||
}), {
|
}), {
|
||||||
hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||||
miner: '0xdcc6960376d6c6dea93647383ffb245cfced97cf',
|
miner: '0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf',
|
||||||
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
||||||
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
||||||
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
difficulty: new BigNumber(1000),
|
difficulty: '1000',
|
||||||
totalDifficulty: new BigNumber(1000),
|
totalDifficulty: '1000',
|
||||||
number: 1000,
|
number: 1000,
|
||||||
gasLimit: 1000,
|
gasLimit: 1000,
|
||||||
gasUsed: 1000,
|
gasUsed: 1000,
|
||||||
@ -42,7 +42,7 @@ describe('formatters', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should return the correct value, when null values are present', function () {
|
it('should return the correct value, when null values are present', function () {
|
||||||
|
|
||||||
assert.deepEqual(formatters.outputBlockFormatter({
|
assert.deepEqual(formatters.outputBlockFormatter({
|
||||||
hash: null,
|
hash: null,
|
||||||
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
|
||||||
@ -66,8 +66,8 @@ describe('formatters', function () {
|
|||||||
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
|
||||||
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
||||||
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
difficulty: new BigNumber(1000),
|
difficulty: '1000',
|
||||||
totalDifficulty: new BigNumber(1000),
|
totalDifficulty: '1000',
|
||||||
number: null,
|
number: null,
|
||||||
gasLimit: 1000,
|
gasLimit: 1000,
|
||||||
gasUsed: 1000,
|
gasUsed: 1000,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('outputLogFormatter', function () {
|
describe('outputLogFormatter', function () {
|
||||||
it('should return the correct value', function () {
|
it('should return the correct value', function () {
|
||||||
|
|
||||||
assert.deepEqual(formatters.outputLogFormatter({
|
assert.deepEqual(formatters.outputLogFormatter({
|
||||||
transactionIndex: '0x3e8',
|
transactionIndex: '0x3e8',
|
||||||
logIndex: '0x3e8',
|
logIndex: '0x3e8',
|
||||||
@ -12,7 +12,8 @@ describe('formatters', function () {
|
|||||||
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
data: '0x7b2274657374223a2274657374227',
|
data: '0x7b2274657374223a2274657374227',
|
||||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
address: "0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae", // lowercase address
|
||||||
|
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||||
}), {
|
}), {
|
||||||
transactionIndex: 1000,
|
transactionIndex: 1000,
|
||||||
logIndex: 1000,
|
logIndex: 1000,
|
||||||
@ -20,11 +21,13 @@ describe('formatters', function () {
|
|||||||
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
|
||||||
data: '0x7b2274657374223a2274657374227',
|
data: '0x7b2274657374223a2274657374227',
|
||||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
topics: ['0x68656c6c6f','0x6d79746f70696373'],
|
||||||
|
address: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // checksum address
|
||||||
|
id: "log_2b801386"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should return the correct value, when null values are present', function () {
|
it('should return the correct value, when null values are present', function () {
|
||||||
|
|
||||||
assert.deepEqual(formatters.outputLogFormatter({
|
assert.deepEqual(formatters.outputLogFormatter({
|
||||||
transactionIndex: null,
|
transactionIndex: null,
|
||||||
logIndex: null,
|
logIndex: null,
|
||||||
@ -32,13 +35,14 @@ describe('formatters', function () {
|
|||||||
transactionHash: null,
|
transactionHash: null,
|
||||||
blockHash: null,
|
blockHash: null,
|
||||||
data: '0x7b2274657374223a2274657374227',
|
data: '0x7b2274657374223a2274657374227',
|
||||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||||
}), {
|
}), {
|
||||||
transactionIndex: null,
|
transactionIndex: null,
|
||||||
logIndex: null,
|
logIndex: null,
|
||||||
blockNumber: null,
|
blockNumber: null,
|
||||||
transactionHash: null,
|
transactionHash: null,
|
||||||
blockHash: null,
|
blockHash: null,
|
||||||
|
id: null,
|
||||||
data: '0x7b2274657374223a2274657374227',
|
data: '0x7b2274657374223a2274657374227',
|
||||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('outputPostFormatter', function () {
|
describe('outputPostFormatter', function () {
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var formatters = require('../lib/web3/formatters.js');
|
var formatters = require('../packages/web3-core-helpers/src/formatters.js');
|
||||||
var BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
describe('formatters', function () {
|
describe('formatters', function () {
|
||||||
describe('outputTransactionFormatter', function () {
|
describe('outputTransactionFormatter', function () {
|
||||||
it('should return the correct value', function () {
|
it('should return the correct value', function () {
|
||||||
|
|
||||||
assert.deepEqual(formatters.outputTransactionFormatter({
|
assert.deepEqual(formatters.outputTransactionFormatter({
|
||||||
input: '0x3454645634534',
|
input: '0x3454645634534',
|
||||||
from: '0x00000',
|
from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
|
||||||
to: '0x00000',
|
to: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae',
|
||||||
value: '0x3e8',
|
value: '0x3e8',
|
||||||
gas: '0x3e8',
|
gas: '0x3e8',
|
||||||
gasPrice: '0x3e8',
|
gasPrice: '0x3e8',
|
||||||
@ -19,11 +18,11 @@ describe('formatters', function () {
|
|||||||
blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9'
|
blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9'
|
||||||
}), {
|
}), {
|
||||||
input: '0x3454645634534',
|
input: '0x3454645634534',
|
||||||
from: '0x00000',
|
from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
|
||||||
to: '0x00000',
|
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
|
||||||
value: new BigNumber(1000),
|
value: '1000',
|
||||||
gas: 1000,
|
gas: 1000,
|
||||||
gasPrice: new BigNumber(1000),
|
gasPrice: '1000',
|
||||||
nonce: 11,
|
nonce: 11,
|
||||||
blockNumber: 1000,
|
blockNumber: 1000,
|
||||||
blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9',
|
blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9',
|
||||||
@ -32,10 +31,10 @@ describe('formatters', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the correct value, when null values are present', function () {
|
it('should return the correct value, when null values are present', function () {
|
||||||
|
|
||||||
assert.deepEqual(formatters.outputTransactionFormatter({
|
assert.deepEqual(formatters.outputTransactionFormatter({
|
||||||
input: '0x3454645634534',
|
input: '0x3454645634534',
|
||||||
from: '0x00000',
|
from: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae',
|
||||||
to: null,
|
to: null,
|
||||||
value: '0x3e8',
|
value: '0x3e8',
|
||||||
gas: '0x3e8',
|
gas: '0x3e8',
|
||||||
@ -46,11 +45,11 @@ describe('formatters', function () {
|
|||||||
blockHash: null
|
blockHash: null
|
||||||
}), {
|
}), {
|
||||||
input: '0x3454645634534',
|
input: '0x3454645634534',
|
||||||
from: '0x00000',
|
from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
|
||||||
to: null,
|
to: null,
|
||||||
value: new BigNumber(1000),
|
value: 1000,
|
||||||
gas: 1000,
|
gas: 1000,
|
||||||
gasPrice: new BigNumber(1000),
|
gasPrice: '1000',
|
||||||
nonce: 11,
|
nonce: 11,
|
||||||
blockNumber: null,
|
blockNumber: null,
|
||||||
blockHash: null,
|
blockHash: null,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var chai = require('chai');
|
var chai = require('chai');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var utils = require('../../lib/utils/utils');
|
var _ = require('lodash');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ var FakeHttpProvider = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
FakeHttpProvider.prototype.sendSync = function (payload) {
|
FakeHttpProvider.prototype.sendSync = function (payload) {
|
||||||
assert.equal(utils.isArray(payload) || utils.isObject(payload), true);
|
assert.equal(_.isArray(payload) || _.isObject(payload), true);
|
||||||
|
|
||||||
var error = this.getResponseOrError('error', payload);
|
var error = this.getResponseOrError('error', payload);
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -59,8 +59,8 @@ FakeHttpProvider.prototype.send = function (payload, callback) {
|
|||||||
// else
|
// else
|
||||||
// this.countId++;
|
// this.countId++;
|
||||||
|
|
||||||
assert.equal(utils.isArray(payload) || utils.isObject(payload), true);
|
assert.equal(_.isArray(payload) || _.isObject(payload), true);
|
||||||
assert.equal(utils.isFunction(callback), true);
|
assert.equal(_.isFunction(callback), true);
|
||||||
|
|
||||||
var validation = this.validation.shift();
|
var validation = this.validation.shift();
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ FakeHttpProvider.prototype.send = function (payload, callback) {
|
|||||||
validation(JSON.parse(JSON.stringify(payload)), callback);
|
validation(JSON.parse(JSON.stringify(payload)), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = _this.getResponseOrError('response', payload);
|
var response = this.getResponseOrError('response', payload);
|
||||||
var error = this.getResponseOrError('error', payload);
|
var error = this.getResponseOrError('error', payload);
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@ -87,13 +87,15 @@ FakeHttpProvider.prototype.getResponseOrError = function (type, payload) {
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
var response;
|
var response;
|
||||||
|
|
||||||
if(type === 'error')
|
if(type === 'error') {
|
||||||
response = this.error.shift();
|
response = this.error.shift();
|
||||||
else
|
} else {
|
||||||
response = this.response.shift() || this.getResponseStub();
|
response = this.response.shift() || this.getResponseStub();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(response) {
|
if(response) {
|
||||||
if(utils.isArray(response)) {
|
if(_.isArray(response)) {
|
||||||
response = response.map(function(resp, index) {
|
response = response.map(function(resp, index) {
|
||||||
resp.id = payload[index] ? payload[index].id : _this.countId++;
|
resp.id = payload[index] ? payload[index].id : _this.countId++;
|
||||||
return resp;
|
return resp;
|
||||||
@ -119,12 +121,7 @@ FakeHttpProvider.prototype.injectNotification = function (notification) {
|
|||||||
// this.response = response;
|
// this.response = response;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
FakeHttpProvider.prototype.injectResult = function (result) {
|
|
||||||
var response = this.getResponseStub();
|
|
||||||
response.result = result;
|
|
||||||
|
|
||||||
this.response.push(response);
|
|
||||||
};
|
|
||||||
|
|
||||||
FakeHttpProvider.prototype.injectBatchResults = function (results, error) {
|
FakeHttpProvider.prototype.injectBatchResults = function (results, error) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@ -140,11 +137,18 @@ FakeHttpProvider.prototype.injectBatchResults = function (results, error) {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeHttpProvider.prototype.injectError = function (error) {
|
FakeHttpProvider.prototype.injectResult = function (result) {
|
||||||
var error = this.getErrorStub();
|
var response = this.getResponseStub();
|
||||||
error.error = error; // message, code
|
response.result = result;
|
||||||
|
|
||||||
this.error.push(error);
|
this.response.push(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeHttpProvider.prototype.injectError = function (error) {
|
||||||
|
var errorStub = this.getErrorStub();
|
||||||
|
errorStub.error = error; // message, code
|
||||||
|
|
||||||
|
this.error.push(errorStub);
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeHttpProvider.prototype.injectValidation = function (callback) {
|
FakeHttpProvider.prototype.injectValidation = function (callback) {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user