mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
feat(p2wdb): Added endpoint to select different P2WDB provider
This commit is contained in:
Vendored
+7
-1
@@ -80,10 +80,16 @@ module.exports = {
|
||||
|
||||
debugLevel: process.env.DEBUG_LEVEL ? parseInt(process.env.DEBUG_LEVEL) : 2,
|
||||
|
||||
// Preferred provider running ipfs-bch-wallet-service for BCH wallet.
|
||||
preferredProvider: process.env.PREFERRED_PROVIDER
|
||||
? process.env.PREFERRED_PROVIDER
|
||||
: ''
|
||||
: '',
|
||||
// : 'QmdBGB8S6sEr19gaAxJYjhRbz5ZmMiH5a1JyyMmaxcRKnY'
|
||||
// : 'QmUTx6KqYKVZbKpKxR7vGDUgZFYVvVVyEWDeCYq4GwBCff'
|
||||
// Used for development
|
||||
|
||||
// Preferred P2WDB provider
|
||||
preferredP2wdbProvider: process.env.PREFERRED_P2WDB_PROVIDER
|
||||
? process.env.PREFERRED_P2WDB_PROVIDER
|
||||
: ''
|
||||
}
|
||||
|
||||
+11
-11
@@ -108,17 +108,17 @@ class P2wdbAdapter {
|
||||
}
|
||||
|
||||
// Choose the BCH wallet service to use.
|
||||
// async selectProvider (providerId) {
|
||||
// try {
|
||||
// this.ipfs.ipfsCoordAdapter.config.preferredProvider = providerId
|
||||
//
|
||||
// return true
|
||||
// } catch (err) {
|
||||
// // console.log('createUser() error: ', err)
|
||||
// wlogger.error('Error in use-cases/bch.js/getStatus()')
|
||||
// throw err
|
||||
// }
|
||||
// }
|
||||
async selectProvider (providerId) {
|
||||
try {
|
||||
this.ipfs.ipfsCoordAdapter.config.preferredP2wdbProvider = providerId
|
||||
|
||||
return true
|
||||
} catch (err) {
|
||||
// console.log('createUser() error: ', err)
|
||||
wlogger.error('Error in adapters/p2wdb/getStatus()')
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Get the BCH balance for an array of addresses.
|
||||
// async getBalances (addrs) {
|
||||
|
||||
@@ -51,23 +51,23 @@ class P2wdbRESTControllerLib {
|
||||
}
|
||||
}
|
||||
|
||||
// async postProvider (ctx) {
|
||||
// try {
|
||||
// const providerId = ctx.request.body.provider
|
||||
//
|
||||
// await this.adapters.bch.selectProvider(providerId)
|
||||
//
|
||||
// const body = {
|
||||
// success: true
|
||||
// }
|
||||
//
|
||||
// ctx.body = body
|
||||
// } catch (err) {
|
||||
// wlogger.error('Error in bch/controller.js/postProvider(): ')
|
||||
// // ctx.throw(422, err.message)
|
||||
// this.handleError(ctx, err)
|
||||
// }
|
||||
// }
|
||||
async postProvider (ctx) {
|
||||
try {
|
||||
const providerId = ctx.request.body.provider
|
||||
|
||||
await this.adapters.p2wdb.selectProvider(providerId)
|
||||
|
||||
const body = {
|
||||
success: true
|
||||
}
|
||||
|
||||
ctx.body = body
|
||||
} catch (err) {
|
||||
wlogger.error('Error in p2wdb/controller.js/postProvider(): ', err)
|
||||
// ctx.throw(422, err.message)
|
||||
this.handleError(ctx, err)
|
||||
}
|
||||
}
|
||||
|
||||
// DRY error handler
|
||||
handleError (ctx, err) {
|
||||
|
||||
@@ -52,7 +52,7 @@ class P2wdbRouter {
|
||||
|
||||
// Define the routes and attach the controller.
|
||||
this.router.get('/', this.getStatus)
|
||||
// this.router.post('/provider', this.postProvider)
|
||||
this.router.post('/provider', this.postProvider)
|
||||
// this.router.post('/balance', this.postBalance)
|
||||
// this.router.post('/utxos', this.postUtxos)
|
||||
// this.router.post('/broadcast', this.postBroadcast)
|
||||
@@ -69,10 +69,10 @@ class P2wdbRouter {
|
||||
await _this.p2wdbRESTController.getStatus(ctx, next)
|
||||
}
|
||||
|
||||
// async postProvider (ctx, next) {
|
||||
// await _this.bchRESTController.postProvider(ctx, next)
|
||||
// }
|
||||
//
|
||||
async postProvider (ctx, next) {
|
||||
await _this.p2wdbRESTController.postProvider(ctx, next)
|
||||
}
|
||||
|
||||
// async postBalance (ctx, next) {
|
||||
// await _this.bchRESTController.balance(ctx, next)
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user