Ethereum Blockchain fully Sync status recognized

This commit is contained in:
Luis Fernando Molina committed 2020-11-17 13:58:13 +01:00
1 parent dff8fc1e18
commit 9bf8c2eed6
16 files changed
+59 -40

No files matched your search

+1
View File
@@ -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
}
+1 -1
View File
@@ -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 {
@@ -8,7 +8,7 @@ function newGeth() {
return thisObject
function install(node) {
callWebServer('ExecuteTerminalCommand/dir')
httpRequest('ExecuteTerminalCommand/dir')
}
function run(node) {
@@ -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()
@@ -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) {
@@ -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)
@@ -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) {
@@ -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) {
@@ -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)
@@ -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) {
@@ -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)
@@ -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) {
+4 -4
View File
@@ -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 = []
+4 -4
View File
@@ -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 {
+10 -10
View File
@@ -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 })
+4 -4
View File
@@ -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 {