Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 61f1ba6

Browse files
committed
Merge pull request #224 from alexvandesande/prefix-name-reorg
Prefix name reorg
2 parents 448dd30 + 5866f08 commit 61f1ba6

File tree

3 files changed

+76
-50
lines changed

3 files changed

+76
-50
lines changed

lib/utils/config.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,34 @@
3636
/// required to define ETH_BIGNUMBER_ROUNDING_MODE
3737
var BigNumber = require('bignumber.js');
3838

39-
var ETH_UNITS = [
40-
'wei',
41-
'Kwei',
42-
'Mwei',
43-
'Gwei',
44-
'szabo',
45-
'finney',
46-
'ether',
47-
'grand',
48-
'Mether',
49-
'Gether',
50-
'Tether',
51-
'Pether',
52-
'Eether',
53-
'Zether',
54-
'Yether',
55-
'Nether',
56-
'Dether',
57-
'Vether',
58-
'Uether'
39+
var ETH_UNITS = [
40+
'wei',
41+
'kwei',
42+
'Mwei',
43+
'Gwei',
44+
'szabo',
45+
'finney',
46+
'femtoether',
47+
'picoether',
48+
'nanoether',
49+
'microether',
50+
'milliether',
51+
'nano',
52+
'micro',
53+
'milli',
54+
'ether',
55+
'grand',
56+
'Mether',
57+
'Gether',
58+
'Tether',
59+
'Pether',
60+
'Eether',
61+
'Zether',
62+
'Yether',
63+
'Nether',
64+
'Dether',
65+
'Vether',
66+
'Uether'
5967
];
6068

6169
module.exports = {

lib/utils/utils.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,30 @@
3636
var BigNumber = require('bignumber.js');
3737

3838
var unitMap = {
39-
'wei': '1',
40-
'kwei': '1000',
41-
'ada': '1000',
42-
'mwei': '1000000',
43-
'babbage': '1000000',
44-
'gwei': '1000000000',
45-
'shannon': '1000000000',
46-
'szabo': '1000000000000',
47-
'finney': '1000000000000000',
48-
'ether': '1000000000000000000',
49-
'kether': '1000000000000000000000',
50-
'grand': '1000000000000000000000',
51-
'einstein': '1000000000000000000000',
52-
'mether': '1000000000000000000000000',
53-
'gether': '1000000000000000000000000000',
54-
'tether': '1000000000000000000000000000000'
39+
'wei': '1',
40+
'kwei': '1000',
41+
'ada': '1000',
42+
'femtoether': '1000',
43+
'mwei': '1000000',
44+
'babbage': '1000000',
45+
'picoether': '1000000',
46+
'gwei': '1000000000',
47+
'shannon': '1000000000',
48+
'nanoether': '1000000000',
49+
'nano': '1000000000',
50+
'szabo': '1000000000000',
51+
'microether': '1000000000000',
52+
'micro': '1000000000000',
53+
'finney': '1000000000000000',
54+
'milliether': '1000000000000000',
55+
'milli': '1000000000000000',
56+
'ether': '1000000000000000000',
57+
'kether': '1000000000000000000000',
58+
'grand': '1000000000000000000000',
59+
'einstein': '1000000000000000000000',
60+
'mether': '1000000000000000000000000',
61+
'gether': '1000000000000000000000000000',
62+
'tether': '1000000000000000000000000000000'
5563
};
5664

5765
/**
@@ -239,13 +247,14 @@ var getValueOfUnit = function (unit) {
239247
* Takes a number of wei and converts it to any other ether unit.
240248
*
241249
* Possible units are:
242-
* - kwei/ada
243-
* - mwei/babbage
244-
* - gwei/shannon
245-
* - szabo
246-
* - finney
247-
* - ether
248-
* - kether/grand/einstein
250+
* SI Short SI Full Effigy Other
251+
* - kwei femtoether ada
252+
* - mwei picoether babbage
253+
* - gwei nanoether shannon nano
254+
* - -- microether szabo micro
255+
* - -- milliether finney milli
256+
* - ether -- --
257+
* - kether einstein grand
249258
* - mether
250259
* - gether
251260
* - tether
@@ -265,13 +274,14 @@ var fromWei = function(number, unit) {
265274
* Takes a number of a unit and converts it to wei.
266275
*
267276
* Possible units are:
268-
* - kwei/ada
269-
* - mwei/babbage
270-
* - gwei/shannon
271-
* - szabo
272-
* - finney
273-
* - ether
274-
* - kether/grand/einstein
277+
* SI Short SI Full Effigy Other
278+
* - kwei femtoether ada
279+
* - mwei picoether babbage
280+
* - gwei nanoether shannon nano
281+
* - -- microether szabo micro
282+
* - -- milliether finney milli
283+
* - ether -- --
284+
* - kether einstein grand
275285
* - mether
276286
* - gether
277287
* - tether

test/utils.toWei.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ describe('lib/utils/utils', function () {
1919
assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000');
2020
assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000');
2121

22+
assert.equal(utils.toWei(1, 'kwei'), utils.toWei(1, 'femtoether'));
23+
assert.equal(utils.toWei(1, 'babbage'), utils.toWei(1, 'picoether'));
24+
assert.equal(utils.toWei(1, 'shannon'), utils.toWei(1, 'nanoether'));
25+
assert.equal(utils.toWei(1, 'szabo'), utils.toWei(1, 'microether'));
26+
assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'milliether'));
27+
assert.equal(utils.toWei(1, 'milli'), utils.toWei(1, 'milliether'));
28+
assert.equal(utils.toWei(1, 'milli'), utils.toWei(1000, 'micro'));
29+
2230
assert.throws(function () {utils.toWei(1, 'wei1');}, Error);
2331
});
2432
});

0 commit comments

Comments
 (0)