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:
parent
ceecfab2b7
commit
58bee2e9db
@ -7400,7 +7400,7 @@ Bitcoin.Util = {
|
|||||||
var change = utxoAmt - sendAmt - fee;
|
var change = utxoAmt - sendAmt - fee;
|
||||||
if (change > 0)
|
if (change > 0)
|
||||||
trx.addoutput(senderAddr, change);
|
trx.addoutput(senderAddr, change);
|
||||||
trx.addflodata(floData.replace(/\n/g,' '));
|
trx.addflodata(floData.replace(/\n/g, ' '));
|
||||||
var signedTxHash = trx.sign(privKey, 1);
|
var signedTxHash = trx.sign(privKey, 1);
|
||||||
this.broadcastTx(signedTxHash)
|
this.broadcastTx(signedTxHash)
|
||||||
.then(txid => resolve(txid))
|
.then(txid => resolve(txid))
|
||||||
@ -7431,7 +7431,7 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
trx.addoutput(floID, utxoAmt - fee);
|
trx.addoutput(floID, utxoAmt - fee);
|
||||||
trx.addflodata(floData.replace(/\n/g,' '));
|
trx.addflodata(floData.replace(/\n/g, ' '));
|
||||||
var signedTxHash = trx.sign(privKey, 1);
|
var signedTxHash = trx.sign(privKey, 1);
|
||||||
this.broadcastTx(signedTxHash)
|
this.broadcastTx(signedTxHash)
|
||||||
.then(txid => resolve(txid))
|
.then(txid => resolve(txid))
|
||||||
@ -7447,11 +7447,11 @@ Bitcoin.Util = {
|
|||||||
* @param {boolean} preserveRatio (optional) preserve ratio or equal contribution
|
* @param {boolean} preserveRatio (optional) preserve ratio or equal contribution
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
writeDataMultiple: function (senderPrivKeys, data, receivers = [floGlobals.adminID], preserveRatio = true){
|
writeDataMultiple: function (senderPrivKeys, data, receivers = [floGlobals.adminID], preserveRatio = true) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!Array.isArray(senderPrivKeys))
|
if (!Array.isArray(senderPrivKeys))
|
||||||
return reject("Invalid senderPrivKeys: SenderPrivKeys must be Array")
|
return reject("Invalid senderPrivKeys: SenderPrivKeys must be Array")
|
||||||
if(!preserveRatio){
|
if (!preserveRatio) {
|
||||||
let tmp = {};
|
let tmp = {};
|
||||||
let amount = (floGlobals.sendAmt * receivers.length) / senderPrivKeys.length;
|
let amount = (floGlobals.sendAmt * receivers.length) / senderPrivKeys.length;
|
||||||
senderPrivKeys.forEach(key => tmp[key] = amount);
|
senderPrivKeys.forEach(key => tmp[key] = amount);
|
||||||
@ -7481,54 +7481,59 @@ Bitcoin.Util = {
|
|||||||
*/
|
*/
|
||||||
sendTxMultiple: function (senderPrivKeys, receivers, floData = '') {
|
sendTxMultiple: function (senderPrivKeys, receivers, floData = '') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
let senders = {}, preserveRatio;
|
let senders = {},
|
||||||
|
preserveRatio;
|
||||||
//check for argument validations
|
//check for argument validations
|
||||||
try{
|
try {
|
||||||
let invalids = {
|
let invalids = {
|
||||||
InvalidSenderPrivKeys: [],
|
InvalidSenderPrivKeys: [],
|
||||||
InvalidSenderAmountFor: [],
|
InvalidSenderAmountFor: [],
|
||||||
InvalidReceiverIDs: [],
|
InvalidReceiverIDs: [],
|
||||||
InvalidReceiveAmountFor: []
|
InvalidReceiveAmountFor: []
|
||||||
}
|
}
|
||||||
let inputVal = 0, outputVal = 0;
|
let inputVal = 0,
|
||||||
|
outputVal = 0;
|
||||||
//Validate sender privatekeys (and send amount if passed)
|
//Validate sender privatekeys (and send amount if passed)
|
||||||
//conversion when only privateKeys are passed (preserveRatio mode)
|
//conversion when only privateKeys are passed (preserveRatio mode)
|
||||||
if(Array.isArray(senderPrivKeys)){
|
if (Array.isArray(senderPrivKeys)) {
|
||||||
senderPrivKeys.forEach(key => {
|
senderPrivKeys.forEach(key => {
|
||||||
try{
|
try {
|
||||||
if(!key)
|
if (!key)
|
||||||
invalids.InvalidSenderPrivKeys.push(key);
|
invalids.InvalidSenderPrivKeys.push(key);
|
||||||
else{
|
else {
|
||||||
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(key));
|
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto
|
||||||
|
.getPubKeyHex(key));
|
||||||
senders[floID] = {
|
senders[floID] = {
|
||||||
wif: key
|
wif: key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(error){
|
} catch (error) {
|
||||||
invalids.InvalidSenderPrivKeys.push(key)
|
invalids.InvalidSenderPrivKeys.push(key)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
preserveRatio = true;
|
preserveRatio = true;
|
||||||
}
|
}
|
||||||
//conversion when privatekeys are passed with send amount
|
//conversion when privatekeys are passed with send amount
|
||||||
else{
|
else {
|
||||||
for(let key in senderPrivKeys){
|
for (let key in senderPrivKeys) {
|
||||||
try{
|
try {
|
||||||
if(!key)
|
if (!key)
|
||||||
invalids.InvalidSenderPrivKeys.push(key);
|
invalids.InvalidSenderPrivKeys.push(key);
|
||||||
else{
|
else {
|
||||||
if(typeof senderPrivKeys[key] !== 'number' || senderPrivKeys[key] <= 0)
|
if (typeof senderPrivKeys[key] !== 'number' || senderPrivKeys[
|
||||||
|
key] <= 0)
|
||||||
invalids.InvalidSenderAmountFor.push(key)
|
invalids.InvalidSenderAmountFor.push(key)
|
||||||
else
|
else
|
||||||
inputVal += senderPrivKeys[key];
|
inputVal += senderPrivKeys[key];
|
||||||
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(key));
|
let floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(
|
||||||
|
key));
|
||||||
senders[floID] = {
|
senders[floID] = {
|
||||||
wif: key,
|
wif: key,
|
||||||
coins: senderPrivKeys[key]
|
coins: senderPrivKeys[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(error){
|
} catch (error) {
|
||||||
invalids.InvalidSenderPrivKeys.push(key)
|
invalids.InvalidSenderPrivKeys.push(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7550,9 +7555,10 @@ Bitcoin.Util = {
|
|||||||
if (Object.keys(invalids).length)
|
if (Object.keys(invalids).length)
|
||||||
return reject(invalids);
|
return reject(invalids);
|
||||||
//Reject if given inputVal and outputVal are not equal
|
//Reject if given inputVal and outputVal are not equal
|
||||||
if(!preserveRatio && inputVal != outputVal)
|
if (!preserveRatio && inputVal != outputVal)
|
||||||
return reject(`Input Amount (${inputVal}) not equal to Output Amount (${outputVal})`)
|
return reject(
|
||||||
}catch(error){
|
`Input Amount (${inputVal}) not equal to Output Amount (${outputVal})`)
|
||||||
|
} catch (error) {
|
||||||
return reject(error)
|
return reject(error)
|
||||||
}
|
}
|
||||||
//Get balance of senders
|
//Get balance of senders
|
||||||
@ -7564,18 +7570,22 @@ Bitcoin.Util = {
|
|||||||
totalFee = floGlobals.fee,
|
totalFee = floGlobals.fee,
|
||||||
balance = {};
|
balance = {};
|
||||||
//Divide fee among sender if not for preserveRatio
|
//Divide fee among sender if not for preserveRatio
|
||||||
if(!preserveRatio)
|
if (!preserveRatio)
|
||||||
var dividedFee = totalFee / Object.keys(senders).length;
|
var dividedFee = totalFee / Object.keys(senders).length;
|
||||||
//Check if balance of each sender is sufficient enough
|
//Check if balance of each sender is sufficient enough
|
||||||
let insufficient = [];
|
let insufficient = [];
|
||||||
for (let floID in senders) {
|
for (let floID in senders) {
|
||||||
balance[floID] = parseFloat(results.shift());
|
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)
|
insufficient.push(floID)
|
||||||
totalBalance += balance[floID];
|
totalBalance += balance[floID];
|
||||||
}
|
}
|
||||||
if (insufficient.length)
|
if (insufficient.length)
|
||||||
return reject({InsufficientBalance: insufficient})
|
return reject({
|
||||||
|
InsufficientBalance: insufficient
|
||||||
|
})
|
||||||
//Calculate totalSentAmount and check if totalBalance is sufficient
|
//Calculate totalSentAmount and check if totalBalance is sufficient
|
||||||
let totalSendAmt = totalFee;
|
let totalSendAmt = totalFee;
|
||||||
for (floID in receivers)
|
for (floID in receivers)
|
||||||
@ -7592,10 +7602,10 @@ Bitcoin.Util = {
|
|||||||
for (floID in senders) {
|
for (floID in senders) {
|
||||||
let utxos = results.shift();
|
let utxos = results.shift();
|
||||||
let sendAmt;
|
let sendAmt;
|
||||||
if(preserveRatio){
|
if (preserveRatio) {
|
||||||
let ratio = (balance[floID] / totalBalance);
|
let ratio = (balance[floID] / totalBalance);
|
||||||
sendAmt = totalSendAmt * ratio;
|
sendAmt = totalSendAmt * ratio;
|
||||||
} else
|
} else
|
||||||
sendAmt = senders[floID].coins + dividedFee;
|
sendAmt = senders[floID].coins + dividedFee;
|
||||||
let wif = senders[floID].wif;
|
let wif = senders[floID].wif;
|
||||||
let utxoAmt = 0.0;
|
let utxoAmt = 0.0;
|
||||||
@ -7616,7 +7626,7 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
for (floID in receivers)
|
for (floID in receivers)
|
||||||
trx.addoutput(floID, receivers[floID]);
|
trx.addoutput(floID, receivers[floID]);
|
||||||
trx.addflodata(floData.replace(/\n/g,' '));
|
trx.addflodata(floData.replace(/\n/g, ' '));
|
||||||
for (let i = 0; i < wifSeq.length; i++)
|
for (let i = 0; i < wifSeq.length; i++)
|
||||||
trx.signinput(i, wifSeq[i], 1);
|
trx.signinput(i, wifSeq[i], 1);
|
||||||
var signedTxHash = trx.serialize();
|
var signedTxHash = trx.serialize();
|
||||||
@ -7698,13 +7708,17 @@ Bitcoin.Util = {
|
|||||||
if (options.sentOnly && response.items[i].vin[0].addr !==
|
if (options.sentOnly && response.items[i].vin[0].addr !==
|
||||||
addr)
|
addr)
|
||||||
continue;
|
continue;
|
||||||
if (options.pattern && !response.items[i].floData
|
if (options.pattern) {
|
||||||
.startsWith(options.pattern, 0) && !response.items[i]
|
try {
|
||||||
.floData.startsWith(options.pattern, 2))
|
let jsonContent = JSON.parse(response.items[i]
|
||||||
continue;
|
.floData)
|
||||||
if (options.contains && !response.items[i].floData.includes(
|
if (!Object.keys(jsonContent).includes(options
|
||||||
options.contains))
|
.pattern))
|
||||||
continue;
|
continue;
|
||||||
|
} catch (error) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (options.filter && !options.filter(response.items[i]
|
if (options.filter && !options.filter(response.items[i]
|
||||||
.floData))
|
.floData))
|
||||||
continue;
|
continue;
|
||||||
@ -8841,6 +8855,8 @@ Bitcoin.Util = {
|
|||||||
for (var i = result.data.length - 1; i >= 0; i--) {
|
for (var i = result.data.length - 1; i >= 0; i--) {
|
||||||
var content = JSON.parse(result.data[i])[floGlobals
|
var content = JSON.parse(result.data[i])[floGlobals
|
||||||
.application];
|
.application];
|
||||||
|
if (!content || typeof content !== "object")
|
||||||
|
continue;
|
||||||
if (Array.isArray(content.removeSubAdmin))
|
if (Array.isArray(content.removeSubAdmin))
|
||||||
for (var j = 0; j < content.removeSubAdmin
|
for (var j = 0; j < content.removeSubAdmin
|
||||||
.length; j++)
|
.length; j++)
|
||||||
@ -8860,10 +8876,12 @@ Bitcoin.Util = {
|
|||||||
floGlobals.adminID);
|
floGlobals.adminID);
|
||||||
compactIDB.readAllData("subAdmins").then(result => {
|
compactIDB.readAllData("subAdmins").then(result => {
|
||||||
floGlobals.subAdmins = Object.keys(result);
|
floGlobals.subAdmins = Object.keys(result);
|
||||||
compactIDB.readAllData("settings").then(result => {
|
compactIDB.readAllData("settings").then(
|
||||||
floGlobals.settings = result;
|
result => {
|
||||||
resolve("Read app configuration from blockchain");
|
floGlobals.settings = result;
|
||||||
})
|
resolve(
|
||||||
|
"Read app configuration from blockchain");
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user