Add layer2 address separately
This commit is contained in:
parent
d9aaf2437f
commit
d1712ce1ce
7 changed files with 85 additions and 31 deletions
|
|
@ -42,11 +42,14 @@ function preProcess (t, oldTx, newTx, pi) {
|
||||||
.then(isHd => nextHd(t, isHd, newTx))
|
.then(isHd => nextHd(t, isHd, newTx))
|
||||||
.then(newTxHd => {
|
.then(newTxHd => {
|
||||||
return pi.newAddress(newTxHd)
|
return pi.newAddress(newTxHd)
|
||||||
.then(_.set('toAddress', _, newTxHd))
|
.then(_.merge(newTxHd))
|
||||||
.then(_.unset('isLightning'))
|
|
||||||
})
|
})
|
||||||
.then(addressedTx => {
|
.then(addressedTx => {
|
||||||
const rec = {to_address: addressedTx.toAddress}
|
const rec = {
|
||||||
|
to_address: addressedTx.toAddress,
|
||||||
|
layer_2_address: addressedTx.layer2Address
|
||||||
|
}
|
||||||
|
|
||||||
return cashOutActions.logAction(t, 'provisionAddress', rec, addressedTx)
|
return cashOutActions.logAction(t, 'provisionAddress', rec, addressedTx)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ const ph = require('./plugin-helper')
|
||||||
|
|
||||||
function fetch (settings, cryptoCode) {
|
function fetch (settings, cryptoCode) {
|
||||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).layer2
|
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).layer2
|
||||||
|
if (plugin === 'no-layer2') return Promise.resolve()
|
||||||
|
|
||||||
const layer2 = ph.load(ph.LAYER2, plugin)
|
const layer2 = ph.load(ph.LAYER2, plugin)
|
||||||
const account = settings.accounts[plugin]
|
const account = settings.accounts[plugin]
|
||||||
|
|
||||||
|
|
@ -11,12 +13,21 @@ function fetch (settings, cryptoCode) {
|
||||||
|
|
||||||
function newAddress (settings, info) {
|
function newAddress (settings, info) {
|
||||||
return fetch(settings, info.cryptoCode)
|
return fetch(settings, info.cryptoCode)
|
||||||
.then(r => r.layer2.newAddress(r.account, info))
|
.then(r => {
|
||||||
|
if (!r) return
|
||||||
|
return r.layer2.newAddress(r.account, info)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatus (settings, tx) {
|
function getStatus (settings, tx) {
|
||||||
|
const toAddress = tx.layer2Address
|
||||||
|
if (!toAddress) return Promise.resolve({status: 'notSeen'})
|
||||||
|
|
||||||
return fetch(settings, tx.cryptoCode)
|
return fetch(settings, tx.cryptoCode)
|
||||||
.then(r => r.layer2.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
.then(r => {
|
||||||
|
if (!r) return {status: 'notSeen'}
|
||||||
|
return r.layer2.getStatus(r.account, toAddress, tx.cryptoAtoms, tx.cryptoCode)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function cryptoNetwork (settings, cryptoCode) {
|
function cryptoNetwork (settings, cryptoCode) {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
|
||||||
|
const options = require('../../../options')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
cryptoNetwork
|
cryptoNetwork
|
||||||
}
|
}
|
||||||
|
|
||||||
|
axios.defaults.baseURL = options.strike.baseUrl
|
||||||
|
|
||||||
function cryptoNetwork (account, cryptoCode) {
|
function cryptoNetwork (account, cryptoCode) {
|
||||||
return Promise.resolve('test')
|
return Promise.resolve('test')
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +23,7 @@ function checkCryptoCode (cryptoCode) {
|
||||||
function getCharge (account, chargeId) {
|
function getCharge (account, chargeId) {
|
||||||
return axios({
|
return axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: `https://api.strike.acinq.co/api/v1/charges/${chargeId}`,
|
url: `v1/charges/${chargeId}`,
|
||||||
auth: {username: account.token, password: ''}
|
auth: {username: account.token, password: ''}
|
||||||
}).then(_.get('data'))
|
}).then(_.get('data'))
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +37,7 @@ function createCharge (account, info) {
|
||||||
|
|
||||||
return axios({
|
return axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: 'https://api.strike.acinq.co/api/v1/charges',
|
url: 'v1/charges',
|
||||||
auth: {username: account.token, password: ''},
|
auth: {username: account.token, password: ''},
|
||||||
data
|
data
|
||||||
}).then(_.get('data'))
|
}).then(_.get('data'))
|
||||||
|
|
|
||||||
|
|
@ -74,16 +74,11 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
||||||
|
|
||||||
return connect()
|
return connect()
|
||||||
.then(c => {
|
.then(c => {
|
||||||
if (isLightning) {
|
return c.lookupInvoice({r_hash_str: rHashStr})
|
||||||
return c.lookupInvoice({r_hash_str: rHashStr})
|
.then(r => {
|
||||||
.then(r => {
|
if (r.settled) return {status: 'confirmed'}
|
||||||
if (r.settled) return {status: 'confirmed'}
|
return {status: 'notSeen'}
|
||||||
return {status: 'notSeen'}
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: this must be handled outside of lnd
|
|
||||||
return {status: 'notSeen'}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ const coinUtils = require('../../../coin-utils')
|
||||||
const NAME = 'FakeWallet'
|
const NAME = 'FakeWallet'
|
||||||
|
|
||||||
const SECONDS = 1000
|
const SECONDS = 1000
|
||||||
const PUBLISH_TIME = 1 * SECONDS
|
const PUBLISH_TIME = 3 * SECONDS
|
||||||
const AUTHORIZE_TIME = PUBLISH_TIME + 1 * SECONDS
|
const AUTHORIZE_TIME = PUBLISH_TIME + 5 * SECONDS
|
||||||
const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
|
const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
|
||||||
|
|
||||||
let t0
|
let t0
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,6 @@ function fetchWallet (settings, cryptoCode) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLayer2 (tx) {
|
|
||||||
return _.isNil(tx.isLightning)
|
|
||||||
? layer2.isLayer2Address(tx.toAddress)
|
|
||||||
: tx.isLightning
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastBalance = {}
|
const lastBalance = {}
|
||||||
|
|
||||||
function _balance (settings, cryptoCode) {
|
function _balance (settings, cryptoCode) {
|
||||||
|
|
@ -81,10 +75,17 @@ function sendCoins (settings, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (settings, info) {
|
function newAddress (settings, info) {
|
||||||
if (isLayer2(info)) return layer2.newAddress(settings, info)
|
const walletAddressPromise = fetchWallet(settings, info.cryptoCode)
|
||||||
|
|
||||||
return fetchWallet(settings, info.cryptoCode)
|
|
||||||
.then(r => r.wallet.newAddress(r.account, info))
|
.then(r => r.wallet.newAddress(r.account, info))
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
walletAddressPromise,
|
||||||
|
layer2.newAddress(settings, info)
|
||||||
|
])
|
||||||
|
.then(([toAddress, layer2Address]) => ({
|
||||||
|
toAddress,
|
||||||
|
layer2Address
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function newFunding (settings, cryptoCode, address) {
|
function newFunding (settings, cryptoCode, address) {
|
||||||
|
|
@ -97,11 +98,38 @@ function newFunding (settings, cryptoCode, address) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWalletStatus (settings, tx) {
|
function mergeStatus (a, b) {
|
||||||
if (isLayer2(tx)) return layer2.getStatus(settings, tx)
|
if (!a) return b
|
||||||
|
if (!b) return a
|
||||||
|
|
||||||
return fetchWallet(settings, tx.cryptoCode)
|
return {status: mergeStatusMode(a.status, b.status)}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeStatusMode (a, b) {
|
||||||
|
const cleared = ['authorized', 'confirmed', 'instant']
|
||||||
|
if (_.includes(a, cleared)) return a
|
||||||
|
if (_.includes(b, cleared)) return b
|
||||||
|
|
||||||
|
if (a === 'published') return a
|
||||||
|
if (b === 'published') return b
|
||||||
|
|
||||||
|
if (a === 'rejected') return a
|
||||||
|
if (b === 'rejected') return b
|
||||||
|
|
||||||
|
return 'notSeen'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWalletStatus (settings, tx) {
|
||||||
|
const walletStatusPromise = fetchWallet(settings, tx.cryptoCode)
|
||||||
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
walletStatusPromise,
|
||||||
|
layer2.getStatus(settings, tx)
|
||||||
|
])
|
||||||
|
.then(([walletStatus, layer2Status]) => {
|
||||||
|
return mergeStatus(walletStatus, layer2Status)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function authorizeZeroConf (settings, tx, machineId) {
|
function authorizeZeroConf (settings, tx, machineId) {
|
||||||
|
|
|
||||||
13
migrations/1528017752387-add-layer2-address.js
Normal file
13
migrations/1528017752387-add-layer2-address.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
var db = require('./db')
|
||||||
|
|
||||||
|
exports.up = function (next) {
|
||||||
|
var sql = [
|
||||||
|
'alter table cash_out_txs add column layer_2_address text null',
|
||||||
|
'alter table cash_out_actions add column layer_2_address text null'
|
||||||
|
]
|
||||||
|
db.multi(sql, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.down = function (next) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue