ElecrumX tests are passing

This commit is contained in:
Chris Troutner
2020-04-16 09:53:34 -07:00
parent f4e90a0518
commit d6925164e0
4 changed files with 106 additions and 9 deletions
+38 -2
View File
@@ -195,11 +195,14 @@ class Electrum {
})
}
wlogger.debug('Executing electrumx/getUtxos with this address: ', cashAddr)
wlogger.debug(
'Executing electrumx/getUtxos with this address: ',
cashAddr
)
// Get data from ElectrumX server.
const electrumResponse = await _this._utxosFromElectrumx(cashAddr)
// console.log(`electrumResponse: ${JSON.stringify(electrumResponse, null, 2)}`)
// console.log(`_utxosFromElectrumx(): ${JSON.stringify(electrumResponse, null, 2)}`)
// Pass the error message if ElectrumX reports an error.
if (Object.prototype.hasOwnProperty.call(electrumResponse, 'code')) {
@@ -245,6 +248,39 @@ class Electrum {
throw err
}
}
// Returns a promise that resolves to a balance for an address. Expects input
// to be a cash address, and input validation to have already been done by
// parent, calling function.
async _balanceFromElectrumx (address) {
try {
// Convert the address to a scripthash.
const scripthash = _this.addressToScripthash(address)
if (!_this.isReady) {
throw new Error(
'ElectrumX server connection is not ready. Call await connectToServer() first.'
)
}
// Query the address balance from the ElectrumX server.
const electrumResponse = await _this.electrumx.request(
'blockchain.scripthash.get_balance',
scripthash
)
console.log(
`electrumResponse: ${JSON.stringify(electrumResponse, null, 2)}`
)
return electrumResponse
} catch (err) {
// console.log('err1: ', err)
// Write out error to error log.
wlogger.error('Error in elecrumx.js/_utxosFromElectrumx(): ', err)
throw err
}
}
}
module.exports = Electrum