feat(slpdb): Removing endpoints that expect SLPDB interface

This commit is contained in:
Chris Troutner
2022-03-14 15:50:21 -07:00
parent 5f8f05d194
commit 857458db57
2 changed files with 0 additions and 310 deletions
-202
View File
@@ -41,208 +41,6 @@ class Utils {
this.util = new Util(config)
}
/**
* @api SLP.Utils.tokenStats() tokenStats()
* @apiName tokenStats
* @apiGroup SLP Utils
* @apiDescription Stats for token by tokenId.
*
* @apiExample Example usage:
*
* (async () => {
* try {
* let stats = await bchjs.SLP.Utils.tokenStats(
* "df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb"
* )
* console.log(stats)
* } catch (error) {
* console.error(error)
* }
* })()
*
* // returns
* { tokenId:
* 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
* documentUri: '',
* symbol: 'NAKAMOTO',
* name: 'NAKAMOTO',
* decimals: 8,
* txnsSinceGenesis: 367,
* validUtxos: 248,
* validAddresses: 195,
* circulatingSupply: 20995990,
* totalBurned: 4010,
* totalMinted: 21000000,
* satoshisLockedUp: 135408
* }
*/
async tokenStats (tokenId) {
try {
const path = `${this.restURL}slp/tokenStats/${tokenId}`
const response = await _this.axios.get(path, this.axiosOptions)
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
throw error
}
}
/**
* @api SLP.Utils.transactions() transactions()
* @apiName transactions
* @apiGroup SLP Utils
* @apiDescription SLP Transactions by tokenId and address.
*
* @apiExample Example usage:
*
* (async () => {
* try {
* let transactions = await bchjs.SLP.Utils.transactions(
* "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a",
* "qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqlsy4gusz"
* )
* console.log(transactions)
* } catch (error) {
* console.error(error)
* }
* })()
*
* // returns
* [
* {
* "txid": "27e27170b546f05b2af69d6eddff8834038facf5d81302e9e562df09a5c4445f",
* "tokenDetails": {
* "valid": true,
* "detail": {
* "decimals": null,
* "tokenIdHex": "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a",
* "timestamp": null,
* "transactionType": "SEND",
* "versionType": 1,
* "documentUri": null,
* "documentSha256Hex": null,
* "symbol": null,
* "name": null,
* "batonVout": null,
* "containsBaton": null,
* "genesisOrMintQuantity": null,
* "sendOutputs": [
* {
* "$numberDecimal": "0"
* },
* {
* "$numberDecimal": "25"
* },
* {
* "$numberDecimal": "77"
* }
* ]
* },
* "invalidReason": null,
* "schema_version": 30
* }
* }
* ]
*/
// Retrieve token transactions for a given tokenId and address.
async transactions (tokenId, address) {
try {
const path = `${this.restURL}slp/transactions/${tokenId}/${address}`
const response = await _this.axios.get(path, this.axiosOptions)
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
throw error
}
}
/**
* @api SLP.Utils.burnTotal() burnTotal()
* @apiName burnTotal
* @apiGroup SLP Utils
* @apiDescription List input, output and burn total for slp transaction.
*
* @apiExample Example usage:
*
* (async () => {
* try {
* const burnTotal = await bchjs.SLP.Utils.burnTotal(
* "c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de"
* )
* console.log(burnTotal)
* } catch (error) {
* console.error(error)
* }
* })()
*
* // returns
* {
* transactionId: 'c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de',
* inputTotal: 100000100,
* outputTotal: 100000000,
* burnTotal: 100
* }
*/
async burnTotal (transactionId) {
try {
const path = `${this.restURL}slp/burnTotal/${transactionId}`
const response = await _this.axios.get(path, this.axiosOptions)
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
throw error
}
}
/**
* @api SLP.Utils.txDetails() txDetails()
* @apiName txDetails
* @apiGroup SLP Utils
* @apiDescription Transaction details on a token transfer.
* There is no bulk method for this endpoint. Can only get one tx at a time.
*
* @apiExample Example usage:
*
* (async () => {
* try {
* const details = await bchjs.SLP.Utils.txDetails(
* "c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de"
* )
* console.log(details)
* } catch (error) {
* console.error(error)
* }
* })()
*
*/
async txDetails (txid) {
try {
if (
!txid ||
txid === '' ||
typeof txid !== 'string' ||
txid.length !== 64
) {
throw new Error('txid string must be included.')
}
// console.log(`this.restURL: ${this.restURL}`)
const path = `${this.restURL}slp/txDetails/${txid}`
const response = await _this.axios.get(path, this.axiosOptions)
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
throw error
}
}
/**
* @api SLP.Utils.decodeOpReturn() decodeOpReturn()
* @apiName decodeOpReturn
-108
View File
@@ -45,43 +45,6 @@ describe('#SLP Utils', () => {
sandbox.restore()
})
describe('#transactions', () => {
it('should retrieve transactions for a given tokenId and address', async () => {
// Mock the call to the REST API
sandbox
.stub(uut.Utils.axios, 'get')
.resolves({ data: mockData.mockTransactions })
const transactions = await uut.Utils.transactions(
'495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a',
'simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu'
)
assert.hasAnyKeys(transactions[0], ['txid', 'tokenDetails'])
})
})
describe('#burnTotal', () => {
it('should retrieve input, output and burn totals', async () => {
// Mock the call to the REST API
sandbox
.stub(uut.Utils.axios, 'get')
.resolves({ data: mockData.mockBurnTotal })
const burnTotal = await uut.Utils.burnTotal(
'c7078a6c7400518a513a0bde1f4158cf740d08d3b5bfb19aa7b6657e2f4160de'
)
// console.log(`burnTotal: ${JSON.stringify(burnTotal, null, 2)}`)
assert.hasAnyKeys(burnTotal, [
'transactionId',
'inputTotal',
'outputTotal',
'burnTotal'
])
})
})
describe('#decodeOpReturn', () => {
it('should throw an error for a non-string input', async () => {
try {
@@ -1737,75 +1700,4 @@ describe('#SLP Utils', () => {
assert.equal(data[0].isValid, false)
})
})
describe('#txDetails', () => {
it('should throw an error if txid is not included', async () => {
try {
await uut.Utils.txDetails()
} catch (err) {
assert.include(
err.message,
'txid string must be included',
'Expected error message.'
)
}
})
it('should throw error for non-existent txid', async () => {
try {
// Mock the call to the REST API
if (process.env.TEST === 'unit') {
sandbox
.stub(uut.Utils.axios, 'get')
// .resolves({ data: mockData.nonSLPTxDetailsWithoutOpReturn })
.throws({ error: 'TXID not found' })
}
const txid =
'd284e71227ec89f714b964d8eda595be6392bebd2fac46082bc5a9ce6fb7b33e'
await uut.Utils.txDetails(txid)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.fail('Unexpected result')
} catch (err) {
// console.log(`err: `, err)
assert.include(err.error, 'TXID not found', 'Expected error message.')
}
})
it('should return details for an SLP txid', async () => {
// Mock the call to the REST API
if (process.env.TEST === 'unit') {
sandbox
.stub(uut.Utils.axios, 'get')
.resolves({ data: mockData.mockTxDetails })
}
const txid =
'9dbaaafc48c49a21beabada8de632009288a2cd52eecefd0c00edcffca9955d0'
const result = await uut.Utils.txDetails(txid)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.hasAnyKeys(result, [
'txid',
'version',
'locktime',
'vin',
'vout',
'blockhash',
'blockheight',
'confirmations',
'time',
'blocktime',
'valueOut',
'size',
'valueIn',
'fees',
'tokenInfo',
'tokenIsValid'
])
})
})
})