-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.js
executable file
·74 lines (58 loc) · 1.47 KB
/
parser.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Parser for Light Token app.
Heavily Based on Aion Web3 API Example
Author: Cosimo Iaia <[email protected]>
Date: 29/04/2018
This file is distribuited under the terms of GNU General Public v3
*/
const tokens = require('./token.js');
// tokens
const DEPLOY = tokens.DEPLOY;
const TRANSFER = tokens.TRANSFER;
const MINT = tokens.MINT;
const BALANCE = tokens.BALANCE;
// special keyword HELP
const parseDeploy = (input) => {
console.log(input);
if (input.length != 0)
throw "should not have any more arguments"
return {
token: DEPLOY
}
}
const parseMint = (input) => {
if (input.length != 2)
throw "mint should have two arguments address (hex) and value (decimal)"
return {
token: MINT,
address: input[0],
value: input[1]
}
}
const parseTransfer = (input) => {
if (input.length != 2)
throw "transfer should have two arguments address (hex) and value (decimal)"
return {
token: TRANSFER,
address: input[0],
value: input[1]
}
}
const parseBalance = (input) => {
if (input.length != 1)
throw "balance should only have one argument (the address)"
return {
token: BALANCE,
address: input[0]
}
}
module.exports.parse = (input) => {
if (input[0] === DEPLOY)
return parseDeploy(input.slice(1));
if (input[0] === MINT)
return parseMint(input.slice(1));
if (input[0] === TRANSFER)
return parseTransfer(input.slice(1));
if (input[0] === BALANCE)
return parseBalance(input.slice(1));
}