mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Minor edits
This commit is contained in:
@@ -225,6 +225,8 @@ class PsfSlpIndexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get mutable and immutable data for a token, if the token was created with
|
||||||
|
// such data.
|
||||||
async getTokenData (req, res, next) {
|
async getTokenData (req, res, next) {
|
||||||
try {
|
try {
|
||||||
// Verify env var is set for interacting with the indexer.
|
// Verify env var is set for interacting with the indexer.
|
||||||
@@ -240,7 +242,7 @@ class PsfSlpIndexer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// get token stats
|
// get token stats from the Genesis TX of the token.
|
||||||
const withTxHistory = false
|
const withTxHistory = false
|
||||||
const response = await _this.axios.post(
|
const response = await _this.axios.post(
|
||||||
`${_this.psfSlpIndexerApi}slp/token/`,
|
`${_this.psfSlpIndexerApi}slp/token/`,
|
||||||
@@ -251,6 +253,7 @@ class PsfSlpIndexer {
|
|||||||
const tokenStats = response.data.tokenData
|
const tokenStats = response.data.tokenData
|
||||||
|
|
||||||
tokenData.genesisData = tokenStats
|
tokenData.genesisData = tokenStats
|
||||||
|
|
||||||
// try to get immutable data
|
// try to get immutable data
|
||||||
try {
|
try {
|
||||||
const immutableData = await _this.getCIDData(tokenStats.documentUri)
|
const immutableData = await _this.getCIDData(tokenStats.documentUri)
|
||||||
@@ -266,6 +269,7 @@ class PsfSlpIndexer {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
tokenData.mutableData = ''
|
tokenData.mutableData = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200)
|
res.status(200)
|
||||||
return res.json(tokenData)
|
return res.json(tokenData)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -282,13 +286,13 @@ class PsfSlpIndexer {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the OP_RETURN data and decodes it
|
// Get the OP_RETURN data and decode it.
|
||||||
const mutableData = await _this.decodeOpReturn(documentHash)
|
const mutableData = await _this.decodeOpReturn(documentHash)
|
||||||
const jsonData = JSON.parse(mutableData)
|
const jsonData = JSON.parse(mutableData)
|
||||||
|
|
||||||
const mspAddress = jsonData.mspAddress
|
const mspAddress = jsonData.mspAddress
|
||||||
|
|
||||||
// Gets the mspAddress transactions
|
// Gets the mutable data address (MDA) transaction history.
|
||||||
const transactions = await _this.bchjs.Electrumx.transactions(mspAddress)
|
const transactions = await _this.bchjs.Electrumx.transactions(mspAddress)
|
||||||
|
|
||||||
const mspTxs = transactions.transactions
|
const mspTxs = transactions.transactions
|
||||||
@@ -355,9 +359,11 @@ class PsfSlpIndexer {
|
|||||||
if (!txid || typeof txid !== 'string') {
|
if (!txid || typeof txid !== 'string') {
|
||||||
throw new Error('txid must be a string.')
|
throw new Error('txid must be a string.')
|
||||||
}
|
}
|
||||||
|
|
||||||
// get transaction data
|
// get transaction data
|
||||||
const txData = await _this.bchjs.Electrumx.txData(txid)
|
const txData = await _this.bchjs.Electrumx.txData(txid)
|
||||||
let data = false
|
let data = false
|
||||||
|
|
||||||
// Maps the vout of the transaction in search of an OP_RETURN
|
// Maps the vout of the transaction in search of an OP_RETURN
|
||||||
for (let i = 0; i < txData.details.vout.length; i++) {
|
for (let i = 0; i < txData.details.vout.length; i++) {
|
||||||
const vout = txData.details.vout[i]
|
const vout = txData.details.vout[i]
|
||||||
@@ -366,11 +372,13 @@ class PsfSlpIndexer {
|
|||||||
Buffer.from(vout.scriptPubKey.hex, 'hex')
|
Buffer.from(vout.scriptPubKey.hex, 'hex')
|
||||||
).split(' ')
|
).split(' ')
|
||||||
|
|
||||||
|
// Exit on the first OP_RETURN found.
|
||||||
if (script[0] === 'OP_RETURN') {
|
if (script[0] === 'OP_RETURN') {
|
||||||
data = Buffer.from(script[1], 'hex').toString('ascii')
|
data = Buffer.from(script[1], 'hex').toString('ascii')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error in decodeOpReturn().')
|
console.log('Error in decodeOpReturn().')
|
||||||
@@ -378,6 +386,7 @@ class PsfSlpIndexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the immutable data stored in the documentUrl field of the token.
|
||||||
async getCIDData (cid) {
|
async getCIDData (cid) {
|
||||||
try {
|
try {
|
||||||
if (!cid || typeof cid !== 'string') {
|
if (!cid || typeof cid !== 'string') {
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ describe('#rate-routelimit', () => {
|
|||||||
assert.property(val, 'error')
|
assert.property(val, 'error')
|
||||||
assert.include(
|
assert.include(
|
||||||
val.error,
|
val.error,
|
||||||
'Too many requests. Your limits are currently 10 requests per minute.'
|
'Too many requests. Your limits are currently'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.equal(res.locals.rateLimitTriggered, true, 'Rate limits triggered')
|
assert.equal(res.locals.rateLimitTriggered, true, 'Rate limits triggered')
|
||||||
|
|||||||
Reference in New Issue
Block a user