mirror of
https://github.com/Permissionless-Software-Foundation/psf-bch-api.git
synced 2026-09-21 16:52:00 -07:00
fix(slp): Removing the data2 path as it never worked well
This commit is contained in:
@@ -32,7 +32,6 @@ class SlpRESTController {
|
||||
this.getTxid = this.getTxid.bind(this)
|
||||
this.getTokenStats = this.getTokenStats.bind(this)
|
||||
this.getTokenData = this.getTokenData.bind(this)
|
||||
this.getTokenData2 = this.getTokenData2.bind(this)
|
||||
this.handleError = this.handleError.bind(this)
|
||||
}
|
||||
|
||||
@@ -206,32 +205,6 @@ class SlpRESTController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /v6/slp/token/data2 Get expanded token data
|
||||
* @apiName GetTokenData2
|
||||
* @apiGroup SLP
|
||||
* @apiDescription Get expanded data for the token, including icons.
|
||||
*/
|
||||
async getTokenData2 (req, res) {
|
||||
try {
|
||||
const tokenId = req.body.tokenId
|
||||
|
||||
if (!tokenId || tokenId === '') {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'tokenId can not be empty'
|
||||
})
|
||||
}
|
||||
|
||||
const updateCache = req.body.updateCache
|
||||
|
||||
const result = await this.slpUseCases.getTokenData2({ tokenId, updateCache })
|
||||
return res.status(200).json(result)
|
||||
} catch (err) {
|
||||
return this.handleError(err, res)
|
||||
}
|
||||
}
|
||||
|
||||
handleError (err, res) {
|
||||
wlogger.error('Error in SlpRESTController:', err)
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ class SlpRouter {
|
||||
this.router.post('/txid', this.slpController.getTxid)
|
||||
this.router.post('/token', this.slpController.getTokenStats)
|
||||
this.router.post('/token/data', this.slpController.getTokenData)
|
||||
this.router.post('/token/data2', this.slpController.getTokenData2)
|
||||
|
||||
app.use(this.baseUrl, this.router)
|
||||
}
|
||||
|
||||
@@ -146,18 +146,6 @@ class SlpUseCases {
|
||||
}
|
||||
}
|
||||
|
||||
async getTokenData2 ({ tokenId, updateCache }) {
|
||||
try {
|
||||
await this._ensureInitialized()
|
||||
|
||||
const tokenData = await this.slpTokenMedia.getIcon({ tokenId, updateCache })
|
||||
return tokenData
|
||||
} catch (err) {
|
||||
wlogger.error('Error in SlpUseCases.getTokenData2()', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async getMutableCid ({ tokenStats }) {
|
||||
// Validate input - this should throw, not be caught
|
||||
if (!tokenStats || !tokenStats.documentHash) {
|
||||
|
||||
@@ -92,7 +92,6 @@ describe('#controllers/rest-api/index.js', () => {
|
||||
getTxid: () => {},
|
||||
getTokenStats: () => {},
|
||||
getTokenData: () => {},
|
||||
getTokenData2: () => {},
|
||||
getMutableCid: () => {},
|
||||
decodeOpReturn: () => {},
|
||||
getCIDData: () => {}
|
||||
|
||||
@@ -25,8 +25,7 @@ describe('#slp-controller.js', () => {
|
||||
getAddress: sandbox.stub().resolves({ balance: 1000 }),
|
||||
getTxid: sandbox.stub().resolves({ txid: 'abc' }),
|
||||
getTokenStats: sandbox.stub().resolves({ tokenData: {} }),
|
||||
getTokenData: sandbox.stub().resolves({ genesisData: {}, immutableData: '', mutableData: '' }),
|
||||
getTokenData2: sandbox.stub().resolves({ tokenIcon: 'test-icon.png' })
|
||||
getTokenData: sandbox.stub().resolves({ genesisData: {}, immutableData: '', mutableData: '' })
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -310,60 +309,4 @@ describe('#slp-controller.js', () => {
|
||||
assert.deepEqual(res.jsonData, { error: 'Token data not found' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getTokenData2()', () => {
|
||||
it('should return expanded token data on success', async () => {
|
||||
const req = createMockRequest({
|
||||
body: { tokenId: 'a'.repeat(64) }
|
||||
})
|
||||
const res = createMockResponse()
|
||||
|
||||
await uut.getTokenData2(req, res)
|
||||
|
||||
assert.equal(res.statusValue, 200)
|
||||
assert.deepEqual(res.jsonData, { tokenIcon: 'test-icon.png' })
|
||||
assert.isTrue(mockUseCases.slp.getTokenData2.calledOnce)
|
||||
})
|
||||
|
||||
it('should pass updateCache flag', async () => {
|
||||
const req = createMockRequest({
|
||||
body: { tokenId: 'a'.repeat(64), updateCache: true }
|
||||
})
|
||||
const res = createMockResponse()
|
||||
|
||||
await uut.getTokenData2(req, res)
|
||||
|
||||
assert.isTrue(mockUseCases.slp.getTokenData2.calledWith({
|
||||
tokenId: 'a'.repeat(64),
|
||||
updateCache: true
|
||||
}))
|
||||
})
|
||||
|
||||
it('should return error if tokenId is empty', async () => {
|
||||
const req = createMockRequest({
|
||||
body: { tokenId: '' }
|
||||
})
|
||||
const res = createMockResponse()
|
||||
|
||||
await uut.getTokenData2(req, res)
|
||||
|
||||
assert.equal(res.statusValue, 400)
|
||||
assert.property(res.jsonData, 'error')
|
||||
})
|
||||
|
||||
it('should handle errors via handleError', async () => {
|
||||
const error = new Error('Token icon not found')
|
||||
error.status = 404
|
||||
mockUseCases.slp.getTokenData2.rejects(error)
|
||||
const req = createMockRequest({
|
||||
body: { tokenId: 'a'.repeat(64) }
|
||||
})
|
||||
const res = createMockResponse()
|
||||
|
||||
await uut.getTokenData2(req, res)
|
||||
|
||||
assert.equal(res.statusValue, 404)
|
||||
assert.deepEqual(res.jsonData, { error: 'Token icon not found' })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -195,21 +195,6 @@ describe('#slp-use-cases.js', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getTokenData2()', () => {
|
||||
it('should call slpTokenMedia getIcon method', async () => {
|
||||
const tokenId = 'a'.repeat(64)
|
||||
const updateCache = false
|
||||
mockSlpTokenMedia.getIcon.resolves({ tokenIcon: 'test-icon.png' })
|
||||
|
||||
const result = await uut.getTokenData2({ tokenId, updateCache })
|
||||
|
||||
assert.isTrue(
|
||||
mockSlpTokenMedia.getIcon.calledOnceWith({ tokenId, updateCache })
|
||||
)
|
||||
assert.deepEqual(result, { tokenIcon: 'test-icon.png' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('#decodeOpReturn()', () => {
|
||||
it('should decode OP_RETURN data from transaction', async () => {
|
||||
const txid = 'a'.repeat(64)
|
||||
|
||||
Reference in New Issue
Block a user