forked from Snipa22/nodejs-pool
-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathscript_account_utils.js
More file actions
50 lines (43 loc) · 1.41 KB
/
script_account_utils.js
File metadata and controls
50 lines (43 loc) · 1.41 KB
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
"use strict";
function splitUser(user) {
const parts = user.split(".");
return {
address: parts.length === 1 ? user : parts[0],
paymentId: parts.length === 2 ? parts[1] : null
};
}
function paymentWhere(account, allowEmptyPaymentId) {
if (account.paymentId !== null) {
return "payment_address = '" + account.address + "' AND payment_id = '" + account.paymentId + "'";
}
return allowEmptyPaymentId === true ?
"payment_address = '" + account.address + "' AND (payment_id IS NULL OR payment_id = '')" :
"payment_address = '" + account.address + "' AND payment_id IS NULL";
}
function logUser(label, account) {
console.log(label + "Address: " + account.address);
console.log(label + "PaymentID: " + account.paymentId);
}
function cacheKeys(user) {
return [user, "stats:" + user, "history:" + user, "identifiers:" + user];
}
function logCacheKeys(user) {
cacheKeys(user).forEach(function (key) {
if (global.database.getCache(key) != false) console.log("Cache key is not empty: " + key);
});
}
function deleteCacheKeys(user) {
const txn = global.database.env.beginTxn();
cacheKeys(user).forEach(function (key) {
if (global.database.getCache(key)) txn.del(global.database.cacheDB, key);
});
txn.commit();
}
module.exports = {
cacheKeys,
deleteCacheKeys,
logCacheKeys,
logUser,
paymentWhere,
splitUser
};