diff options
| author | Adam Soltys <[email protected]> | 2018-02-15 20:45:10 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2018-02-15 20:45:10 -0800 |
| commit | b0ef3db4a931646bd39be6e6a48745c121144291 (patch) | |
| tree | 1fb7e7ed22992d519ed3ccbd65a90a3fd9482d71 | |
| parent | 6d40624ff510387f75f2d96f421f1ffb6c39ae1c (diff) | |
| download | coinos-server-b0ef3db4a931646bd39be6e6a48745c121144291.tar.gz coinos-server-b0ef3db4a931646bd39be6e6a48745c121144291.zip | |
open channel
| -rw-r--r-- | index.js | 43 | ||||
| -rw-r--r-- | migrations/20180215052148-addChannelPoint.js | 11 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | yarn.lock | 8 |
4 files changed, 56 insertions, 8 deletions
@@ -34,7 +34,7 @@ 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' }) + const lnrpc = await require('lnrpc')({ server: 'localhost:10001', tls: '/home/adam/.lnd.testa/tls.cert' }) const adminMacaroon = fs.readFileSync('/home/adam/.lnd.testa/admin.macaroon') const meta = new grpc.Metadata() meta.add('macaroon', adminMacaroon.toString('hex')) @@ -47,9 +47,10 @@ const l = console.log }) const db = await require('./db.js')(lnrpc) - const addresses = await db['User'].findAll({ - attributes: ['address'], - }).map(u => u.address) + const addresses = {} + await db['User'].findAll({ + attributes: ['username', 'address'], + }).map(u => { addresses[u.address] = u.username }) console.log(addresses) @@ -67,17 +68,25 @@ const l = console.log let tx = bitcoin.Transaction.fromHex(message) let total = tx.outs.reduce((a, b) => a + b.value, 0) console.log(total) - tx.outs.map(o => { + tx.outs.map(async o => { try { let address = bitcoin.address.fromOutputScript(o.script, bitcoin.networks.testnet) console.log(address, o.value) - if (addresses.includes(address)) { + if (Object.keys(addresses).includes(address)) { + let user = await db['User'].findOne({ + where: { + username: addresses[address], + } + }) + + user.balance += o.value + await user.save() console.log('HIT!') + io.emit('tx', message) } } catch(e) { } }) - io.emit('tx', message) break } @@ -93,6 +102,26 @@ const l = console.log res.json(await lnrpc.walletBalance({witness_only: true}, meta)) }) + app.post('/openchannel', async (req, res) => { + let user = await db['User'].findOne({ + where: { + username: req.body.username, + } + }) + + let channel = lnrpc.openChannelSync({ + node_pubkey_string: '022ea315e5052b152579e70a90bacfd6aa7420f2ce94674d4ca8da29d709bc70fd', + local_funding_amount: user.balance, + }, meta, (err, data) => { + if (err) { + l(err) + return res.status(500).send(err) + } + + res.json(data) + }) + }) + app.post('/sendPayment', async (req, res) => { const payments = lnrpc.sendPayment(meta, {}) payments.write({ payment_request: req.body.payreq }) diff --git a/migrations/20180215052148-addChannelPoint.js b/migrations/20180215052148-addChannelPoint.js new file mode 100644 index 00000000..3c175713 --- /dev/null +++ b/migrations/20180215052148-addChannelPoint.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.addColumn('users', 'channel', { type: Sequelize.STRING }) + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.removeColumn('users', 'channel') + } +}; diff --git a/package.json b/package.json index 507c68a6..e7477d04 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "http-proxy-middleware": "^0.17.2", "jsonwebtoken": "^8.1.1", "less": "2.7.1", - "lnrpc": "https://github.com/asoltys/lnrpc#d3f6196", + "lnrpc": "https://github.com/asoltys/lnrpc#b32f349", "lodash": "^4.17.4", "moment": "^2.10.6", "mysql": "^2.15.0", @@ -3765,6 +3765,14 @@ limiter@^1.0.5: version "1.1.0" resolved "https://registry.yarnpkg.com/limiter/-/limiter-1.1.0.tgz#6e2bd12ca3fcdaa11f224e2e53c896df3f08d913" +"lnrpc@https://github.com/asoltys/lnrpc#b32f349": + version "0.0.3" + resolved "https://github.com/asoltys/lnrpc#b32f34914a735e25064365eb036fae620ba13dc7" + dependencies: + grpc "^1.6.0" + napa "^3.0.0" + pkg-dir "^2.0.0" + "lnrpc@https://github.com/asoltys/lnrpc#d3f6196": version "0.0.3" resolved "https://github.com/asoltys/lnrpc#d3f6196af87d4cc86d59d4b39627d9368ee0e988" |
