Support Strike for Lightning Network
This commit is contained in:
parent
8d4a36865b
commit
3f9c139f83
11 changed files with 175 additions and 11 deletions
58
lib/plugins/layer2/strike/strike.js
Normal file
58
lib/plugins/layer2/strike/strike.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
const axios = require('axios')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
module.exports = {
|
||||
newAddress,
|
||||
getStatus,
|
||||
cryptoNetwork
|
||||
}
|
||||
|
||||
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 getCharge (account, chargeId) {
|
||||
return axios({
|
||||
method: 'get',
|
||||
url: `https://api.strike.acinq.co/api/v1/charges/${chargeId}`,
|
||||
auth: {username: account.token, password: ''}
|
||||
}).then(_.get('data'))
|
||||
}
|
||||
|
||||
function createCharge (account, info) {
|
||||
const data = {
|
||||
amount: info.cryptoAtoms.toNumber(),
|
||||
currency: 'btc',
|
||||
description: 'Lamassu cryptomat cash-out'
|
||||
}
|
||||
|
||||
return axios({
|
||||
method: 'post',
|
||||
url: 'https://api.strike.acinq.co/api/v1/charges',
|
||||
auth: {username: account.token, password: ''},
|
||||
data
|
||||
}).then(_.get('data'))
|
||||
}
|
||||
|
||||
function newAddress (account, info) {
|
||||
return checkCryptoCode(info.cryptoCode)
|
||||
.then(() => createCharge(account, info))
|
||||
.then(_.tap(console.log))
|
||||
.then(r => `strike:${r.id}:${r.payment_hash}:${r.payment_request}`)
|
||||
}
|
||||
|
||||
function getStatus (account, toAddress, requested, cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const parts = _.split(':', toAddress)
|
||||
const chargeId = parts[1]
|
||||
|
||||
return getCharge(account, chargeId)
|
||||
.then(r => ({status: r.paid ? 'confirmed' : 'notSeen'}))
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue