master
Raw Download raw file
 1function(context, args) { // count:5
 2    var caller = context.caller;
 3    var l = #s.scripts.lib();
 4    var d = #s.dtr.lib();
 5    var list = #s.accts.transactions(args);
 6
 7    var balance = -1;
 8    if (!args || !args.from && !args.to && !args.script) {
 9        balance = #s.accts.balance();
10    }
11
12    l.each(list, function(_, transaction) {
13        transaction.time = l.to_game_timestr(transaction.time);
14        transaction.description = transaction.memo || transaction.script;
15        if (transaction.sender == caller) {
16            transaction.withdrawal = transaction.amount;
17            transaction.opposit = transaction.recipient;
18        } else {
19            transaction.deposit = transaction.amount;
20            transaction.opposit = transaction.sender;
21        }
22        if (balance >= 0) {
23            transaction.balance = balance;
24            balance += (transaction.withdrawal || 0) - (transaction.deposit || 0);
25        }
26    });
27
28    var titles = [
29        { name: "+date+", key: "time" },
30        { name: "+description+", key: "description" },
31        { name: "+opposit+", key: "opposit" },
32        { name: "+withdrawals+", key: "withdrawal", dir: -1, func: d.expandGC },
33        { name: "+deposits+", key: "deposit", dir: -1, func: d.expandGC }
34    ];
35
36    if (balance >= 0) {
37        titles.push(
38            { name: "+balance+", key: "balance", dir: -1, func: d.expandGC });
39    }
40
41    var usage = '\n\nFor more transactions, add count:<"all" or number>\nFilter for sender, recipient or script, add from:"<user>", to:"<user>" or script:"<script>".\n';
42
43    return {
44        ok: true,
45        msg: d.columns(list.reverse(), titles, {pre:"", suf:""}, true) + usage
46    };
47}