Minor fixes

floCrypto v2.3.3e
- Adding options args to toFloID function. options object accept std and/or bech properties. if specified only converts if given address are from specified version

floBlockchainAPI v2.3.3c
- Fixed: tx failing due to dust amount in change value
- readData: when passes tx option as true, now also gives senders and receivers (Set)

btcOperator v1.0.10b
- Fixed: minor bugs
This commit is contained in:
sairajzero 2022-10-14 23:11:05 +05:30
parent 7d84ded426
commit c38b7257cf
3 changed files with 75 additions and 66 deletions

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //btcOperator v1.0.10a
(function (EXPORTS) { //btcOperator v1.0.10b
/* BTC Crypto and API Operator */
const btcOperator = EXPORTS;
@ -340,7 +340,7 @@
let net_fee = BASE_TX_SIZE * fee_rate;
net_fee += (output_size * fee_rate);
addUTXOs(tx, senders, redeemScripts, total_amount + net_fee, fee_rate).then(result => {
result.fee_amount = parseFloat((net_fee + (result.input_size * fee_rate)).toFixed(8));
result.fee = parseFloat((net_fee + (result.input_size * fee_rate)).toFixed(8));
result.fee_rate = fee_rate;
resolve(result);
}).catch(error => reject(error))
@ -665,7 +665,7 @@
}
btcOperator.getTx = txid => new Promise((resolve, reject) => {
fetch_api(`get_tx/BTC/${txid}`)
fetch_api(`tx/BTC/${txid}`)
.then(result => resolve(result.data))
.catch(error => reject(error))
});

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floBlockchainAPI v2.3.3b
(function (EXPORTS) { //floBlockchainAPI v2.3.3c
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
'use strict';
const floBlockchainAPI = EXPORTS;
@ -11,6 +11,7 @@
},
sendAmt: 0.001,
fee: 0.0005,
minChangeAmt: 0.0005,
receiverID: floGlobals.adminID
};
@ -171,7 +172,7 @@
else {
trx.addoutput(receiverAddr, sendAmt);
var change = utxoAmt - sendAmt - fee;
if (change > 0)
if (change > DEFAULT.minChangeAmt)
trx.addoutput(senderAddr, change);
trx.addflodata(floData.replace(/\n/g, ' '));
var signedTxHash = trx.sign(privKey, 1);
@ -555,6 +556,8 @@
d.txid = response.items[i].txid;
d.time = response.items[i].time;
d.blockheight = response.items[i].blockheight;
d.senders = new Set(response.items[i].vin.map(v => v.addr));
d.receivers = new Set(response.items[i].vout.map(v => v.scriptPubKey.addresses[0]));
d.data = response.items[i].floData;
filteredData.push(d);
} else

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floCrypto v2.3.3d
(function (EXPORTS) { //floCrypto v2.3.3e
/* FLO Crypto Operators */
'use strict';
const floCrypto = EXPORTS;
@ -276,12 +276,18 @@
}
//Convert the given address (any blockchain) to equivalent floID
floCrypto.toFloID = function(address) {
floCrypto.toFloID = function (address, options = null) {
if (!address)
return;
let raw = decodeAddress(address);
if (!raw)
return;
else if (options) {
if (typeof raw.version !== 'undefined' && (!options.std || !options.std.includes(raw.version)))
return;
if (typeof raw.bech_version !== 'undefined' && (!options.bech || !options.bech.includes(raw.bech_version)))
return;
}
raw.bytes.unshift(bitjs.pub);
let hash = Crypto.SHA256(Crypto.SHA256(raw.bytes, {
asBytes: true