-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallets.js
50 lines (33 loc) · 970 Bytes
/
wallets.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
const fs = require('fs').promises; // Using fs.promises to access the promised-based fs functions
const { Wallet } = require('./wallet');
const createWalletFile = (node) => {
return `wallet-${node}.data`
}
class Wallets {
wallets = {};
addWallet(){
let wallet = new Wallet();
wallet.makeWallet();
let address = wallet.getAddress();
this.wallets[address] = wallet;
return address;
}
getWallet(address){
return this.wallets[address];
}
async loadFile(nodeId){
try {
const file = await fs.readFile(createWalletFile(nodeId));
let wallets = JSON.parse(file);
this.wallets = wallets;
} catch (error) {
console.log("error",error)
}
}
saveFile(nodeId){
fs.writeFile(createWalletFile(nodeId), JSON.stringify(this.wallets), (err) => {})
}
}
module.exports = {
Wallets
}