-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (38 loc) · 1.46 KB
/
app.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
const Web3 = require('web3');
const constant = require('./app/utils/constant')
const {isTONAddr} = require("./app/utils/utils");
module.exports = app => {
app.validator.addRule('address', (rule, value) => {
if (isTONAddr(value)) {
return;
}
if (Web3.utils.isAddress(value)) {
value = Web3.utils.toChecksumAddress(value);
}
// check is ETH addr
if (!Web3.utils.checkAddressChecksum(value)) {
// check is FLOW contract or FLOW addr
let splits = value.split(".");
if (!Web3.utils.isAddress(splits[0] + "000000000000000000000000")) {
if (splits.length === 1) {
return 'illegal addr';
} else {
return 'illegal contract';
}
}
}
})
app.validator.addRule('tonAddress', (rule, value) => {
if (!isTONAddr(value)) {
return false;
}
})
app.validator.addRule('chainName', (rule, value) => {
if (value !== constant.CHAIN_NAME_MUMBAI && value !== constant.CHAIN_NAME_POLYGON &&
value !== constant.CHAIN_NAME_RINKEBY && value !== constant.CHAIN_NAME_MAINNET &&
value !== constant.CHAIN_NAME_FLOW_MAINNET && value !== constant.CHAIN_NAME_FLOW_TESTNET
&& value !== constant.CHAIN_NAME_TON_MAINNET && value !== constant.CHAIN_NAME_TON_TESTNET) {
return 'illegal chain name';
}
})
};