1 |
|
2 |
|
3 | const hash = require("hash.js")
|
4 | const TRACING = false
|
5 |
|
6 |
|
7 | function log(message, data) {
|
8 | if (TRACING == true) {
|
9 | console.log(message, data)
|
10 | }
|
11 | }
|
12 |
|
13 |
|
14 | function encryptParams(params) {
|
15 | var hash = require("hash.js")
|
16 | let encryptedParams = {}
|
17 | Object.keys(params).map(key => {
|
18 | encryptedParams[key] = hash.sha256().update(params[key]).digest('hex')
|
19 | })
|
20 | return encryptedParams
|
21 | }
|
22 |
|
23 |
|
24 | function getTokenAmount(tokenAmount, tokenSymbol = "CPU") {
|
25 | try {
|
26 | if (typeof tokenAmount === "number") {
|
27 | const amount = parseFloat(tokenAmount).toFixed(4)
|
28 | return amount.toString() + " " + tokenSymbol
|
29 | } else if (typeof tokenAmount === "string") {
|
30 | if (tokenAmount.split(" ")[1] === tokenSymbol) {
|
31 | return tokenAmount
|
32 | } else {
|
33 | return parseFloat(tokenAmount).toFixed(4).toString() + " " + tokenSymbol
|
34 | }
|
35 | } else {
|
36 | throw err
|
37 | }
|
38 | } catch (err) {
|
39 | console.info(err)
|
40 | }
|
41 | }
|
42 |
|
43 | module.exports = {
|
44 | log,
|
45 | encryptParams,
|
46 | getTokenAmount
|
47 | } |
\ | No newline at end of file |