aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.js70
-rw-r--r--package.json1
-rw-r--r--yarn.lock75
3 files changed, 102 insertions, 44 deletions
diff --git a/index.js b/index.js
index baf1cf6a..fd8e6ae0 100644
--- a/index.js
+++ b/index.js
@@ -98,7 +98,7 @@ const l = console.log
if (!payment) return
payment.received = true
- payment.user.channelbalance += parseInt(msg.value)
+ payment.user.balance += parseInt(msg.value)
payment.rate = app.get('rates').ask
console.log(payment.rate)
@@ -244,7 +244,7 @@ const l = console.log
channel.on('data', async data => {
if (sent || !data.chan_pending) return
- req.user.channelbalance += amount
+ req.user.balance += amount
req.user.balance -= amount
req.user.channel = reverse(data.chan_pending.txid).toString('hex')
await req.user.save()
@@ -281,21 +281,6 @@ const l = console.log
}
})
- app.post('/closechannels', auth, async (req, res) => {
- req.user.balance += req.user.channelbalance
- req.user.channelbalance = 0
- await req.user.save()
- res.send(req.user)
- })
-
-
- app.post('/faucet', auth, async (req, res) => {
- return res.send('not for mainnet')
- // await bc.walletPassphrase('kek', 30000)
- // await bc.sendToAddress(req.user.address, 0.001)
- // res.send('success')
- })
-
app.get('/channels', auth, async (req, res) => {
return res.send(await lna.listChannels())
})
@@ -313,18 +298,8 @@ const l = console.log
return res.status(500).send('Invoice has been paid, can\'t pay again')
}
- if (req.user.channelbalance < payreq.satoshis) {
- if (req.user.balance + req.user.channelbalance < payreq.satoshis) {
- return res.status(500).send('Not enough satoshis')
- }
-
- req.user.balance -= payreq.satoshis
- req.user.channelbalance += payreq.satoshis
-
- if (req.user.balance < 0) {
- req.user.channelbalance += req.user.balance
- req.user.balance = 0
- }
+ if (req.user.balance < payreq.satoshis) {
+ return res.status(500).send('Not enough satoshis')
}
const stream = lna.sendPayment(lna.meta, {})
@@ -338,7 +313,7 @@ const l = console.log
seen.push(m.payment_preimage)
let total = parseInt(m.payment_route.total_amt) + parseInt(m.payment_route.total_fees)
- req.user.channelbalance -= total
+ req.user.balance -= total
await db.Payment.create({
amount: -total,
@@ -369,26 +344,35 @@ const l = console.log
})
})
+ app.post('/send', async (req, res) => {
+ await bc.walletPassphrase('kek', 300)
+ let txid = await bc.sendToAddress('2NDFRT4PAXWsJS2XeXHsqjyhEoTgG563nGd', 0.001)
+ let txhex = await bc.getRawTransaction(txid)
+ let tx = bitcoin.Transaction.fromHex(txhex)
+ let input_total = await tx.ins.reduce(async (a, input) => {
+ let h = await bc.getRawTransaction(reverse(input.hash).toString('hex'))
+ return a + bitcoin.Transaction.fromHex(h).outs[input.index].value
+ }, 0)
+ let output_total = tx.outs.reduce((a, b) => a + b.value, 0)
+ let fees = input_total - output_total
+
+ console.log(input_total, output_total)
+ res.send({ fees })
+ })
+
app.post('/sendCoins', auth, async (req, res) => {
await req.user.reload()
- const MINFEE = 180
+ const MINFEE = 3000
let { address, amount } = req.body
- if (amount === req.user.balance + req.user.channelbalance) {
- amount = req.user.balance + req.user.channelbalance - MINFEE
+ if (amount === req.user.balance) {
+ amount = req.user.balance - MINFEE
}
- if (req.user.balance < amount - MINFEE) {
- if (req.user.balance + req.user.channelbalance < amount - MINFEE) {
- return res.status(500).send('Not enough satoshis')
- }
- req.user.channelbalance -= (amount + MINFEE)
- req.user.balance += amount
- }
-
try {
- let txid = (await lna.sendCoins({ addr: address, amount })).txid
+ await bc.walletPassphrase(config.bitcoin.walletpass, 300)
+ let txid = await bc.sendToAddress(address, (amount / 100000000).toFixed(8))
let txhex = await bc.getRawTransaction(txid)
let tx = bitcoin.Transaction.fromHex(txhex)
@@ -399,7 +383,7 @@ const l = console.log
let output_total = tx.outs.reduce((a, b) => a + b.value, 0)
let fees = input_total - output_total
- let total = Math.min(parseInt(amount) + fees, req.user.balance)
+ let total = Math.min(parseInt(amount) + MINFEE, req.user.balance)
req.user.balance -= total
await req.user.save()
diff --git a/package.json b/package.json
index 41bcabe0..5389b455 100644
--- a/package.json
+++ b/package.json
@@ -70,6 +70,7 @@
},
"devDependencies": {
"babel-preset-es2015": "^6.24.1",
+ "eslint-plugin-html": "^5.0.0",
"pm2": "^2.10.4"
}
}
diff --git a/yarn.lock b/yarn.lock
index 55d721fa..248106d3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2364,6 +2364,39 @@ doctrine@^2.1.0:
dependencies:
esutils "^2.0.2"
+dom-serializer@0:
+ version "0.1.0"
+ resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82"
+ integrity sha1-BzxpdUbOB4DOI75KKOKT5AvDDII=
+ dependencies:
+ domelementtype "~1.1.1"
+ entities "~1.1.1"
+
+domelementtype@1, domelementtype@^1.3.0:
+ version "1.3.1"
+ resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.1.tgz#d048c44b37b0d10a7f2a3d5fee3f4333d790481f"
+ integrity sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==
+
+domelementtype@~1.1.1:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b"
+ integrity sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=
+
+domhandler@^2.3.0:
+ version "2.4.2"
+ resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.4.2.tgz#8805097e933d65e85546f726d60f5eb88b44f803"
+ integrity sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==
+ dependencies:
+ domelementtype "1"
+
+domutils@^1.5.1:
+ version "1.7.0"
+ resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a"
+ integrity sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==
+ dependencies:
+ dom-serializer "0"
+ domelementtype "1"
+
dotenv@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"
@@ -2608,6 +2641,11 @@ engine.io@~3.1.0:
optionalDependencies:
uws "~9.14.0"
+entities@^1.1.1, entities@~1.1.1:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
+ integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==
+
errno@^0.1.1:
version "0.1.4"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.4.tgz#b896e23a9e5e8ba33871fc996abd3635fc9a1c7d"
@@ -2667,6 +2705,13 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
+eslint-plugin-html@^5.0.0:
+ version "5.0.0"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-html/-/eslint-plugin-html-5.0.0.tgz#396e30a60dedee0122fe08f11d13c5ab22f20d32"
+ integrity sha512-f7p/7YQdgQUFVAX3nB4dnMQbrDeTalcA01PDhuvTLk0ZadCwM4Pb+639SRuqEf1zMkIxckLY+ckCr0hVP5zl6A==
+ dependencies:
+ htmlparser2 "^3.10.0"
+
eslint-scope@^3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
@@ -3702,6 +3747,18 @@ hosted-git-info@^2.1.4:
version "2.4.2"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.2.tgz#0076b9f46a270506ddbaaea56496897460612a67"
+htmlparser2@^3.10.0:
+ version "3.10.0"
+ resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.10.0.tgz#5f5e422dcf6119c0d983ed36260ce9ded0bee464"
+ integrity sha512-J1nEUGv+MkXS0weHNWVKJJ+UrLfePxRWpN3C9bEi9fLxL2+ggW94DQvgYVXsaT30PGwYRIZKNZXuyMhp3Di4bQ==
+ dependencies:
+ domelementtype "^1.3.0"
+ domhandler "^2.3.0"
+ domutils "^1.5.1"
+ entities "^1.1.1"
+ inherits "^2.0.1"
+ readable-stream "^3.0.6"
+
[email protected], http-errors@^1.3.0:
version "1.6.2"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.2.tgz#0a002cc85707192a7e7946ceedc11155f60ec736"
@@ -6033,6 +6090,15 @@ readable-stream@^2.0.2, readable-stream@~2.0.5:
string_decoder "~0.10.x"
util-deprecate "~1.0.1"
+readable-stream@^3.0.6:
+ version "3.1.0"
+ resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.1.0.tgz#19c2e9c1ce43507c53f6eefbcf1ee3d4aaa786f5"
+ integrity sha512-vpydAvIJvPODZNagCPuHG87O9JNPtvFEtjHHRVwNVsVVRBqemvPJkc2SYbxJsiZXawJdtZNmkmnsPuE3IgsG0A==
+ dependencies:
+ inherits "^2.0.3"
+ string_decoder "^1.1.1"
+ util-deprecate "^1.0.1"
+
readable-stream@~1.0.26:
version "1.0.34"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c"
@@ -7022,6 +7088,13 @@ string.prototype.startswith@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/string.prototype.startswith/-/string.prototype.startswith-0.2.0.tgz#da68982e353a4e9ac4a43b450a2045d1c445ae7b"
+string_decoder@^1.1.1:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d"
+ integrity sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==
+ dependencies:
+ safe-buffer "~5.1.0"
+
string_decoder@~0.10.x:
version "0.10.31"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
@@ -7442,7 +7515,7 @@ user-home@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"
-util-deprecate@~1.0.1:
+util-deprecate@^1.0.1, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"