Browse Source

Allow nice names from JS.

cl-refactor
Gav Wood 10 years ago
parent
commit
852d3c5bb5
  1. 2
      libethcore/CommonEth.cpp
  2. 8
      libethcore/CommonEth.h
  3. 21
      libjsqrc/ethereum.js

2
libethcore/CommonEth.cpp

@ -48,7 +48,7 @@ static const vector<pair<u256, string>> g_units =
{((u256(1000000000) * 1000000000) * 1000000000) * 1000, "Tether"}, {((u256(1000000000) * 1000000000) * 1000000000) * 1000, "Tether"},
{(u256(1000000000) * 1000000000) * 1000000000, "Gether"}, {(u256(1000000000) * 1000000000) * 1000000000, "Gether"},
{(u256(1000000000) * 1000000000) * 1000000, "Mether"}, {(u256(1000000000) * 1000000000) * 1000000, "Mether"},
{(u256(1000000000) * 1000000000) * 1000, "Kether"}, {(u256(1000000000) * 1000000000) * 1000, "grand"},
{u256(1000000000) * 1000000000, "ether"}, {u256(1000000000) * 1000000000, "ether"},
{u256(1000000000) * 1000000, "finney"}, {u256(1000000000) * 1000000, "finney"},
{u256(1000000000) * 1000, "szabo"}, {u256(1000000000) * 1000, "szabo"},

8
libethcore/CommonEth.h

@ -48,7 +48,7 @@ std::vector<std::pair<u256, std::string>> const& units();
using LogBloom = h512; using LogBloom = h512;
// The various denominations; here for ease of use where needed within code. // The various denominations; here for ease of use where needed within code.
static const u256 Uether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000; /*static const u256 Uether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000;
static const u256 Vether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000; static const u256 Vether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000;
static const u256 Dether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000; static const u256 Dether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000;
static const u256 Nether = (((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000; static const u256 Nether = (((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000;
@ -59,13 +59,13 @@ static const u256 Pether = ((u256(1000000000) * 1000000000) * 1000000000) * 1000
static const u256 Tether = ((u256(1000000000) * 1000000000) * 1000000000) * 1000; static const u256 Tether = ((u256(1000000000) * 1000000000) * 1000000000) * 1000;
static const u256 Gether = (u256(1000000000) * 1000000000) * 1000000000; static const u256 Gether = (u256(1000000000) * 1000000000) * 1000000000;
static const u256 Mether = (u256(1000000000) * 1000000000) * 1000000; static const u256 Mether = (u256(1000000000) * 1000000000) * 1000000;
static const u256 Kether = (u256(1000000000) * 1000000000) * 1000; static const u256 grand = (u256(1000000000) * 1000000000) * 1000;*/
static const u256 ether = u256(1000000000) * 1000000000; static const u256 ether = u256(1000000000) * 1000000000;
static const u256 finney = u256(1000000000) * 1000000; static const u256 finney = u256(1000000000) * 1000000;
static const u256 szabo = u256(1000000000) * 1000; static const u256 szabo = u256(1000000000) * 1000;
static const u256 Gwei = u256(1000000000); /*static const u256 Gwei = u256(1000000000);
static const u256 Mwei = u256(1000000); static const u256 Mwei = u256(1000000);
static const u256 Kwei = u256(1000); static const u256 Kwei = u256(1000);*/
static const u256 wei = u256(1); static const u256 wei = u256(1);
} }

21
libjsqrc/ethereum.js

@ -714,6 +714,25 @@ var web3 = {
return "0x" + hex; return "0x" + hex;
}, },
toEth: function(str) {
var val = parseInt(str, 16);
var unit = 0;
var units = [ 'wei', 'Kwei', 'Mwei', 'Gwei', 'szabo', 'finney', 'ether', 'grand', 'Mether', 'Gether', 'Tether', 'Pether', 'Eether', 'Zether', 'Yether', 'Nether', 'Dether', 'Vether', 'Uether' ];
while (val > 3000 && unit < units.length - 1)
{
val /= 1000;
unit++;
}
var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);
while (true) {
var o = s;
s = s.replace(/(\d)(\d\d\d[\.\,])/, function($0, $1, $2) { return $1 + ',' + $2; });
if (o == s)
break;
}
return s + ' ' + units[unit];
},
eth: { eth: {
prototype: Object(), // jshint ignore:line prototype: Object(), // jshint ignore:line
watch: function (params) { watch: function (params) {
@ -1065,4 +1084,4 @@ module.exports = web3;
},{"./lib/autoprovider":2,"./lib/contract":3,"./lib/httprpc":4,"./lib/main":5,"./lib/qt":6,"./lib/websocket":7}]},{},[]) },{"./lib/autoprovider":2,"./lib/contract":3,"./lib/httprpc":4,"./lib/main":5,"./lib/qt":6,"./lib/websocket":7}]},{},[])
//# sourceMappingURL=ethereum.js.map //# sourceMappingURL=ethereum.js.map

Loading…
Cancel
Save