diff --git a/Client/web3Server.js b/Client/web3Server.js index 29861db60..3ed6816d8 100644 --- a/Client/web3Server.js +++ b/Client/web3Server.js @@ -68,6 +68,7 @@ exports.newWeb3Server = function newWeb3Server() { let status = {} status.isSyncing = await web3.eth.isSyncing() status.chainId = await web3.eth.getChainId() + status.currentBlockNumber = await web3.eth.getBlockNumber() status.result = 'Ok' return status } diff --git a/Data-Files/src/FileStorage.js b/Data-Files/src/FileStorage.js index 77992863c..776435d22 100644 --- a/Data-Files/src/FileStorage.js +++ b/Data-Files/src/FileStorage.js @@ -44,7 +44,7 @@ function newFileStorage(host, port) { url = folder + filePath } - callWebServer(undefined, url, (response, fileContent) => { + httpRequest(undefined, url, (response, fileContent) => { if (response.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, fileContent) } else { diff --git a/Integrations/Projects/Ethereum/Function-Libraries/Geth.js b/Integrations/Projects/Ethereum/Function-Libraries/Geth.js index c4e4f2d66..73db923fe 100644 --- a/Integrations/Projects/Ethereum/Function-Libraries/Geth.js +++ b/Integrations/Projects/Ethereum/Function-Libraries/Geth.js @@ -8,7 +8,7 @@ function newGeth() { return thisObject function install(node) { - callWebServer('ExecuteTerminalCommand/dir') + httpRequest('ExecuteTerminalCommand/dir') } function run(node) { diff --git a/Integrations/Projects/Ethereum/Spaces/Blockchain-Space/Blockchain.js b/Integrations/Projects/Ethereum/Spaces/Blockchain-Space/Blockchain.js index 5b8bae5d8..4626f3f6a 100644 --- a/Integrations/Projects/Ethereum/Spaces/Blockchain-Space/Blockchain.js +++ b/Integrations/Projects/Ethereum/Spaces/Blockchain-Space/Blockchain.js @@ -85,7 +85,19 @@ function newEthereumBlockchainSpace() { interface: clientInterface } - callWebServer(JSON.stringify(params), 'WEB3', onResponse) + /* + Next, we will check which Superalgos Network Node we need as a gateway + to the Ethereum Client. We will use the current node reference parent for that. + */ + if (networkClient.payload.referenceParent === undefined) { + networkClient.payload.uiObject.setErrorMessage('You need to reference a Superalgos Network Node so that it acts as a gateway to the Ethereum Client.') + return + } + + let networkNodeConfig = JSON.parse(networkClient.payload.referenceParent.config) + let url = 'http://' + networkNodeConfig.host + ':' + networkNodeConfig.webPort + '/' + 'WEB3' + + httpRequest(JSON.stringify(params), url, onResponse) function onResponse(err, data) { /* Lets check the result of the call through the http interface */ @@ -117,7 +129,13 @@ function newEthereumBlockchainSpace() { if (status.chainId > 0) { let networkName = UI.projects.ethereum.globals.chainIds.chainNameById(status.chainId) - networkClient.payload.uiObject.setStatus('Connected to ' + networkName + ' via http. ', ANNIMATION_CYCLES_TO_LAST) + networkClient.payload.uiObject.setStatus('Connected to ' + networkName + ' via the ' + clientInterface + ' interface, through ' + networkClient.payload.referenceParent.name + ' Network Node.', ANNIMATION_CYCLES_TO_LAST) + + networkClient.payload.uiObject.valueAtAngle = false + networkClient.payload.uiObject.setValue( + 'Current Block Number ' + splitLargeNumber(status.currentBlockNumber) + , 200) + networkClient.payload.uiObject.setPercentage('100.00', ANNIMATION_CYCLES_TO_LAST) return } @@ -141,7 +159,7 @@ function newEthereumBlockchainSpace() { if (status.isSyncing.currentBlock !== status.isSyncing.highestBlock) { networkClient.payload.uiObject.setStatus('Connected via http. Client is Syncing... ' + extraStatus, ANNIMATION_CYCLES_TO_LAST) - } + } function splitLargeNumber(number) { let label = number.toString() diff --git a/Integrations/Projects/Superalgos/Function-Libraries/CryptoEcosystemFunctions.js b/Integrations/Projects/Superalgos/Function-Libraries/CryptoEcosystemFunctions.js index c2373a016..386fe466d 100644 --- a/Integrations/Projects/Superalgos/Function-Libraries/CryptoEcosystemFunctions.js +++ b/Integrations/Projects/Superalgos/Function-Libraries/CryptoEcosystemFunctions.js @@ -31,7 +31,7 @@ function newCryptoEcosystemFunctions() { } } - callWebServer(JSON.stringify(params), 'CCXT', onResponse) + httpRequest(JSON.stringify(params), 'CCXT', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { @@ -79,7 +79,7 @@ function newCryptoEcosystemFunctions() { exchangeId: exchangeId, method: 'fetchMarkets' } - callWebServer(JSON.stringify(params), 'CCXT', onResponse) + httpRequest(JSON.stringify(params), 'CCXT', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { @@ -161,7 +161,7 @@ function newCryptoEcosystemFunctions() { exchangeId: exchangeId, method: 'fetchMarkets' } - callWebServer(JSON.stringify(params), 'CCXT', onResponse) + httpRequest(JSON.stringify(params), 'CCXT', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/Integrations/Projects/Superalgos/Function-Libraries/PluginsFunctions.js b/Integrations/Projects/Superalgos/Function-Libraries/PluginsFunctions.js index 240580a15..eac6aa87a 100644 --- a/Integrations/Projects/Superalgos/Function-Libraries/PluginsFunctions.js +++ b/Integrations/Projects/Superalgos/Function-Libraries/PluginsFunctions.js @@ -11,7 +11,7 @@ function newPluginsFunctions() { return thisObject function getPluginFileNames(projectName, pluginType, callBack) { - callWebServer(undefined, 'PluginFileNames/' + projectName + '/' + pluginType, onResponse) + httpRequest(undefined, 'PluginFileNames/' + projectName + '/' + pluginType, onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { @@ -37,7 +37,7 @@ function newPluginsFunctions() { function pluginMissingProjects(node, rootNodes, functionLibraryUiObjectsFromNodes) { let url = 'ProjectNames' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, pProjects) { let projects = JSON.parse(pProjects) diff --git a/Integrations/Projects/Superalgos/Function-Libraries/UiObjectsFromNodes.js b/Integrations/Projects/Superalgos/Function-Libraries/UiObjectsFromNodes.js index 4e0d078d8..eba25b1ef 100644 --- a/Integrations/Projects/Superalgos/Function-Libraries/UiObjectsFromNodes.js +++ b/Integrations/Projects/Superalgos/Function-Libraries/UiObjectsFromNodes.js @@ -99,7 +99,7 @@ function newUiObjectsFromNodes() { for (let i = 0; i < pluginFiles.length; i++) { let pluginFile = pluginFiles[i] let name = pluginFile.name - callWebServer(undefined, 'LoadPlugin' + '/' + 'Superalgos' + '/' + pluginType + '/' + name + '.json', onFileReceived) + httpRequest(undefined, 'LoadPlugin' + '/' + 'Superalgos' + '/' + pluginType + '/' + name + '.json', onFileReceived) function onFileReceived(err, text, response) { diff --git a/Integrations/Projects/Superalgos/Function-Libraries/WebhookFunctions.js b/Integrations/Projects/Superalgos/Function-Libraries/WebhookFunctions.js index daa51483c..da1228dea 100644 --- a/Integrations/Projects/Superalgos/Function-Libraries/WebhookFunctions.js +++ b/Integrations/Projects/Superalgos/Function-Libraries/WebhookFunctions.js @@ -9,7 +9,7 @@ function newWebhookFunctions() { let testMessage = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'testMessage') let letURL = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'webhookURL') - callWebServer(testMessage, letURL, onResponse) + httpRequest(testMessage, letURL, onResponse) function onResponse(err) { if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/Integrations/Projects/Superalgos/Function-Libraries/WorkspaceFunctions.js b/Integrations/Projects/Superalgos/Function-Libraries/WorkspaceFunctions.js index d477ea2d0..b99334046 100644 --- a/Integrations/Projects/Superalgos/Function-Libraries/WorkspaceFunctions.js +++ b/Integrations/Projects/Superalgos/Function-Libraries/WorkspaceFunctions.js @@ -7,7 +7,7 @@ function newWorkspaceFunctions() { function addMissingWorkspaceProjects(node, rootNodes, functionLibraryUiObjectsFromNodes) { let url = 'ProjectNames' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, pProjects) { let projects = JSON.parse(pProjects) diff --git a/Integrations/Projects/Superalgos/Spaces/Design-Space/DesignSpace.js b/Integrations/Projects/Superalgos/Spaces/Design-Space/DesignSpace.js index 51267a439..64f4e3d39 100644 --- a/Integrations/Projects/Superalgos/Spaces/Design-Space/DesignSpace.js +++ b/Integrations/Projects/Superalgos/Spaces/Design-Space/DesignSpace.js @@ -60,7 +60,7 @@ function newSuperalgosDesignSpace() { function loadIconCollection(callBack) { - callWebServer(undefined, 'IconNames', onResponse) + httpRequest(undefined, 'IconNames', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/Integrations/Projects/Superalgos/Spaces/Design-Space/Workspace.js b/Integrations/Projects/Superalgos/Spaces/Design-Space/Workspace.js index e064db9eb..8e2a477da 100644 --- a/Integrations/Projects/Superalgos/Spaces/Design-Space/Workspace.js +++ b/Integrations/Projects/Superalgos/Spaces/Design-Space/Workspace.js @@ -75,7 +75,7 @@ function newWorkspace() { let lastUsedWorkspace = window.localStorage.getItem('Last Used Workspace') if (lastUsedWorkspace !== 'undefined' && lastUsedWorkspace !== null && lastUsedWorkspace !== undefined) { - callWebServer(undefined, 'LoadMyWorkspace' + '/' + lastUsedWorkspace, onFileReceived) + httpRequest(undefined, 'LoadMyWorkspace' + '/' + lastUsedWorkspace, onFileReceived) function onFileReceived(err, text, response) { if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { UI.projects.superalgos.spaces.cockpitSpace.setStatus('Could not load the last Workspace used, called "' + lastUsedWorkspace + '". Will switch to the default Workspace instead.', 500, UI.projects.superalgos.spaces.cockpitSpace.statusTypes.WARNING) @@ -172,7 +172,7 @@ function newWorkspace() { } let url = 'SaveWorkspace/' + workspace.name - callWebServer(textToSave, url, onResponse) + httpRequest(textToSave, url, onResponse) return true function onResponse(err) { @@ -431,7 +431,7 @@ function newWorkspace() { webCommand = 'LoadMyWorkspace' + '/' + name } - callWebServer(undefined, webCommand, onFileReceived) + httpRequest(undefined, webCommand, onFileReceived) function onFileReceived(err, text, response) { if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { UI.projects.superalgos.spaces.cockpitSpace.setStatus('Could not load the Workspace called "' + name + '". ', 500, UI.projects.superalgos.spaces.cockpitSpace.statusTypes.WARNING) diff --git a/Integrations/Projects/Superalgos/Spaces/Side-Space/ListView.js b/Integrations/Projects/Superalgos/Spaces/Side-Space/ListView.js index 653fe2c2f..5000efb16 100644 --- a/Integrations/Projects/Superalgos/Spaces/Side-Space/ListView.js +++ b/Integrations/Projects/Superalgos/Spaces/Side-Space/ListView.js @@ -90,7 +90,7 @@ function newListView() { function turnOn() { firstVisibleListItem = 1 - callWebServer(undefined, 'ListWorkspaces', onResponse) + httpRequest(undefined, 'ListWorkspaces', onResponse) function onResponse(err, text) { if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/UI/AppLoader.js b/UI/AppLoader.js index 904f7aab1..ac4543db4 100644 --- a/UI/AppLoader.js +++ b/UI/AppLoader.js @@ -57,7 +57,7 @@ function newAppLoader() { function functionLibraries() { let url = 'ListFunctionLibraries' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, fileList) { let urlArray = [] @@ -77,7 +77,7 @@ function newAppLoader() { function utilities() { let url = 'ListUtilitiesFiles' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, fileList) { let urlArray = [] @@ -97,7 +97,7 @@ function newAppLoader() { function globals() { let url = 'ListGlobalFiles' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, fileList) { let urlArray = [] @@ -117,7 +117,7 @@ function newAppLoader() { function spaces() { let url = 'ListSpaceFiles' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, fileList) { let urlArray = [] diff --git a/UI/AppPostLoader.js b/UI/AppPostLoader.js index cfb5488db..ed905d728 100644 --- a/UI/AppPostLoader.js +++ b/UI/AppPostLoader.js @@ -22,7 +22,7 @@ function newAppPostLoader() { setupProjectsSchema() function setupProjectsSchema() { - callWebServer(undefined, 'ProjectsSchema', onResponse) + httpRequest(undefined, 'ProjectsSchema', onResponse) function onResponse(err, file) { PROJECTS_SCHEMA = JSON.parse(file) @@ -52,7 +52,7 @@ function newAppPostLoader() { SCHEMAS_BY_PROJECT.set(project, schemas) totalWebServerCalls++ - callWebServer(undefined, 'Schema/' + project + '/AppSchema', onResponseAppSchema) + httpRequest(undefined, 'Schema/' + project + '/AppSchema', onResponseAppSchema) function onResponseAppSchema(err, schema) { try { @@ -72,7 +72,7 @@ function newAppPostLoader() { } totalWebServerCalls++ - callWebServer(undefined, 'Schema/' + project + '/DocSchema', onResponseDocSchema) + httpRequest(undefined, 'Schema/' + project + '/DocSchema', onResponseDocSchema) function onResponseDocSchema(err, schema) { try { @@ -92,7 +92,7 @@ function newAppPostLoader() { } totalWebServerCalls++ - callWebServer(undefined, 'Schema/' + project + '/ConceptSchema', onResponseConceptSchema) + httpRequest(undefined, 'Schema/' + project + '/ConceptSchema', onResponseConceptSchema) function onResponseConceptSchema(err, schema) { try { diff --git a/UI/AppPreLoader.js b/UI/AppPreLoader.js index 2e9df25c5..2fb263427 100644 --- a/UI/AppPreLoader.js +++ b/UI/AppPreLoader.js @@ -109,7 +109,7 @@ function loadSuperalgos() { function setUpProjects() { let url = 'ProjectNames' - callWebServer(undefined, url, onResponse) + httpRequest(undefined, url, onResponse) function onResponse(err, projects) { window.PROJECTS = JSON.parse(projects) @@ -130,26 +130,26 @@ function loadSuperalgos() { } } -function callWebServer(pContentToSend, pPath, callBackFunction) { - let xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function () { +function httpRequest(pContentToSend, pPath, callBackFunction) { + let xmlHttpRequest = new XMLHttpRequest(); + xmlHttpRequest.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xhttp.responseText); + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText); return; } else if (this.readyState === 4 && this.status === 404) { - callBackFunction({ result: "Fail", message: xhttp.responseText.trim(), code: xhttp.responseText.trim() }); + callBackFunction({ result: "Fail", message: xmlHttpRequest.responseText.trim(), code: xmlHttpRequest.responseText.trim() }); return; } }; if (pContentToSend === undefined) { - xhttp.open("GET", pPath, true); - xhttp.send(); + xmlHttpRequest.open("GET", pPath, true); + xmlHttpRequest.send(); } else { try { let blob = new Blob([pContentToSend], { type: 'text/plain' }); - xhttp.open("POST", pPath, true); - xhttp.send(blob); + xmlHttpRequest.open("POST", pPath, true); + xmlHttpRequest.send(blob); } catch (err) { if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); } callBackFunction({ result: "Fail", message: err.message }) diff --git a/UI/PostLoader.js b/UI/PostLoader.js index cfb5488db..ed905d728 100644 --- a/UI/PostLoader.js +++ b/UI/PostLoader.js @@ -22,7 +22,7 @@ function newAppPostLoader() { setupProjectsSchema() function setupProjectsSchema() { - callWebServer(undefined, 'ProjectsSchema', onResponse) + httpRequest(undefined, 'ProjectsSchema', onResponse) function onResponse(err, file) { PROJECTS_SCHEMA = JSON.parse(file) @@ -52,7 +52,7 @@ function newAppPostLoader() { SCHEMAS_BY_PROJECT.set(project, schemas) totalWebServerCalls++ - callWebServer(undefined, 'Schema/' + project + '/AppSchema', onResponseAppSchema) + httpRequest(undefined, 'Schema/' + project + '/AppSchema', onResponseAppSchema) function onResponseAppSchema(err, schema) { try { @@ -72,7 +72,7 @@ function newAppPostLoader() { } totalWebServerCalls++ - callWebServer(undefined, 'Schema/' + project + '/DocSchema', onResponseDocSchema) + httpRequest(undefined, 'Schema/' + project + '/DocSchema', onResponseDocSchema) function onResponseDocSchema(err, schema) { try { @@ -92,7 +92,7 @@ function newAppPostLoader() { } totalWebServerCalls++ - callWebServer(undefined, 'Schema/' + project + '/ConceptSchema', onResponseConceptSchema) + httpRequest(undefined, 'Schema/' + project + '/ConceptSchema', onResponseConceptSchema) function onResponseConceptSchema(err, schema) { try {