Paweł Bylica
10 years ago
133 changed files with 7110 additions and 4652 deletions
File diff suppressed because it is too large
@ -1,601 +0,0 @@ |
|||
// ratio_io |
|||
// |
|||
// (C) Copyright Howard Hinnant |
|||
// Use, modification and distribution are subject to the Boost Software License, |
|||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|||
// http://www.boost.org/LICENSE_1_0.txt). |
|||
|
|||
#ifndef _RATIO_IO |
|||
#define _RATIO_IO |
|||
|
|||
/* |
|||
|
|||
ratio_io synopsis |
|||
|
|||
#include <ratio> |
|||
#include <string> |
|||
|
|||
namespace std |
|||
{ |
|||
|
|||
template <class Ratio, class charT> |
|||
struct ratio_string |
|||
{ |
|||
static basic_string<charT> symbol(); |
|||
static basic_string<charT> prefix(); |
|||
}; |
|||
|
|||
} // std |
|||
|
|||
*/ |
|||
|
|||
#include <ratio> |
|||
#include <string> |
|||
#include <sstream> |
|||
|
|||
namespace std { |
|||
|
|||
template <class _Ratio, class _CharT> |
|||
struct ratio_string |
|||
{ |
|||
static basic_string<_CharT> symbol() {return prefix();} |
|||
static basic_string<_CharT> prefix(); |
|||
}; |
|||
|
|||
template <class _Ratio, class _CharT> |
|||
basic_string<_CharT> |
|||
ratio_string<_Ratio, _CharT>::prefix() |
|||
{ |
|||
basic_ostringstream<_CharT> __os; |
|||
__os << _CharT('[') << _Ratio::num << _CharT('/') |
|||
<< _Ratio::den << _CharT(']'); |
|||
return __os.str(); |
|||
} |
|||
|
|||
// atto |
|||
|
|||
template <> |
|||
struct ratio_string<atto, char> |
|||
{ |
|||
static string symbol() {return string(1, 'a');} |
|||
static string prefix() {return string("atto");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<atto, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'a');} |
|||
static u16string prefix() {return u16string(u"atto");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<atto, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'a');} |
|||
static u32string prefix() {return u32string(U"atto");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<atto, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'a');} |
|||
static wstring prefix() {return wstring(L"atto");} |
|||
}; |
|||
|
|||
// femto |
|||
|
|||
template <> |
|||
struct ratio_string<femto, char> |
|||
{ |
|||
static string symbol() {return string(1, 'f');} |
|||
static string prefix() {return string("femto");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<femto, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'f');} |
|||
static u16string prefix() {return u16string(u"femto");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<femto, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'f');} |
|||
static u32string prefix() {return u32string(U"femto");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<femto, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'f');} |
|||
static wstring prefix() {return wstring(L"femto");} |
|||
}; |
|||
|
|||
// pico |
|||
|
|||
template <> |
|||
struct ratio_string<pico, char> |
|||
{ |
|||
static string symbol() {return string(1, 'p');} |
|||
static string prefix() {return string("pico");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<pico, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'p');} |
|||
static u16string prefix() {return u16string(u"pico");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<pico, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'p');} |
|||
static u32string prefix() {return u32string(U"pico");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<pico, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'p');} |
|||
static wstring prefix() {return wstring(L"pico");} |
|||
}; |
|||
|
|||
// nano |
|||
|
|||
template <> |
|||
struct ratio_string<nano, char> |
|||
{ |
|||
static string symbol() {return string(1, 'n');} |
|||
static string prefix() {return string("nano");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<nano, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'n');} |
|||
static u16string prefix() {return u16string(u"nano");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<nano, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'n');} |
|||
static u32string prefix() {return u32string(U"nano");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<nano, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'n');} |
|||
static wstring prefix() {return wstring(L"nano");} |
|||
}; |
|||
|
|||
// micro |
|||
|
|||
template <> |
|||
struct ratio_string<micro, char> |
|||
{ |
|||
static string symbol() {return string("\xC2\xB5");} |
|||
static string prefix() {return string("micro");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<micro, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'\xB5');} |
|||
static u16string prefix() {return u16string(u"micro");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<micro, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'\xB5');} |
|||
static u32string prefix() {return u32string(U"micro");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<micro, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'\xB5');} |
|||
static wstring prefix() {return wstring(L"micro");} |
|||
}; |
|||
|
|||
// milli |
|||
|
|||
template <> |
|||
struct ratio_string<milli, char> |
|||
{ |
|||
static string symbol() {return string(1, 'm');} |
|||
static string prefix() {return string("milli");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<milli, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'm');} |
|||
static u16string prefix() {return u16string(u"milli");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<milli, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'm');} |
|||
static u32string prefix() {return u32string(U"milli");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<milli, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'm');} |
|||
static wstring prefix() {return wstring(L"milli");} |
|||
}; |
|||
|
|||
// centi |
|||
|
|||
template <> |
|||
struct ratio_string<centi, char> |
|||
{ |
|||
static string symbol() {return string(1, 'c');} |
|||
static string prefix() {return string("centi");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<centi, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'c');} |
|||
static u16string prefix() {return u16string(u"centi");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<centi, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'c');} |
|||
static u32string prefix() {return u32string(U"centi");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<centi, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'c');} |
|||
static wstring prefix() {return wstring(L"centi");} |
|||
}; |
|||
|
|||
// deci |
|||
|
|||
template <> |
|||
struct ratio_string<deci, char> |
|||
{ |
|||
static string symbol() {return string(1, 'd');} |
|||
static string prefix() {return string("deci");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<deci, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'd');} |
|||
static u16string prefix() {return u16string(u"deci");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<deci, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'd');} |
|||
static u32string prefix() {return u32string(U"deci");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<deci, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'd');} |
|||
static wstring prefix() {return wstring(L"deci");} |
|||
}; |
|||
|
|||
// deca |
|||
|
|||
template <> |
|||
struct ratio_string<deca, char> |
|||
{ |
|||
static string symbol() {return string("da");} |
|||
static string prefix() {return string("deca");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<deca, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(u"da");} |
|||
static u16string prefix() {return u16string(u"deca");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<deca, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(U"da");} |
|||
static u32string prefix() {return u32string(U"deca");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<deca, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(L"da");} |
|||
static wstring prefix() {return wstring(L"deca");} |
|||
}; |
|||
|
|||
// hecto |
|||
|
|||
template <> |
|||
struct ratio_string<hecto, char> |
|||
{ |
|||
static string symbol() {return string(1, 'h');} |
|||
static string prefix() {return string("hecto");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<hecto, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'h');} |
|||
static u16string prefix() {return u16string(u"hecto");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<hecto, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'h');} |
|||
static u32string prefix() {return u32string(U"hecto");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<hecto, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'h');} |
|||
static wstring prefix() {return wstring(L"hecto");} |
|||
}; |
|||
|
|||
// kilo |
|||
|
|||
template <> |
|||
struct ratio_string<kilo, char> |
|||
{ |
|||
static string symbol() {return string(1, 'k');} |
|||
static string prefix() {return string("kilo");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<kilo, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'k');} |
|||
static u16string prefix() {return u16string(u"kilo");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<kilo, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'k');} |
|||
static u32string prefix() {return u32string(U"kilo");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<kilo, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'k');} |
|||
static wstring prefix() {return wstring(L"kilo");} |
|||
}; |
|||
|
|||
// mega |
|||
|
|||
template <> |
|||
struct ratio_string<mega, char> |
|||
{ |
|||
static string symbol() {return string(1, 'M');} |
|||
static string prefix() {return string("mega");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<mega, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'M');} |
|||
static u16string prefix() {return u16string(u"mega");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<mega, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'M');} |
|||
static u32string prefix() {return u32string(U"mega");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<mega, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'M');} |
|||
static wstring prefix() {return wstring(L"mega");} |
|||
}; |
|||
|
|||
// giga |
|||
|
|||
template <> |
|||
struct ratio_string<giga, char> |
|||
{ |
|||
static string symbol() {return string(1, 'G');} |
|||
static string prefix() {return string("giga");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<giga, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'G');} |
|||
static u16string prefix() {return u16string(u"giga");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<giga, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'G');} |
|||
static u32string prefix() {return u32string(U"giga");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<giga, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'G');} |
|||
static wstring prefix() {return wstring(L"giga");} |
|||
}; |
|||
|
|||
// tera |
|||
|
|||
template <> |
|||
struct ratio_string<tera, char> |
|||
{ |
|||
static string symbol() {return string(1, 'T');} |
|||
static string prefix() {return string("tera");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<tera, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'T');} |
|||
static u16string prefix() {return u16string(u"tera");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<tera, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'T');} |
|||
static u32string prefix() {return u32string(U"tera");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<tera, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'T');} |
|||
static wstring prefix() {return wstring(L"tera");} |
|||
}; |
|||
|
|||
// peta |
|||
|
|||
template <> |
|||
struct ratio_string<peta, char> |
|||
{ |
|||
static string symbol() {return string(1, 'P');} |
|||
static string prefix() {return string("peta");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<peta, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'P');} |
|||
static u16string prefix() {return u16string(u"peta");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<peta, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'P');} |
|||
static u32string prefix() {return u32string(U"peta");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<peta, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'P');} |
|||
static wstring prefix() {return wstring(L"peta");} |
|||
}; |
|||
|
|||
// exa |
|||
|
|||
template <> |
|||
struct ratio_string<exa, char> |
|||
{ |
|||
static string symbol() {return string(1, 'E');} |
|||
static string prefix() {return string("exa");} |
|||
}; |
|||
|
|||
#if HAS_UNICODE_SUPPORT |
|||
|
|||
template <> |
|||
struct ratio_string<exa, char16_t> |
|||
{ |
|||
static u16string symbol() {return u16string(1, u'E');} |
|||
static u16string prefix() {return u16string(u"exa");} |
|||
}; |
|||
|
|||
template <> |
|||
struct ratio_string<exa, char32_t> |
|||
{ |
|||
static u32string symbol() {return u32string(1, U'E');} |
|||
static u32string prefix() {return u32string(U"exa");} |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
template <> |
|||
struct ratio_string<exa, wchar_t> |
|||
{ |
|||
static wstring symbol() {return wstring(1, L'E');} |
|||
static wstring prefix() {return wstring(L"exa");} |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // _RATIO_IO |
@ -1,13 +1,17 @@ |
|||
language: node_js |
|||
node_js: |
|||
- "0.12" |
|||
- "0.11" |
|||
- "0.10" |
|||
before_script: |
|||
- npm install |
|||
- npm install jshint |
|||
- export DISPLAY=:99.0 |
|||
- sh -e /etc/init.d/xvfb start |
|||
script: |
|||
- "jshint *.js lib" |
|||
after_script: |
|||
- npm run-script build |
|||
- npm run-script karma |
|||
- npm run-script test-coveralls |
|||
|
|||
|
@ -0,0 +1,4 @@ |
|||
3stack:bignumber@2.0.0 |
|||
ethereum:js@0.0.15-rc12 |
|||
meteor@1.1.4 |
|||
underscore@1.0.2 |
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@ |
|||
var web3 = require('./lib/web3'); |
|||
web3.providers.HttpSyncProvider = require('./lib/httpsync'); |
|||
web3.providers.QtSyncProvider = require('./lib/qtsync'); |
|||
web3.eth.contract = require('./lib/contract'); |
|||
web3.abi = require('./lib/abi'); |
|||
web3.providers.HttpProvider = require('./lib/web3/httpprovider'); |
|||
web3.providers.QtSyncProvider = require('./lib/web3/qtsync'); |
|||
web3.eth.contract = require('./lib/web3/contract'); |
|||
web3.abi = require('./lib/solidity/abi'); |
|||
|
|||
module.exports = web3; |
|||
|
@ -0,0 +1,96 @@ |
|||
// Karma configuration
|
|||
// Generated on Thu Feb 19 2015 19:57:47 GMT+0100 (W. Europe Standard Time)
|
|||
|
|||
module.exports = function (config) { |
|||
config.set({ |
|||
|
|||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|||
basePath: '', |
|||
|
|||
// level of logging
|
|||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|||
|
|||
// Continuous Integration mode
|
|||
// if true, Karma captures browsers, runs the tests and exits
|
|||
singleRun: true, logLevel: config.LOG_INFO, |
|||
//singleRun: true, logLevel: config.LOG_DEBUG,
|
|||
|
|||
// frameworks to use
|
|||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|||
frameworks: ['browserify', 'mocha'], |
|||
|
|||
|
|||
// list of files / patterns to load in the browser
|
|||
files: [ |
|||
'node_modules/bignumber.js/bignumber.js', |
|||
'test/*.js', |
|||
], |
|||
|
|||
|
|||
// list of files to exclude
|
|||
exclude: [ |
|||
], |
|||
|
|||
client: { |
|||
mocha: { |
|||
//ui: 'tdd'
|
|||
timeout: 5000 // especially for the post requests
|
|||
} |
|||
}, |
|||
browserify: { |
|||
bundleDelay: 750, |
|||
debug: true |
|||
// transform: [],
|
|||
// //extensions: ['.js']
|
|||
}, |
|||
|
|||
// preprocess matching files before serving them to the browser
|
|||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|||
preprocessors: { |
|||
'test/*.js': ['browserify'] |
|||
}, |
|||
|
|||
|
|||
// test results reporter to use
|
|||
// possible values: 'dots', 'progress'
|
|||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|||
reporters: ['dots'], |
|||
|
|||
|
|||
// web server port
|
|||
port: 9876, |
|||
|
|||
|
|||
// enable / disable colors in the output (reporters and logs)
|
|||
colors: true, |
|||
|
|||
|
|||
// enable / disable watching file and executing tests whenever any file changes
|
|||
autoWatch: true, |
|||
|
|||
|
|||
// start these browsers
|
|||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
|||
// // Chrome
|
|||
// // PhantomJS
|
|||
browsers: ['Chrome', 'Safari', 'Firefox'], |
|||
browserNoActivityTimeout: 10000, |
|||
browserDisconnectTimeout: 5000, |
|||
|
|||
customLaunchers: { |
|||
chromeWithoutSecurity: { |
|||
base: 'Chrome', |
|||
flags: ['--disable-web-security'] |
|||
}, |
|||
|
|||
IE9: { |
|||
base: 'IE', |
|||
'x-ua-compatible': 'IE=EmulateIE9' |
|||
}, |
|||
IE8: { |
|||
base: 'IE', |
|||
'x-ua-compatible': 'IE=EmulateIE8' |
|||
} |
|||
} |
|||
}); |
|||
}; |
@ -1,85 +0,0 @@ |
|||
/* |
|||
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 eth.js |
|||
* @authors: |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
/// @returns an array of objects describing web3.eth api methods
|
|||
var methods = function () { |
|||
var blockCall = function (args) { |
|||
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber"; |
|||
}; |
|||
|
|||
var transactionCall = function (args) { |
|||
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber'; |
|||
}; |
|||
|
|||
var uncleCall = function (args) { |
|||
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber'; |
|||
}; |
|||
|
|||
var transactionCountCall = function (args) { |
|||
return typeof args[0] === "string" ? 'eth_transactionCountByHash' : 'eth_transactionCountByNumber'; |
|||
}; |
|||
|
|||
var uncleCountCall = function (args) { |
|||
return typeof args[0] === "string" ? 'eth_uncleCountByHash' : 'eth_uncleCountByNumber'; |
|||
}; |
|||
|
|||
return [ |
|||
{ name: 'balanceAt', call: 'eth_balanceAt' }, |
|||
{ name: 'stateAt', call: 'eth_stateAt' }, |
|||
{ name: 'storageAt', call: 'eth_storageAt' }, |
|||
{ name: 'countAt', call: 'eth_countAt'}, |
|||
{ name: 'codeAt', call: 'eth_codeAt' }, |
|||
{ name: 'transact', call: 'eth_transact' }, |
|||
{ name: 'call', call: 'eth_call' }, |
|||
{ name: 'block', call: blockCall }, |
|||
{ name: 'transaction', call: transactionCall }, |
|||
{ name: 'uncle', call: uncleCall }, |
|||
{ name: 'compilers', call: 'eth_compilers' }, |
|||
{ name: 'flush', call: 'eth_flush' }, |
|||
{ name: 'lll', call: 'eth_lll' }, |
|||
{ name: 'solidity', call: 'eth_solidity' }, |
|||
{ name: 'serpent', call: 'eth_serpent' }, |
|||
{ name: 'logs', call: 'eth_logs' }, |
|||
{ name: 'transactionCount', call: transactionCountCall }, |
|||
{ name: 'uncleCount', call: uncleCountCall } |
|||
]; |
|||
}; |
|||
|
|||
/// @returns an array of objects describing web3.eth api properties
|
|||
var properties = function () { |
|||
return [ |
|||
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' }, |
|||
{ name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' }, |
|||
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' }, |
|||
{ name: 'gasPrice', getter: 'eth_gasPrice' }, |
|||
{ name: 'accounts', getter: 'eth_accounts' }, |
|||
{ name: 'peerCount', getter: 'eth_peerCount' }, |
|||
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' }, |
|||
{ name: 'number', getter: 'eth_number'} |
|||
]; |
|||
}; |
|||
|
|||
module.exports = { |
|||
methods: methods, |
|||
properties: properties |
|||
}; |
|||
|
@ -1,18 +0,0 @@ |
|||
var addressName = {"0x12378912345789": "Gav", "0x57835893478594739854": "Jeff"}; |
|||
var nameAddress = {}; |
|||
|
|||
for (var prop in addressName) { |
|||
if (addressName.hasOwnProperty(prop)) { |
|||
nameAddress[addressName[prop]] = prop; |
|||
} |
|||
} |
|||
|
|||
var local = { |
|||
addressBook:{ |
|||
byName: addressName, |
|||
byAddress: nameAddress |
|||
} |
|||
}; |
|||
|
|||
if (typeof(module) !== "undefined") |
|||
module.exports = local; |
@ -1,112 +0,0 @@ |
|||
/* |
|||
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 requestmanager.js |
|||
* @authors: |
|||
* Jeffrey Wilcke <jeff@ethdev.com> |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* Marian Oancea <marian@ethdev.com> |
|||
* Gav Wood <g@ethdev.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
var jsonrpc = require('./jsonrpc'); |
|||
var c = require('./const'); |
|||
|
|||
/** |
|||
* It's responsible for passing messages to providers |
|||
* It's also responsible for polling the ethereum node for incoming messages |
|||
* Default poll timeout is 1 second |
|||
*/ |
|||
var requestManager = function() { |
|||
var polls = []; |
|||
var timeout = null; |
|||
var provider; |
|||
|
|||
var send = function (data) { |
|||
var payload = jsonrpc.toPayload(data.method, data.params); |
|||
|
|||
if (!provider) { |
|||
console.error('provider is not set'); |
|||
return null; |
|||
} |
|||
|
|||
var result = provider.send(payload); |
|||
|
|||
if (!jsonrpc.isValidResponse(result)) { |
|||
console.log(result); |
|||
return null; |
|||
} |
|||
|
|||
return result.result; |
|||
}; |
|||
|
|||
var setProvider = function (p) { |
|||
provider = p; |
|||
}; |
|||
|
|||
/*jshint maxparams:4 */ |
|||
var startPolling = function (data, pollId, callback, uninstall) { |
|||
polls.push({data: data, id: pollId, callback: callback, uninstall: uninstall}); |
|||
}; |
|||
/*jshint maxparams:3 */ |
|||
|
|||
var stopPolling = function (pollId) { |
|||
for (var i = polls.length; i--;) { |
|||
var poll = polls[i]; |
|||
if (poll.id === pollId) { |
|||
polls.splice(i, 1); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var reset = function () { |
|||
polls.forEach(function (poll) { |
|||
poll.uninstall(poll.id); |
|||
}); |
|||
polls = []; |
|||
|
|||
if (timeout) { |
|||
clearTimeout(timeout); |
|||
timeout = null; |
|||
} |
|||
poll(); |
|||
}; |
|||
|
|||
var poll = function () { |
|||
polls.forEach(function (data) { |
|||
var result = send(data.data); |
|||
if (!(result instanceof Array) || result.length === 0) { |
|||
return; |
|||
} |
|||
data.callback(result); |
|||
}); |
|||
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT); |
|||
}; |
|||
|
|||
poll(); |
|||
|
|||
return { |
|||
send: send, |
|||
setProvider: setProvider, |
|||
startPolling: startPolling, |
|||
stopPolling: stopPolling, |
|||
reset: reset |
|||
}; |
|||
}; |
|||
|
|||
module.exports = requestManager; |
|||
|
@ -1,143 +0,0 @@ |
|||
/* |
|||
This file is part of ethereum.js. |
|||
|
|||
ethereum.js is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Lesser General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethereum.js is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public License |
|||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file utils.js |
|||
* @authors: |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
var c = require('./const'); |
|||
|
|||
/// Finds first index of array element matching pattern
|
|||
/// @param array
|
|||
/// @param callback pattern
|
|||
/// @returns index of element
|
|||
var findIndex = function (array, callback) { |
|||
var end = false; |
|||
var i = 0; |
|||
for (; i < array.length && !end; i++) { |
|||
end = callback(array[i]); |
|||
} |
|||
return end ? i - 1 : -1; |
|||
}; |
|||
|
|||
/// @returns ascii string representation of hex value prefixed with 0x
|
|||
var toAscii = function(hex) { |
|||
// Find termination
|
|||
var str = ""; |
|||
var i = 0, l = hex.length; |
|||
if (hex.substring(0, 2) === '0x') { |
|||
i = 2; |
|||
} |
|||
for (; i < l; i+=2) { |
|||
var code = parseInt(hex.substr(i, 2), 16); |
|||
if (code === 0) { |
|||
break; |
|||
} |
|||
|
|||
str += String.fromCharCode(code); |
|||
} |
|||
|
|||
return str; |
|||
}; |
|||
|
|||
var toHex = function(str) { |
|||
var hex = ""; |
|||
for(var i = 0; i < str.length; i++) { |
|||
var n = str.charCodeAt(i).toString(16); |
|||
hex += n.length < 2 ? '0' + n : n; |
|||
} |
|||
|
|||
return hex; |
|||
}; |
|||
|
|||
/// @returns hex representation (prefixed by 0x) of ascii string
|
|||
var fromAscii = function(str, pad) { |
|||
pad = pad === undefined ? 0 : pad; |
|||
var hex = toHex(str); |
|||
while (hex.length < pad*2) |
|||
hex += "00"; |
|||
return "0x" + hex; |
|||
}; |
|||
|
|||
/// @returns display name for function/event eg. multiply(uint256) -> multiply
|
|||
var extractDisplayName = function (name) { |
|||
var length = name.indexOf('('); |
|||
return length !== -1 ? name.substr(0, length) : name; |
|||
}; |
|||
|
|||
/// @returns overloaded part of function/event name
|
|||
var extractTypeName = function (name) { |
|||
/// TODO: make it invulnerable
|
|||
var length = name.indexOf('('); |
|||
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; |
|||
}; |
|||
|
|||
/// Filters all function from input abi
|
|||
/// @returns abi array with filtered objects of type 'function'
|
|||
var filterFunctions = function (json) { |
|||
return json.filter(function (current) { |
|||
return current.type === 'function'; |
|||
}); |
|||
}; |
|||
|
|||
/// Filters all events form input abi
|
|||
/// @returns abi array with filtered objects of type 'event'
|
|||
var filterEvents = function (json) { |
|||
return json.filter(function (current) { |
|||
return current.type === 'event'; |
|||
}); |
|||
}; |
|||
|
|||
/// used to transform value/string to eth string
|
|||
/// TODO: use BigNumber.js to parse int
|
|||
/// TODO: add tests for it!
|
|||
var toEth = function (str) { |
|||
/*jshint maxcomplexity:7 */ |
|||
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; |
|||
var unit = 0; |
|||
var units = c.ETH_UNITS; |
|||
while (val > 3000 && unit < units.length - 1) |
|||
{ |
|||
val /= 1000; |
|||
unit++; |
|||
} |
|||
var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); |
|||
var replaceFunction = function($0, $1, $2) { |
|||
return $1 + ',' + $2; |
|||
}; |
|||
|
|||
while (true) { |
|||
var o = s; |
|||
s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction); |
|||
if (o === s) |
|||
break; |
|||
} |
|||
return s + ' ' + units[unit]; |
|||
}; |
|||
|
|||
module.exports = { |
|||
findIndex: findIndex, |
|||
toAscii: toAscii, |
|||
fromAscii: fromAscii, |
|||
extractDisplayName: extractDisplayName, |
|||
extractTypeName: extractTypeName, |
|||
filterFunctions: filterFunctions, |
|||
filterEvents: filterEvents, |
|||
toEth: toEth |
|||
}; |
|||
|
@ -0,0 +1,448 @@ |
|||
/* |
|||
This file is part of ethereum.js. |
|||
|
|||
ethereum.js is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Lesser General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethereum.js is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public License |
|||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file utils.js |
|||
* @authors: |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
/** |
|||
* Utils |
|||
* |
|||
* @module utils |
|||
*/ |
|||
|
|||
/** |
|||
* Utility functions |
|||
* |
|||
* @class [utils] utils |
|||
* @constructor |
|||
*/ |
|||
|
|||
if (process.env.NODE_ENV !== 'build') { |
|||
var BigNumber = require('bignumber.js'); // jshint ignore:line
|
|||
} |
|||
|
|||
var unitMap = { |
|||
'wei': '1', |
|||
'kwei': '1000', |
|||
'ada': '1000', |
|||
'mwei': '1000000', |
|||
'babbage': '1000000', |
|||
'gwei': '1000000000', |
|||
'shannon': '1000000000', |
|||
'szabo': '1000000000000', |
|||
'finney': '1000000000000000', |
|||
'ether': '1000000000000000000', |
|||
'kether': '1000000000000000000000', |
|||
'grand': '1000000000000000000000', |
|||
'einstein': '1000000000000000000000', |
|||
'mether': '1000000000000000000000000', |
|||
'gether': '1000000000000000000000000000', |
|||
'tether': '1000000000000000000000000000000' |
|||
}; |
|||
|
|||
|
|||
/** Finds first index of array element matching pattern |
|||
* |
|||
* @method findIndex |
|||
* @param {Array} |
|||
* @param {Function} pattern |
|||
* @returns {Number} index of element |
|||
*/ |
|||
var findIndex = function (array, callback) { |
|||
var end = false; |
|||
var i = 0; |
|||
for (; i < array.length && !end; i++) { |
|||
end = callback(array[i]); |
|||
} |
|||
return end ? i - 1 : -1; |
|||
}; |
|||
|
|||
/** |
|||
* Should be called to get sting from it's hex representation |
|||
* |
|||
* @method toAscii |
|||
* @param {String} string in hex |
|||
* @returns {String} ascii string representation of hex value |
|||
*/ |
|||
var toAscii = function(hex) { |
|||
// Find termination
|
|||
var str = ""; |
|||
var i = 0, l = hex.length; |
|||
if (hex.substring(0, 2) === '0x') { |
|||
i = 2; |
|||
} |
|||
for (; i < l; i+=2) { |
|||
var code = parseInt(hex.substr(i, 2), 16); |
|||
if (code === 0) { |
|||
break; |
|||
} |
|||
|
|||
str += String.fromCharCode(code); |
|||
} |
|||
|
|||
return str; |
|||
}; |
|||
|
|||
/** |
|||
* Shold be called to get hex representation (prefixed by 0x) of ascii string |
|||
* |
|||
* @method fromAscii |
|||
* @param {String} string |
|||
* @returns {String} hex representation of input string |
|||
*/ |
|||
var toHexNative = function(str) { |
|||
var hex = ""; |
|||
for(var i = 0; i < str.length; i++) { |
|||
var n = str.charCodeAt(i).toString(16); |
|||
hex += n.length < 2 ? '0' + n : n; |
|||
} |
|||
|
|||
return hex; |
|||
}; |
|||
|
|||
/** |
|||
* Shold be called to get hex representation (prefixed by 0x) of ascii string |
|||
* |
|||
* @method fromAscii |
|||
* @param {String} string |
|||
* @param {Number} optional padding |
|||
* @returns {String} hex representation of input string |
|||
*/ |
|||
var fromAscii = function(str, pad) { |
|||
pad = pad === undefined ? 0 : pad; |
|||
var hex = toHexNative(str); |
|||
while (hex.length < pad*2) |
|||
hex += "00"; |
|||
return "0x" + hex; |
|||
}; |
|||
|
|||
/** |
|||
* Should be called to get display name of contract function |
|||
* |
|||
* @method extractDisplayName |
|||
* @param {String} name of function/event |
|||
* @returns {String} display name for function/event eg. multiply(uint256) -> multiply |
|||
*/ |
|||
var extractDisplayName = function (name) { |
|||
var length = name.indexOf('('); |
|||
return length !== -1 ? name.substr(0, length) : name; |
|||
}; |
|||
|
|||
/// @returns overloaded part of function/event name
|
|||
var extractTypeName = function (name) { |
|||
/// TODO: make it invulnerable
|
|||
var length = name.indexOf('('); |
|||
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; |
|||
}; |
|||
|
|||
/** |
|||
* Filters all functions from input abi |
|||
* |
|||
* @method filterFunctions |
|||
* @param {Array} abi |
|||
* @returns {Array} abi array with filtered objects of type 'function' |
|||
*/ |
|||
var filterFunctions = function (json) { |
|||
return json.filter(function (current) { |
|||
return current.type === 'function'; |
|||
}); |
|||
}; |
|||
|
|||
/** |
|||
* Filters all events from input abi |
|||
* |
|||
* @method filterEvents |
|||
* @param {Array} abi |
|||
* @returns {Array} abi array with filtered objects of type 'event' |
|||
*/ |
|||
var filterEvents = function (json) { |
|||
return json.filter(function (current) { |
|||
return current.type === 'event'; |
|||
}); |
|||
}; |
|||
|
|||
/** |
|||
* Converts value to it's decimal representation in string |
|||
* |
|||
* @method toDecimal |
|||
* @param {String|Number|BigNumber} |
|||
* @return {String} |
|||
*/ |
|||
var toDecimal = function (value) { |
|||
return toBigNumber(value).toNumber(); |
|||
}; |
|||
|
|||
/** |
|||
* Converts value to it's hex representation |
|||
* |
|||
* @method fromDecimal |
|||
* @param {String|Number|BigNumber} |
|||
* @return {String} |
|||
*/ |
|||
var fromDecimal = function (value) { |
|||
var number = toBigNumber(value); |
|||
var result = number.toString(16); |
|||
|
|||
return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; |
|||
}; |
|||
|
|||
/** |
|||
* Auto converts any given value into it's hex representation. |
|||
* |
|||
* And even stringifys objects before. |
|||
* |
|||
* @method toHex |
|||
* @param {String|Number|BigNumber|Object} |
|||
* @return {String} |
|||
*/ |
|||
var toHex = function (val) { |
|||
/*jshint maxcomplexity:7 */ |
|||
|
|||
if(isBoolean(val)) |
|||
return val; |
|||
|
|||
if(isBigNumber(val)) |
|||
return fromDecimal(val); |
|||
|
|||
if(isObject(val)) |
|||
return fromAscii(JSON.stringify(val)); |
|||
|
|||
// if its a negative number, pass it through fromDecimal
|
|||
if (isString(val)) { |
|||
if (val.indexOf('-0x') === 0) |
|||
return fromDecimal(val); |
|||
else if (!isFinite(val)) |
|||
return fromAscii(val); |
|||
} |
|||
|
|||
return fromDecimal(val); |
|||
}; |
|||
|
|||
/** |
|||
* Returns value of unit in Wei |
|||
* |
|||
* @method getValueOfUnit |
|||
* @param {String} unit the unit to convert to, default ether |
|||
* @returns {BigNumber} value of the unit (in Wei) |
|||
* @throws error if the unit is not correct:w |
|||
*/ |
|||
var getValueOfUnit = function (unit) { |
|||
unit = unit ? unit.toLowerCase() : 'ether'; |
|||
var unitValue = unitMap[unit]; |
|||
if (unitValue === undefined) { |
|||
throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); |
|||
} |
|||
return new BigNumber(unitValue, 10); |
|||
}; |
|||
|
|||
/** |
|||
* Takes a number of wei and converts it to any other ether unit. |
|||
* |
|||
* Possible units are: |
|||
* - kwei/ada |
|||
* - mwei/babbage |
|||
* - gwei/shannon |
|||
* - szabo |
|||
* - finney |
|||
* - ether |
|||
* - kether/grand/einstein |
|||
* - mether |
|||
* - gether |
|||
* - tether |
|||
* |
|||
* @method fromWei |
|||
* @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 |
|||
* @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number |
|||
*/ |
|||
var fromWei = function(number, unit) { |
|||
var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); |
|||
|
|||
return isBigNumber(number) ? returnValue : returnValue.toString(10); |
|||
}; |
|||
|
|||
/** |
|||
* Takes a number of a unit and converts it to wei. |
|||
* |
|||
* Possible units are: |
|||
* - kwei/ada |
|||
* - mwei/babbage |
|||
* - gwei/shannon |
|||
* - szabo |
|||
* - finney |
|||
* - ether |
|||
* - kether/grand/einstein |
|||
* - mether |
|||
* - gether |
|||
* - tether |
|||
* |
|||
* @method toWei |
|||
* @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 |
|||
* @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number |
|||
*/ |
|||
var toWei = function(number, unit) { |
|||
var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); |
|||
|
|||
return isBigNumber(number) ? returnValue : returnValue.toString(10); |
|||
}; |
|||
|
|||
/** |
|||
* Takes an input and transforms it into an bignumber |
|||
* |
|||
* @method toBigNumber |
|||
* @param {Number|String|BigNumber} a number, string, HEX string or BigNumber |
|||
* @return {BigNumber} BigNumber |
|||
*/ |
|||
var toBigNumber = function(number) { |
|||
/*jshint maxcomplexity:5 */ |
|||
number = number || 0; |
|||
if (isBigNumber(number)) |
|||
return number; |
|||
|
|||
if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { |
|||
return new BigNumber(number.replace('0x',''), 16); |
|||
} |
|||
|
|||
return new BigNumber(number.toString(10), 10); |
|||
}; |
|||
|
|||
/** |
|||
* Takes and input transforms it into bignumber and if it is negative value, into two's complement |
|||
* |
|||
* @method toTwosComplement |
|||
* @param {Number|String|BigNumber} |
|||
* @return {BigNumber} |
|||
*/ |
|||
var toTwosComplement = function (number) { |
|||
var bigNumber = toBigNumber(number); |
|||
if (bigNumber.lessThan(0)) { |
|||
return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); |
|||
} |
|||
return bigNumber; |
|||
}; |
|||
|
|||
/** |
|||
* Checks if the given string has proper length |
|||
* |
|||
* @method isAddress |
|||
* @param {String} address the given HEX adress |
|||
* @return {Boolean} |
|||
*/ |
|||
var isAddress = function(address) { |
|||
if (!isString(address)) { |
|||
return false; |
|||
} |
|||
|
|||
return ((address.indexOf('0x') === 0 && address.length === 42) || |
|||
(address.indexOf('0x') === -1 && address.length === 40)); |
|||
}; |
|||
|
|||
/** |
|||
* Returns true if object is BigNumber, otherwise false |
|||
* |
|||
* @method isBigNumber |
|||
* @param {Object} |
|||
* @return {Boolean} |
|||
*/ |
|||
var isBigNumber = function (object) { |
|||
return object instanceof BigNumber || |
|||
(object && object.constructor && object.constructor.name === 'BigNumber'); |
|||
}; |
|||
|
|||
/** |
|||
* Returns true if object is string, otherwise false |
|||
* |
|||
* @method isString |
|||
* @param {Object} |
|||
* @return {Boolean} |
|||
*/ |
|||
var isString = function (object) { |
|||
return typeof object === 'string' || |
|||
(object && object.constructor && object.constructor.name === 'String'); |
|||
}; |
|||
|
|||
/** |
|||
* Returns true if object is function, otherwise false |
|||
* |
|||
* @method isFunction |
|||
* @param {Object} |
|||
* @return {Boolean} |
|||
*/ |
|||
var isFunction = function (object) { |
|||
return typeof object === 'function'; |
|||
}; |
|||
|
|||
/** |
|||
* Returns true if object is Objet, otherwise false |
|||
* |
|||
* @method isObject |
|||
* @param {Object} |
|||
* @return {Boolean} |
|||
*/ |
|||
var isObject = function (object) { |
|||
return typeof object === 'object'; |
|||
}; |
|||
|
|||
/** |
|||
* Returns true if object is boolean, otherwise false |
|||
* |
|||
* @method isBoolean |
|||
* @param {Object} |
|||
* @return {Boolean} |
|||
*/ |
|||
var isBoolean = function (object) { |
|||
return typeof object === 'boolean'; |
|||
}; |
|||
|
|||
/** |
|||
* Returns true if object is array, otherwise false |
|||
* |
|||
* @method isArray |
|||
* @param {Object} |
|||
* @return {Boolean} |
|||
*/ |
|||
var isArray = function (object) { |
|||
return object instanceof Array; |
|||
}; |
|||
|
|||
module.exports = { |
|||
findIndex: findIndex, |
|||
toHex: toHex, |
|||
toDecimal: toDecimal, |
|||
fromDecimal: fromDecimal, |
|||
toAscii: toAscii, |
|||
fromAscii: fromAscii, |
|||
extractDisplayName: extractDisplayName, |
|||
extractTypeName: extractTypeName, |
|||
filterFunctions: filterFunctions, |
|||
filterEvents: filterEvents, |
|||
toWei: toWei, |
|||
fromWei: fromWei, |
|||
toBigNumber: toBigNumber, |
|||
toTwosComplement: toTwosComplement, |
|||
isBigNumber: isBigNumber, |
|||
isAddress: isAddress, |
|||
isFunction: isFunction, |
|||
isString: isString, |
|||
isObject: isObject, |
|||
isBoolean: isBoolean, |
|||
isArray: isArray |
|||
}; |
|||
|
@ -0,0 +1,148 @@ |
|||
/* |
|||
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 eth.js |
|||
* @authors: |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
/** |
|||
* Web3 |
|||
* |
|||
* @module web3 |
|||
*/ |
|||
|
|||
/** |
|||
* Eth methods and properties |
|||
* |
|||
* An example method object can look as follows: |
|||
* |
|||
* { |
|||
* name: 'getBlock', |
|||
* call: blockCall, |
|||
* outputFormatter: formatters.outputBlockFormatter, |
|||
* inputFormatter: [ // can be a formatter funciton or an array of functions. Where each item in the array will be used for one parameter
|
|||
* utils.toHex, // formats paramter 1
|
|||
* function(param){ if(!param) return false; } // formats paramter 2
|
|||
* ] |
|||
* }, |
|||
* |
|||
* @class [web3] eth |
|||
* @constructor |
|||
*/ |
|||
|
|||
|
|||
var formatters = require('./formatters'); |
|||
var utils = require('../utils/utils'); |
|||
|
|||
|
|||
var blockCall = function (args) { |
|||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; |
|||
}; |
|||
|
|||
var transactionFromBlockCall = function (args) { |
|||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; |
|||
}; |
|||
|
|||
var uncleCall = function (args) { |
|||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; |
|||
}; |
|||
|
|||
var getBlockTransactionCountCall = function (args) { |
|||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; |
|||
}; |
|||
|
|||
var uncleCountCall = function (args) { |
|||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; |
|||
}; |
|||
|
|||
/// @returns an array of objects describing web3.eth api methods
|
|||
var methods = [ |
|||
{ name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2, |
|||
outputFormatter: formatters.convertToBigNumber}, |
|||
{ name: 'getStorage', call: 'eth_getStorage', addDefaultblock: 2}, |
|||
{ name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, |
|||
inputFormatter: utils.toHex}, |
|||
{ name: 'getData', call: 'eth_getData', addDefaultblock: 2}, |
|||
{ name: 'getBlock', call: blockCall, |
|||
outputFormatter: formatters.outputBlockFormatter, |
|||
inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]}, |
|||
{ name: 'getUncle', call: uncleCall, |
|||
outputFormatter: formatters.outputBlockFormatter, |
|||
inputFormatter: [utils.toHex, utils.toHex, function(param){ return (!param) ? false : true; }]}, |
|||
{ name: 'getCompilers', call: 'eth_getCompilers' }, |
|||
{ name: 'getBlockTransactionCount', call: getBlockTransactionCountCall, |
|||
outputFormatter: utils.toDecimal, |
|||
inputFormatter: utils.toHex }, |
|||
{ name: 'getBlockUncleCount', call: uncleCountCall, |
|||
outputFormatter: utils.toDecimal, |
|||
inputFormatter: utils.toHex }, |
|||
{ name: 'getTransaction', call: 'eth_getTransactionByHash', |
|||
outputFormatter: formatters.outputTransactionFormatter }, |
|||
{ name: 'getTransactionFromBlock', call: transactionFromBlockCall, |
|||
outputFormatter: formatters.outputTransactionFormatter, |
|||
inputFormatter: utils.toHex }, |
|||
{ name: 'getTransactionCount', call: 'eth_getTransactionCount', addDefaultblock: 2, |
|||
outputFormatter: utils.toDecimal}, |
|||
{ name: 'sendTransaction', call: 'eth_sendTransaction', |
|||
inputFormatter: formatters.inputTransactionFormatter }, |
|||
{ name: 'call', call: 'eth_call', addDefaultblock: 2, |
|||
inputFormatter: formatters.inputCallFormatter }, |
|||
{ name: 'compile.solidity', call: 'eth_compileSolidity', inputFormatter: utils.toHex }, |
|||
{ name: 'compile.lll', call: 'eth_compileLLL', inputFormatter: utils.toHex }, |
|||
{ name: 'compile.serpent', call: 'eth_compileSerpent', inputFormatter: utils.toHex }, |
|||
{ name: 'flush', call: 'eth_flush' }, |
|||
|
|||
// deprecated methods
|
|||
{ name: 'balanceAt', call: 'eth_balanceAt', newMethod: 'eth.getBalance' }, |
|||
{ name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' }, |
|||
{ name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' }, |
|||
{ name: 'countAt', call: 'eth_countAt', newMethod: 'eth.getTransactionCount' }, |
|||
{ name: 'codeAt', call: 'eth_codeAt', newMethod: 'eth.getData' }, |
|||
{ name: 'transact', call: 'eth_transact', newMethod: 'eth.sendTransaction' }, |
|||
{ name: 'block', call: blockCall, newMethod: 'eth.getBlock' }, |
|||
{ name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' }, |
|||
{ name: 'uncle', call: uncleCall, newMethod: 'eth.getUncle' }, |
|||
{ name: 'compilers', call: 'eth_compilers', newMethod: 'eth.getCompilers' }, |
|||
{ name: 'solidity', call: 'eth_solidity', newMethod: 'eth.compile.solidity' }, |
|||
{ name: 'lll', call: 'eth_lll', newMethod: 'eth.compile.lll' }, |
|||
{ name: 'serpent', call: 'eth_serpent', newMethod: 'eth.compile.serpent' }, |
|||
{ name: 'transactionCount', call: getBlockTransactionCountCall, newMethod: 'eth.getBlockTransactionCount' }, |
|||
{ name: 'uncleCount', call: uncleCountCall, newMethod: 'eth.getBlockUncleCount' }, |
|||
{ name: 'logs', call: 'eth_logs' } |
|||
]; |
|||
|
|||
/// @returns an array of objects describing web3.eth api properties
|
|||
var properties = [ |
|||
{ name: 'coinbase', getter: 'eth_coinbase'}, |
|||
{ name: 'mining', getter: 'eth_mining'}, |
|||
{ name: 'gasPrice', getter: 'eth_gasPrice', outputFormatter: formatters.convertToBigNumber}, |
|||
{ name: 'accounts', getter: 'eth_accounts' }, |
|||
{ name: 'blockNumber', getter: 'eth_blockNumber', outputFormatter: utils.toDecimal}, |
|||
|
|||
// deprecated properties
|
|||
{ name: 'listening', getter: 'net_listening', setter: 'eth_setListening', newProperty: 'net.listening'}, |
|||
{ name: 'peerCount', getter: 'net_peerCount', newProperty: 'net.peerCount'}, |
|||
{ name: 'number', getter: 'eth_number', newProperty: 'eth.blockNumber'} |
|||
]; |
|||
|
|||
|
|||
module.exports = { |
|||
methods: methods, |
|||
properties: properties |
|||
}; |
|||
|
@ -0,0 +1,203 @@ |
|||
/* |
|||
This file is part of ethereum.js. |
|||
|
|||
ethereum.js is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU Lesser General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethereum.js is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public License |
|||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file formatters.js |
|||
* @authors: |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* Fabian Vogelsteller <fabian@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
var utils = require('../utils/utils'); |
|||
|
|||
/** |
|||
* Should the input to a big number |
|||
* |
|||
* @method convertToBigNumber |
|||
* @param {String|Number|BigNumber} |
|||
* @returns {BigNumber} object |
|||
*/ |
|||
var convertToBigNumber = function (value) { |
|||
return utils.toBigNumber(value); |
|||
}; |
|||
|
|||
/** |
|||
* Formats the input of a transaction and converts all values to HEX |
|||
* |
|||
* @method inputTransactionFormatter |
|||
* @param {Object} transaction options |
|||
* @returns object |
|||
*/ |
|||
var inputTransactionFormatter = function (options){ |
|||
|
|||
// make code -> data
|
|||
if (options.code) { |
|||
options.data = options.code; |
|||
delete options.code; |
|||
} |
|||
|
|||
['gasPrice', 'gas', 'value'].forEach(function(key){ |
|||
options[key] = utils.fromDecimal(options[key]); |
|||
}); |
|||
|
|||
return options; |
|||
}; |
|||
|
|||
/** |
|||
* Formats the output of a transaction to its proper values |
|||
* |
|||
* @method outputTransactionFormatter |
|||
* @param {Object} transaction |
|||
* @returns {Object} transaction |
|||
*/ |
|||
var outputTransactionFormatter = function (tx){ |
|||
tx.gas = utils.toDecimal(tx.gas); |
|||
tx.gasPrice = utils.toBigNumber(tx.gasPrice); |
|||
tx.value = utils.toBigNumber(tx.value); |
|||
return tx; |
|||
}; |
|||
|
|||
/** |
|||
* Formats the input of a call and converts all values to HEX |
|||
* |
|||
* @method inputCallFormatter |
|||
* @param {Object} transaction options |
|||
* @returns object |
|||
*/ |
|||
var inputCallFormatter = function (options){ |
|||
|
|||
// make code -> data
|
|||
if (options.code) { |
|||
options.data = options.code; |
|||
delete options.code; |
|||
} |
|||
|
|||
return options; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Formats the output of a block to its proper values |
|||
* |
|||
* @method outputBlockFormatter |
|||
* @param {Object} block object |
|||
* @returns {Object} block object |
|||
*/ |
|||
var outputBlockFormatter = function(block){ |
|||
|
|||
// transform to number
|
|||
block.gasLimit = utils.toDecimal(block.gasLimit); |
|||
block.gasUsed = utils.toDecimal(block.gasUsed); |
|||
block.size = utils.toDecimal(block.size); |
|||
block.timestamp = utils.toDecimal(block.timestamp); |
|||
block.number = utils.toDecimal(block.number); |
|||
|
|||
block.minGasPrice = utils.toBigNumber(block.minGasPrice); |
|||
block.difficulty = utils.toBigNumber(block.difficulty); |
|||
block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); |
|||
|
|||
if(block.transactions instanceof Array) { |
|||
block.transactions.forEach(function(item){ |
|||
if(!utils.isString(item)) |
|||
return outputTransactionFormatter(item); |
|||
}); |
|||
} |
|||
|
|||
return block; |
|||
}; |
|||
|
|||
/** |
|||
* Formats the output of a log |
|||
* |
|||
* @method outputLogFormatter |
|||
* @param {Object} log object |
|||
* @returns {Object} log |
|||
*/ |
|||
var outputLogFormatter = function(log){ |
|||
log.blockNumber = utils.toDecimal(log.blockNumber); |
|||
log.transactionIndex = utils.toDecimal(log.transactionIndex); |
|||
log.logIndex = utils.toDecimal(log.logIndex); |
|||
|
|||
return log; |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Formats the input of a whisper post and converts all values to HEX |
|||
* |
|||
* @method inputPostFormatter |
|||
* @param {Object} transaction object |
|||
* @returns {Object} |
|||
*/ |
|||
var inputPostFormatter = function(post){ |
|||
|
|||
post.payload = utils.toHex(post.payload); |
|||
post.ttl = utils.fromDecimal(post.ttl); |
|||
post.priority = utils.fromDecimal(post.priority); |
|||
|
|||
if(!(post.topics instanceof Array)) |
|||
post.topics = [post.topics]; |
|||
|
|||
|
|||
// format the following options
|
|||
post.topics = post.topics.map(function(topic){ |
|||
return utils.fromAscii(topic); |
|||
}); |
|||
|
|||
return post; |
|||
}; |
|||
|
|||
/** |
|||
* Formats the output of a received post message |
|||
* |
|||
* @method outputPostFormatter |
|||
* @param {Object} |
|||
* @returns {Object} |
|||
*/ |
|||
var outputPostFormatter = function(post){ |
|||
|
|||
post.expiry = utils.toDecimal(post.expiry); |
|||
post.sent = utils.toDecimal(post.sent); |
|||
post.ttl = utils.toDecimal(post.ttl); |
|||
post.workProved = utils.toDecimal(post.workProved); |
|||
post.payloadRaw = post.payload; |
|||
post.payload = utils.toAscii(post.payload); |
|||
|
|||
if(post.payload.indexOf('{') === 0 || post.payload.indexOf('[') === 0) { |
|||
try { |
|||
post.payload = JSON.parse(post.payload); |
|||
} catch (e) { } |
|||
} |
|||
|
|||
// format the following options
|
|||
post.topics = post.topics.map(function(topic){ |
|||
return utils.toAscii(topic); |
|||
}); |
|||
|
|||
return post; |
|||
}; |
|||
|
|||
module.exports = { |
|||
convertToBigNumber: convertToBigNumber, |
|||
inputTransactionFormatter: inputTransactionFormatter, |
|||
outputTransactionFormatter: outputTransactionFormatter, |
|||
inputCallFormatter: inputCallFormatter, |
|||
outputBlockFormatter: outputBlockFormatter, |
|||
outputLogFormatter: outputLogFormatter, |
|||
inputPostFormatter: inputPostFormatter, |
|||
outputPostFormatter: outputPostFormatter |
|||
}; |
|||
|
@ -0,0 +1,41 @@ |
|||
/* |
|||
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 eth.js |
|||
* @authors: |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
var utils = require('../utils/utils'); |
|||
|
|||
/// @returns an array of objects describing web3.eth api methods
|
|||
var methods = [ |
|||
// { name: 'getBalance', call: 'eth_balanceAt', outputFormatter: formatters.convertToBigNumber},
|
|||
]; |
|||
|
|||
/// @returns an array of objects describing web3.eth api properties
|
|||
var properties = [ |
|||
{ name: 'listening', getter: 'net_listening'}, |
|||
{ name: 'peerCount', getter: 'net_peerCount', outputFormatter: utils.toDecimal }, |
|||
]; |
|||
|
|||
|
|||
module.exports = { |
|||
methods: methods, |
|||
properties: properties |
|||
}; |
|||
|
@ -0,0 +1,161 @@ |
|||
/* |
|||
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 requestmanager.js |
|||
* @authors: |
|||
* Jeffrey Wilcke <jeff@ethdev.com> |
|||
* Marek Kotewicz <marek@ethdev.com> |
|||
* Marian Oancea <marian@ethdev.com> |
|||
* Gav Wood <g@ethdev.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
var jsonrpc = require('./jsonrpc'); |
|||
var c = require('../utils/config'); |
|||
|
|||
/** |
|||
* It's responsible for passing messages to providers |
|||
* It's also responsible for polling the ethereum node for incoming messages |
|||
* Default poll timeout is 1 second |
|||
*/ |
|||
var requestManager = function() { |
|||
var polls = []; |
|||
var timeout = null; |
|||
var provider; |
|||
|
|||
var send = function (data, callback) { |
|||
/*jshint maxcomplexity: 8 */ |
|||
|
|||
// FORMAT BASED ON ONE FORMATTER function
|
|||
if(typeof data.inputFormatter === 'function') { |
|||
data.params = Array.prototype.map.call(data.params, function(item, index){ |
|||
// format everything besides the defaultblock, which is already formated
|
|||
return (!data.addDefaultblock || index+1 < data.addDefaultblock) ? data.inputFormatter(item) : item; |
|||
}); |
|||
|
|||
// FORMAT BASED ON the input FORMATTER ARRAY
|
|||
} else if(data.inputFormatter instanceof Array) { |
|||
data.params = Array.prototype.map.call(data.inputFormatter, function(formatter, index){ |
|||
// format everything besides the defaultblock, which is already formated
|
|||
return (!data.addDefaultblock || index+1 < data.addDefaultblock) ? formatter(data.params[index]) : data.params[index]; |
|||
}); |
|||
} |
|||
|
|||
|
|||
var payload = jsonrpc.toPayload(data.method, data.params); |
|||
|
|||
if (!provider) { |
|||
console.error('provider is not set'); |
|||
return null; |
|||
} |
|||
|
|||
// HTTP ASYNC (only when callback is given, and it a HttpProvidor)
|
|||
if(typeof callback === 'function' && provider.name === 'HTTP'){ |
|||
provider.send(payload, function(result, status){ |
|||
|
|||
if (!jsonrpc.isValidResponse(result)) { |
|||
if(typeof result === 'object' && result.error && result.error.message) { |
|||
console.error(result.error.message); |
|||
callback(result.error); |
|||
} else { |
|||
callback(new Error({ |
|||
status: status, |
|||
error: result, |
|||
message: 'Bad Request' |
|||
})); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
// format the output
|
|||
callback(null, (typeof data.outputFormatter === 'function') ? data.outputFormatter(result.result) : result.result); |
|||
}); |
|||
|
|||
// SYNC
|
|||
} else { |
|||
var result = provider.send(payload); |
|||
|
|||
if (!jsonrpc.isValidResponse(result)) { |
|||
console.log(result); |
|||
if(typeof result === 'object' && result.error && result.error.message) |
|||
console.error(result.error.message); |
|||
return null; |
|||
} |
|||
|
|||
// format the output
|
|||
return (typeof data.outputFormatter === 'function') ? data.outputFormatter(result.result) : result.result; |
|||
} |
|||
|
|||
}; |
|||
|
|||
var setProvider = function (p) { |
|||
provider = p; |
|||
}; |
|||
|
|||
/*jshint maxparams:4 */ |
|||
var startPolling = function (data, pollId, callback, uninstall) { |
|||
polls.push({data: data, id: pollId, callback: callback, uninstall: uninstall}); |
|||
}; |
|||
/*jshint maxparams:3 */ |
|||
|
|||
var stopPolling = function (pollId) { |
|||
for (var i = polls.length; i--;) { |
|||
var poll = polls[i]; |
|||
if (poll.id === pollId) { |
|||
polls.splice(i, 1); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var reset = function () { |
|||
polls.forEach(function (poll) { |
|||
poll.uninstall(poll.id); |
|||
}); |
|||
polls = []; |
|||
|
|||
if (timeout) { |
|||
clearTimeout(timeout); |
|||
timeout = null; |
|||
} |
|||
poll(); |
|||
}; |
|||
|
|||
var poll = function () { |
|||
polls.forEach(function (data) { |
|||
// send async
|
|||
send(data.data, function(error, result){ |
|||
if (!(result instanceof Array) || result.length === 0) { |
|||
return; |
|||
} |
|||
data.callback(result); |
|||
}); |
|||
}); |
|||
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT); |
|||
}; |
|||
|
|||
poll(); |
|||
|
|||
return { |
|||
send: send, |
|||
setProvider: setProvider, |
|||
startPolling: startPolling, |
|||
stopPolling: stopPolling, |
|||
reset: reset |
|||
}; |
|||
}; |
|||
|
|||
module.exports = requestManager; |
|||
|
@ -0,0 +1,7 @@ |
|||
/* jshint ignore:start */ |
|||
|
|||
if(typeof web3 === 'undefined') { |
|||
web3 = require('web3'); |
|||
} |
|||
|
|||
/* jshint ignore:end */ |
@ -0,0 +1,29 @@ |
|||
/* jshint ignore:start */ |
|||
Package.describe({ |
|||
name: 'ethereum:js', |
|||
version: '0.1.2', |
|||
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC', |
|||
git: 'https://github.com/ethereum/ethereum.js', |
|||
// By default, Meteor will default to using README.md for documentation.
|
|||
// To avoid submitting documentation, set this field to null.
|
|||
documentation: 'README.md' |
|||
}); |
|||
|
|||
Package.onUse(function(api) { |
|||
api.versionsFrom('1.0.3.2'); |
|||
|
|||
api.use('3stack:bignumber@2.0.0', 'client'); |
|||
|
|||
api.export('BigNumber', 'client'); |
|||
api.export('web3', 'client'); |
|||
|
|||
api.addFiles('dist/ethereum.js', 'client'); |
|||
api.addFiles('package-init.js', 'client'); |
|||
}); |
|||
|
|||
// Package.onTest(function(api) {
|
|||
// api.use('tinytest');
|
|||
// api.use('test');
|
|||
// api.addFiles('test-tests.js');
|
|||
// });
|
|||
/* jshint ignore:end */ |
@ -0,0 +1,28 @@ |
|||
var chai = require('chai'); |
|||
var formatters = require('../lib/web3/formatters.js'); |
|||
var assert = chai.assert; |
|||
|
|||
describe('formatters', function () { |
|||
describe('inputPostFormatter', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
// input as strings and numbers
|
|||
assert.deepEqual(formatters.inputPostFormatter({ |
|||
from: '0x00000', |
|||
to: '0x00000', |
|||
payload: {test: 'test'}, |
|||
ttl: 200, |
|||
priority: 1000, |
|||
topics: ['hello','mytopics'] |
|||
}), { |
|||
from: '0x00000', |
|||
to: '0x00000', |
|||
payload: '0x7b2274657374223a2274657374227d', |
|||
ttl: '0xc8', |
|||
priority: '0x3e8', |
|||
topics: ['0x68656c6c6f','0x6d79746f70696373'] |
|||
}); |
|||
|
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,26 @@ |
|||
var assert = require('assert'); |
|||
var formatters = require('../lib/web3/formatters.js'); |
|||
var BigNumber = require('bignumber.js'); |
|||
|
|||
describe('formatters', function () { |
|||
describe('inputTransactionFormatter', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.deepEqual(formatters.inputTransactionFormatter({ |
|||
data: '0x34234kjh23kj4234', |
|||
value: new BigNumber(100), |
|||
from: '0x00000', |
|||
to: '0x00000', |
|||
gas: 1000, |
|||
gasPrice: new BigNumber(1000), |
|||
}), { |
|||
data: '0x34234kjh23kj4234', |
|||
value: '0x64', |
|||
from: '0x00000', |
|||
to: '0x00000', |
|||
gas: '0x3e8', |
|||
gasPrice: '0x3e8', |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,48 @@ |
|||
var assert = require('assert'); |
|||
var formatters = require('../lib/web3/formatters.js'); |
|||
var BigNumber = require('bignumber.js'); |
|||
|
|||
describe('formatters', function () { |
|||
describe('outputBlockFormatter', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.deepEqual(formatters.outputBlockFormatter({ |
|||
hash: '0x34234kjh23kj4234', |
|||
parentHash: '0x34234kjh23kj4234', |
|||
miner: '0x34234kjh23kj4234', |
|||
stateRoot: '0x34234kjh23kj4234', |
|||
sha3Uncles: '0x34234kjh23kj4234', |
|||
bloom: '0x34234kjh23kj4234', |
|||
difficulty: '0x3e8', |
|||
totalDifficulty: '0x3e8', |
|||
number: '0x3e8', |
|||
minGasPrice: '0x3e8', |
|||
gasLimit: '0x3e8', |
|||
gasUsed: '0x3e8', |
|||
timestamp: '0x3e8', |
|||
extraData: '0x34234kjh23kj4234', |
|||
nonce: '0x34234kjh23kj4234', |
|||
children: ['0x34234kjh23kj4234'], |
|||
size: '0x3e8' |
|||
}), { |
|||
hash: '0x34234kjh23kj4234', |
|||
parentHash: '0x34234kjh23kj4234', |
|||
miner: '0x34234kjh23kj4234', |
|||
stateRoot: '0x34234kjh23kj4234', |
|||
sha3Uncles: '0x34234kjh23kj4234', |
|||
bloom: '0x34234kjh23kj4234', |
|||
difficulty: new BigNumber(1000), |
|||
totalDifficulty: new BigNumber(1000), |
|||
number: 1000, |
|||
minGasPrice: new BigNumber(1000), |
|||
gasLimit: 1000, |
|||
gasUsed: 1000, |
|||
timestamp: 1000, |
|||
extraData: '0x34234kjh23kj4234', |
|||
nonce: '0x34234kjh23kj4234', |
|||
children: ['0x34234kjh23kj4234'], |
|||
size: 1000 |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,27 @@ |
|||
var assert = require('assert'); |
|||
var formatters = require('../lib/web3/formatters.js'); |
|||
|
|||
describe('formatters', function () { |
|||
describe('outputLogFormatter', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.deepEqual(formatters.outputLogFormatter({ |
|||
transactionIndex: '0x3e8', |
|||
logIndex: '0x3e8', |
|||
blockNumber: '0x3e8', |
|||
transactionHash: '0x7b2274657374223a2274657374227d', |
|||
blockHash: '0x7b2274657374223a2274657374227d', |
|||
data: '0x7b2274657374223a2274657374227d', |
|||
topics: ['0x68656c6c6f','0x6d79746f70696373'] |
|||
}), { |
|||
transactionIndex: 1000, |
|||
logIndex: 1000, |
|||
blockNumber: 1000, |
|||
transactionHash: '0x7b2274657374223a2274657374227d', |
|||
blockHash: '0x7b2274657374223a2274657374227d', |
|||
data: '0x7b2274657374223a2274657374227d', |
|||
topics: ['0x68656c6c6f','0x6d79746f70696373'] |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,26 @@ |
|||
var assert = require('assert'); |
|||
var formatters = require('../lib/web3/formatters.js'); |
|||
|
|||
describe('formatters', function () { |
|||
describe('outputPostFormatter', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.deepEqual(formatters.outputPostFormatter({ |
|||
expiry: '0x3e8', |
|||
sent: '0x3e8', |
|||
ttl: '0x3e8', |
|||
workProved: '0x3e8', |
|||
payload: '0x7b2274657374223a2274657374227d', |
|||
topics: ['0x68656c6c6f','0x6d79746f70696373'] |
|||
}), { |
|||
expiry: 1000, |
|||
sent: 1000, |
|||
ttl: 1000, |
|||
workProved: 1000, |
|||
payload: {test: 'test'}, |
|||
payloadRaw: '0x7b2274657374223a2274657374227d', |
|||
topics: ['hello','mytopics'] |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,26 @@ |
|||
var assert = require('assert'); |
|||
var formatters = require('../lib/web3/formatters.js'); |
|||
var BigNumber = require('bignumber.js'); |
|||
|
|||
describe('formatters', function () { |
|||
describe('outputTransactionFormatter', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.deepEqual(formatters.outputTransactionFormatter({ |
|||
input: '0x34234kjh23kj4234', |
|||
from: '0x00000', |
|||
to: '0x00000', |
|||
value: '0x3e8', |
|||
gas: '0x3e8', |
|||
gasPrice: '0x3e8' |
|||
}), { |
|||
input: '0x34234kjh23kj4234', |
|||
from: '0x00000', |
|||
to: '0x00000', |
|||
value: new BigNumber(1000), |
|||
gas: 1000, |
|||
gasPrice: new BigNumber(1000), |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,10 @@ |
|||
var assert = require('assert'); |
|||
var web3 = require('../index.js'); |
|||
var u = require('./test.utils.js'); |
|||
|
|||
describe('web3', function() { |
|||
describe('net', function() { |
|||
u.propertyExists(web3.net, 'listening'); |
|||
u.propertyExists(web3.net, 'peerCount'); |
|||
}); |
|||
}); |
@ -0,0 +1,43 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: 1, expected: '0x1' }, |
|||
{ value: '1', expected: '0x1' }, |
|||
{ value: '0x1', expected: '0x1'}, |
|||
{ value: '0x01', expected: '0x1'}, |
|||
{ value: 15, expected: '0xf'}, |
|||
{ value: '15', expected: '0xf'}, |
|||
{ value: '0xf', expected: '0xf'}, |
|||
{ value: '0x0f', expected: '0xf'}, |
|||
{ value: -1, expected: '-0x1'}, |
|||
{ value: '-1', expected: '-0x1'}, |
|||
{ value: '-0x1', expected: '-0x1'}, |
|||
{ value: '-0x01', expected: '-0x1'}, |
|||
{ value: -15, expected: '-0xf'}, |
|||
{ value: '-15', expected: '-0xf'}, |
|||
{ value: '-0xf', expected: '-0xf'}, |
|||
{ value: '-0x0f', expected: '-0xf'}, |
|||
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, |
|||
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, |
|||
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, |
|||
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, |
|||
{ value: 0, expected: '0x0'}, |
|||
{ value: '0', expected: '0x0'}, |
|||
{ value: '0x0', expected: '0x0'}, |
|||
{ value: -0, expected: '0x0'}, |
|||
{ value: '-0', expected: '0x0'}, |
|||
{ value: '-0x0', expected: '0x0'} |
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('fromDecimal', function () { |
|||
tests.forEach(function (test) { |
|||
it('should turn ' + test.value + ' to ' + test.expected, function () { |
|||
assert.equal(utils.fromDecimal(test.value), test.expected); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,22 @@ |
|||
var assert = require('assert'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
|
|||
describe('utils', function () { |
|||
describe('fromWei', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.equal(utils.fromWei(1000000000000000000, 'wei'), '1000000000000000000'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'kwei'), '1000000000000000'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'mwei'), '1000000000000'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'gwei'), '1000000000'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'szabo'), '1000000'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'finney'), '1000'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'ether'), '1'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'kether'), '0.001'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'grand'), '0.001'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'mether'), '0.000001'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'gether'), '0.000000001'); |
|||
assert.equal(utils.fromWei(1000000000000000000, 'tether'), '0.000000000001'); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,23 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: function () {}, is: false}, |
|||
{ value: new Function(), is: false}, |
|||
{ value: 'function', is: false}, |
|||
{ value: {}, is: false}, |
|||
{ value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, |
|||
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true } |
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('isAddress', function () { |
|||
tests.forEach(function (test) { |
|||
it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { |
|||
assert.equal(utils.isAddress(test.value), test.is); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,26 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var BigNumber = require('bignumber.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: function () {}, is: false}, |
|||
{ value: new Function(), is: false}, |
|||
{ value: 'function', is: false}, |
|||
{ value: {}, is: false}, |
|||
{ value: new String('hello'), is: false}, |
|||
{ value: new BigNumber(0), is: true}, |
|||
{ value: 132, is: false}, |
|||
{ value: '0x12', is: false}, |
|||
|
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('isBigNumber', function () { |
|||
tests.forEach(function (test) { |
|||
it('shoud test if value ' + test.func + ' is BigNumber: ' + test.is, function () { |
|||
assert.equal(utils.isBigNumber(test.value), test.is); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,21 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ func: function () {}, is: true}, |
|||
{ func: new Function(), is: true}, |
|||
{ func: 'function', is: false}, |
|||
{ func: {}, is: false} |
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('isFunction', function () { |
|||
tests.forEach(function (test) { |
|||
it('shoud test if value ' + test.func + ' is function: ' + test.is, function () { |
|||
assert.equal(utils.isFunction(test.func), test.is); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,22 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: function () {}, is: false}, |
|||
{ value: new Function(), is: false}, |
|||
{ value: 'function', is: true}, |
|||
{ value: {}, is: false}, |
|||
{ value: new String('hello'), is: true} |
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('isString', function () { |
|||
tests.forEach(function (test) { |
|||
it('shoud test if value ' + test.func + ' is string: ' + test.is, function () { |
|||
assert.equal(utils.isString(test.value), test.is); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,45 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
var BigNumber = require('bignumber.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: 1, expected: '1' }, |
|||
{ value: '1', expected: '1' }, |
|||
{ value: '0x1', expected: '1'}, |
|||
{ value: '0x01', expected: '1'}, |
|||
{ value: 15, expected: '15'}, |
|||
{ value: '15', expected: '15'}, |
|||
{ value: '0xf', expected: '15'}, |
|||
{ value: '0x0f', expected: '15'}, |
|||
{ value: new BigNumber('f', 16), expected: '15'}, |
|||
{ value: -1, expected: '-1'}, |
|||
{ value: '-1', expected: '-1'}, |
|||
{ value: '-0x1', expected: '-1'}, |
|||
{ value: '-0x01', expected: '-1'}, |
|||
{ value: -15, expected: '-15'}, |
|||
{ value: '-15', expected: '-15'}, |
|||
{ value: '-0xf', expected: '-15'}, |
|||
{ value: '-0x0f', expected: '-15'}, |
|||
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935'}, |
|||
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933'}, |
|||
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935'}, |
|||
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933'}, |
|||
{ value: 0, expected: '0'}, |
|||
{ value: '0', expected: '0'}, |
|||
{ value: '0x0', expected: '0'}, |
|||
{ value: -0, expected: '0'}, |
|||
{ value: '-0', expected: '0'}, |
|||
{ value: '-0x0', expected: '0'}, |
|||
{ value: new BigNumber(0), expected: '0'} |
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('toBigNumber', function () { |
|||
tests.forEach(function (test) { |
|||
it('should turn ' + test.value + ' to ' + test.expected, function () { |
|||
assert.equal(utils.toBigNumber(test.value).toString(10), test.expected); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,14 @@ |
|||
var assert = require('assert'); |
|||
var utils = require('../lib/utils/utils.js'); |
|||
|
|||
describe('utils', function () { |
|||
describe('toDecimal', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.equal(utils.toDecimal("0x3e8"), '1000'); |
|||
// allow compatiblity
|
|||
assert.equal(utils.toDecimal(100000), '100000'); |
|||
assert.equal(utils.toDecimal('100000'), '100000'); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1,42 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils'); |
|||
var BigNumber = require('bignumber.js'); |
|||
var assert = chai.assert; |
|||
|
|||
var tests = [ |
|||
{ value: 1, expected: '0x1' }, |
|||
{ value: '1', expected: '0x1' }, |
|||
{ value: '0x1', expected: '0x1'}, |
|||
{ value: '15', expected: '0xf'}, |
|||
{ value: '0xf', expected: '0xf'}, |
|||
{ value: -1, expected: '-0x1'}, |
|||
{ value: '-1', expected: '-0x1'}, |
|||
{ value: '-0x1', expected: '-0x1'}, |
|||
{ value: '-15', expected: '-0xf'}, |
|||
{ value: '-0xf', expected: '-0xf'}, |
|||
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, |
|||
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, |
|||
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, |
|||
{ value: 0, expected: '0x0'}, |
|||
{ value: '0', expected: '0x0'}, |
|||
{ value: '0x0', expected: '0x0'}, |
|||
{ value: -0, expected: '0x0'}, |
|||
{ value: '-0', expected: '0x0'}, |
|||
{ value: '-0x0', expected: '0x0'}, |
|||
{ value: [1,2,3,{test: 'data'}], expected: '0x5b312c322c332c7b2274657374223a2264617461227d5d'}, |
|||
{ value: {test: 'test'}, expected: '0x7b2274657374223a2274657374227d'}, |
|||
{ value: '{"test": "test"}', expected: '0x7b2274657374223a202274657374227d'}, |
|||
{ value: 'myString', expected: '0x6d79537472696e67'}, |
|||
{ value: new BigNumber(15), expected: '0xf'} |
|||
]; |
|||
|
|||
describe('utils', function () { |
|||
describe('toHex', function () { |
|||
tests.forEach(function (test) { |
|||
it('should turn ' + test.value + ' to ' + test.expected, function () { |
|||
assert.equal(utils.toHex(test.value), test.expected); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
|
@ -0,0 +1,25 @@ |
|||
var chai = require('chai'); |
|||
var utils = require('../lib/utils/utils'); |
|||
var assert = chai.assert; |
|||
|
|||
describe('utils', function () { |
|||
describe('toWei', function () { |
|||
it('should return the correct value', function () { |
|||
|
|||
assert.equal(utils.toWei(1, 'wei'), '1'); |
|||
assert.equal(utils.toWei(1, 'kwei'), '1000'); |
|||
assert.equal(utils.toWei(1, 'mwei'), '1000000'); |
|||
assert.equal(utils.toWei(1, 'gwei'), '1000000000'); |
|||
assert.equal(utils.toWei(1, 'szabo'), '1000000000000'); |
|||
assert.equal(utils.toWei(1, 'finney'), '1000000000000000'); |
|||
assert.equal(utils.toWei(1, 'ether'), '1000000000000000000'); |
|||
assert.equal(utils.toWei(1, 'kether'), '1000000000000000000000'); |
|||
assert.equal(utils.toWei(1, 'grand'), '1000000000000000000000'); |
|||
assert.equal(utils.toWei(1, 'mether'), '1000000000000000000000000'); |
|||
assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); |
|||
assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); |
|||
|
|||
assert.throws(function () {utils.toWei(1, 'wei1');}, Error); |
|||
}); |
|||
}); |
|||
}); |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue