Beta 7, again, with ETH Node connectivity

This commit is contained in:
Luis Fernando Molina committed 2020-11-13 19:13:27 +01:00
1 parent 04f20402fa
commit 6969542ed6
15 files changed
+359 -14

No files matched your search

@@ -0,0 +1,18 @@
function newEthereumGlobalsChainIds() {
thisObject = {
chainNameById: chainNameById
}
return thisObject
function chainNameById(chainId) {
switch(chainId) {
case 1: return 'Ethereum Mainnet'
case 3: return 'Ethereum Ropsten'
case 4: return 'Ethereum Rinkeby'
case 42: return 'Ethereum Kovan'
case 61: return 'Ethereum Classic Mainnet'
case 62: return 'Ethereum Classic Morden'
default: return 'Unknown Network'
}
}
}
Whitespace-only changes.
@@ -46,6 +46,14 @@
{
"type": "Ethereum Wallet",
"menuItems": [
{
"action": "Add UI Object",
"label": "Add Network Reference",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "networkReference",
"relatedUiObject": "Network Reference",
"actionFunction": "payload.executeAction"
},
{
"action": "Add UI Object",
"label": "Add Wallet Keys",
@@ -74,6 +82,12 @@
"addLeftIcons": true,
"level": 0,
"properties": [
{
"name": "networkReference",
"type": "node",
"childType": "Network Reference",
"autoAdd": true
},
{
"name": "walletKeys",
"type": "node",
@@ -88,6 +102,33 @@
],
"icon": "ethereum"
},
{
"type": "Network Reference",
"menuItems": [
{
"action": "Delete UI Object",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete",
"iconPathOff": "delete",
"actionFunction": "payload.executeAction"
}
],
"title": [
"Use Reference Parent"
],
"referenceAttachesTo": {
"compatibleTypes": "->Blockchain Network->"
},
"addLeftIcons": true,
"level": 3,
"chainAttachesTo": {
"compatibleTypes": "->Ethereum Wallet->"
},
"propertyNameAtParent": "networkReference",
"icon": "ethereum"
},
{
"type": "Wallet Keys",
"menuItems": [
@@ -563,7 +604,7 @@
"config": true
},
"initialValues": {
"config": "{ \n\"host\": \"localhost\", \n\"webSocketsPort\": \"8545\"\n}"
"config": "{ \n\"host\": \"localhost\", \n\"httpPort\": \"8545\"\n}"
},
"addLeftIcons": true,
"level": 1,
@@ -0,0 +1,150 @@
function newEthereumBlockchainSpace() {
const MODULE_NAME = 'Blockchain Space'
let thisObject = {
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
let clientMap = new Map()
let lastTryToReconnectDatetime
return thisObject
function finalize() {
thisObject.container.finalize()
thisObject.container = undefined
clientMap = undefined
}
function initialize() {
}
function physics() {
/* We will query the node only every 3 seconds */
if (lastTryToReconnectDatetime === undefined) {
connectingPhysics()
lastTryToReconnectDatetime = (new Date()).valueOf()
} else {
let now = (new Date()).valueOf()
if (now - lastTryToReconnectDatetime > 3000) {
connectingPhysics()
lastTryToReconnectDatetime = now
}
}
}
async function connectingPhysics() {
try {
if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return }
let blockchain = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByType('Ethereum Blockchain')
if (blockchain === undefined) { return }
for (let i = 0; i < blockchain.blockchainNetworks.length; i++) {
let blockchainNetwork = blockchain.blockchainNetworks[i]
for (let j = 0; j < blockchainNetwork.networkClients.length; j++) {
let networkClient = blockchainNetwork.networkClients[j]
/*
We will check now if this network client is already at the networkClientsMap,
if not, we will add it and stablish the connection to the ethereum node.
*/
let client = clientMap.get(networkClient.id)
if (client === undefined) {
client = {}
let config = JSON.parse(networkClient.config)
if (config.host === undefined) {
networkClient.payload.uiObject.setErrorMessage('Property host not defined at node config.')
continue
}
if (config.httpPort === undefined) {
networkClient.payload.uiObject.setErrorMessage('Property httpPort not defined at node config.')
continue
}
try {
client.web3 = new window.Web3('http://' + config.host + ':' + config.httpPort + '');
if (client.web3.currentProvider.currentProvider === false) {
networkClient.payload.uiObject.setErrorMessage('Can not connect to this client.')
return
}
client.chainId = await client.web3.eth.getChainId()
clientMap.set(networkClient.id, client)
setStatus()
} catch (err) {
networkClient.payload.uiObject.setErrorMessage('Error connecting to this client: ' + err.message)
}
} else {
setStatus()
}
async function setStatus() {
networkClient.payload.uiObject.resetErrorMessage()
try {
client.isSyncing = await client.web3.eth.isSyncing()
client.chainId = await client.web3.eth.getChainId()
} catch {
networkClient.payload.uiObject.resetStatus()
networkClient.payload.uiObject.setErrorMessage('Connection to client lost.')
clientMap.delete(networkClient.id)
return
}
client.networkName = UI.projects.ethereum.globals.chainIds.chainNameById(client.chainId)
if (client.isSyncing === false) {
networkClient.payload.uiObject.setStatus('Client is looking for peers...')
return
}
/* If it is not syncing, then we have the current block and the highets block too */
let percentage = (client.isSyncing.currentBlock * 100 / client.isSyncing.highestBlock).toFixed(4)
let extraStatus = ''
if (client.isSyncing.highestBlock - client.isSyncing.currentBlock < 100) {
extraStatus = 'Block Download Finished. Downloading Trie Data Structure.'
} else {
extraStatus = 'Block Download Phase.'
networkClient.payload.uiObject.setPercentage(percentage)
}
networkClient.payload.uiObject.valueAtAngle = false
networkClient.payload.uiObject.setValue('Block ' + client.isSyncing.currentBlock + ' from ' + client.isSyncing.highestBlock + '. State ' + client.isSyncing.pulledStates + ' from ' + client.isSyncing.knownStates)
if (client.isSyncing.currentBlock !== client.isSyncing.highestBlock) {
networkClient.payload.uiObject.setStatus('Connected via http. Client is Syncing... ' + extraStatus)
} else {
networkClient.payload.uiObject.setStatus('Connected to ' + client.networkName + ' via http. ')
}
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] physics -> err = ' + err.stack) }
}
}
function getContainer(point) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
thisObject.container.space = MODULE_NAME
return thisObject.container
} else {
return undefined
}
}
function draw() {
}
}
Whitespace-only changes.
@@ -0,0 +1,45 @@
function newEthereumWalletSpace() {
const MODULE_NAME = 'Wallet Space'
let thisObject = {
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
return thisObject
function finalize() {
thisObject.container.finalize()
thisObject.container = undefined
}
function initialize() {
}
function physics() {
}
function getContainer(point) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
thisObject.container.space = MODULE_NAME
return thisObject.container
} else {
return undefined
}
}
function draw() {
}
}
+35 -1
View File
@@ -219,6 +219,40 @@
{
"name": "Ethereum",
"propertyName": "ethereum",
"spaces": []
"globals": [
{
"name": "ChainIds",
"propertyName": "chainIds",
"functionName": "newEthereumGlobalsChainIds"
}
],
"spaces": [
{
"name": "Blockchain Space",
"folderName": "Blockchain-Space",
"propertyName": "blockchainSpace",
"functionName": "newEthereumBlockchainSpace",
"initializationIndex": 0,
"animationPhysicsIndex": 0,
"animationDrawIndex": 0,
"onMouseWheelIndex": 0,
"onMouseOverIndex": 0,
"onMouseClickIndex": 0,
"onMouseDownIndex": 0
},
{
"name": "Wallet Space",
"folderName": "Wallet-Space",
"propertyName": "walletSpace",
"functionName": "newEthereumWalletSpace",
"initializationIndex": 1,
"animationPhysicsIndex": 1,
"animationDrawIndex": 1,
"onMouseWheelIndex": 1,
"onMouseOverIndex": 1,
"onMouseClickIndex": 1,
"onMouseDownIndex": 1
}
]
}
]
@@ -72,7 +72,7 @@ function newCircularProgressBar() {
thisObject.payload.uiObject.setValue(message.event.processingDate, 2000)
}
if (message.event.percentage !== undefined) {
thisObject.payload.uiObject.setPercentage(message.event.percentage, 2000)
thisObject.payload.uiObject.setPercentage(message.event.percentage.toFixed(0), 2000)
}
if (message.event.status !== undefined) {
needToDrawRing = false
@@ -1835,7 +1835,7 @@ function newUiObject() {
if (radius > 6) {
const MAX_LABEL_LENGTH = 65
label = Number(currentPercentage).toFixed(0) + '%'
label = Number(currentPercentage) + '%'
if (label.length > MAX_LABEL_LENGTH) {
label = label.substring(0, MAX_LABEL_LENGTH) + '...'