fix(sweep balanceOnly): Added balanceOnly to retrieve just the balance of a WIF

This commit is contained in:
Chris Troutner
2019-10-28 09:55:42 -07:00
parent 83d47bfda9
commit 01c3e61d19
2 changed files with 41 additions and 3 deletions
+13 -3
View File
@@ -199,6 +199,7 @@ class UtilRoute {
// Validate input
const wif = req.body.wif
const toAddr = req.body.toAddr
const balanceOnly = req.body.balanceOnly
if (typeof wif !== "string" || wif.length !== 52) {
res.status(400)
@@ -207,9 +208,12 @@ class UtilRoute {
})
}
if (!toAddr || toAddr === "") {
res.status(400)
return res.json({ error: "address can not be empty" })
if (!balanceOnly) {
// Only throw error if balanceOnly is false or undefined.
if (!toAddr || toAddr === "") {
res.status(400)
return res.json({ error: "address can not be empty" })
}
}
wlogger.debug(`Executing util/sweepWif with this address: `, toAddr)
@@ -234,6 +238,12 @@ class UtilRoute {
return res.json({ error: "No balance found at BCH address." })
}
// Exit if this is a balance-only call.
if (balanceOnly) {
res.status(200)
return res.json(totalBalance)
}
// Get all UTXOs help by the address.
const utxos = await _this.blockbook.testableComponents.utxosFromBlockbook(
fromAddr