Organizing scripts: floBlockchainAPI v2.2.0

- converted XMLHttpRequest to fetch request
This commit is contained in:
sairajzero 2022-02-27 20:38:14 +05:30
parent 3cb6c3f60c
commit 10fa130229

View File

@ -6637,8 +6637,8 @@
</script> </script>
<script id="floCrypto" version="2.2.0"> <script id="floCrypto" version="2.2.0">
/* FLO Crypto Operators*/
'use strict'; 'use strict';
(function(GLOBAL) { (function(GLOBAL) {
const floCrypto = GLOBAL.floCrypto = { const floCrypto = GLOBAL.floCrypto = {
@ -6977,9 +6977,11 @@
})(typeof global !== "undefined" ? global : window); })(typeof global !== "undefined" ? global : window);
</script> </script>
<script id="floBlockchainAPI" version="2.1.1a"> <script id="floBlockchainAPI" version="2.2.0">
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/ /* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
const floBlockchainAPI = { 'use strict';
(function(GLOBAL) {
const floBlockchainAPI = GLOBAL.floBlockchainAPI = {
util: { util: {
serverList: floGlobals.apiURL[floGlobals.blockchain].slice(0), serverList: floGlobals.apiURL[floGlobals.blockchain].slice(0),
@ -7338,25 +7340,21 @@
//Broadcast signed Tx in blockchain using API //Broadcast signed Tx in blockchain using API
broadcastTx: function(signedTxHash) { broadcastTx: function(signedTxHash) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var request = new XMLHttpRequest();
var url = this.util.serverList[this.util.curPos] + 'api/tx/send';
console.log(url);
if (signedTxHash.length < 1) if (signedTxHash.length < 1)
reject("Empty Signature"); return reject("Empty Signature");
else { var url = this.util.serverList[this.util.curPos] + 'api/tx/send';
var params = `{"rawtx":"${signedTxHash}"}`; fetch(url, {
request.open('POST', url, true); method: "POST",
//Send the proper header information along with the request headers: {
request.setRequestHeader('Content-type', 'application/json'); 'Content-Type': 'application/json'
request.onload = function() { },
if (request.readyState == 4 && request.status == 200) { body: `{"rawtx":"${signedTxHash}"}`
console.log(request.response); }).then(response => {
resolve(JSON.parse(request.response).txid.result); if (response.ok)
} else response.json().then(data => resolve(data.txid.result));
reject(request.responseText); else
} response.text().then(data => resolve(data));
request.send(params); }).catch(error => reject(error));
}
}) })
}, },
@ -7412,7 +7410,8 @@
if (options.limit <= 0) if (options.limit <= 0)
options.limit = response.items.length; options.limit = response.items.length;
var filteredData = []; var filteredData = [];
for (let i = 0; i < (response.totalItems - options.ignoreOld) && filteredData.length < options.limit; i++) { for (let i = 0; i < (response.totalItems - options.ignoreOld) &&
filteredData.length < options.limit; i++) {
if (options.pattern) { if (options.pattern) {
try { try {
let jsonContent = JSON.parse(response.items[i].floData); let jsonContent = JSON.parse(response.items[i].floData);
@ -7484,6 +7483,7 @@
}); });
} }
} }
})(typeof global !== "undefined" ? global : window);
</script> </script>
<script id="compactIDB" version="2.0.1"> <script id="compactIDB" version="2.0.1">
/* Compact IndexedDB operations */ /* Compact IndexedDB operations */