diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-05 04:52:17 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-05 04:52:34 +0800 |
commit | 7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94 (patch) | |
tree | b3e541941c0a6b8f8c9772034bd77cece339b355 /cmd/mist/assets/ext/ethereum.js/lib/jsonrpc.js | |
parent | 3f03197daebace568a61bf69c06c97e30080a749 (diff) | |
parent | 859a1999cb204d2c6fcb08d6569c738c5af5cd86 (diff) | |
download | go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.tar go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.tar.gz go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.tar.bz2 go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.tar.lz go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.tar.xz go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.tar.zst go-tangerine-7c278d6ac20e7f34816f02d6db7f8aeb5d8ebc94.zip |
updated tests
Diffstat (limited to 'cmd/mist/assets/ext/ethereum.js/lib/jsonrpc.js')
-rw-r--r-- | cmd/mist/assets/ext/ethereum.js/lib/jsonrpc.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/cmd/mist/assets/ext/ethereum.js/lib/jsonrpc.js b/cmd/mist/assets/ext/ethereum.js/lib/jsonrpc.js new file mode 100644 index 000000000..b2d6922c0 --- /dev/null +++ b/cmd/mist/assets/ext/ethereum.js/lib/jsonrpc.js @@ -0,0 +1,65 @@ +/* + This file is part of ethereum.js. + + ethereum.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethereum.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with ethereum.js. If not, see <http://www.gnu.org/licenses/>. +*/ +/** @file jsonrpc.js + * @authors: + * Marek Kotewicz <marek@ethdev.com> + * @date 2015 + */ + +var messageId = 1; + +/// Should be called to valid json create payload object +/// @param method of jsonrpc call, required +/// @param params, an array of method params, optional +/// @returns valid jsonrpc payload object +var toPayload = function (method, params) { + if (!method) + console.error('jsonrpc method should be specified!'); + + return { + jsonrpc: '2.0', + method: method, + params: params || [], + id: messageId++ + }; +}; + +/// Should be called to check if jsonrpc response is valid +/// @returns true if response is valid, otherwise false +var isValidResponse = function (response) { + return !!response && + !response.error && + response.jsonrpc === '2.0' && + typeof response.id === 'number' && + response.result !== undefined; // only undefined is not valid json object +}; + +/// Should be called to create batch payload object +/// @param messages, an array of objects with method (required) and params (optional) fields +var toBatchPayload = function (messages) { + return messages.map(function (message) { + return toPayload(message.method, message.params); + }); +}; + +module.exports = { + toPayload: toPayload, + isValidResponse: isValidResponse, + toBatchPayload: toBatchPayload +}; + + |