forked from ethereum-plasma/plasma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
34 lines (27 loc) · 664 Bytes
/
utils.js
File metadata and controls
34 lines (27 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const Web3 = require("web3");
const addHexPrefix = (msg) => {
return '0x' + msg;
};
const removeHexPrefix = (msg) => {
if (Web3.utils.isHexStrict(msg)) {
return msg.slice(2);
} else {
return msg;
}
};
const bufferToHex = (buf, withPrefix) => {
if (withPrefix) {
return addHexPrefix(buf.toString('hex'));
} else {
return buf.toString('hex');
}
};
const weiToEther = (data) => {
return data / 1000000000000000000;
};
const etherToWei = (data) => {
return data * 1000000000000000000;
};
module.exports = {addHexPrefix, removeHexPrefix, bufferToHex, weiToEther,
etherToWei};