Merge branch 'develop' of https://github.com/Superalgos/Superalgos into develop

This commit is contained in:
Julian Molina committed 2021-09-03 12:59:19 +02:00
commit 91d4d395ea
36 files changed
+649 -326

No files matched your search

+32 -5
View File
@@ -7,15 +7,42 @@ exports.newDesktopApp = function newDesktopApp() {
return thisObject
async function run() {
/*
let socialGraphService = NT.projects.network.modules.socialGraph.newSocialGraph()
await socialGraphService.initialize()
*/
/*
let socialGraphService = NT.projects.network.modules.socialGraph.newSocialGraph()
await socialGraphService.initialize()
*/
/*
Let's start the Network Interfaces
*/
DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient()
DK.webSocketsClient.initialize()
await DK.webSocketsClient.initialize()
let queryMessage = {
equeryId: "123",
queryType: 0,
emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID,
initialIndex: 'Last',
amountRequested: 10,
direction: 'Past'
}
let query = {
requestType: 'Query',
queryMessage : JSON.stringify(queryMessage )
}
await DK.webSocketsClient.sendMessage(
JSON.stringify(query)
)
.then(showProfiles)
.catch(onError)
function showProfiles(profiles){
console.log(profiles)
}
function onError(errorMessage) {
console.log('[ERROR] Query not executed. ' + errorMessage)
}
}
}
@@ -1 +1 @@
{"type":"Data Mine","name":"Delta","config":"{\n \"codeName\": \"Delta\"\n}","project":"Foundations","sensorBots":[],"indicatorBots":[{"type":"Indicator Bot","name":"Relative Strenght Index - Wilder Method (RSI-W)","config":"{\n \"codeName\": \"RSI-W\"\n}","project":"Foundations","processes":[{"type":"Process Definition","name":"Multi-Time-Frame-Market","config":"{\n \"codeName\": \"Multi-Time-Frame-Market\",\n \"description\": \"Calculates Wilder RSI.\",\n \"deadWaitTime\": 0,\n \"normalWaitTime\": 0,\n \"retryWaitTime\": 10000,\n \"sleepWaitTime\": 3600000,\n \"comaWaitTime\": 86400000,\n \"framework\": {\n \"name\": \"Multi-Time-Frame-Market\"\n }\n}","project":"Foundations","processOutput":{"type":"Process Output","name":"New Process Output","project":"Foundations","outputDatasets":[{"type":"Output Dataset","name":"Multi-Time-Frame-Market RSI-W14","project":"Foundations","id":"75881553-ec60-4954-9404-052ba11904f4","savedPayload":{"position":{"x":19646.18251638588,"y":17789.2053813897},"targetPosition":{"x":19675.299658959913,"y":17897.87203684722},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Dataset Definition","name":"Multi-Time-Frame-Market","id":"a94722c3-a453-4f46-931f-aeb244e7cb66"}}}],"outputDatasetFolders":[],"id":"ffb59a7e-565a-4588-bd44-999a7cb66122","savedPayload":{"position":{"x":19675.299658959913,"y":17897.87203684722},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":1,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"processDependencies":{"type":"Process Dependencies","name":"New Process Dependencies","project":"Foundations","statusDependencies":[{"type":"Status Dependency","name":"Candles Volumes Multi-Time-Frame-Market","config":"{\n \"mainUtility\": \"Market Ending Point\"\n}","project":"Foundations","id":"b0af9801-ba4e-4bfd-a605-98d9ac121b5f","savedPayload":{"position":{"x":19650.151086682014,"y":17594.3496655382},"targetPosition":{"x":19762.651086682014,"y":17789.2053813897},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Status Report","name":"New Status Report","id":"a0a61ba9-91cb-4ec7-92fe-134ff079de2d"}}},{"type":"Status Dependency","name":"Relative Strenght Index - Wilder Method (RSI-W) Multi-Time-Frame-Market","config":"{\n \"mainUtility\": \"Self Reference\"\n}","project":"Foundations","id":"02d64b4a-7c3c-4c89-918d-b3697b5955b2","savedPayload":{"position":{"x":19820.88537183008,"y":17571.87207047466},"targetPosition":{"x":19762.651086682014,"y":17789.2053813897},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Status Report","name":"New Status Report","id":"2b961dac-9f41-4eed-a495-4e55f26714c3"}}}],"dataDependencies":[{"type":"Data Dependency","name":"Candles Multi-Time-Frame-Market","project":"Foundations","id":"25315413-2e01-4a7d-83bc-1257d43f8fe6","savedPayload":{"position":{"x":19957.506802533513,"y":17676.7053813897},"targetPosition":{"x":19762.651086682014,"y":17789.2053813897},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Dataset Definition","name":"Multi-Time-Frame-Market","id":"2b03494a-67d6-47f1-89b6-53fc4c9116a8"}}}],"dataMineDataDependencies":[],"id":"b14516a1-e5cc-48f8-ab0f-0e46faf6c41c","savedPayload":{"position":{"x":19762.651086682014,"y":17789.2053813897},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":2,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"statusReport":{"type":"Status Report","name":"New Status Report","project":"Foundations","id":"2b961dac-9f41-4eed-a495-4e55f26714c3","savedPayload":{"position":{"x":19863.51582730092,"y":17847.439666537768},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":2,"arrangementStyle":0},"uiObject":{}}},"executionStartedEvent":{"type":"Execution Started Event","name":"Candles Volumes Multi-Time-Frame-Market","project":"Foundations","id":"c1598823-e0b3-4036-8ad6-669ae0e3f638","savedPayload":{"position":{"x":19921.750112448986,"y":17948.304407156673},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":2,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Execution FinisheLine truncated
{"type":"Data Mine","name":"Delta","config":"{\n \"codeName\": \"Delta\"\n}","project":"Foundations","sensorBots":[],"indicatorBots":[{"type":"Indicator Bot","name":"Relative Strength Index - Wilder Method (RSI-W)","config":"{\n \"codeName\": \"RSI-W\"\n}","project":"Foundations","processes":[{"type":"Process Definition","name":"Multi-Time-Frame-Market","config":"{\n \"codeName\": \"Multi-Time-Frame-Market\",\n \"description\": \"Calculates Wilder RSI.\",\n \"deadWaitTime\": 0,\n \"normalWaitTime\": 0,\n \"retryWaitTime\": 10000,\n \"sleepWaitTime\": 3600000,\n \"comaWaitTime\": 86400000,\n \"framework\": {\n \"name\": \"Multi-Time-Frame-Market\"\n }\n}","project":"Foundations","processOutput":{"type":"Process Output","name":"New Process Output","project":"Foundations","outputDatasets":[{"type":"Output Dataset","name":"Multi-Time-Frame-Market RSI-W14","project":"Foundations","id":"75881553-ec60-4954-9404-052ba11904f4","savedPayload":{"position":{"x":19646.18251638588,"y":17789.2053813897},"targetPosition":{"x":19675.299658959913,"y":17897.87203684722},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Dataset Definition","name":"Multi-Time-Frame-Market","id":"a94722c3-a453-4f46-931f-aeb244e7cb66"}}}],"outputDatasetFolders":[],"id":"ffb59a7e-565a-4588-bd44-999a7cb66122","savedPayload":{"position":{"x":19675.299658959913,"y":17897.87203684722},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":1,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"processDependencies":{"type":"Process Dependencies","name":"New Process Dependencies","project":"Foundations","statusDependencies":[{"type":"Status Dependency","name":"Candles Volumes Multi-Time-Frame-Market","config":"{\n \"mainUtility\": \"Market Ending Point\"\n}","project":"Foundations","id":"b0af9801-ba4e-4bfd-a605-98d9ac121b5f","savedPayload":{"position":{"x":19650.151086682014,"y":17594.3496655382},"targetPosition":{"x":19762.651086682014,"y":17789.2053813897},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Status Report","name":"New Status Report","id":"a0a61ba9-91cb-4ec7-92fe-134ff079de2d"}}},{"type":"Status Dependency","name":"Relative Strength Index - Wilder Method (RSI-W) Multi-Time-Frame-Market","config":"{\n \"mainUtility\": \"Self Reference\"\n}","project":"Foundations","id":"02d64b4a-7c3c-4c89-918d-b3697b5955b2","savedPayload":{"position":{"x":19820.88537183008,"y":17571.87207047466},"targetPosition":{"x":19762.651086682014,"y":17789.2053813897},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Status Report","name":"New Status Report","id":"2b961dac-9f41-4eed-a495-4e55f26714c3"}}}],"dataDependencies":[{"type":"Data Dependency","name":"Candles Multi-Time-Frame-Market","project":"Foundations","id":"25315413-2e01-4a7d-83bc-1257d43f8fe6","savedPayload":{"position":{"x":19957.506802533513,"y":17676.7053813897},"targetPosition":{"x":19762.651086682014,"y":17789.2053813897},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Dataset Definition","name":"Multi-Time-Frame-Market","id":"2b03494a-67d6-47f1-89b6-53fc4c9116a8"}}}],"dataMineDataDependencies":[],"id":"b14516a1-e5cc-48f8-ab0f-0e46faf6c41c","savedPayload":{"position":{"x":19762.651086682014,"y":17789.2053813897},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":2,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"statusReport":{"type":"Status Report","name":"New Status Report","project":"Foundations","id":"2b961dac-9f41-4eed-a495-4e55f26714c3","savedPayload":{"position":{"x":19863.51582730092,"y":17847.439666537768},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":2,"arrangementStyle":0},"uiObject":{}}},"executionStartedEvent":{"type":"Execution Started Event","name":"Candles Volumes Multi-Time-Frame-Market","project":"Foundations","id":"c1598823-e0b3-4036-8ad6-669ae0e3f638","savedPayload":{"position":{"x":19921.750112448986,"y":17948.304407156673},"targetPosition":{"x":19704.416801533946,"y":18006.53869230474},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":2,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Execution FinisheLine truncated
@@ -3,7 +3,7 @@
"pageNumber": 1,
"type": "Sparta By @julian-molina",
"definition": {
"text": "The set of indicators built in the Sparta data mine include Simple Moving Average (SMA), Exponential Moving Averege (EMA), Relative Strenght Index (RSI), and Moving Average convergence Divergence (MACD).",
"text": "The set of indicators built in the Sparta data mine include Simple Moving Average (SMA), Exponential Moving Averege (EMA), Relative Strength Index (RSI), and Moving Average convergence Divergence (MACD).",
"updated": 1611685345604
},
"paragraphs": [
@@ -22,4 +22,4 @@
"text": "Collaborate with this data mine and report issues directly at the Superalgos repository."
}
]
}
}
@@ -1,9 +1,9 @@
{
"topic": "Sparta Data Mine",
"pageNumber": 4,
"type": "Relative Strenght Index (RSI) - Sparta Indicator",
"type": "Relative Strength Index (RSI) - Sparta Indicator",
"definition": {
"text": "The indicator produces the standard 14 setting of the Relative Strenght Index.",
"text": "The indicator produces the standard 14 setting of the Relative Strength Index.",
"updated": 1611662214310
},
"paragraphs": [
@@ -59,4 +59,4 @@
"text": "How’s the trend going at the 24-hours chart?"
}
]
}
}
@@ -186,7 +186,9 @@ function newFoundationsChartingSpace() {
}
function resize() {
thisObject.viewport.resize()
if (thisObject.viewport !== undefined) {
thisObject.viewport.resize()
}
thisObject.container.frame.width = browserCanvas.width
thisObject.container.frame.height = COCKPIT_SPACE_POSITION
}
@@ -106,8 +106,13 @@ function newGovernanceFunctionLibraryAirdropProgram() {
userProfile.payload.blockchainTokens === undefined
) {
node.payload.airdropProgram.isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.")
userProfile.payload.uiObject.setErrorMessage(
"Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
} else {
userProfile.payload.uiObject.resetErrorMessage()
}
/*
Next thing to do is to validate if the airdrop user profile has a star at the Superalgos repository.
@@ -117,7 +122,10 @@ function newGovernanceFunctionLibraryAirdropProgram() {
profileSignature === undefined
) {
node.payload.airdropProgram.isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, and produce a signature of your Airdrop Username.")
userProfile.payload.uiObject.setErrorMessage(
"You need to setup this profile with the Profile Constructor, and produce a signature of your Airdrop Username.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
@@ -154,7 +162,10 @@ function newGovernanceFunctionLibraryAirdropProgram() {
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) {
programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.")
programNode.payload.uiObject.setErrorMessage(
"Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
programNode.payload.airdropProgram.awarded.tokens = programNode.payload.airdropProgram.ownPower / totalPowerRewardRatio
@@ -170,7 +181,7 @@ function newGovernanceFunctionLibraryAirdropProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Airdrop Power')
node.payload.uiObject.setStatus(ownPowerText + ' Airdrop Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
@@ -180,12 +191,12 @@ function newGovernanceFunctionLibraryAirdropProgram() {
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
node.tokensAwarded.payload.uiObject.valueAtAngle = false
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC)
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.tokensAwarded.payload.uiObject.statusAngleOffset = 0
node.tokensAwarded.payload.uiObject.statusAtAngle = false
node.tokensAwarded.payload.uiObject.setStatus('For creating your Superalgos profile!')
node.tokensAwarded.payload.uiObject.setStatus('For creating your Superalgos profile!', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -12,10 +12,16 @@ function newGovernanceFunctionLibraryAssets() {
let folderPath = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'folderPath')
if (folderPath === undefined || folderPath === "") {
node.payload.uiObject.setErrorMessage("folderPath Config Property undefined.")
node.payload.uiObject.setErrorMessage(
"folderPath Config Property undefined.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
node.payload.uiObject.setInfoMessage("Hold on while we install all the assets inside the this path: " + folderPath + ". This might take a minute or two.")
node.payload.uiObject.setInfoMessage(
"Hold on while we install all the assets inside the this path: " + folderPath + ". This might take a minute or two.",
UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR
)
httpRequest(undefined, 'DirContent' + '/' + folderPath, onResponse)
function onResponse(err, data) {
@@ -32,7 +38,10 @@ function newGovernanceFunctionLibraryAssets() {
totalAssets++
createNodesFromPath(node, foldersArray)
}
node.payload.uiObject.setInfoMessage("A total of : " + totalAssets + " assets have been installed.")
node.payload.uiObject.setInfoMessage(
"A total of : " + totalAssets + " assets have been installed.",
UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR
)
}
function removeFirstFromArray(array) {
@@ -350,7 +350,10 @@ function newGovernanceFunctionLibraryClaimsProgram() {
}
}
if (totalPercentage > 100) {
node.payload.uiObject.setErrorMessage('Claim Power Switching Error. Total Percentage of children nodes is grater that 100.')
node.payload.uiObject.setErrorMessage(
'Claim Power Switching Error. Total Percentage of children nodes is grater that 100.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
let defaultPercentage = 0
@@ -446,7 +449,7 @@ function newGovernanceFunctionLibraryClaimsProgram() {
'Shared Between: ' + node.payload.claimsProgram.share.count + ' claims' + ' - ' +
'Share of Claims: ' + node.payload.claimsProgram.share.percentage.toFixed(2) + '%'
node.payload.uiObject.setStatus(status)
node.payload.uiObject.setStatus(status, UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
function drawProgram(node) {
@@ -457,7 +460,7 @@ function newGovernanceFunctionLibraryClaimsProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Claim Power')
node.payload.uiObject.setStatus(ownPowerText + ' Claim Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
@@ -472,8 +475,8 @@ function newGovernanceFunctionLibraryClaimsProgram() {
node.tokensAwarded.payload.uiObject.statusAngleOffset = 0
node.tokensAwarded.payload.uiObject.statusAtAngle = true
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC)
node.tokensAwarded.payload.uiObject.setStatus('From ' + node.payload.claimsProgram.count + ' Claims.')
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.tokensAwarded.payload.uiObject.setStatus('From ' + node.payload.claimsProgram.count + ' Claims.', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
@@ -486,10 +489,12 @@ function newGovernanceFunctionLibraryClaimsProgram() {
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
node.payload.uiObject.setValue(programPowerText)
node.payload.uiObject.setValue(programPowerText, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
if (percentage !== undefined) {
node.payload.uiObject.setPercentage(percentage.toFixed(2))
node.payload.uiObject.setPercentage(percentage.toFixed(2),
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
}
}
}
@@ -498,7 +503,10 @@ function newGovernanceFunctionLibraryClaimsProgram() {
function installMissingClaims(node, rootNodes) {
if (node.payload === undefined) { return }
if (node.payload.referenceParent === undefined) {
node.payload.uiObject.setErrorMessage('To Install Missing Claims you need a Reference Parent')
node.payload.uiObject.setErrorMessage(
'To Install Missing Claims you need a Reference Parent',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
scanNodeBranch(node, node.payload.referenceParent)
@@ -211,7 +211,10 @@ function newGovernanceFunctionLibraryDelegationProgram() {
}
}
if (totalPercentage > 100) {
node.payload.uiObject.setErrorMessage('Delegate Power Switching Error. Total Percentage of children nodes is grater that 100.')
node.payload.uiObject.setErrorMessage(
'Delegate Power Switching Error. Total Percentage of children nodes is grater that 100.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
let defaultPercentage = 0
@@ -278,7 +281,9 @@ function newGovernanceFunctionLibraryDelegationProgram() {
drawProgram(node)
if (percentage !== undefined) {
node.payload.uiObject.setPercentage(percentage.toFixed(2))
node.payload.uiObject.setPercentage(percentage.toFixed(2),
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
}
return
}
@@ -294,10 +299,12 @@ function newGovernanceFunctionLibraryDelegationProgram() {
let powerType = 'Delegate Power'
const programPowerText = parseFloat(programPower.toFixed(0)).toLocaleString('en') + ' ' + powerType
node.payload.uiObject.setValue(programPowerText)
node.payload.uiObject.setValue(programPowerText, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
if (percentage !== undefined) {
node.payload.uiObject.setPercentage(percentage.toFixed(2))
node.payload.uiObject.setPercentage(percentage.toFixed(2),
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
}
}
}
@@ -310,18 +317,20 @@ function newGovernanceFunctionLibraryDelegationProgram() {
node.payload.uiObject.valueAngleOffset = 180
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.setValue(outgoingPowerText + ' Delegate Power')
node.payload.uiObject.setValue(outgoingPowerText + ' Delegate Power', UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
node.payload.uiObject.setPercentage(percentage)
node.payload.uiObject.setPercentage(percentage,
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
if (node.payload.referenceParent !== undefined) {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = true
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power')
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -334,7 +343,7 @@ function newGovernanceFunctionLibraryDelegationProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Delegate Power')
node.payload.uiObject.setStatus(ownPowerText + ' Delegate Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -106,8 +106,13 @@ function newGovernanceFunctionLibraryGithubProgram() {
userProfile.payload.blockchainTokens === undefined
) {
node.payload.githubProgram.isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.")
userProfile.payload.uiObject.setErrorMessage(
"Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
} else {
userProfile.payload.uiObject.resetErrorMessage()
}
/*
Next thing to do is to validate if the github user profile has a star at the Superalgos repository.
@@ -117,7 +122,10 @@ function newGovernanceFunctionLibraryGithubProgram() {
profileSignature === undefined
) {
node.payload.githubProgram.isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, and produce a signature of your Github Username.")
userProfile.payload.uiObject.setErrorMessage(
"You need to setup this profile with the Profile Constructor, and produce a signature of your Github Username.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
let githubUsername = profileSignature.message
@@ -168,7 +176,10 @@ function newGovernanceFunctionLibraryGithubProgram() {
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) {
programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.")
programNode.payload.uiObject.setErrorMessage(
"Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
const MAX_ENGAGEMENT = 3
@@ -185,7 +196,7 @@ function newGovernanceFunctionLibraryGithubProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Github Power')
node.payload.uiObject.setStatus(ownPowerText + ' Github Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
@@ -195,7 +206,7 @@ function newGovernanceFunctionLibraryGithubProgram() {
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
node.tokensAwarded.payload.uiObject.valueAtAngle = false
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC)
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.tokensAwarded.payload.uiObject.statusAngleOffset = 0
node.tokensAwarded.payload.uiObject.statusAtAngle = false
@@ -211,7 +222,7 @@ function newGovernanceFunctionLibraryGithubProgram() {
extraText = extraText + ' + 1 Fork'
}
node.tokensAwarded.payload.uiObject.setStatus('From' + extraText)
node.tokensAwarded.payload.uiObject.setStatus('From' + extraText, UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -12,7 +12,10 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
let projectName = UI.projects.foundations.utilities.plugins.getProjectName(node)
if (projectName === "" || projectName === undefined) {
if (node.payload.parentNode !== undefined) {
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
node.payload.parentNode.payload.uiObject.setErrorMessage(
"Config codeName must have the name of the project.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
}
@@ -28,7 +31,10 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
let projectName = UI.projects.foundations.utilities.plugins.getProjectName(node)
if (projectName === "" || projectName === undefined) {
if (node.payload.parentNode !== undefined) {
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
node.payload.parentNode.payload.uiObject.setErrorMessage(
"Config codeName must have the name of the project.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
}
@@ -44,7 +50,10 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
let projectName = UI.projects.foundations.utilities.plugins.getProjectName(node)
if (projectName === "" || projectName === undefined) {
if (node.payload.parentNode !== undefined) {
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
node.payload.parentNode.payload.uiObject.setErrorMessage(
"Config codeName must have the name of the project.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
}
@@ -60,7 +69,10 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
let projectName = UI.projects.foundations.utilities.plugins.getProjectName(node)
if (projectName === "" || projectName === undefined) {
if (node.payload.parentNode !== undefined) {
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
node.payload.parentNode.payload.uiObject.setErrorMessage(
"Config codeName must have the name of the project.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
}
@@ -76,7 +88,10 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
let projectName = UI.projects.foundations.utilities.plugins.getProjectName(node)
if (projectName === "" || projectName === undefined) {
if (node.payload.parentNode !== undefined) {
node.payload.parentNode.payload.uiObject.setErrorMessage("Config codeName must have the name of the project.")
node.payload.parentNode.payload.uiObject.setErrorMessage(
"Config codeName must have the name of the project.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
}
@@ -16,7 +16,10 @@ function newGovernanceFunctionLibraryProfileConstructor() {
let mnemonic = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'mnemonic')
if (githubUsername === undefined || githubUsername === "") {
node.payload.uiObject.setErrorMessage("githubUsername config property missing.")
node.payload.uiObject.setErrorMessage(
"githubUsername config property missing.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
@@ -48,7 +51,10 @@ function newGovernanceFunctionLibraryProfileConstructor() {
function onResponse(err, data) {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
node.payload.uiObject.setErrorMessage(
'Call via HTTP Interface failed.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
@@ -58,11 +64,17 @@ function newGovernanceFunctionLibraryProfileConstructor() {
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
if (mnemonic === undefined || mnemonic === "") {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
node.payload.uiObject.setErrorMessage(
'Call to WEB3 Server failed. ' + response.error,
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
console.log('Call to WEB3 Server failed. ' + response.error)
return
} else {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error)
node.payload.uiObject.setErrorMessage(
'Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error,
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
console.log('Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error)
return
}
@@ -88,7 +100,10 @@ function newGovernanceFunctionLibraryProfileConstructor() {
function onResponse(err, data) {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
node.payload.uiObject.setErrorMessage(
'Call via HTTP Interface failed.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
@@ -96,7 +111,10 @@ function newGovernanceFunctionLibraryProfileConstructor() {
/* Lets check the result of the method call */
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
node.payload.uiObject.setErrorMessage(
'Call to WEB3 Server failed. ' + response.error,
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
console.log('Call to WEB3 Server failed. ' + response.error)
return
}
@@ -124,9 +142,15 @@ function newGovernanceFunctionLibraryProfileConstructor() {
Show nice message.
*/
if (mnemonic === undefined || mnemonic === "") {
node.payload.uiObject.setInfoMessage("Profile Private Key has been successfully created. User Profile installed as a plugin and saved. Use the Private Key at a crypto wallet and delete this node once done.", 10000)
node.payload.uiObject.setInfoMessage(
"Profile Private Key has been successfully created. User Profile installed as a plugin and saved. Use the Private Key at a crypto wallet and delete this node once done.",
UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR
)
} else {
node.payload.uiObject.setInfoMessage("Mnemonic successfully imported. User Profile installed as a plugin and saved. Your external wallet was sucessfully linked to your profile.", 10000)
node.payload.uiObject.setInfoMessage(
"Mnemonic successfully imported. User Profile installed as a plugin and saved. Your external wallet was sucessfully linked to your profile.",
UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR
)
}
}
}
@@ -106,10 +106,15 @@ function newGovernanceFunctionLibraryStakingProgram() {
userProfile.payload.blockchainTokens === undefined
) {
node.payload.stakingProgram.isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.")
userProfile.payload.uiObject.setErrorMessage(
"Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
} else {
userProfile.payload.uiObject.resetErrorMessage()
node.payload.stakingProgram.isActive = true
}
node.payload.stakingProgram.isActive = true
}
function distributeProgram(programNode) {
@@ -142,7 +147,10 @@ function newGovernanceFunctionLibraryStakingProgram() {
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) {
programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.")
programNode.payload.uiObject.setErrorMessage(
"Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
programNode.payload.stakingProgram.awarded.tokens = programNode.payload.stakingProgram.ownPower / totalPowerRewardRatio
@@ -158,7 +166,7 @@ function newGovernanceFunctionLibraryStakingProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Staking Power')
node.payload.uiObject.setStatus(ownPowerText + ' Staking Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
@@ -168,7 +176,7 @@ function newGovernanceFunctionLibraryStakingProgram() {
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
node.tokensAwarded.payload.uiObject.valueAtAngle = false
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC)
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
}
}
}
@@ -174,8 +174,8 @@ function newGovernanceFunctionLibraryTokenMining() {
userProfile.tokensMined.payload.uiObject.valueAngleOffset = 0
userProfile.tokensMined.payload.uiObject.valueAtAngle = true
userProfile.tokensMined.payload.uiObject.setStatus(awarded + ' Awarded + ' + bonus + ' Bonus')
userProfile.tokensMined.payload.uiObject.setValue(total + ' SA Tokens' + tokensAwardedBTC)
userProfile.tokensMined.payload.uiObject.setStatus(awarded + ' Awarded + ' + bonus + ' Bonus', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
userProfile.tokensMined.payload.uiObject.setValue(total + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
}
}
}
@@ -96,7 +96,10 @@ function newGovernanceFunctionLibraryTokenPower() {
Before we start we will do some validations:
*/
if (userProfile.tokenPowerSwitch === undefined) {
userProfile.payload.uiObject.setErrorMessage("You need to have a Token Power Switch child node.")
userProfile.payload.uiObject.setErrorMessage(
"You need to have a Token Power Switch child node.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
distributeTokenPower(
@@ -119,7 +122,10 @@ function newGovernanceFunctionLibraryTokenPower() {
Before we start we will do some validations:
*/
if (userProfile.tokenPowerSwitch === undefined) {
userProfile.payload.uiObject.setErrorMessage("You need to have a Token Power Switch child node.")
userProfile.payload.uiObject.setErrorMessage(
"You need to have a Token Power Switch child node.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
distributeTokenPower(
@@ -213,7 +219,10 @@ function newGovernanceFunctionLibraryTokenPower() {
}
}
if (totalPercentage > 100) {
node.payload.uiObject.setErrorMessage('Token Power Switching Error. Total Percentage of children nodes is grater that 100.')
node.payload.uiObject.setErrorMessage(
'Token Power Switching Error. Total Percentage of children nodes is grater that 100.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
let defaultPercentage = 0
@@ -287,7 +296,7 @@ function newGovernanceFunctionLibraryTokenPower() {
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' + ' + incomingPowerText)
node.payload.uiObject.setStatus(ownPowerText + ' + ' + incomingPowerText, UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
return
}
@@ -297,12 +306,14 @@ function newGovernanceFunctionLibraryTokenPower() {
node.payload.uiObject.valueAngleOffset = 180
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.setValue(tokenPowerText)
node.payload.uiObject.setValue(tokenPowerText, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
if (percentage !== undefined) {
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
node.payload.uiObject.setPercentage(percentage.toFixed(2))
node.payload.uiObject.setPercentage(percentage.toFixed(2),
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
}
}
}
@@ -173,7 +173,7 @@ function newGovernanceFunctionLibraryTokens() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = true
node.payload.uiObject.setStatus(status)
node.payload.uiObject.setStatus(status, UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
} else {
status = 'Reward: ' + tokens.toLocaleString('en')
+ ' ' + 'SA' + ' ≃ ' + UI.projects.governance.utilities.conversions.estimateSATokensInBTC(tokens | 0) + ' BTC '
@@ -181,7 +181,7 @@ function newGovernanceFunctionLibraryTokens() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(status)
node.payload.uiObject.setStatus(status, UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -334,7 +334,10 @@ function newGovernanceFunctionLibraryVotingProgram() {
}
}
if (totalPercentage > 100) {
node.payload.uiObject.setErrorMessage('Voting Power Switching Error. Total Percentage of children nodes is grater that 100.')
node.payload.uiObject.setErrorMessage(
'Voting Power Switching Error. Total Percentage of children nodes is grater that 100.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
let defaultPercentage = 0
@@ -406,7 +409,9 @@ function newGovernanceFunctionLibraryVotingProgram() {
drawProgram(node, userProfile)
if (percentage !== undefined) {
node.payload.uiObject.setPercentage(percentage.toFixed(2))
node.payload.uiObject.setPercentage(percentage.toFixed(2),
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
}
return
}
@@ -457,10 +462,12 @@ function newGovernanceFunctionLibraryVotingProgram() {
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.setValue(votesText)
node.payload.uiObject.setValue(votesText, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
if (percentage !== undefined) {
node.payload.uiObject.setPercentage(percentage.toFixed(2))
node.payload.uiObject.setPercentage(percentage.toFixed(2),
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
}
}
@@ -472,18 +479,20 @@ function newGovernanceFunctionLibraryVotingProgram() {
node.payload.uiObject.valueAngleOffset = 180
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.setValue(outgoingPowerText + ' Voting Power')
node.payload.uiObject.setValue(outgoingPowerText + ' Voting Power', UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
node.payload.uiObject.setPercentage(percentage)
node.payload.uiObject.setPercentage(percentage,
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
if (node.payload.referenceParent !== undefined) {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = true
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power')
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -502,7 +511,7 @@ function newGovernanceFunctionLibraryVotingProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Own Power' + ' + ' + incomingPowerText + ' Incoming Voting Power' + ' + ' + reputationPowerText + ' Reputation Power')
node.payload.uiObject.setStatus(ownPowerText + ' Own Power' + ' + ' + incomingPowerText + ' Incoming Voting Power' + ' + ' + reputationPowerText + ' Reputation Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -510,7 +519,10 @@ function newGovernanceFunctionLibraryVotingProgram() {
function installMissingVotes(node, rootNodes) {
if (node.payload === undefined) { return }
if (node.payload.referenceParent === undefined) {
node.payload.uiObject.setErrorMessage('To install votes you need a Reference Parent')
node.payload.uiObject.setErrorMessage(
'To install votes you need a Reference Parent',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
scanNodeBranch(node, node.payload.referenceParent)
@@ -0,0 +1,11 @@
function newGovernanceGlobalsDesigner() {
let thisObject = {
SET_VALUE_COUNTER: 1000,
SET_STATUS_COUNTER: 1000,
SET_ERROR_COUNTER_FACTOR: 10,
SET_INFO_COUNTER_FACTOR: 10,
SET_WARNING_COUNTER: 1000,
SET_PERCENTAGE_COUNTER: 1000
}
return thisObject
}
@@ -46,6 +46,8 @@ function newGobernanceReportsSpace() {
if (isInitialized === false) { return }
hidAppDiv()
thisObject.container.finalize()
thisObject.container = undefined
@@ -215,22 +217,38 @@ function newGobernanceReportsSpace() {
if (isInitialized === false) { return }
docsAppDivPhysics()
}
function docsAppDivPhysics() {
let docsSpaceDiv = document.getElementById('governance-reports-space-div')
docsAppDivPosition = {
x: 0,
y: 0
}
docsAppDivPosition = thisObject.container.frame.frameThisPoint(docsAppDivPosition)
docsSpaceDiv.style = ' ' +
'overflow-y: scroll;' +
'overflow-x: hidden;' +
'position:fixed; top:' + docsAppDivPosition.y + 'px; ' +
'left:' + docsAppDivPosition.x + 'px; z-index:1; ' +
'width: ' + thisObject.container.frame.width + 'px;' +
'height: ' + thisObject.container.frame.height + 'px'
function docsAppDivPhysics() {
let docsSpaceDiv = document.getElementById('governance-reports-space-div')
docsAppDivPosition = {
x: 0,
y: 0
}
docsAppDivPosition = thisObject.container.frame.frameThisPoint(docsAppDivPosition)
docsSpaceDiv.style = ' ' +
'overflow-y: scroll;' +
'overflow-x: hidden;' +
'position:fixed; top:' + docsAppDivPosition.y + 'px; ' +
'left:' + docsAppDivPosition.x + 'px; z-index:1; ' +
'width: ' + thisObject.container.frame.width + 'px;' +
'height: ' + thisObject.container.frame.height + 'px'
}
function hidAppDiv() {
let docsSpaceDiv = document.getElementById('governance-reports-space-div')
docsAppDivPosition = {
x: 100000000000,
y: 0
}
docsAppDivPosition = thisObject.container.frame.frameThisPoint(docsAppDivPosition)
docsSpaceDiv.style = ' ' +
'overflow-y: scroll;' +
'overflow-x: hidden;' +
'position:fixed; top:' + docsAppDivPosition.y + 'px; ' +
'left:' + docsAppDivPosition.x + 'px; z-index:1; ' +
'width: ' + thisObject.container.frame.width + 'px;' +
'height: ' + thisObject.container.frame.height + 'px'
}
function getContainer(point, purpose) {
@@ -365,7 +365,10 @@ function newGovernanceUserProfileSpace() {
function onResponse(err, data) {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
userProfile.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
userProfile.payload.uiObject.setErrorMessage(
'Call via HTTP Interface failed.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
@@ -373,7 +376,10 @@ function newGovernanceUserProfileSpace() {
/* Lets check the result of the method call */
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
userProfile.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
userProfile.payload.uiObject.setErrorMessage(
'Call to WEB3 Server failed. ' + response.error,
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
console.log('Call to WEB3 Server failed. ' + response.error)
return
}
@@ -403,7 +409,9 @@ function newGovernanceUserProfileSpace() {
if (data.result === "Max rate limit reached, please use API Key for higher rate limit") {
userProfile.payload.blockchainTokens = undefined // This enables this profile to query the blockchain again.
} else {
userProfile.payload.uiObject.setInfoMessage(data)
userProfile.payload.uiObject.setInfoMessage(data,
UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR
)
userProfile.payload.blockchainTokens = Number(data.result) / 1000000000000000000
userProfile.payload.reputation = Math.min(reputationByAddress.get(blockchainAccount.toLowerCase()) | 0, userProfile.payload.blockchainTokens)
}
@@ -412,7 +420,9 @@ function newGovernanceUserProfileSpace() {
const message = err.message + ' - ' + 'Can not access BSC SCAN servers.'
console.log(message)
if (userProfile.payload !== undefined) {
userProfile.payload.uiObject.setErrorMessage(message, 1000)
userProfile.payload.uiObject.setErrorMessage(message,
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
}
waitingForResponses--
});
@@ -101,8 +101,13 @@ function newGovernanceUtilitiesBonusProgram() {
userProfile.payload.blockchainTokens === undefined
) {
node.payload[programPropertyName].isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.")
userProfile.payload.uiObject.setErrorMessage(
"Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
} else {
userProfile.payload.uiObject.resetErrorMessage()
}
}
@@ -135,7 +140,10 @@ function newGovernanceUtilitiesBonusProgram() {
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
if (programNode.tokensBonus === undefined || programNode.tokensBonus.payload === undefined) {
programNode.payload.uiObject.setErrorMessage("Tokens Bonus Node is needed in order for this Program to get Tokens from the Bonus Program Pool.")
programNode.payload.uiObject.setErrorMessage(
"Tokens Bonus Node is needed in order for this Program to get Tokens from the Bonus Program Pool.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
programNode.payload[programPropertyName].bonus.tokens = programNode.payload[programPropertyName].bonusPower / totalPowerRewardRatio
@@ -152,7 +160,7 @@ function newGovernanceUtilitiesBonusProgram() {
node.tokensBonus.payload.uiObject.valueAngleOffset = 0
node.tokensBonus.payload.uiObject.valueAtAngle = true
node.tokensBonus.payload.uiObject.setValue(tokensBonusText + ' SA Tokens' + tokensAwardedBTC)
node.tokensBonus.payload.uiObject.setValue(tokensBonusText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
}
}
}
@@ -168,8 +168,13 @@ function newGovernanceUtilitiesDecendentProgram() {
userProfile.payload.blockchainTokens === undefined
) {
node.payload[programPropertyName].isActive = false
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.")
userProfile.payload.uiObject.setErrorMessage(
"Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
} else {
userProfile.payload.uiObject.resetErrorMessage()
}
/*
As per the system rules, the Program will not give tokens
@@ -182,7 +187,10 @@ function newGovernanceUtilitiesDecendentProgram() {
(node[usersArrayPropertyName] === undefined || hasUsersDefined(node[usersArrayPropertyName]) === false)
) {
node.payload[programPropertyName].isActive = false
node.payload.uiObject.setErrorMessage("In order to enable this program you need to add " + userNodeType + " nodes and reference a User Profile from each one.")
node.payload.uiObject.setErrorMessage(
"In order to enable this program you need to add " + userNodeType + " nodes and reference a User Profile from each one.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
} else {
node.payload[programPropertyName].isActive = true
}
@@ -282,7 +290,10 @@ function newGovernanceUtilitiesDecendentProgram() {
}
}
if (totalPercentage > 100) {
node.payload.uiObject.setErrorMessage('Program Power Switching Error. Total Percentage of children nodes is grater that 100.')
node.payload.uiObject.setErrorMessage(
'Program Power Switching Error. Total Percentage of children nodes is grater that 100.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
let defaultPercentage = 0
@@ -371,7 +382,10 @@ function newGovernanceUtilitiesDecendentProgram() {
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) {
programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.")
programNode.payload.uiObject.setErrorMessage(
"Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
programNode.payload[programPropertyName].awarded.tokens = programNode.payload[programPropertyName].incomingPower / totalPowerRewardRatio
@@ -387,17 +401,19 @@ function newGovernanceUtilitiesDecendentProgram() {
node.payload.uiObject.valueAngleOffset = 180
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.setValue(outgoingPowerText + ' ' + programPowerName)
node.payload.uiObject.setValue(outgoingPowerText + ' ' + programPowerName, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
node.payload.uiObject.setPercentage(percentage)
node.payload.uiObject.setPercentage(percentage,
UI.projects.governance.globals.designer.SET_PERCENTAGE_COUNTER
)
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = true
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power')
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
@@ -410,7 +426,7 @@ function newGovernanceUtilitiesDecendentProgram() {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Own Power' + ' + ' + incomingPowerText + ' Incoming ' + programPowerName)
node.payload.uiObject.setStatus(ownPowerText + ' Own Power' + ' + ' + incomingPowerText + ' Incoming ' + programPowerName, UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
@@ -422,8 +438,8 @@ function newGovernanceUtilitiesDecendentProgram() {
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
node.tokensAwarded.payload.uiObject.valueAtAngle = true
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC)
node.tokensAwarded.payload.uiObject.setStatus('From ' + node.payload[programPropertyName].count + ' Descendants.')
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
node.tokensAwarded.payload.uiObject.setStatus('From ' + node.payload[programPropertyName].count + ' Descendants.', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
}
}
@@ -12,7 +12,10 @@ function newGovernanceUtilitiesValidations () {
let programs = UI.projects.foundations.utilities.branches.nodeBranchToArray(userProfile, programNodeType)
if (programs !== undefined) {
if (programs.length > 1) {
userProfile.payload.uiObject.setErrorMessage('Only one ' + programNodeType + ' is allowed.')
userProfile.payload.uiObject.setErrorMessage(
'Only one ' + programNodeType + ' is allowed.',
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
if (programs.length === 1) {
@@ -94,6 +94,14 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
}
break
}
default: {
let response = {
result: 'Error',
message: 'messageType Not Supported.'
}
socket.send(JSON.stringify(response))
break
}
}
} catch (err) {
console.log('[ERROR] Web Sockets Interface -> setUpWebSocketServer -> err.stack = ' + err.stack)
+167 -161
View File
@@ -7,7 +7,6 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
}
let socketClient
let callbackFunction
let web3 = new SA.nodeModules.web3()
let called = {}
@@ -25,7 +24,7 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
called = undefined
}
function initialize() {
async function initialize() {
/*
Here we will pick a Network Node from all users profiles available that do have a Network Node running. // TODO
In the meantime, we will assume that we have chosen the following Network Node to connect to.
@@ -43,205 +42,212 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
}
socketClient = new SA.nodeModules.ws('ws://' + selectedNetworkNode.host + ':' + selectedNetworkNode.port)
//networkInterface = SA.projects.socialTrading.modules.networkInterface.newSocialTradingModulesNetworkInterface()
setUpWebsocketClient()
await setUpWebsocketClient()
}
function setUpWebsocketClient() {
try {
let handshakeDone = false
async function setUpWebsocketClient() {
socketClient.onopen = () => { onConnection() }
socketClient.onerror = err => { onError(err) }
return new Promise(connectToNewtwork)
function onConnection() {
function connectToNewtwork(resolve, reject) {
handshakeProcedure()
try {
function handshakeProcedure() {
socketClient.onopen = () => { onConnection() }
socketClient.onerror = err => { onError(err) }
let callerTimestamp
function onConnection() {
stepOneRequest()
handshakeProcedure()
function stepOneRequest() {
/*
Send Handshake Message Step One:
At Step One we will just say hello, identify ourselves
as a Network Client, and send the Network Node our
User Profile Handle.
This Handle will be signed by the Network Node to prove
it's ouwn identity, and later we will sign it's own handle
to prove ours.
*/
socketClient.onmessage = socketMessage => { stepOneResponse(socketMessage) }
function handshakeProcedure() {
callerTimestamp = (new Date()).valueOf()
let callerTimestamp
let message = {
messageType: 'Handshake',
callerRole: 'Network Client',
callerProfileHandle: DK.TEST_NETWORK_CLIENT_USER_PROFILE_HANDLE,
callerTimestamp: callerTimestamp,
step: 'One'
}
socketClient.send(JSON.stringify(message))
}
stepOneRequest()
function stepOneResponse(socketMessage) {
let response = JSON.parse(socketMessage.data)
function stepOneRequest() {
/*
Send Handshake Message Step One:
At Step One we will just say hello, identify ourselves
as a Network Client, and send the Network Node our
User Profile Handle.
This Handle will be signed by the Network Node to prove
it's ouwn identity, and later we will sign it's own handle
to prove ours.
*/
socketClient.onmessage = socketMessage => { stepOneResponse(socketMessage) }
if (response.result !== 'Ok') {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> response.message = ' + response.message)
return
callerTimestamp = (new Date()).valueOf()
let message = {
messageType: 'Handshake',
callerRole: 'Network Client',
callerProfileHandle: DK.TEST_NETWORK_CLIENT_USER_PROFILE_HANDLE,
callerTimestamp: callerTimestamp,
step: 'One'
}
socketClient.send(JSON.stringify(message))
}
let signature = JSON.parse(response.signature)
called.blockchainAccount = web3.eth.accounts.recover(signature)
/*
We will check that the signature received produces a valid Blockchain Account.
*/
if (called.blockchainAccount === undefined) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> Signature does not produce a valid Blockchain Account.')
return
}
/*
We will check that the blockchain account taken from the signature matches
the one we have on record for the user profile of the Network Node we are calling.
*/
if (called.blockchainAccount !== selectedNetworkNode.blockchainAccount) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node called does not have the expected Profile Handle.')
return
function stepOneResponse(socketMessage) {
let response = JSON.parse(socketMessage.data)
if (response.result !== 'Ok') {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> response.message = ' + response.message)
reject()
return
}
let signature = JSON.parse(response.signature)
called.blockchainAccount = web3.eth.accounts.recover(signature)
/*
We will check that the signature received produces a valid Blockchain Account.
*/
if (called.blockchainAccount === undefined) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> Signature does not produce a valid Blockchain Account.')
reject()
return
}
/*
We will check that the blockchain account taken from the signature matches
the one we have on record for the user profile of the Network Node we are calling.
*/
if (called.blockchainAccount !== selectedNetworkNode.blockchainAccount) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node called does not have the expected Profile Handle.')
reject()
return
}
let signedMessage = JSON.parse(signature.message)
/*
We will check that the Network Node that responded has the same User Profile Handle
that we have on record, otherwise something is wrong and we should not proceed.
*/
if (signedMessage.calledProfileHandle !== selectedNetworkNode.userProfileHandle) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node called does not have the expected Profile Handle.')
reject()
return
}
/*
We will check that the profile handle we sent to the Network Node, is returned at the
signed message, to avoid man in the middle attackts.
*/
if (signedMessage.callerProfileHandle !== DK.TEST_NETWORK_CLIENT_USER_PROFILE_HANDLE) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node callerProfileHandle does not match my own userProfileHandle.')
reject()
return
}
/*
We will also check that the callerTimestamp we sent to the Network Node, is returned at the
signed message, also to avoid man in the middle attackts.
*/
if (signedMessage.callerTimestamp !== callerTimestamp) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node callerTimestamp does not match my own callerTimestamp.')
reject()
return
}
/*
All validations passed, it seems we can continue with Step Two.
*/
stepTwoRequest(signedMessage)
}
let signedMessage = JSON.parse(signature.message)
function stepTwoRequest(signedMessage) {
/*
Send Handshake Message Step Two:
Here we will sign a message with the Network Node profile
handle and timestamp to prove our own identity.
*/
socketClient.onmessage = socketMessage => { stepTwoResponse(socketMessage) }
/*
We will check that the Network Node that responded has the same User Profile Handle
that we have on record, otherwise something is wrong and we should not proceed.
*/
if (signedMessage.calledProfileHandle !== selectedNetworkNode.userProfileHandle) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node called does not have the expected Profile Handle.')
return
}
/*
We will check that the profile handle we sent to the Network Node, is returned at the
signed message, to avoid man in the middle attackts.
*/
if (signedMessage.callerProfileHandle !== DK.TEST_NETWORK_CLIENT_USER_PROFILE_HANDLE) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node callerProfileHandle does not match my own userProfileHandle.')
return
}
/*
We will also check that the callerTimestamp we sent to the Network Node, is returned at the
signed message, also to avoid man in the middle attackts.
*/
if (signedMessage.callerTimestamp !== callerTimestamp) {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node callerTimestamp does not match my own callerTimestamp.')
return
let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), DK.TEST_NETWORK_CLIENT_USER_PROFILE_PRIVATE_KEY)
let message = {
messageType: 'Handshake',
signature: JSON.stringify(signature),
step: 'Two'
}
socketClient.send(JSON.stringify(message))
}
/*
All validations passed, it seems we can continue with Step Two.
*/
stepTwoRequest(signedMessage)
}
function stepTwoResponse(socketMessage) {
let response = JSON.parse(socketMessage.data)
function stepTwoRequest(signedMessage) {
/*
Send Handshake Message Step Two:
Here we will sign a message with the Network Node profile
handle and timestamp to prove our own identity.
*/
socketClient.onmessage = socketMessage => { stepTwoResponse(socketMessage) }
let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), DK.TEST_NETWORK_CLIENT_USER_PROFILE_PRIVATE_KEY)
let message = {
messageType: 'Handshake',
signature: JSON.stringify(signature),
step: 'Two'
if (response.result !== 'Ok') {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> response.message = ' + response.message)
reject()
return
}
console.log('[INFO] Web Sockets Client -> stepTwoResponse -> response.message = ' + response.message)
/*
This was the end of the Handshake producere. We are connected to the
Network Node and from now on, all response messages will be received
at this following function.
*/
resolve()
}
socketClient.send(JSON.stringify(message))
}
function stepTwoResponse(socketMessage) {
let response = JSON.parse(socketMessage.data)
if (response.result !== 'Ok') {
console.log('[ERROR] Web Sockets Client -> stepOneResponse -> response.message = ' + response.message)
return
}
console.log('[INFO] Web Sockets Client -> stepTwoResponse -> response.message = ' + response.message)
/*
This was the end of the Handshake producere. We are connected to the
Network Node and from now on, all response messages will be received
at this following function.
*/
socketClient.onmessage = socketMessage => { onMenssage(socketMessage) }
}
}
function onError(err) {
console.log('[ERROR] Web Sockets Client -> onError -> err.message = ' + err.message)
console.log('[ERROR] Web Sockets Client -> onError -> err.stack = ' + err.stack)
}
} catch (err) {
console.log('[ERROR] Web Sockets Client -> setUpWebsocketClient -> err.stack = ' + err.stack)
}
async function onMenssage(socketMessage) {
}
}
function sendMessage(message) {
return new Promise(sendSocketMessage)
function sendSocketMessage(resolve, reject) {
if (socketClient.readyState !== 1) { // 1 means connected and ready.
console.log('[ERROR] Web Sockets Client -> sendMessage -> Cannot send message while connection is closed.')
reject('Websockets Connection Not Ready.')
}
let socketMessage = {
messageType: 'Request',
payload: message
}
socketClient.onmessage = socketMessage => { onMenssage(socketMessage) }
socketClient.send(
JSON.stringify(socketMessage)
)
function onMenssage(socketMessage) {
try {
let response = JSON.parse(socketMessage.data)
/*
Chack if we are waiting for the Handshake response.
*/
if (handshakeDone === false) {
if (response.result === 'Ok') {
handshakeDone = true
return
} else {
console.log('[ERROR] Web Sockets Client -> onMenssage -> handshakeDone -> response.message = ' + response.message)
return
}
}
callbackFunction.receiveResponse(message)
callbackFunction = undefined
if (response.result === 'Ok') {
resolve(response.data)
} else {
console.log('[ERROR] Web Sockets Client -> onMenssage -> response.message = ' + response.message)
reject(response.message)
}
} catch (err) {
callbackFunction = undefined
console.log('[ERROR] Web Sockets Client -> err.stack = ' + err.stack)
}
}
function onError(err) {
console.log('[ERROR] Web Sockets Client -> onError -> err.message = ' + err.message)
console.log('[ERROR] Web Sockets Client -> onError -> err.stack = ' + err.stack)
}
} catch (err) {
console.log('[ERROR] Web Sockets Client -> setUpWebsocketClient -> err.stack = ' + err.stack)
}
}
function sendMessage(message, callback) {
if (callbackFunction !== undefined) {
console.log('[ERROR] Web Sockets Client -> sendMessage -> Cannot send more messages while waiting for a response.')
return false
}
if (socketClient.readyState !== 1) { // 1 means connected and ready.
console.log('[ERROR] Web Sockets Client -> sendMessage -> Cannot send message while connection is closed.')
return false
}
try {
callbackFunction = callback
socketClient.send(message)
return true
} catch (err) {
callbackFunction = false
console.log('[ERROR] Web Sockets Client -> sendMessage -> err.stack = ' + err.stack)
return false
}
}
}
+6 -1
View File
@@ -1079,6 +1079,11 @@
"propertyName": "governance",
"UI": {
"globals": [
{
"name": "Designer",
"propertyName": "designer",
"functionName": "newGovernanceGlobalsDesigner"
},
{
"name": "Reports",
"propertyName": "reports",
@@ -1395,7 +1400,7 @@
},
{
"name": "Query",
"propertyName": "Query",
"propertyName": "query",
"functionName": "newSocialTradingModulesQuery",
"fileName": "Query.js"
},
@@ -35,23 +35,23 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
return response
}
if (messageHeader.messageType === undefined) {
if (messageHeader.requestType === undefined) {
let response = {
result: 'Error',
message: 'Client Interface messageType Not Provided.'
message: 'Client Interface requestType Not Provided.'
}
return response
}
if (messageHeader.messageType !== 'Event' && messageHeader.messageType !== 'Query') {
if (messageHeader.requestType !== 'Event' && messageHeader.requestType !== 'Query') {
let response = {
result: 'Error',
message: 'Client Interface messageType Not Supported.'
message: 'Client Interface requestType Not Supported.'
}
return response
}
switch (messageHeader.messageType) {
switch (messageHeader.requestType) {
case 'Event': {
return await eventReceived(messageHeader.eventMessage, userProfile)
}
@@ -190,9 +190,15 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
Here we will process the query. This does not change the state of the Social Graph.
*/
try {
let query = NT.projects.socialTrading.modules.queriesQuery.newSocialTradingModulesQuery()
let query = NT.projects.socialTrading.modules.query.newSocialTradingModulesQuery()
query.initialize(queryReceived)
return query.execute()
let response = {
result: 'Ok',
message: 'Client Interface Query Processed.',
data: query.execute()
}
return response
} catch (err) {
/*
@@ -200,7 +206,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
*/
let response = {
result: 'Error',
message: 'Client Interface ' + err.message
message: err.message
}
return response
}
@@ -21,8 +21,8 @@ exports.newSocialTradingModulesQueriesEvents = function newSocialTradingModulesQ
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, NT.memory.arrays.EVENTS)
}
@@ -8,6 +8,7 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod
of a certain post, with all its replies.
*/
let thisObject = {
array: undefined,
profile: undefined,
post: undefined,
initialIndex: undefined,
@@ -21,27 +22,30 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
thisObject.post = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.postValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.post.replies)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.postValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.post.replies)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (post === undefined) { break }
addToResponse(arrayItem)
}
@@ -49,7 +53,7 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (post === undefined) { break }
addToResponse(arrayItem)
}
@@ -4,6 +4,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
all the User or Bot profiles that are following a certain User or Bot profile.
*/
let thisObject = {
array: undefined,
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
@@ -16,25 +17,27 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.profile.followers)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.followers)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -42,7 +45,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -4,6 +4,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
all the User or Bot profiles that are being followed by a certain User or Bot profile.
*/
let thisObject = {
array: undefined,
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
@@ -16,25 +17,27 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.profile.following)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.following)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -42,7 +45,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -8,6 +8,7 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
with all of its posts.
*/
let thisObject = {
array: undefined,
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
@@ -20,24 +21,26 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
return thisObject
function finalize() {
thisObject.array = undefined
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
thisObject.array = Array.from(thisObject.profile.posts)
NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.posts)
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -45,7 +48,7 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
@@ -0,0 +1,75 @@
exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingModulesQueriesUserProfiles() {
/*
This query returns a list of user profiles ordered
by Ranking. It is useful to bootstrap new users
and provide them with alternative of who to follow.
*/
let thisObject = {
array: undefined,
initialIndex: undefined,
amountRequested: undefined,
direction: undefined,
execute: execute,
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
thisObject.array = undefined
}
function initialize(queryReceived) {
thisObject.array = Array.from(
NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID,
x => x[1]
)
thisObject.array.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1)
NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array)
}
function execute() {
let response = []
switch (thisObject.direction) {
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
break
}
case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = thisObject.array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
break
}
}
return response
function addToResponse(profile) {
let postResponse = {
"userProfileId": profile.userProfileId,
"userProfileHandle": profile.userProfileHandle,
"blockchainAccount": profile.blockchainAccount,
"ranking": profile.ranking,
"followingCount": profile.following.size,
"followersCount": profile.followers.size,
"postsCount": profile.posts.size,
"botsCount": profile.bots.size,
"emitterEventsCount": profile.emitterEventsCount,
"targetEventsCount": profile.targetEventsCount
}
response.push(postResponse)
}
}
}
+13 -19
View File
@@ -40,67 +40,61 @@ exports.newSocialTradingModulesQuery = function newSocialTradingModulesQuery() {
thisObject.queryType = queryReceived.queryType
switch (thisObject.queryType) {
case QUERY_TYPES.USER_PROFILES: {
thisObject.query = NT.projects.socialTrading.modules.queriesUserProfiles.newSocialTradingModulesQueriesUserProfiles()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.USER_PROFILE_STATS: {
thisObject.query = NT.projects.socialTrading.modules.queriesUserProfileStats.newSocialTradingModulesQueriesUserProfileStats()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.BOT_PROFILE_STATS: {
thisObject.query = NT.projects.socialTrading.modules.queriesBotProfileStats.newSocialTradingModulesQueriesBotProfileStats()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.PROFILE_POSTS: {
thisObject.query = NT.projects.socialTrading.modules.queriesProfilePosts.newSocialTradingModulesQueriesProfilePosts()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.POST_REPLIES: {
thisObject.query = NT.projects.socialTrading.modules.queriesPostReplies.newSocialTradingModulesQueriesPostReplies()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.PROFILE_FOLLOWERS: {
thisObject.query = NT.projects.socialTrading.modules.queriesProfileFollowers.newSocialTradingModulesQueriesProfileFollowers()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.PROFILE_FOLLOWING: {
thisObject.query = NT.projects.socialTrading.modules.queriesProfileFollowing.newSocialTradingModulesQueriesProfileFollowing()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
case QUERY_TYPES.maps.EVENTS: {
thisObject.query = NT.projects.socialTrading.modules.queriesEvents.newSocialTradingModulesQueriesEvents()
query.initialize(queryReceived)
query.finalize()
thisObject.query.initialize(queryReceived)
break
}
default: throw('Query Type Not Supported.')
default: throw ('Query Type Not Supported.')
}
}
function execute() {
return thisObject.query.execute()
let response = thisObject.query.execute()
thisObject.query.finalize()
return response
}
}
@@ -43,7 +43,7 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
}
}
function arrayValidations(queryReceived, thisObject) {
function arrayValidations(queryReceived, thisObject, array) {
/*
Validate Initial Index
*/
@@ -52,7 +52,7 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
}
if (queryReceived.initialIndex === NT.projects.socialTrading.globals.queryConstants.INITIAL_INDEX_LAST) {
queryReceived.initialIndex = thisObject.profile.posts.length - 1
queryReceived.initialIndex = array.length - 1
}
if (queryReceived.initialIndex === NT.projects.socialTrading.globals.queryConstants.INITIAL_INDEX_FIRST) {
@@ -82,6 +82,8 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU
if (queryReceived.amountRequested > NT.projects.socialTrading.globals.queryConstants.MAX_AMOUNT_REQUESTED) {
throw ('Amount Requested Above Max.')
}
thisObject.amountRequested = queryReceived.amountRequested
/*
Validate Direction
*/
+1
View File
@@ -54,6 +54,7 @@ We will use this User Profile for Testing Purposes.
}
*/
DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID = "baa2f02c-2920-4edb-a103-d452fc61d82f"
DK.TEST_NETWORK_CLIENT_USER_PROFILE_HANDLE = "Test-Network-Client-Profile"
DK.TEST_NETWORK_CLIENT_USER_PROFILE_PRIVATE_KEY = "0x5fed4817a87431c8a328d0936561e63f45b6db289adac6125b9306ded644dfe9"