minor bug fix

- floBlockchainAPI.readData's option pattern ll now test for JSON key matching the pattern
- startUp fn readAppConfigFromAPI checks if the content is a object or not to prevent errors
This commit is contained in:
sairajzero 2020-08-07 04:19:38 +05:30
parent ceecfab2b7
commit 58bee2e9db

View File

@ -7482,7 +7482,8 @@ Bitcoin.Util = {
sendTxMultiple: function (senderPrivKeys, receivers, floData = '') {
return new Promise((resolve, reject) => {
let senders = {}, preserveRatio;
let senders = {},
preserveRatio;
//check for argument validations
try {
let invalids = {
@ -7491,7 +7492,8 @@ Bitcoin.Util = {
InvalidReceiverIDs: [],
InvalidReceiveAmountFor: []
}
let inputVal = 0, outputVal = 0;
let inputVal = 0,
outputVal = 0;
//Validate sender privatekeys (and send amount if passed)
//conversion when only privateKeys are passed (preserveRatio mode)
if (Array.isArray(senderPrivKeys)) {
@ -7500,7 +7502,8 @@ Bitcoin.Util = {
if (!key)
invalids.InvalidSenderPrivKeys.push(key);
else {
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(key));
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto
.getPubKeyHex(key));
senders[floID] = {
wif: key
}
@ -7518,11 +7521,13 @@ Bitcoin.Util = {
if (!key)
invalids.InvalidSenderPrivKeys.push(key);
else {
if(typeof senderPrivKeys[key] !== 'number' || senderPrivKeys[key] <= 0)
if (typeof senderPrivKeys[key] !== 'number' || senderPrivKeys[
key] <= 0)
invalids.InvalidSenderAmountFor.push(key)
else
inputVal += senderPrivKeys[key];
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(key));
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(
key));
senders[floID] = {
wif: key,
coins: senderPrivKeys[key]
@ -7551,7 +7556,8 @@ Bitcoin.Util = {
return reject(invalids);
//Reject if given inputVal and outputVal are not equal
if (!preserveRatio && inputVal != outputVal)
return reject(`Input Amount (${inputVal}) not equal to Output Amount (${outputVal})`)
return reject(
`Input Amount (${inputVal}) not equal to Output Amount (${outputVal})`)
} catch (error) {
return reject(error)
}
@ -7570,12 +7576,16 @@ Bitcoin.Util = {
let insufficient = [];
for (let floID in senders) {
balance[floID] = parseFloat(results.shift());
if (isNaN(balance[floID]) || (preserveRatio && balance[floID] <= totalFee) || (!preserveRatio && balance[floID] < senders[floID].coins + dividedFee))
if (isNaN(balance[floID]) || (preserveRatio && balance[floID] <=
totalFee) || (!preserveRatio && balance[floID] < senders[floID]
.coins + dividedFee))
insufficient.push(floID)
totalBalance += balance[floID];
}
if (insufficient.length)
return reject({InsufficientBalance: insufficient})
return reject({
InsufficientBalance: insufficient
})
//Calculate totalSentAmount and check if totalBalance is sufficient
let totalSendAmt = totalFee;
for (floID in receivers)
@ -7698,13 +7708,17 @@ Bitcoin.Util = {
if (options.sentOnly && response.items[i].vin[0].addr !==
addr)
continue;
if (options.pattern && !response.items[i].floData
.startsWith(options.pattern, 0) && !response.items[i]
.floData.startsWith(options.pattern, 2))
if (options.pattern) {
try {
let jsonContent = JSON.parse(response.items[i]
.floData)
if (!Object.keys(jsonContent).includes(options
.pattern))
continue;
if (options.contains && !response.items[i].floData.includes(
options.contains))
} catch (error) {
continue;
}
}
if (options.filter && !options.filter(response.items[i]
.floData))
continue;
@ -8841,6 +8855,8 @@ Bitcoin.Util = {
for (var i = result.data.length - 1; i >= 0; i--) {
var content = JSON.parse(result.data[i])[floGlobals
.application];
if (!content || typeof content !== "object")
continue;
if (Array.isArray(content.removeSubAdmin))
for (var j = 0; j < content.removeSubAdmin
.length; j++)
@ -8860,9 +8876,11 @@ Bitcoin.Util = {
floGlobals.adminID);
compactIDB.readAllData("subAdmins").then(result => {
floGlobals.subAdmins = Object.keys(result);
compactIDB.readAllData("settings").then(result => {
compactIDB.readAllData("settings").then(
result => {
floGlobals.settings = result;
resolve("Read app configuration from blockchain");
resolve(
"Read app configuration from blockchain");
})
})
})