Gobernance: Project Setup ready to code Spaces
This commit is contained in:
1 parent
9160dbe203
commit
ca7db1e5e6
6 files changed
+113
-310
No files matched your search
@@ -6,7 +6,6 @@ function newGovernanceActionSwitch() {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function newEthereumBlockchainSpace() {
|
||||
const MODULE_NAME = 'Blockchain Space'
|
||||
function newGobernanceAssetsSpace() {
|
||||
const MODULE_NAME = 'Assets Space'
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
@@ -13,15 +13,11 @@ function newEthereumBlockchainSpace() {
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
let lastTryToReconnectDatetime
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
clientMap = undefined
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
@@ -29,139 +25,7 @@ function newEthereumBlockchainSpace() {
|
||||
}
|
||||
|
||||
function physics() {
|
||||
networkClientStatusPhysics()
|
||||
}
|
||||
|
||||
async function networkClientStatusPhysics() {
|
||||
|
||||
/* We will query the node only every 3 seconds */
|
||||
if (lastTryToReconnectDatetime === undefined) {
|
||||
checkStatus()
|
||||
lastTryToReconnectDatetime = (new Date()).valueOf()
|
||||
} else {
|
||||
let now = (new Date()).valueOf()
|
||||
if (now - lastTryToReconnectDatetime > 3000) {
|
||||
checkStatus()
|
||||
lastTryToReconnectDatetime = now
|
||||
}
|
||||
}
|
||||
|
||||
async function checkStatus() {
|
||||
try {
|
||||
if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return }
|
||||
|
||||
let blockchain = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadByNodeType('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]
|
||||
|
||||
let route = UI.projects.ethereum.utilities.routeToClient.buildRouteToClient(networkClient)
|
||||
|
||||
if (route === undefined) { continue } // something went wrong building the route.
|
||||
|
||||
route.params.method = 'getNetworkClientStatus'
|
||||
|
||||
httpRequest(JSON.stringify(route.params), route.url, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
|
||||
return
|
||||
}
|
||||
|
||||
let status = JSON.parse(data)
|
||||
|
||||
/* Lets check the result of the method call */
|
||||
if (status.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + status.error)
|
||||
return
|
||||
}
|
||||
|
||||
showStatus(status)
|
||||
}
|
||||
|
||||
async function showStatus(status) {
|
||||
const ANNIMATION_CYCLES_TO_LAST = 300
|
||||
|
||||
networkClient.payload.uiObject.resetErrorMessage()
|
||||
|
||||
if (status.isSyncing === false && status.chainId === 0) {
|
||||
networkClient.payload.uiObject.setStatus('Client is looking for peers...', ANNIMATION_CYCLES_TO_LAST)
|
||||
return
|
||||
}
|
||||
|
||||
if (status.chainId > 0) {
|
||||
let networkName = UI.projects.ethereum.globals.chainIds.chainNameById(status.chainId)
|
||||
networkClient.payload.uiObject.setStatus('Connected to ' + networkName + ' via the ' + route.params.interface + ' 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
|
||||
}
|
||||
|
||||
/* If it is not syncing, then we have the current block and the highets block too */
|
||||
let percentage = (status.isSyncing.currentBlock * 100 / status.isSyncing.highestBlock).toFixed(4)
|
||||
let extraStatus = ''
|
||||
if (status.isSyncing.highestBlock - status.isSyncing.currentBlock < 300) {
|
||||
extraStatus = 'Block Download Phase Finished. Downloading Trie Data Structure.'
|
||||
} else {
|
||||
extraStatus = 'Block Download Phase.'
|
||||
networkClient.payload.uiObject.setPercentage(percentage, ANNIMATION_CYCLES_TO_LAST)
|
||||
}
|
||||
|
||||
networkClient.payload.uiObject.valueAtAngle = false
|
||||
networkClient.payload.uiObject.setValue(
|
||||
'Block ' + splitLargeNumber(status.isSyncing.currentBlock) +
|
||||
' from ' + splitLargeNumber(status.isSyncing.highestBlock) +
|
||||
'. State ' + splitLargeNumber(status.isSyncing.pulledStates) +
|
||||
' from ' + splitLargeNumber(status.isSyncing.knownStates)
|
||||
, 200)
|
||||
|
||||
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()
|
||||
let result = label
|
||||
switch (label.length) {
|
||||
case 4: {
|
||||
return label[0] + ',' + label[1] + label[2] + label[3]
|
||||
}
|
||||
case 5: {
|
||||
return label[0] + label[1] + ',' + label[2] + label[3] + label[4]
|
||||
}
|
||||
case 6: {
|
||||
return label[0] + label[1] + label[2] + ',' + label[3] + label[4] + label[5]
|
||||
}
|
||||
case 7: {
|
||||
return label[0] + ',' + label[1] + label[2] + label[3] + ',' + label[4] + label[5] + label[6]
|
||||
}
|
||||
case 8: {
|
||||
return label[0] + label[1] + ',' + label[2] + label[3] + label[4] + ',' + label[5] + label[6] + label[7]
|
||||
}
|
||||
case 9: {
|
||||
return label[0] + label[1] + label[2] + ',' + label[3] + label[4] + label[5] + ',' + label[6] + label[7] + label[8]
|
||||
}
|
||||
case 10: {
|
||||
return label[0] + ',' + label[1] + label[2] + label[3] + ',' + label[4] + label[5] + label[6] + ',' + label[7] + label[8] + label[9]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[ERROR] checkStatus -> err = ' + err.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
function newGovernanceRankingSpace() {
|
||||
const MODULE_NAME = 'Ranking Space'
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
finalize: finalize,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
let lastTryToReconnectDatetime
|
||||
|
||||
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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
function newGovernanceUserContributionsSpace() {
|
||||
const MODULE_NAME = 'User Contributions 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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
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)
|
||||
|
||||
let lastTryToReconnectDatetime
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
|
||||
}
|
||||
|
||||
function physics() {
|
||||
walletBalancesPhysics()
|
||||
}
|
||||
|
||||
async function walletBalancesPhysics() {
|
||||
|
||||
/* We will query the node only every 3 seconds */
|
||||
if (lastTryToReconnectDatetime === undefined) {
|
||||
checkBalances()
|
||||
lastTryToReconnectDatetime = (new Date()).valueOf()
|
||||
} else {
|
||||
let now = (new Date()).valueOf()
|
||||
if (now - lastTryToReconnectDatetime > 3000) {
|
||||
checkBalances()
|
||||
lastTryToReconnectDatetime = now
|
||||
}
|
||||
}
|
||||
|
||||
async function checkBalances() {
|
||||
try {
|
||||
if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return }
|
||||
|
||||
let wallets = []
|
||||
let hierarchyHeads = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeads()
|
||||
for (let i = 0; i < hierarchyHeads.length; i++) {
|
||||
let hierarchyHead = hierarchyHeads[i]
|
||||
if (hierarchyHead.type === 'Ethereum Wallet') {
|
||||
wallets.push(hierarchyHead)
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < wallets.length; i++) {
|
||||
let wallet = wallets[i]
|
||||
|
||||
if (wallet.networkClientReference === undefined) {
|
||||
wallet.payload.uiObject.setWarningMessage('A Network Client Reference is needed in order to fetch Account Balances from a Network Client.')
|
||||
continue
|
||||
}
|
||||
|
||||
if (wallet.networkClientReference.payload === undefined) {
|
||||
// node exists without payload, probably has been deleted.
|
||||
continue
|
||||
}
|
||||
|
||||
if (wallet.networkClientReference.payload.referenceParent === undefined) {
|
||||
wallet.networkClientReference.payload.uiObject.setWarningMessage('A reference to a Network Client is needed in order to fetch Account Balances from a Network Client.')
|
||||
continue
|
||||
}
|
||||
|
||||
let networkClient = wallet.networkClientReference.payload.referenceParent
|
||||
|
||||
let route = UI.projects.ethereum.utilities.routeToClient.buildRouteToClient(networkClient)
|
||||
|
||||
if (route === undefined) { continue } // something went wrong building the route.
|
||||
|
||||
route.params.method = 'getWalletBalances'
|
||||
|
||||
let lightingPath = '' +
|
||||
'Ethereum Wallet->' +
|
||||
'Wallet Account->' +
|
||||
'ETH Balance->' +
|
||||
'Token Balance->' +
|
||||
'Ethereum Token->Smart Contract->' +
|
||||
'ERC-20 Token Type->ERC-223 Token Type->ERC-721 Token Type->ERC-777 Token Type->'
|
||||
|
||||
route.params.walletDefinition = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(wallet, false, true, true, false, false, lightingPath)
|
||||
|
||||
httpRequest(JSON.stringify(route.params), route.url, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
|
||||
return
|
||||
}
|
||||
|
||||
let response = JSON.parse(data)
|
||||
|
||||
/* Lets check the result of the method call */
|
||||
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
networkClient.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
|
||||
return
|
||||
}
|
||||
|
||||
showBalances(response.walletDefinition)
|
||||
}
|
||||
|
||||
function showBalances(walletDefinition) {
|
||||
for (let i = 0; i < walletDefinition.walletAccounts.length; i++) {
|
||||
let walletAccount = walletDefinition.walletAccounts[i]
|
||||
|
||||
if (walletAccount.ethBalance !== undefined) {
|
||||
|
||||
let uiObject = wallet.walletAccounts[i].ethBalance.payload.uiObject
|
||||
|
||||
if (walletAccount.error !== undefined) {
|
||||
uiObject.setErrorMessage(walletAccount.error)
|
||||
} else {
|
||||
let value = walletAccount.ethBalance.value / 1000000000000000000
|
||||
uiObject.valueAtAngle = false
|
||||
uiObject.setValue(value + ' ETH')
|
||||
}
|
||||
}
|
||||
|
||||
for (let j = 0; j < walletAccount.tokenBalances.length; j++) {
|
||||
let tokenBalance = walletAccount.tokenBalances[j]
|
||||
let uiObject = wallet.walletAccounts[i].tokenBalances[j].payload.uiObject
|
||||
let value = tokenBalance.value / 1000000000000000000
|
||||
uiObject.valueAtAngle = false
|
||||
uiObject.setValue(value + ' ' + tokenBalance.referenceParent.config.codeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[ERROR] checkBalances -> 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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1010,10 +1010,10 @@
|
||||
],
|
||||
"spaces": [
|
||||
{
|
||||
"name": "Blockchain Space",
|
||||
"folderName": "Blockchain-Space",
|
||||
"propertyName": "blockchainSpace",
|
||||
"functionName": "newEthereumBlockchainSpace",
|
||||
"name": "Assets Space",
|
||||
"folderName": "Assets-Space",
|
||||
"propertyName": "assetsSpace",
|
||||
"functionName": "newGobernanceAssetsSpace",
|
||||
"initializationIndex": 0,
|
||||
"animationPhysicsIndex": 0,
|
||||
"animationDrawIndex": 0,
|
||||
@@ -1023,10 +1023,10 @@
|
||||
"onMouseDownIndex": 0
|
||||
},
|
||||
{
|
||||
"name": "Wallet Space",
|
||||
"folderName": "Wallet-Space",
|
||||
"propertyName": "walletSpace",
|
||||
"functionName": "newEthereumWalletSpace",
|
||||
"name": "Ranking Space",
|
||||
"folderName": "Ranking-Space",
|
||||
"propertyName": "rankingSpace",
|
||||
"functionName": "newGovernanceRankingSpace",
|
||||
"initializationIndex": 1,
|
||||
"animationPhysicsIndex": 1,
|
||||
"animationDrawIndex": 1,
|
||||
@@ -1034,6 +1034,19 @@
|
||||
"onMouseOverIndex": 1,
|
||||
"onMouseClickIndex": 1,
|
||||
"onMouseDownIndex": 1
|
||||
},
|
||||
{
|
||||
"name": "User Contributions Space",
|
||||
"folderName": "User-Contributions-Space",
|
||||
"propertyName": "userContributionsSpace",
|
||||
"functionName": "newGovernanceUserContributionsSpace",
|
||||
"initializationIndex": 2,
|
||||
"animationPhysicsIndex": 2,
|
||||
"animationDrawIndex": 2,
|
||||
"onMouseWheelIndex": 2,
|
||||
"onMouseOverIndex": 2,
|
||||
"onMouseClickIndex": 2,
|
||||
"onMouseDownIndex": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user