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:
sairajzero 2022-05-21 22:19:54 +05:30
parent 8603cde17e
commit 5d7d3bdb53
2 changed files with 47 additions and 44 deletions

View File

@ -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*/
'use strict';
const floBlockchainAPI = EXPORTS;
@ -125,6 +125,10 @@
else if (typeof sendAmt !== 'number' || sendAmt <= 0)
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
promisedAPI(`api/addr/${senderAddr}`).then(result => {
readTxs(senderAddr, 0, result.unconfirmedTxApperances).then(result => {
@ -143,7 +147,6 @@
//form/construct the transaction data
var trx = bitjs.transaction();
var utxoAmt = 0.0;
var fee = DEFAULT.fee;
for (var i = utxos.length - 1;
(i >= 0) && (utxoAmt < sendAmt + fee); i--) {
//use only utxos with confirmations (strict_utxo mode)
@ -155,7 +158,7 @@
};
}
if (utxoAmt < sendAmt + fee)
reject("Insufficient FLO balance!");
reject("Insufficient FLO: Some UTXOs are unconfirmed");
else {
trx.addoutput(receiverAddr, sendAmt);
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))
});
}

View File

@ -8,7 +8,6 @@
const floGlobals = {
blockchain: "FLO",
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
fee: 0.01,
application: "TEST_MODE",
}
</script>