mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
fix(sweep balanceOnly): Added balanceOnly to retrieve just the balance of a WIF
This commit is contained in:
+13
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user