Support Strike for Lightning Network

This commit is contained in:
Josh Harvey 2018-05-26 14:09:47 +03:00
parent 8d4a36865b
commit 3f9c139f83
11 changed files with 175 additions and 11 deletions

View file

@ -8,6 +8,7 @@ const fs = pify(require('fs'))
const options = require('./options')
const ph = require('./plugin-helper')
const layer2 = require('./layer2')
const FETCH_INTERVAL = 5000
const INSUFFICIENT_FUNDS_CODE = 570
@ -39,6 +40,12 @@ function fetchWallet (settings, cryptoCode) {
})
}
function isLayer2 (tx) {
return _.isNil(tx.isLightning)
? layer2.isLayer2Address(tx.toAddress)
: tx.isLightning
}
const lastBalance = {}
function _balance (settings, cryptoCode) {
@ -74,6 +81,8 @@ function sendCoins (settings, toAddress, cryptoAtoms, cryptoCode) {
}
function newAddress (settings, info) {
if (isLayer2(info)) return layer2.newAddress(settings, info)
return fetchWallet(settings, info.cryptoCode)
.then(r => r.wallet.newAddress(r.account, info))
}
@ -89,6 +98,8 @@ function newFunding (settings, cryptoCode, address) {
}
function getWalletStatus (settings, tx) {
if (isLayer2(tx)) return layer2.getStatus(settings, tx)
return fetchWallet(settings, tx.cryptoCode)
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
}