fix(ElectrumX): get methods for balance, utxos, and tx history compelte

This commit is contained in:
Chris Troutner
2020-04-16 18:37:57 -07:00
parent d6925164e0
commit 7bb3741fa9
3 changed files with 125 additions and 6 deletions
+36 -3
View File
@@ -268,9 +268,9 @@ class Electrum {
'blockchain.scripthash.get_balance',
scripthash
)
console.log(
`electrumResponse: ${JSON.stringify(electrumResponse, null, 2)}`
)
// console.log(
// `electrumResponse: ${JSON.stringify(electrumResponse, null, 2)}`
// )
return electrumResponse
} catch (err) {
@@ -281,6 +281,39 @@ class Electrum {
throw err
}
}
// Returns a promise that resolves an array of transaction history for an
// address. Expects input to be a cash address, and input validation to have
// already been done by parent, calling function.
async _transactionsFromElectrumx (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 transaction history from the ElectrumX server.
const electrumResponse = await _this.electrumx.request(
'blockchain.scripthash.get_history',
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/_transactionsFromElectrumx(): ', err)
throw err
}
}
}
module.exports = Electrum