mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(nft): Removing NFT parent and child functions from SLPDB that have been replaced with psf-slp-indexer
This commit is contained in:
+1
-92
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Public npm libraries
|
// Public npm libraries
|
||||||
const axios = require('axios')
|
// const axios = require('axios')
|
||||||
|
|
||||||
// Local libraries.
|
// Local libraries.
|
||||||
const Address = require('./address')
|
const Address = require('./address')
|
||||||
@@ -419,97 +419,6 @@ class Nft1 {
|
|||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @api SLP.NFT1.listNFTGroupChildren() listNFTGroupChildren()
|
|
||||||
* @apiName listNFTGroupChildren
|
|
||||||
* @apiGroup SLP NFT1
|
|
||||||
* @apiDescription Return list of NFT children tokens in a NFT Group.
|
|
||||||
* It's assumed provided groupId parameter is for an NFT Group token (type=129)
|
|
||||||
*
|
|
||||||
* Returns an Array with GENESIS transaction IDs of the children tokens.
|
|
||||||
*
|
|
||||||
* @apiExample Example usage:
|
|
||||||
*
|
|
||||||
* const groupId = '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
|
|
||||||
* const children = await bchjs.SLP.Nft1.listNFTGroupChildren(groupId)
|
|
||||||
*
|
|
||||||
* children = {
|
|
||||||
* "nftChildren": [
|
|
||||||
* "45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9",
|
|
||||||
* "928ce61fe1006b1325a0ba0dce700bf83986a6f0691ba26e121c9ac035d12a55"
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
async listNFTGroupChildren (groupId) {
|
|
||||||
try {
|
|
||||||
if (typeof groupId === 'string') {
|
|
||||||
const response = await axios.get(
|
|
||||||
`${this.restURL}slp/nftChildren/${groupId}`,
|
|
||||||
this.axiosOptions
|
|
||||||
)
|
|
||||||
return response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('groupId must be a string.')
|
|
||||||
} catch (error) {
|
|
||||||
// console.log('Error in listNFTGroupChildren()')
|
|
||||||
if (error.response && error.response.data) throw error.response.data
|
|
||||||
else throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @api SLP.NFT1.parentNFTGroup() parentNFTGroup()
|
|
||||||
* @apiName parentNFTGroup
|
|
||||||
* @apiGroup SLP NFT1
|
|
||||||
* @apiDescription Return parent NFT Group information for a given NFT child token.
|
|
||||||
* It's assumed provided groupId parameter is for an NFT Child token (type=65)
|
|
||||||
*
|
|
||||||
* Returns a JSON with NFT group information.
|
|
||||||
*
|
|
||||||
* @apiExample Example usage:
|
|
||||||
*
|
|
||||||
* const tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
|
|
||||||
* const group = await bchjs.SLP.Nft1.parentNFTGroup(tokenId)
|
|
||||||
*
|
|
||||||
* group = {
|
|
||||||
* "nftGroup": {
|
|
||||||
* "decimals": 0,
|
|
||||||
* "timestamp": "2021-05-03 10:36:01",
|
|
||||||
* "timestamp_unix": 1620038161,
|
|
||||||
* "versionType": 129,
|
|
||||||
* "documentUri": "psfoundation.cash",
|
|
||||||
* "symbol": "PSF.TEST.GROUP",
|
|
||||||
* "name": "PSF Test NFT Group",
|
|
||||||
* "containsBaton": true,
|
|
||||||
* "id": "68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a",
|
|
||||||
* "documentHash": null,
|
|
||||||
* "initialTokenQty": 1000000,
|
|
||||||
* "blockCreated": 686117,
|
|
||||||
* "totalMinted": null,
|
|
||||||
* "totalBurned": null,
|
|
||||||
* "circulatingSupply": null
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
async parentNFTGroup (tokenId) {
|
|
||||||
try {
|
|
||||||
if (typeof tokenId === 'string') {
|
|
||||||
const response = await axios.get(
|
|
||||||
`${this.restURL}slp/nftGroup/${tokenId}`,
|
|
||||||
this.axiosOptions
|
|
||||||
)
|
|
||||||
return response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('tokenId must be a string.')
|
|
||||||
} catch (error) {
|
|
||||||
// console.log('Error in parentNFTGroup()')
|
|
||||||
if (error.response && error.response.data) throw error.response.data
|
|
||||||
else throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Nft1
|
module.exports = Nft1
|
||||||
|
|||||||
+2
-93
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
const assert = require('chai').assert
|
const assert = require('chai').assert
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const axios = require('axios')
|
// const axios = require('axios')
|
||||||
|
|
||||||
// Default to unit tests unless some other value for TEST is passed.
|
// Default to unit tests unless some other value for TEST is passed.
|
||||||
if (!process.env.TEST) process.env.TEST = 'unit'
|
if (!process.env.TEST) process.env.TEST = 'unit'
|
||||||
@@ -14,7 +14,7 @@ const BCHJS = require('../../src/bch-js')
|
|||||||
const bchjs = new BCHJS()
|
const bchjs = new BCHJS()
|
||||||
|
|
||||||
// Mock data used for unit tests
|
// Mock data used for unit tests
|
||||||
const mockData = require('./fixtures/slp/mock-utils')
|
// const mockData = require('./fixtures/slp/mock-utils')
|
||||||
|
|
||||||
// Default to unit tests unless some other value for TEST is passed.
|
// Default to unit tests unless some other value for TEST is passed.
|
||||||
if (!process.env.TEST) process.env.TEST = 'unit'
|
if (!process.env.TEST) process.env.TEST = 'unit'
|
||||||
@@ -253,95 +253,4 @@ describe('#SLP NFT1', () => {
|
|||||||
assert.isNumber(result.outputs)
|
assert.isNumber(result.outputs)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('#listNFTGroupChildren', () => {
|
|
||||||
it('should throw an error for improper input', async () => {
|
|
||||||
try {
|
|
||||||
const groupId = 12345
|
|
||||||
|
|
||||||
await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
|
|
||||||
assert.equal(true, false, 'Unexpected result!')
|
|
||||||
} catch (err) {
|
|
||||||
// console.log(`err: `, err)
|
|
||||||
assert.include(
|
|
||||||
err.message,
|
|
||||||
'groupId must be a string'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
it('should handle API response error', async () => {
|
|
||||||
try {
|
|
||||||
const error = new Error()
|
|
||||||
error.response = {
|
|
||||||
error: 'NFT group does not exists'
|
|
||||||
}
|
|
||||||
sandbox.stub(axios, 'get').throws(error)
|
|
||||||
|
|
||||||
const groupId = 'non-exists'
|
|
||||||
await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
|
|
||||||
} catch (err) {
|
|
||||||
assert.include(
|
|
||||||
err.response,
|
|
||||||
{ error: 'NFT group does not exists' }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
it('should return array of children GENESIS transactions IDs', async () => {
|
|
||||||
sandbox.stub(axios, 'get').resolves({ data: mockData.mockNftChildrenList })
|
|
||||||
|
|
||||||
const groupId = '68cd33ecd909068fbea318ae5ff1d6207cf754e53b191327d6d73b6916424c0a'
|
|
||||||
const result = await bchjs.SLP.NFT1.listNFTGroupChildren(groupId)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.property(result, 'nftChildren')
|
|
||||||
assert.isArray(result.nftChildren)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
describe('#parentNFTGroup', () => {
|
|
||||||
it('should throw an error for improper input', async () => {
|
|
||||||
try {
|
|
||||||
const tokenId = 12345
|
|
||||||
|
|
||||||
await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
|
|
||||||
assert.equal(true, false, 'Unexpected result!')
|
|
||||||
} catch (err) {
|
|
||||||
// console.log(`err: `, err)
|
|
||||||
assert.include(
|
|
||||||
err.message,
|
|
||||||
'tokenId must be a string'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
it('should handle API response error', async () => {
|
|
||||||
try {
|
|
||||||
const error = new Error()
|
|
||||||
error.response = {
|
|
||||||
error: 'NFT child does not exists'
|
|
||||||
}
|
|
||||||
sandbox.stub(axios, 'get').throws(error)
|
|
||||||
|
|
||||||
const tokenId = 'non-exists'
|
|
||||||
await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
|
|
||||||
} catch (err) {
|
|
||||||
assert.include(
|
|
||||||
err.response,
|
|
||||||
{ error: 'NFT child does not exists' }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
it('should return parent NFT group information', async () => {
|
|
||||||
sandbox.stub(axios, 'get').resolves({ data: mockData.mockNftGroup })
|
|
||||||
|
|
||||||
const tokenId = '45a30085691d6ea586e3ec2aa9122e9b0e0d6c3c1fd357decccc15d8efde48a9'
|
|
||||||
const result = await bchjs.SLP.NFT1.parentNFTGroup(tokenId)
|
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
||||||
|
|
||||||
assert.property(result, 'nftGroup')
|
|
||||||
assert.property(result.nftGroup, 'id')
|
|
||||||
assert.property(result.nftGroup, 'name')
|
|
||||||
assert.property(result.nftGroup, 'symbol')
|
|
||||||
assert.property(result.nftGroup, 'documentUri')
|
|
||||||
assert.property(result.nftGroup, 'versionType')
|
|
||||||
assert.property(result.nftGroup, 'initialTokenQty')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user