floBlockchainAPI v2.3.2a
sendTx: - check total balance before processing utxos - reject "Insufficient FLO: Some UTXOs are unconfirmed" when balance is there but some utxo are used/unconfimed
This commit is contained in:
parent
8603cde17e
commit
5d7d3bdb53
@ -1,4 +1,4 @@
|
|||||||
(function(EXPORTS) { //floBlockchainAPI v2.3.2
|
(function(EXPORTS) { //floBlockchainAPI v2.3.2a
|
||||||
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
|
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const floBlockchainAPI = EXPORTS;
|
const floBlockchainAPI = EXPORTS;
|
||||||
@ -125,6 +125,10 @@
|
|||||||
else if (typeof sendAmt !== 'number' || sendAmt <= 0)
|
else if (typeof sendAmt !== 'number' || sendAmt <= 0)
|
||||||
return reject(`Invalid sendAmt : ${sendAmt}`);
|
return reject(`Invalid sendAmt : ${sendAmt}`);
|
||||||
|
|
||||||
|
getBalance(senderAddr).then(balance => {
|
||||||
|
var fee = DEFAULT.fee;
|
||||||
|
if (balance < sendAmt + fee)
|
||||||
|
return reject("Insufficient FLO balance!");
|
||||||
//get unconfirmed tx list
|
//get unconfirmed tx list
|
||||||
promisedAPI(`api/addr/${senderAddr}`).then(result => {
|
promisedAPI(`api/addr/${senderAddr}`).then(result => {
|
||||||
readTxs(senderAddr, 0, result.unconfirmedTxApperances).then(result => {
|
readTxs(senderAddr, 0, result.unconfirmedTxApperances).then(result => {
|
||||||
@ -143,7 +147,6 @@
|
|||||||
//form/construct the transaction data
|
//form/construct the transaction data
|
||||||
var trx = bitjs.transaction();
|
var trx = bitjs.transaction();
|
||||||
var utxoAmt = 0.0;
|
var utxoAmt = 0.0;
|
||||||
var fee = DEFAULT.fee;
|
|
||||||
for (var i = utxos.length - 1;
|
for (var i = utxos.length - 1;
|
||||||
(i >= 0) && (utxoAmt < sendAmt + fee); i--) {
|
(i >= 0) && (utxoAmt < sendAmt + fee); i--) {
|
||||||
//use only utxos with confirmations (strict_utxo mode)
|
//use only utxos with confirmations (strict_utxo mode)
|
||||||
@ -155,7 +158,7 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (utxoAmt < sendAmt + fee)
|
if (utxoAmt < sendAmt + fee)
|
||||||
reject("Insufficient FLO balance!");
|
reject("Insufficient FLO: Some UTXOs are unconfirmed");
|
||||||
else {
|
else {
|
||||||
trx.addoutput(receiverAddr, sendAmt);
|
trx.addoutput(receiverAddr, sendAmt);
|
||||||
var change = utxoAmt - sendAmt - fee;
|
var change = utxoAmt - sendAmt - fee;
|
||||||
@ -170,6 +173,7 @@
|
|||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
const floGlobals = {
|
const floGlobals = {
|
||||||
blockchain: "FLO",
|
blockchain: "FLO",
|
||||||
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
||||||
fee: 0.01,
|
|
||||||
application: "TEST_MODE",
|
application: "TEST_MODE",
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user