aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-08 20:57:06 -0700
committerAdam Soltys <[email protected]>2024-09-08 20:57:06 -0700
commit5c105c8f4738ab1ead3c5b92f465f899cf0a7446 (patch)
tree9cea2d1b46cdab9869f742e3286c9fb0762f8948 /lib/payments.ts
parent92bd9085a576517e06dc000d1e1ff11d27bc34b4 (diff)
downloadcoinos-server-5c105c8f4738ab1ead3c5b92f465f899cf0a7446.tar.gz
coinos-server-5c105c8f4738ab1ead3c5b92f465f899cf0a7446.zip
refactor rpc helper, accounts endpoints
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts29
1 files changed, 13 insertions, 16 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 5d578af9..36f18e71 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -133,7 +133,14 @@ export let debit = async ({
return p;
};
-export let credit = async (hash, amount, memo, ref, type = types.internal) => {
+export let credit = async ({
+ hash,
+ amount,
+ memo = undefined,
+ ref = undefined,
+ type = types.internal,
+ account = undefined,
+}) => {
amount = parseInt(amount) || 0;
let inv = await getInvoice(hash);
@@ -169,6 +176,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
let id = v4();
let p = {
+ account,
id,
iid: inv.id,
hash,
@@ -208,8 +216,8 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
m.set(`invoice:${inv.id}`, JSON.stringify(inv))
.set(`payment:${p.id}`, JSON.stringify(p))
- .lPush(`${uid}:payments`, p.id)
- .incrBy(`${balanceKey}:${uid}`, amount)
+ .lPush(`${account || uid}:payments`, p.id)
+ .incrBy(`${balanceKey}:${account || uid}`, amount)
.exec();
emit(uid, "payment", p);
@@ -355,7 +363,7 @@ export let sendOnchain = async (params) => {
if (!hex) ({ hex } = await build(params));
let { tx, type } = await decode(hex);
- let node = getNode(type);
+ let node = rpc(config[type]);
let { txid } = tx;
try {
@@ -582,16 +590,6 @@ export let sendLightning = async ({
}
};
-export let getNode = (type, wallet = undefined) => {
- if (type === types.bitcoin) {
- return bc;
- } else if (type === types.liquid) {
- return lq;
- } else if (wallet) {
- return rpc({ ...config.bitcoin, wallet });
- } else fail("unrecognized transaction type");
-};
-
let getAddressType = async (a) => {
try {
await bc.getAddressInfo(a);
@@ -608,8 +606,7 @@ let getAddressType = async (a) => {
export let build = async ({ amount, address, feeRate, user, subtract }) => {
let type = await getAddressType(address);
-
- let node = getNode(type);
+ let node = rpc(config[type]);
amount = parseInt(amount);
if (amount < 0) fail("invalid amount");