Skip to content

Commit d011183

Browse files
committed
gas
2 parents d386faf + 370bcda commit d011183

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8563
-5218
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ build/Release
3434
package-lock.json
3535
# Dependency directories
3636
node_modules/
37+
dist/
3738
jspm_packages/
3839

3940
# Typescript v1 declaration files

package-lock.json

Lines changed: 2936 additions & 1360 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"name": "loopring.js",
33
"version": "0.0.8",
44
"description": "Loopring javascript library",
5+
"scripts": {
6+
"build": "webpack"
7+
},
58
"repository": {
69
"type": "git",
710
"url": "git+https://github.com/loopring/loopring.js.git"
@@ -27,13 +30,18 @@
2730
"whatwg-fetch": "^2.0.4"
2831
},
2932
"devDependencies": {
33+
"@babel/core": "^7.0.0-beta.49",
34+
"@babel/preset-env": "^7.0.0-beta.49",
35+
"babel-core": "^6.26.3",
36+
"babel-loader": "^8.0.0-beta.0",
3037
"eslint": "^4.12.1",
3138
"eslint-config-standard": "^10.2.1",
3239
"eslint-plugin-import": "^2.8.0",
3340
"eslint-plugin-node": "^5.2.1",
3441
"eslint-plugin-promise": "^3.6.0",
3542
"eslint-plugin-standard": "^3.0.1",
3643
"uglifyjs-webpack-plugin": "^1.2.4",
37-
"webpack": "^4.4.1"
44+
"webpack": "^4.11.0",
45+
"webpack-cli": "^3.0.2"
3846
}
3947
}

src/common/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default {
2-
SUCC: {code:0, msg:"success"},
3-
PARAM_INVALID: {code:1001, msg:"parameter invalid"}
4-
}
2+
SUCC: {code: 0, msg: 'success'},
3+
PARAM_INVALID: {code: 1001, msg: 'parameter invalid'}
4+
};

src/common/formatter.js

Lines changed: 140 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,206 @@
11
import ethUtil from 'ethereumjs-util';
22
import BigNumber from 'bignumber.js';
3-
import BN from "bn.js";
3+
import BN from 'bn.js';
44

