diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 20:54:39 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 20:54:39 +0800 |
commit | 4bdf52fc1e5030d53a8b7337051e12ebd0509009 (patch) | |
tree | 68a2e7415e035fe946b229bc78ac405f4a4d8710 /lib/web3.js | |
parent | 0b82a05a75a0a7592e4fe391120f90d7cee495ac (diff) | |
download | dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.gz dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.bz2 dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.lz dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.xz dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.zst dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.zip |
toAscii && fromAscii moved to utils
Diffstat (limited to 'lib/web3.js')
-rw-r--r-- | lib/web3.js | 38 |
1 files changed, 4 insertions, 34 deletions
diff --git a/lib/web3.js b/lib/web3.js index 88dc6931b..c99c76421 100644 --- a/lib/web3.js +++ b/lib/web3.js @@ -27,6 +27,8 @@ if (process.env.NODE_ENV !== 'build') { var BigNumber = require('bignumber.js'); } +var utils = require('./utils'); + var ETH_UNITS = [ 'wei', 'Kwei', @@ -192,43 +194,11 @@ var web3 = { _events: {}, providers: {}, - toHex: function(str) { - var hex = ""; - for(var i = 0; i < str.length; i++) { - var n = str.charCodeAt(i).toString(16); - hex += n.length < 2 ? '0' + n : n; - } - - return hex; - }, - /// @returns ascii string representation of hex value prefixed with 0x - 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; - }, + toAscii: utils.toAscii, /// @returns hex representation (prefixed by 0x) of ascii string - fromAscii: function(str, pad) { - pad = pad === undefined ? 0 : pad; - var hex = this.toHex(str); - while(hex.length < pad*2) - hex += "00"; - return "0x" + hex; - }, + fromAscii: utils.fromAscii, /// @returns decimal representaton of hex value prefixed by 0x toDecimal: function (val) { |