forked from Dapp-Learning-DAO/Dapp-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
40 lines (36 loc) · 858 Bytes
/
utils.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
// read and save redpacket contract deployment json file
const path = require('path');
const fs = require('fs');
const DEPLOYMENGT_DIR = path.join(__dirname, '/scripts/redpacket/deployment.json');
/*
* deployment:
* redPacketAddress
* redPacketOwner
* redPacketID
* simpleTokenAddress
*/
function readRedpacketDeployment() {
if (!fs.existsSync(DEPLOYMENGT_DIR)) return null;
try {
return JSON.parse(fs.readFileSync(DEPLOYMENGT_DIR, { encoding: 'utf-8' }));
} catch {
return null;
}
}
function saveRedpacketDeployment(payload) {
let oldData = readRedpacketDeployment();
if (!oldData) oldData = {};
fs.writeFileSync(
DEPLOYMENGT_DIR,
JSON.stringify({
...oldData,
...payload,
}),
{ flag: 'w+' }
);
return true;
}
module.exports = {
readRedpacketDeployment,
saveRedpacketDeployment,
};