-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathescrow.1.jsb.exp
39 lines (33 loc) · 1.03 KB
/
escrow.1.jsb.exp
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
module.exports = class Escrow {
constructor(buyer, amount, payee, arbiter, fee) {
let main = this;
this._escrow = 0;
this.buyer = buyer;
this.payee = payee;
this.arbiter = arbiter;
this.amount = amount;
this.fee = fee;
this._pay(this.buyer, 'escrow', this.amount);
}
pay_out(caller) {
if(caller == this.arbiter) {
this._pay('escrow', this.arbiter, this.fee);
this._pay('escrow', this.payee, this._escrow);
} else {
return 'not permitted.';
}
}
pay_back(caller) {
if(caller == this.arbiter) {
this._pay('escrow', this.arbiter, this.fee);
this._pay('escrow', this.buyer, this._escrow);
} else {
return 'not permitted.';
}
}
_pay(from, to, amount) {
console.log(`➠ system message: pay ${amount} from ${from} to ${to}.`);
if(from == 'escrow') main._escrow -= amount;
if(to == 'escrow') main._escrow += amount;
}
}