aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-02-17 21:08:37 -0800
committerAdam Soltys <[email protected]>2018-02-17 21:08:37 -0800
commitba202a956cc73e9eddda78318220b54b66666200 (patch)
tree56774d8b364bfcf6c5992ac52ea949a0d93c98ac
parent82ea50b1bfef490009afb48c4fcb7986c764886d (diff)
downloadcoinos-server-ba202a956cc73e9eddda78318220b54b66666200.tar.gz
coinos-server-ba202a956cc73e9eddda78318220b54b66666200.zip
add channel balance column
-rw-r--r--index.js24
-rw-r--r--migrations/20180217065619-addChannelBalance.js11
2 files changed, 34 insertions, 1 deletions
diff --git a/index.js b/index.js
index d71327ca..44dc2dbf 100644
--- a/index.js
+++ b/index.js
@@ -37,7 +37,11 @@ const l = console.log
io.origins('http://localhost:8085')
const restClient = ba.restfulClient(process.env.BITCOINAVERAGE_PUBLIC, process.env.BITCOINAVERAGE_SECRET)
- const lnrpc = await require('lnrpc')({ server: 'localhost:10001', tls: '/home/adam/.lnd.testa/tls.cert' })
+ const lnrpc = await require('lnrpc')({
+ server: 'localhost:10001',
+ tls: '/home/adam/.lnd.testa/tls.cert',
+ macaroon: '/home/adam/.lnd.testa/admin.macaroon',
+ })
const adminMacaroon = fs.readFileSync('/home/adam/.lnd.testa/admin.macaroon')
const meta = new grpc.Metadata()
meta.add('macaroon', adminMacaroon.toString('hex'))
@@ -55,6 +59,8 @@ const l = console.log
zmqSock.subscribe('rawblock')
zmqSock.subscribe('rawtx')
+ const seen = []
+
zmqSock.on('message', async (topic, message, sequence) => {
const addresses = {}
await db['User'].findAll({
@@ -66,6 +72,8 @@ const l = console.log
switch (topic) {
case 'rawtx': {
+ if (seen.includes(message)) return
+
let tx = bitcoin.Transaction.fromHex(message)
let total = tx.outs.reduce((a, b) => a + b.value, 0)
l(total)
@@ -84,6 +92,7 @@ const l = console.log
await user.save()
l('HIT!')
io.emit('tx', message)
+ seen.push(message)
}
} catch(e) { }
})
@@ -103,6 +112,10 @@ const l = console.log
res.json(await lnrpc.walletBalance({witness_only: true}, meta))
})
+ app.get('/pendingchannels', async (req, res) => {
+ res.json(await lnrpc.pendingChannels({}, meta))
+ })
+
app.post('/openchannel', async (req, res) => {
let user = await db['User'].findOne({
where: {
@@ -121,7 +134,16 @@ const l = console.log
user.balance = 0
user.channel = reverse(data.funding_txid).toString('hex')
+
+ let list = await lnrpc.listChannels({}, meta)
+ let channels = list.channels.filter(c => c.channel_point.includes(user.channel))
+
+ if (channels.length) {
+ user.channelbalance = channels[0].local_balance
+ }
+
await user.save()
+
res.json(data)
})
})
diff --git a/migrations/20180217065619-addChannelBalance.js b/migrations/20180217065619-addChannelBalance.js
new file mode 100644
index 00000000..fc909f53
--- /dev/null
+++ b/migrations/20180217065619-addChannelBalance.js
@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = {
+ up: (queryInterface, Sequelize) => {
+ return queryInterface.addColumn('users', 'channelbalance', { type: Sequelize.INTEGER })
+ },
+
+ down: (queryInterface, Sequelize) => {
+ return queryInterface.removeColumn('users', 'channelbalance')
+ }
+};