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