mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-22 00:52:01 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86a1cadfac | ||
|
|
7000a83a37 | ||
|
|
b331450473 | ||
|
|
af7c8ffa6d | ||
|
|
2e04548ade | ||
|
|
412fa5e1ce | ||
|
|
a08a4236d6 | ||
|
|
e700a22560 | ||
|
|
4573c63ca3 | ||
|
|
bd18e8a755 | ||
|
|
cf8f48ffe1 | ||
|
|
fc96b04a64 | ||
|
|
661a759f80 | ||
|
|
ba915e84cf |
@@ -197,6 +197,9 @@ class Blockchain {
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.log('Error in bch-js/blockchain.js/getBlockCount()')
|
||||
console.log('blockchain.js restURL: ', this.restURL)
|
||||
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
}
|
||||
|
||||
+7
-3
@@ -289,12 +289,12 @@ class ElectrumX {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async transactions (address, usrObj = null) {
|
||||
async transactions (address, usrObj = null, allTxs = false) {
|
||||
try {
|
||||
// Handle single address.
|
||||
if (typeof address === 'string') {
|
||||
const response = await axios.get(
|
||||
`${this.restURL}electrumx/transactions/${address}`,
|
||||
`${this.restURL}electrumx/transactions/${address}/${allTxs}`,
|
||||
this.axiosOptions
|
||||
)
|
||||
return response.data
|
||||
@@ -305,7 +305,8 @@ class ElectrumX {
|
||||
`${this.restURL}electrumx/transactions`,
|
||||
{
|
||||
addresses: address,
|
||||
usrObj // pass user data when making an internal call.
|
||||
usrObj, // pass user data when making an internal call.
|
||||
allTxs
|
||||
},
|
||||
this.axiosOptions
|
||||
)
|
||||
@@ -315,6 +316,7 @@ class ElectrumX {
|
||||
|
||||
throw new Error('Input address must be a string or array of strings.')
|
||||
} catch (error) {
|
||||
// console.log('Error in transactions(): ', error)
|
||||
if (error.response && error.response.data) throw error.response.data
|
||||
else throw error
|
||||
}
|
||||
@@ -718,6 +720,8 @@ class ElectrumX {
|
||||
return this.sortConfTxs(modifiedTxs, sortingOrder)
|
||||
} catch (err) {
|
||||
console.log('Error in util.js/sort0ConfTxs')
|
||||
console.log('electrumx.js restURL: ', this.restURL)
|
||||
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,6 +407,7 @@ class RawTransactions {
|
||||
// pass back the raw transaction data.
|
||||
/* exit quietly */
|
||||
}
|
||||
// console.log(`txDetails: ${JSON.stringify(txDetails, null, 2)}`)
|
||||
|
||||
return txDetails
|
||||
} catch (error) {
|
||||
|
||||
+11
-1
@@ -32,6 +32,8 @@ class UTXO {
|
||||
* properties:
|
||||
* - address: "" - the address these UTXOs are associated with
|
||||
* - bchUtxos: [] - UTXOs confirmed to be spendable as normal BCH
|
||||
* - infoUtxos: [] - UTXOs under of 1000 sats or less that can not be categorized
|
||||
* as another type of UTXO (like a token).
|
||||
* - nullUtxo: [] - UTXOs that did not pass SLP validation. Should be ignored and
|
||||
* not spent, to be safe.
|
||||
* - slpUtxos: {} - UTXOs confirmed to be colored as valid SLP tokens
|
||||
@@ -177,8 +179,15 @@ class UTXO {
|
||||
// Hydrate the UTXOs with additional token data.
|
||||
type1TokenUtxos = await this.hydrateTokenData(type1TokenUtxos)
|
||||
|
||||
// Collect BCH UTXOs above 1000 sats
|
||||
const bchUtxos = utxos.filter(x => x.isSlp === false && x.value > 1000)
|
||||
|
||||
// Collect all BCH UTXOs at 1000 sats or smaller
|
||||
// The prevents SLP tokens, BCMR, and other 'colored' UTXOs from being
|
||||
// accidentally included into normal BCH transactions.
|
||||
const infoUtxos = utxos.filter(x => x.isSlp === false && x.value <= 1000)
|
||||
|
||||
// Collect and hydrate any type1 baton UTXOs
|
||||
const bchUtxos = utxos.filter(x => x.isSlp === false)
|
||||
let type1BatonUtxos = utxos.filter(
|
||||
x => x.isSlp === true && x.type === 'baton' && x.tokenType === 1
|
||||
)
|
||||
@@ -208,6 +217,7 @@ class UTXO {
|
||||
const outObj = {
|
||||
address: addr,
|
||||
bchUtxos,
|
||||
infoUtxos,
|
||||
slpUtxos: {
|
||||
type1: {
|
||||
tokens: type1TokenUtxos,
|
||||
|
||||
@@ -318,7 +318,9 @@ describe('#blockchain', () => {
|
||||
it('should get info about the blockchain', async () => {
|
||||
const result = await bchjs.Blockchain.getBlockchainInfo()
|
||||
|
||||
console.log(`blockchain info: ${JSON.stringify(result, null, 2)}`)
|
||||
// console.log(`blockchain info: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'blocks')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -79,6 +79,7 @@ describe('#UTXO', () => {
|
||||
assert.property(result, 'nullUtxos')
|
||||
|
||||
assert.isAbove(result.bchUtxos.length, 0)
|
||||
assert.isAbove(result.infoUtxos.length, 0)
|
||||
assert.isAbove(result.slpUtxos.type1.tokens.length, 0)
|
||||
assert.equal(result.slpUtxos.type1.mintBatons.length, 0)
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('#control', () => {
|
||||
describe('#getNetworkInfo', () => {
|
||||
it('should get info on the full node', async () => {
|
||||
const result = await bchjs.Control.getNetworkInfo()
|
||||
console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.property(result, 'version')
|
||||
})
|
||||
|
||||
@@ -371,8 +371,13 @@ describe('#ElectrumX', () => {
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
CT 3/14/23 - This test is frequently failing in BVT due to 429 errors.
|
||||
describe('#sortAllTxs', () => {
|
||||
it('should GET transaction history for a single address', async () => {
|
||||
// Add delay for this endpoint.
|
||||
await sleep(6000)
|
||||
|
||||
const addr = 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v'
|
||||
|
||||
const txs = await bchjs.Electrumx.transactions(addr)
|
||||
@@ -386,6 +391,7 @@ describe('#ElectrumX', () => {
|
||||
assert.isAbove(sortedTransactions[0].height, sortedTransactions[1].height)
|
||||
})
|
||||
})
|
||||
*/
|
||||
})
|
||||
|
||||
function sleep (ms) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const assert = require('chai').assert
|
||||
// const assert = require('chai').assert
|
||||
|
||||
const BCHJS = require('../../src/bch-js')
|
||||
const bchjs = new BCHJS()
|
||||
// const BCHJS = require('../../src/bch-js')
|
||||
// const bchjs = new BCHJS()
|
||||
|
||||
describe('#Encryption', () => {
|
||||
beforeEach(async () => {
|
||||
@@ -9,7 +9,12 @@ describe('#Encryption', () => {
|
||||
})
|
||||
|
||||
describe('#getPubKey', () => {
|
||||
// Commenting out these tests since they are failing in BVT due to 429 errors
|
||||
/*
|
||||
it('should get a public key', async () => {
|
||||
// Add delay for this endpoint.
|
||||
await sleep(8000)
|
||||
|
||||
const addr = 'bitcoincash:qpf8jv9hmqcda0502gjp7nm3g24y5h5s4unutghsxq'
|
||||
|
||||
const result = await bchjs.encryption.getPubKey(addr)
|
||||
@@ -21,6 +26,9 @@ describe('#Encryption', () => {
|
||||
})
|
||||
|
||||
it('should report when public key can not be found', async () => {
|
||||
// Add delay for this endpoint.
|
||||
await sleep(8000)
|
||||
|
||||
const addr = 'bitcoincash:qrgqqkky28jdkv3w0ctrah0mz3jcsnsklc34gtukrh'
|
||||
|
||||
const result = await bchjs.encryption.getPubKey(addr)
|
||||
@@ -31,6 +39,7 @@ describe('#Encryption', () => {
|
||||
assert.property(result, 'publicKey')
|
||||
assert.equal(result.publicKey, 'not found')
|
||||
})
|
||||
*/
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -204,7 +204,9 @@ describe('#rawtransaction', () => {
|
||||
const result = await bchjs.RawTransactions.decodeScript(hex)
|
||||
// console.log(`result ${JSON.stringify(result, null, 2)}`)
|
||||
|
||||
assert.hasAllKeys(result, ['asm', 'type', 'p2sh'])
|
||||
assert.property(result, 'asm')
|
||||
assert.property(result, 'type')
|
||||
assert.property(result, 'p2sh')
|
||||
})
|
||||
|
||||
// CT 2/20/19 - Waiting for this PR to be merged complete the test:
|
||||
|
||||
@@ -142,7 +142,8 @@ describe('#utxo', () => {
|
||||
assert.property(result.slpUtxos, 'nft')
|
||||
assert.property(result, 'nullUtxos')
|
||||
|
||||
assert.equal(result.bchUtxos.length, 4)
|
||||
assert.equal(result.bchUtxos.length, 1)
|
||||
assert.equal(result.infoUtxos.length, 3)
|
||||
assert.equal(result.slpUtxos.type1.tokens.length, 1)
|
||||
assert.equal(result.slpUtxos.type1.mintBatons.length, 1)
|
||||
assert.equal(result.nullUtxos.length, 0)
|
||||
|
||||
Reference in New Issue
Block a user