lightning network support
This commit is contained in:
parent
1a31b27845
commit
4625ffef0f
7 changed files with 1305 additions and 101 deletions
|
|
@ -173,6 +173,7 @@ function fetchData () {
|
||||||
{code: 'coinbase', display: 'Coinbase', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC', 'BCH']},
|
{code: 'coinbase', display: 'Coinbase', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC', 'BCH']},
|
||||||
{code: 'mock-ticker', display: 'Mock ticker', class: 'ticker', cryptos: ALL_CRYPTOS},
|
{code: 'mock-ticker', display: 'Mock ticker', class: 'ticker', cryptos: ALL_CRYPTOS},
|
||||||
{code: 'bitcoind', display: 'bitcoind', class: 'wallet', cryptos: ['BTC']},
|
{code: 'bitcoind', display: 'bitcoind', class: 'wallet', cryptos: ['BTC']},
|
||||||
|
{code: 'lnd', display: 'Lightning Network', class: 'wallet', cryptos: ['BTC']},
|
||||||
{code: 'geth', display: 'geth', class: 'wallet', cryptos: ['ETH']},
|
{code: 'geth', display: 'geth', class: 'wallet', cryptos: ['ETH']},
|
||||||
{code: 'zcashd', display: 'zcashd', class: 'wallet', cryptos: ['ZEC']},
|
{code: 'zcashd', display: 'zcashd', class: 'wallet', cryptos: ['ZEC']},
|
||||||
{code: 'litecoind', display: 'litecoind', class: 'wallet', cryptos: ['LTC']},
|
{code: 'litecoind', display: 'litecoind', class: 'wallet', cryptos: ['LTC']},
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,7 @@ function preProcess (oldTx, newTx, pi) {
|
||||||
.then(newTxHd => {
|
.then(newTxHd => {
|
||||||
return pi.newAddress(newTxHd)
|
return pi.newAddress(newTxHd)
|
||||||
.then(_.set('toAddress', _, newTxHd))
|
.then(_.set('toAddress', _, newTxHd))
|
||||||
|
.then(_.unset('isLightning'))
|
||||||
})
|
})
|
||||||
.then(addressedTx => {
|
.then(addressedTx => {
|
||||||
const rec = {to_address: addressedTx.toAddress}
|
const rec = {to_address: addressedTx.toAddress}
|
||||||
|
|
|
||||||
|
|
@ -24,3 +24,4 @@ register('NoDataError')
|
||||||
register('InsufficientFundsError')
|
register('InsufficientFundsError')
|
||||||
register('StaleTxError')
|
register('StaleTxError')
|
||||||
register('RatchetError')
|
register('RatchetError')
|
||||||
|
register('NotImplementedError')
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,9 @@ function plugins (settings, deviceId) {
|
||||||
cryptoCode: tx.cryptoCode,
|
cryptoCode: tx.cryptoCode,
|
||||||
label: 'TX ' + Date.now(),
|
label: 'TX ' + Date.now(),
|
||||||
account: 'deposit',
|
account: 'deposit',
|
||||||
hdIndex: tx.hdIndex
|
hdIndex: tx.hdIndex,
|
||||||
|
cryptoAtoms: tx.cryptoAtoms,
|
||||||
|
isLightning: tx.isLightning
|
||||||
}
|
}
|
||||||
return wallet.newAddress(settings, info)
|
return wallet.newAddress(settings, info)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
89
lib/plugins/wallet/lnd/lnd.js
Normal file
89
lib/plugins/wallet/lnd/lnd.js
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
const lnd = require('lnd-async')
|
||||||
|
|
||||||
|
const BN = require('../../../bn')
|
||||||
|
const E = require('../../../error')
|
||||||
|
const coinUtils = require('../../../coin-utils')
|
||||||
|
const options = require('../../../options')
|
||||||
|
|
||||||
|
const _ = require('lodash/fp')
|
||||||
|
|
||||||
|
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
||||||
|
const unitScale = cryptoRec.unitScale
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
balance,
|
||||||
|
sendCoins,
|
||||||
|
newAddress,
|
||||||
|
getStatus,
|
||||||
|
newFunding,
|
||||||
|
cryptoNetwork
|
||||||
|
}
|
||||||
|
|
||||||
|
function connect () {
|
||||||
|
return lnd.connect(options.lnd || {})
|
||||||
|
}
|
||||||
|
|
||||||
|
function cryptoNetwork (account, cryptoCode) {
|
||||||
|
return Promise.resolve('test')
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
if (cryptoCode !== 'BTC') return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
function balance (acount, cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(connect)
|
||||||
|
.then(c => c.channelBalance({}))
|
||||||
|
.then(_.get('balance'))
|
||||||
|
.then(BN)
|
||||||
|
.then(r => r.shift(unitScale).round())
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
|
// Not implemented yet
|
||||||
|
return Promise.reject(new E.NotImplementedError())
|
||||||
|
}
|
||||||
|
|
||||||
|
function newFunding (account, cryptoCode) {
|
||||||
|
// Not implemented yet
|
||||||
|
return Promise.reject(new E.NotImplementedError())
|
||||||
|
}
|
||||||
|
|
||||||
|
function newAddress (account, info) {
|
||||||
|
return checkCryptoCode(info.cryptoCode)
|
||||||
|
.then(connect)
|
||||||
|
.then(c => {
|
||||||
|
if (info.isLightning) {
|
||||||
|
return c.addInvoice({memo: 'Lamassu cryptomat deposit', value: info.cryptoAtoms.toNumber()})
|
||||||
|
.then(r => `${r.r_hash.toString('hex')}:${r.payment_request}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.newAddress({type: 2})
|
||||||
|
.then(_.get('address'))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatus (account, toAddress, requested, cryptoCode) {
|
||||||
|
return checkCryptoCode(cryptoCode)
|
||||||
|
.then(() => {
|
||||||
|
const parts = _.split(':', toAddress)
|
||||||
|
const isLightning = _.size(parts) === 2
|
||||||
|
const rHashStr = isLightning && _.head(parts)
|
||||||
|
|
||||||
|
return connect()
|
||||||
|
.then(c => {
|
||||||
|
if (isLightning) {
|
||||||
|
return c.lookupInvoice({r_hash_str: rHashStr})
|
||||||
|
.then(r => {
|
||||||
|
if (r.settled) return {status: 'confirmed'}
|
||||||
|
return {status: 'notSeen'}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: this must be handled outside of lnd
|
||||||
|
return {status: 'notSeen'}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
1303
package-lock.json
generated
1303
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -12,6 +12,8 @@
|
||||||
"bignumber.js": "^4.0.2",
|
"bignumber.js": "^4.0.2",
|
||||||
"bip39": "^2.3.1",
|
"bip39": "^2.3.1",
|
||||||
"bitcoind-rpc": "^0.7.0",
|
"bitcoind-rpc": "^0.7.0",
|
||||||
|
"bitcore-lib": "^0.15.0",
|
||||||
|
"bitcore-lib-cash": "git+https://github.com/bitpay/bitcore-lib.git#cash",
|
||||||
"bitgo": "3.4.11",
|
"bitgo": "3.4.11",
|
||||||
"body-parser": "^1.15.1",
|
"body-parser": "^1.15.1",
|
||||||
"coinbase": "^2.0.6",
|
"coinbase": "^2.0.6",
|
||||||
|
|
@ -27,6 +29,7 @@
|
||||||
"helmet": "^3.8.1",
|
"helmet": "^3.8.1",
|
||||||
"inquirer": "^3.2.1",
|
"inquirer": "^3.2.1",
|
||||||
"kraken-api": "github:DeX3/npm-kraken-api",
|
"kraken-api": "github:DeX3/npm-kraken-api",
|
||||||
|
"lnd-async": "^1.0.1",
|
||||||
"lodash": "^4.17.2",
|
"lodash": "^4.17.2",
|
||||||
"make-dir": "^1.0.0",
|
"make-dir": "^1.0.0",
|
||||||
"mem": "^1.1.0",
|
"mem": "^1.1.0",
|
||||||
|
|
@ -50,9 +53,7 @@
|
||||||
"uuid": "^3.1.0",
|
"uuid": "^3.1.0",
|
||||||
"web3": "^0.19.1",
|
"web3": "^0.19.1",
|
||||||
"winston": "^2.3.0",
|
"winston": "^2.3.0",
|
||||||
"ws": "^3.1.0",
|
"ws": "^3.1.0"
|
||||||
"bitcore-lib": "^0.15.0",
|
|
||||||
"bitcore-lib-cash": "git+https://github.com/bitpay/bitcore-lib.git#cash"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue