mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-22 09:02:01 -07:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aef56c5c14 | ||
|
|
2472dc3606 | ||
|
|
2df36124b4 | ||
|
|
c422d8db34 |
@@ -35,15 +35,15 @@ const BCHJS = require("@psf/bch-js")
|
||||
let bchjs = new BCHJS() // Defaults to BCHN network.
|
||||
|
||||
// testnet
|
||||
bchjs = new BCHJS({ restURL: 'https://testnet3.fullstack.cash/v3/' })
|
||||
bchjs = new BCHJS({ restURL: 'https://testnet3.fullstack.cash/v4/' })
|
||||
```
|
||||
|
||||
This library is intended to be paired with
|
||||
the [bch-api](https://github.com/Permissionless-Software-Foundation/bch-api) REST API, and the infrastructure provided by [FullStack.cash](https://fullstack.cash). The `restURL` property can be changed to work with different Bitcoin Cash networks:
|
||||
|
||||
- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v3/
|
||||
- ABC Mainnet REST API server: https://abc.fullstack.cash/v3/
|
||||
- Testnet3 REST API server: https://testnet3.fullstack.cash/v3/
|
||||
- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v4/
|
||||
- ABC Mainnet REST API server: https://abc.fullstack.cash/v4/
|
||||
- Testnet3 REST API server: https://testnet3.fullstack.cash/v4/
|
||||
- Check server status: https://metrics.fullstack.cash
|
||||
|
||||
### API Key
|
||||
|
||||
@@ -220,7 +220,12 @@ class TokenType1 {
|
||||
// Calculate the total amount of tokens owned by the wallet.
|
||||
let totalTokens = 0
|
||||
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
|
||||
|
||||
+12
-11
@@ -1073,17 +1073,18 @@ class Utils {
|
||||
for (let i = 0; i < utxos.length; i++) {
|
||||
const utxo = utxos[i]
|
||||
|
||||
if (!utxo.satoshis) {
|
||||
// If Electrumx, convert the value to satoshis.
|
||||
if (utxo.value) {
|
||||
utxo.satoshis = utxo.value
|
||||
} else {
|
||||
// If there is neither a satoshis or value property, throw an error.
|
||||
throw new Error(
|
||||
`utxo ${i} does not have a satoshis or value property.`
|
||||
)
|
||||
}
|
||||
}
|
||||
// CT 1/9/21: This code can be removed after 2/1/21
|
||||
// if (!utxo.satoshis) {
|
||||
// // If Electrumx, convert the value to satoshis.
|
||||
// if (utxo.value) {
|
||||
// utxo.satoshis = utxo.value
|
||||
// } else {
|
||||
// // If there is neither a satoshis or value property, throw an error.
|
||||
// throw new Error(
|
||||
// `utxo ${i} does not have a satoshis or value property.`
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!utxo.txid) {
|
||||
// If Electrumx, convert the tx_hash property to txid.
|
||||
|
||||
@@ -1217,11 +1217,11 @@ describe('#SLP TokenType1', () => {
|
||||
tokenDocumentUrl: '',
|
||||
tokenDocumentHash: '',
|
||||
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: `, result)
|
||||
|
||||
|
||||
+34
-33
@@ -497,39 +497,40 @@ describe('#SLP Utils', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if utxo does not have satoshis or value property.', async () => {
|
||||
try {
|
||||
const utxos = [
|
||||
{
|
||||
txid:
|
||||
'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
|
||||
vout: 3,
|
||||
amount: 0.00002015,
|
||||
satoshis: 2015,
|
||||
height: 594892,
|
||||
confirmations: 5
|
||||
},
|
||||
{
|
||||
txid:
|
||||
'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
|
||||
vout: 2,
|
||||
amount: 0.00000546,
|
||||
height: 594892,
|
||||
confirmations: 5
|
||||
}
|
||||
]
|
||||
|
||||
await uut.Utils.tokenUtxoDetails(utxos)
|
||||
|
||||
assert.equal(true, false, 'Unexpected result.')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'utxo 1 does not have a satoshis or value property',
|
||||
'Expected error message.'
|
||||
)
|
||||
}
|
||||
})
|
||||
// CT 1/9/21: This test can be removed after 2/1/21
|
||||
// it('should throw error if utxo does not have satoshis or value property.', async () => {
|
||||
// try {
|
||||
// const utxos = [
|
||||
// {
|
||||
// txid:
|
||||
// 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
|
||||
// vout: 3,
|
||||
// amount: 0.00002015,
|
||||
// satoshis: 2015,
|
||||
// height: 594892,
|
||||
// confirmations: 5
|
||||
// },
|
||||
// {
|
||||
// txid:
|
||||
// 'bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90',
|
||||
// vout: 2,
|
||||
// amount: 0.00000546,
|
||||
// height: 594892,
|
||||
// confirmations: 5
|
||||
// }
|
||||
// ]
|
||||
//
|
||||
// await uut.Utils.tokenUtxoDetails(utxos)
|
||||
//
|
||||
// assert.equal(true, false, 'Unexpected result.')
|
||||
// } catch (err) {
|
||||
// assert.include(
|
||||
// err.message,
|
||||
// 'utxo 1 does not have a satoshis or value property',
|
||||
// 'Expected error message.'
|
||||
// )
|
||||
// }
|
||||
// })
|
||||
|
||||
it('should throw error if utxo does not have txid or tx_hash property.', async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user