From cd3977c1c8fedecbb344f774024c91a66be054de Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 1 Oct 2020 00:17:09 -0700 Subject: add privkey column --- db/models/accounts.js | 9 +++++++++ db/schema.sql | 15 ++++++++------- lib/buildtx.js | 6 ++++-- routes/bitcoin/send.js | 2 +- routes/liquid/fee.js | 1 + routes/users.js | 6 ++++-- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/db/models/accounts.js b/db/models/accounts.js index 17e03857..12fef548 100644 --- a/db/models/accounts.js +++ b/db/models/accounts.js @@ -151,6 +151,15 @@ const attributes = { comment: null, field: "index" }, + privkey: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + primaryKey: false, + autoIncrement: false, + comment: null, + field: "privkey" + }, pubkey: { type: DataTypes.STRING, allowNull: true, diff --git a/db/schema.sql b/db/schema.sql index 2eee5c19..f61482d6 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -64,8 +64,9 @@ CREATE TABLE `accounts` ( `seed` varchar(255) DEFAULT NULL, `path` varchar(255) DEFAULT NULL, `network` varchar(255) DEFAULT NULL, + `privkey` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4062 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=4076 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -108,7 +109,7 @@ CREATE TABLE `invoices` ( `account_id` int(11) DEFAULT NULL, `path` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=6311 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=6422 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -125,7 +126,7 @@ CREATE TABLE `linkingkeys` ( `createdAt` datetime NOT NULL, `updatedAt` datetime NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4598 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=4605 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -157,7 +158,7 @@ CREATE TABLE `payments` ( `redeemed` tinyint(1) NOT NULL DEFAULT 0, `path` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=6167 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=6682 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -183,7 +184,7 @@ CREATE TABLE `proposals` ( `a2_id` int(11) DEFAULT NULL, `fee` double DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=918 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=1023 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -229,7 +230,7 @@ CREATE TABLE `users` ( `index` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), KEY `ip` (`ip`) -) ENGINE=InnoDB AUTO_INCREMENT=724 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=729 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -241,4 +242,4 @@ CREATE TABLE `users` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2020-09-28 0:55:47 +-- Dump completed on 2020-10-01 0:16:52 diff --git a/lib/buildtx.js b/lib/buildtx.js index 0f63f641..876f6fff 100644 --- a/lib/buildtx.js +++ b/lib/buildtx.js @@ -20,10 +20,12 @@ module.exports = async ({ address, amount, feeRate, replaceable, user }) => { } }); + + const addresses = [...new Set(payments.map(p => p.address))]; const utxos = []; - for (let i = 0; i < payments.length; i++) { + for (let i = 0; i < addresses.length; i++) { try { - utxos.push(...(await axios.get(`${api}/address/${payments[i].address}/utxo`)).data); + utxos.push(...(await axios.get(`${api}/address/${addresses[i]}/utxo`)).data); } catch (e) { l.error("problem fetching utxos", e.message); } diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index f76329f9..2089adfa 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -65,7 +65,7 @@ module.exports = ah(async (req, res) => { address, confirmed: true, received: false, - network: "liquid" + network: "bitcoin" }; }); } catch (e) { diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js index d8be6de8..489c5c4b 100644 --- a/routes/liquid/fee.js +++ b/routes/liquid/fee.js @@ -17,6 +17,7 @@ module.exports = ah(async (req, res) => { }); return res.send(psbt); } catch (e) { + l.error(e.message, e.stack); return res.status(500).send(e.message); } } diff --git a/routes/users.js b/routes/users.js index 3d0b50e4..d40ad5a8 100644 --- a/routes/users.js +++ b/routes/users.js @@ -259,7 +259,7 @@ app.post( "/accounts", auth, ah(async (req, res) => { - const { name, seed, pubkey, ticker, precision, path, network } = req.body; + const { name, seed, pubkey, ticker, precision, path, privkey, network } = req.body; const { user } = req; let account = await db.Account.create({ @@ -271,6 +271,7 @@ app.post( ticker, precision, pubkey, + privkey, seed, path, network @@ -420,6 +421,7 @@ app.post( domain, seed, pubkey, + privkey, path, hide, index @@ -427,7 +429,7 @@ app.post( try { await db.Account.update( - { name, ticker, precision, domain, seed, pubkey, path, hide, index }, + { name, ticker, precision, domain, seed, pubkey, path, hide, index, privkey }, { where: { id, user_id: user.id } } -- cgit v1.2.3