-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.js
47 lines (39 loc) · 1021 Bytes
/
entry.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
class Entry {
constructor ({ trace, code, db = 0, cr = 0, param1, param2, param3 }, adapter) {
if (!code) {
throw new Error('Undefined account');
}
if ((db <= 0 && cr <= 0) || !((db <= 0 && cr > 0) || (cr <= 0 && db > 0))) {
throw new Error('DBCR must be exclusive');
}
Object.defineProperties(this, {
adapter: {
get: () => adapter,
},
});
this.trace = trace;
this.code = code;
this.db = db;
this.cr = cr;
this.param1 = param1;
this.param2 = param2;
this.param3 = param3;
}
get currency () {
if (!this.account) {
throw new Error('Not validate yet');
}
return this.account.currency;
}
async validate (options) {
let account = await this.getAccount(options);
if (!account) {
throw new Error(`Invalid account, ${this.code}`);
}
}
async getAccount (options) {
this.account = await this.adapter._get(this.code, options);
return this.account;
}
}
module.exports = { Entry };