aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-08-09 22:13:47 -0700
committerAdam Soltys <[email protected]>2020-08-09 22:13:47 -0700
commitf89b0ffde25292909bd398430e84e6c693084582 (patch)
tree36e418ae2efffc8bcc57d44b0955b43782f8c475 /routes/bitcoin
parent23fa7f40f1cbc94238f836876a31480a4a23b785 (diff)
downloadcoinos-server-f89b0ffde25292909bd398430e84e6c693084582.tar.gz
coinos-server-f89b0ffde25292909bd398430e84e6c693084582.zip
handle receiving to non-custodial account
Diffstat (limited to 'routes/bitcoin')
-rw-r--r--routes/bitcoin/fee.js32
-rw-r--r--routes/bitcoin/receive.js5
2 files changed, 25 insertions, 12 deletions
diff --git a/routes/bitcoin/fee.js b/routes/bitcoin/fee.js
index da0fb9e9..cd99d363 100644
--- a/routes/bitcoin/fee.js
+++ b/routes/bitcoin/fee.js
@@ -1,32 +1,42 @@
+const buildTx = ({ address, amount, feeRate }) => {};
+
module.exports = ah(async (req, res) => {
let { user } = req;
let { address, amount, feeRate } = req.body;
let tx, fee;
+ if (user.account.pubkey) {
+ tx = buildTx(req.body);
+ return res.end();
+ }
+
let invoice = await db.Invoice.findOne({
where: { address },
include: {
- attributes: ['username'],
+ attributes: ["username"],
model: db.User,
- as: 'user',
- }
+ as: "user",
+ },
});
if (invoice) {
- emit(user.username, "to", invoice.user);
- return res.end();
+ let { ismine } = await bc.getAddressInfo(address);
+ if (ismine) {
+ emit(user.username, "to", invoice.user);
+ return res.end();
+ }
}
try {
amount = parseInt(amount);
let partial = await bc.createRawTransaction([], {
- [address]: (amount / SATS).toFixed(8)
+ [address]: (amount / SATS).toFixed(8),
});
let params = {
- subtractFeeFromOutputs: amount === user.balance ? [0] : []
- }
+ subtractFeeFromOutputs: amount === user.balance ? [0] : [],
+ };
if (feeRate) params.feeRate = (feeRate / SATS).toFixed(8);
@@ -35,10 +45,10 @@ module.exports = ah(async (req, res) => {
if (config.bitcoin.walletpass)
await bc.walletPassphrase(config.bitcoin.walletpass, 300);
- let signed = (await bc.signRawTransactionWithWallet(tx.hex));
+ let signed = await bc.signRawTransactionWithWallet(tx.hex);
decoded = await bc.decodeRawTransaction(signed.hex);
- feeRate = Math.round(tx.fee * SATS * 1000 / decoded.vsize);
-
+ feeRate = Math.round((tx.fee * SATS * 1000) / decoded.vsize);
+
res.send({ feeRate, tx });
} catch (e) {
l.error("bitcoin fee estimation error", e);
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 1ee9f323..1c731118 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -59,13 +59,16 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
let confirmed = false;
- const account = await db.Account.findOne({
+ const accounts = await db.Account.findAll({
where: {
user_id: user.id,
asset: config.liquid.btcasset,
},
});
+ let account = accounts.find(a => a.address === address);
+ if (!account) account = accounts[0];
+
account.pending += value;
await account.save();