From 12ef86ebbfba06a0b165f322c0b7cf0e6d98ec0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 10 Mar 2022 14:39:51 +0000 Subject: [PATCH] feat: wallet plugin structure --- lib/blockchain/lightning.js | 0 lib/plugins/wallet/lightning/galoy.js | 61 +++++++++++++++++++++++ lib/plugins/wallet/lightning/lightning.js | 0 3 files changed, 61 insertions(+) delete mode 100644 lib/blockchain/lightning.js create mode 100644 lib/plugins/wallet/lightning/galoy.js delete mode 100644 lib/plugins/wallet/lightning/lightning.js diff --git a/lib/blockchain/lightning.js b/lib/blockchain/lightning.js deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/plugins/wallet/lightning/galoy.js b/lib/plugins/wallet/lightning/galoy.js new file mode 100644 index 00000000..459675df --- /dev/null +++ b/lib/plugins/wallet/lightning/galoy.js @@ -0,0 +1,61 @@ +const BN = require('../../../bn') + +const NAME = 'LN' +const SUPPORTED_COINS = ['BTC'] + +function checkCryptoCode (cryptoCode) { + if (!SUPPORTED_COINS.includes(cryptoCode)) { + return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode)) + } + + return Promise.resolve() +} + +function getWallet () { + // Create wallet instance +} + +function sendCoins (account, tx, settings, operatorId) { + // const { toAddress, cryptoAtoms, cryptoCode } = tx + return {} +} + +function balance (account, cryptoCode, settings, operatorId) { + return checkCryptoCode(cryptoCode) + .then(() => getWallet(account, cryptoCode)) + .then(wallet => new BN(wallet._wallet.spendableBalanceString)) +} + +function newAddress (account, info, tx, settings, operatorId) { + return checkCryptoCode(info.cryptoCode) +} + +function getStatus (account, tx, requested, settings, operatorId) { + const { cryptoCode } = tx + return checkCryptoCode(cryptoCode).then(() => {}) +} + +function newFunding (account, cryptoCode, settings, operatorId) { + return checkCryptoCode(cryptoCode) +} + +function cryptoNetwork (account, cryptoCode, settings, operatorId) { + return checkCryptoCode(cryptoCode) + .then(() => account.environment === 'test' ? 'test' : 'main') +} + +function checkBlockchainStatus (cryptoCode) { + return checkCryptoCode(cryptoCode) + .then(() => Promise.resolve('ready')) +} + +module.exports = { + NAME, + balance, + sendCoins, + newAddress, + getStatus, + newFunding, + cryptoNetwork, + checkBlockchainStatus +} diff --git a/lib/plugins/wallet/lightning/lightning.js b/lib/plugins/wallet/lightning/lightning.js deleted file mode 100644 index e69de29b..00000000