mirror of
https://github.com/Permissionless-Software-Foundation/psf-bch-api.git
synced 2026-09-22 01:01:59 -07:00
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
/*
|
|
REST API router for /full-node/dsproof routes.
|
|
*/
|
|
|
|
import express from 'express'
|
|
import DSProofRESTController from './controller.js'
|
|
|
|
class DSProofRouter {
|
|
constructor (localConfig = {}) {
|
|
this.adapters = localConfig.adapters
|
|
if (!this.adapters) {
|
|
throw new Error(
|
|
'Instance of Adapters library required when instantiating DSProof REST Router.'
|
|
)
|
|
}
|
|
|
|
this.useCases = localConfig.useCases
|
|
if (!this.useCases) {
|
|
throw new Error(
|
|
'Instance of Use Cases library required when instantiating DSProof REST Router.'
|
|
)
|
|
}
|
|
|
|
const dependencies = {
|
|
adapters: this.adapters,
|
|
useCases: this.useCases
|
|
}
|
|
|
|
this.dsproofController = new DSProofRESTController(dependencies)
|
|
|
|
this.apiPrefix = (localConfig.apiPrefix || '').replace(/\/$/, '')
|
|
this.baseUrl = `${this.apiPrefix}/full-node/dsproof`
|
|
if (!this.baseUrl.startsWith('/')) {
|
|
this.baseUrl = `/${this.baseUrl}`
|
|
}
|
|
this.router = express.Router()
|
|
}
|
|
|
|
attach (app) {
|
|
if (!app) {
|
|
throw new Error('Must pass app object when attaching REST API controllers.')
|
|
}
|
|
|
|
this.router.get('/', this.dsproofController.root)
|
|
this.router.get('/getDSProof/:txid', this.dsproofController.getDSProof)
|
|
|
|
app.use(this.baseUrl, this.router)
|
|
}
|
|
}
|
|
|
|
export default DSProofRouter
|