55
BigNumber.config({
6-
EXPONENTIAL_AT:20,
7-
RANGE:[-20,10000000],
8-
ROUNDING_MODE:1
6+
EXPONENTIAL_AT: 20,
7+
RANGE: [-20, 10000000],
8+
ROUNDING_MODE: 1
99
});
1010
/**
1111
*
1212
* @param mixed Buffer|number|string (hex string must be with '0x' prefix)
1313
* @returns {Buffer}
1414
*/
15-
export function toBuffer(mixed) {
16-
if (mixed instanceof Buffer) {
17-
return mixed;
18-
} else {
19-
return ethUtil.toBuffer(mixed)
20-
}
15+
export function toBuffer (mixed)
16+
{
17+
if (mixed instanceof Buffer)
18+
{
19+
return mixed;
20+
}
21+
else
22+
{
23+
return ethUtil.toBuffer(mixed);
24+
}
2125
}
2226

2327
/**
2428
*
2529
* @param mixed number | BigNumber | BN | Buffer | string
2630
* @returns {string}
2731
*/
28-
export function toHex(mixed) {
29-
30-
if (typeof mixed === 'number' || mixed instanceof BigNumber || mixed instanceof BN) {
31-
return addHexPrefix(mixed.toString(16))
32-
}
33-
34-
if (mixed instanceof Buffer) {
35-
return addHexPrefix(mixed.toString('hex'))
36-
}
37-
38-
if (typeof mixed === 'string') {
39-
const regex = new RegExp(/^0x[0-9a-fA-F]*$/);
40-
return regex.test(mixed) ? mixed : addHexPrefix(toBuffer(String).toString('hex'))
41-
}
42-
throw new Error('Unsupported type')
32+
export function toHex (mixed)
33+
{
34+
if (typeof mixed === 'number' || mixed instanceof BigNumber || mixed instanceof BN)
35+
{
36+
return addHexPrefix(mixed.toString(16));
37+
}
38+
39+
if (mixed instanceof Buffer)
40+
{
41+
return addHexPrefix(mixed.toString('hex'));
42+
}
43+
44+
if (typeof mixed === 'string')
45+
{
46+
const regex = new RegExp(/^0x[0-9a-fA-F]*$/);
47+
return regex.test(mixed) ? mixed : addHexPrefix(toBuffer(String).toString('hex'));
48+
}
49+
throw new Error('Unsupported type');
4350
}
4451

4552
/**
4653
*
4754
* @param mixed number | BigNumber | BN | Buffer | string
4855
* @returns {number}
4956
*/
50-
export function toNumber(mixed) {
51-
if (typeof mixed === 'number') {
52-
return mixed
53-
}
54-
55-
if (mixed instanceof BigNumber || mixed instanceof BN) {
56-
return mixed.toNumber()
57-
}
58-
59-
if (typeof mixed === 'string') {
60-
return Number(mixed)
61-
}
62-
63-
throw new Error('Unsupported type')
57+
export function toNumber (mixed)
58+
{
59+
if (typeof mixed === 'number')
60+
{
61+
return mixed;
62+
}
63+
64+
if (mixed instanceof BigNumber || mixed instanceof BN)
65+
{
66+
return mixed.toNumber();
67+
}
68+
69+
if (typeof mixed === 'string')
70+
{
71+
return Number(mixed);
72+
}
73+
74+
throw new Error('Unsupported type');
6475
}
6576

6677
/**
6778
*
6879
* @param mixed number | BigNumber | BN | Buffer | string
6980
* @returns {BigNumber}
7081
*/
71-
export function toBig(mixed) {
72-
73-
if (mixed instanceof BigNumber) {
74-
return mixed;
75-
}
76-
77-
if (typeof mixed === 'number') {
78-
79-
return new BigNumber(mixed.toString())
80-
}
81-
82-
if (typeof mixed === 'string') {
83-
84-
return new BigNumber(mixed)
85-
}
86-
87-
throw new Error('Unsupported type')
88-
82+
export function toBig (mixed)
83+
{
84+
if (mixed instanceof BigNumber)
85+
{
86+
return mixed;
87+
}
88+
89+
if (typeof mixed === 'number')
90+
{
91+
return new BigNumber(mixed.toString());
92+
}
93+
94+
if (typeof mixed === 'string')
95+
{
96+
return new BigNumber(mixed);
97+
}
98+
99+
throw new Error('Unsupported type');
89100
}
90101

91-
92102
/**
93103
*
94104
* @param mixed number | BigNumber | BN | Buffer | string
95105
* @returns {BN}
96106
*/
97-
export function toBN(mixed) {
98-
return (mixed instanceof BN) ? mixed : new BN(toBig(mixed).toString(10), 10);
107+
export function toBN (mixed)
108+
{
109+
return (mixed instanceof BN) ? mixed : new BN(toBig(mixed).toString(10), 10);
99110
}
100111

101112
/**
102113
* Returns formatted hex string of a given private key
103114
* @param mixed Buffer| string
104115
* @returns {string}
105116
*/
106-
export function formatKey(mixed) {
107-
108-
if (mixed instanceof Buffer) {
109-
return mixed.toString('hex')
110-
}
111-
112-
if (typeof mixed === 'string') {
113-
return mixed.startsWith("0x") ? mixed : mixed
114-
}
115-
throw new Error('Unsupported type')
117+
export function formatKey (mixed)
118+
{
119+
if (mixed instanceof Buffer)
120+
{
121+
return mixed.toString('hex');
122+
}
123+
124+
if (typeof mixed === 'string')
125+
{
126+
return mixed.startsWith('0x') ? mixed : mixed;
127+
}
128+
throw new Error('Unsupported type');
116129
}
117130

118131
/**
119132
* Returns hex string of a given address
120133
* @param mixed Buffer | string
121134
* @returns {string}
122135
*/
123-
export function formatAddress(mixed) {
124-
if (mixed instanceof Buffer) {
125-
return ethUtil.toChecksumAddress('0x' + mixed.toString('hex'))
126-
}
127-
128-
if (typeof mixed === 'string') {
129-
return ethUtil.toChecksumAddress(mixed.startsWith("0x") ? mixed : "0x" + mixed)
130-
}
131-
throw new Error('Unsupported type')
132-
136+
export function formatAddress (mixed)
137+
{
138+
if (mixed instanceof Buffer)
139+
{
140+
return ethUtil.toChecksumAddress('0x' + mixed.toString('hex'));
141+
}
142+
143+
if (typeof mixed === 'string')
144+
{
145+
return ethUtil.toChecksumAddress(mixed.startsWith('0x') ? mixed : '0x' + mixed);
146+
}
147+
throw new Error('Unsupported type');
133148
}
134149

135150
/**
136151
* Returns hex string with '0x' prefix
137152
* @param input
138153
* @returns {string}
139154
*/
140-
export function addHexPrefix(input) {
141-
142-
if (typeof input === 'string') {
143-
return input.startsWith('0x') ? input : "0x" + input;
144-
}
145-
throw new Error('Unsupported type')
155+
export function addHexPrefix (input)
156+
{
157+
if (typeof input === 'string')
158+
{
159+
return input.startsWith('0x') ? input : '0x' + input;
160+
}
161+
throw new Error('Unsupported type');
146162
}
147163

148164
/**
149165
* Returns hex string without '0x' prefix
150166
* @param input string
151167
* @returns {string}
152168
*/
153-
export function clearHexPrefix(input) {
154-
if (typeof input === 'string') {
155-
return input.startsWith('0x') ? input.slice(2) : input;
156-
}
157-
throw new Error('Unsupported type')
169+
export function clearHexPrefix (input)
170+
{
171+
if (typeof input === 'string')
172+
{
173+
return input.startsWith('0x') ? input.slice(2) : input;
174+
}
175+
throw new Error('Unsupported type');
158176
}
159177

160178
/**
161179
*
162180
* @param hex
163181
* @returns {string}
164182
*/
165-
export function padLeftEven(hex) {
166-
return hex.length % 2 !== 0 ? `0${hex}` : hex;
183+
export function padLeftEven (hex)
184+
{
185+
return hex.length % 2 !== 0 ? `0${hex}` : hex;
167186
}
168187

169188
/**
170189
* Returns symbol of a given kind of currency
171190
* @param settingsCurrency
172191
* @returns {*}
173192
*/
174-
export function getDisplaySymbol(settingsCurrency) {
175-
switch (settingsCurrency) {
176-
case 'CNY':
177-
return '¥';
178-
case 'USD':
179-
return '$';
180-
default:
181-
return ''
182-
}
193+
export function getDisplaySymbol (settingsCurrency)
194+
{
195+
switch (settingsCurrency)
196+
{
197+
case 'CNY':
198+
return '¥';
199+
case 'USD':
200+
return '$';
201+
default:
202+
return '';
203+
}
183204
}
184205

185206
/**
@@ -189,23 +210,21 @@ export function getDisplaySymbol(settingsCurrency) {
189210
* @param ceil bool round up
190211
* @returns {string}
191212
*/
192-
export function toFixed(number, precision, ceil) {
193-
precision = precision || 0;
194-
ceil = ceil || false;
195-
if (number instanceof BigNumber) {
196-
const rm = ceil ? 0 : 1;
197-
return number.toFixed(precision, rm)
198-
}
199-
200-
if (typeof number === 'number') {
201-
return ceil ? (Math.ceil(number * Number('1e' + precision)) / Number('1e' + precision)).toFixed(precision) :
202-
(Math.floor(number * Number('1e' + precision)) / Number('1e' + precision)).toFixed(precision);
203-
}
204-
205-
throw new Error('Unsupported type')
213+
export function toFixed (number, precision, ceil)
214+
{
215+
precision = precision || 0;
216+
ceil = ceil || false;
217+
if (number instanceof BigNumber)
218+
{
219+
const rm = ceil ? 0 : 1;
220+
return number.toFixed(precision, rm);
221+
}
222+
223+
if (typeof number === 'number')
224+
{
225+
return ceil ? (Math.ceil(number * Number('1e' + precision)) / Number('1e' + precision)).toFixed(precision)
226+
: (Math.floor(number * Number('1e' + precision)) / Number('1e' + precision)).toFixed(precision);
227+
}
228+
229+
throw new Error('Unsupported type');
206230
}
207-
208-
209-
210-
211-

0 commit comments

Comments
 (0)