mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(generateBurnOpReturn): Added handler when burning amount is higher than token amount
This commit is contained in:
@@ -220,7 +220,12 @@ class TokenType1 {
|
|||||||
// Calculate the total amount of tokens owned by the wallet.
|
// Calculate the total amount of tokens owned by the wallet.
|
||||||
let totalTokens = 0
|
let totalTokens = 0
|
||||||
for (let i = 0; i < tokenUtxos.length; i++) {
|
for (let i = 0; i < tokenUtxos.length; i++) {
|
||||||
totalTokens += tokenUtxos[i].tokenQty
|
totalTokens += parseFloat(tokenUtxos[i].tokenQty)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure burn quantity isn't bigger than the total amount in tokens
|
||||||
|
if (burnQty > totalTokens) {
|
||||||
|
burnQty = totalTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
const remainder = totalTokens - burnQty
|
const remainder = totalTokens - burnQty
|
||||||
|
|||||||
@@ -1217,11 +1217,11 @@ describe('#SLP TokenType1', () => {
|
|||||||
tokenDocumentUrl: '',
|
tokenDocumentUrl: '',
|
||||||
tokenDocumentHash: '',
|
tokenDocumentHash: '',
|
||||||
decimals: 8,
|
decimals: 8,
|
||||||
tokenQty: 7
|
tokenQty: '7'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const result = bchjs.SLP.TokenType1.generateBurnOpReturn(tokenUtxos, 1)
|
const result = bchjs.SLP.TokenType1.generateBurnOpReturn(tokenUtxos, 8)
|
||||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||||
// console.log(`result: `, result)
|
// console.log(`result: `, result)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user