From a52e9aa0a98b42577480b7828a673bcf2fb9fb90 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 30 Aug 2021 16:28:05 +0200 Subject: [PATCH] Ready for first debug --- Network/NetwokNode.js | 8 +++++ Network/clientsInterface.js | 4 +-- Projects/Network/NT/Modules/Bootstrap.js | 34 +++++++++++++++++++ Projects/Network/NT/Modules/Event.js | 4 +-- .../NT/Modules/Queries/BotProfileStats.js | 4 +-- Projects/Network/NT/Modules/Queries/Events.js | 4 +-- .../NT/Modules/Queries/UserProfileStats.js | 4 +-- .../NT/Modules/Social-Graph/BotProfile.js | 4 +-- .../Network/NT/Modules/Social-Graph/Post.js | 4 +-- .../NT/Modules/Social-Graph/UserProfile.js | 4 +-- .../NT/Utilities/QueriesValidations.js | 2 +- 11 files changed, 59 insertions(+), 17 deletions(-) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index 268078a19..5f596b8d3 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -21,6 +21,10 @@ The SA object is accesible everywhere at the Superalgos Network. It provides access to all modules built for Superalgos in general. */ global.SA = {} +/* Load Environment Variables */ +let ENVIRONMENT = require('../Environment.js'); +let ENVIRONMENT_MODULE = ENVIRONMENT.newEnvironment() +global.env = ENVIRONMENT_MODULE /* First thing is to load the project schema file. */ @@ -32,6 +36,10 @@ let MULTI_PROJECT = require('../MultiProject.js'); let MULTI_PROJECT_MODULE = MULTI_PROJECT.newMultiProject() MULTI_PROJECT_MODULE.initialize(CL, 'CL') MULTI_PROJECT_MODULE.initialize(SA, 'SA') +/* +Node Modules Dependencies +*/ +NT.nodeModules.web3 = require('web3') let socialGraphService = NT.modules.socialGraph.newSocialGraph() socialGraphService.initialize() \ No newline at end of file diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 5fdbf56aa..186fb456b 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -45,13 +45,13 @@ exports.newClientInterface = function newClientInterface() { */ let eventReceived = JSON.parse(eventMessage) - if (NT.globals.memory.EVENTS.get(eventReceived.eventId) !== undefined) { + if (NT.globals.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) { throw ('Event Already Exists.') } let event = NT.modules.event.newNetworkModulesEvent() event.initialize(eventReceived) - NT.globals.memory.EVENTS.set(eventReceived.eventId, event) + NT.globals.memory.maps.EVENTS.set(eventReceived.eventId, event) } function queryReceived(queryMessage) { diff --git a/Projects/Network/NT/Modules/Bootstrap.js b/Projects/Network/NT/Modules/Bootstrap.js index 1bfc06d40..a0399fe33 100644 --- a/Projects/Network/NT/Modules/Bootstrap.js +++ b/Projects/Network/NT/Modules/Bootstrap.js @@ -17,6 +17,40 @@ exports.newBootstrap = function newBootstrap() { } function initialize() { + + let pluginFileNames = await SA.projects.foundations.utilities.plugins.getPluginFileNames( + 'Governance', + 'User-Profiles' + ) + for (let i = 0; i < pluginFileNames.length; i++) { + let pluginFileName = pluginFileNames[i] + let pluginFileContent = await SA.projects.foundations.utilities.plugins.getPluginFileContent( + 'Governance', + 'User-Profiles', + pluginFileName + ) + + let userProfilePlugin = JSON.parse(pluginFileContent) + let config = JSON.parse(userProfilePlugin.config) + let signatureObject = JSON.parse(config.signature) + let web3 = new NT.nodeModules.web3() + let bloackchainAddress = web3.eth.accounts.recover(signatureObject) + let ranking = 0 // TODO: read the blockchain balance and transactions from the Treasury Account to calculate the profile ranking. + let userProfileId = userProfilePlugin.id + let userHandle = config.signature.message + + let userProfile = NT.modules.socialGraphUserProfile.newNetworkModulesSocialGraphUserProfile() + userProfile.initialize( + userProfileId, + userHandle, + bloackchainAddress, + ranking + ) + + NT.globals.memory.maps.USER_PROFILES_BY_ID.set(userProfileId, userProfile) + NT.globals.memory.maps.USER_PROFILES_BY_HANDLE.set(userHandle, userProfile) + + } } } \ No newline at end of file diff --git a/Projects/Network/NT/Modules/Event.js b/Projects/Network/NT/Modules/Event.js index a7feafb07..d4dfd4614 100644 --- a/Projects/Network/NT/Modules/Event.js +++ b/Projects/Network/NT/Modules/Event.js @@ -104,7 +104,7 @@ exports.newNetworkModulesEvent = function newNetworkModulesEvent() { if (emitterUserProfileId === undefined) { throw ('Emitter User Profile Id Not Provided.') } - emitterUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) + emitterUserProfile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) if (emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } @@ -112,7 +112,7 @@ exports.newNetworkModulesEvent = function newNetworkModulesEvent() { Validate Target User Profile. */ if (thisObject.targetUserProfileId !== undefined) { - targetUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + targetUserProfile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } diff --git a/Projects/Network/NT/Modules/Queries/BotProfileStats.js b/Projects/Network/NT/Modules/Queries/BotProfileStats.js index 87b7b3708..81c09c2f0 100644 --- a/Projects/Network/NT/Modules/Queries/BotProfileStats.js +++ b/Projects/Network/NT/Modules/Queries/BotProfileStats.js @@ -19,9 +19,9 @@ exports.newNetworkModulesQueriesBotProfileStats = function newNetworkModulesQuer */ let userProfile if (queryReceived.targetUserProfileId !== undefined) { - userProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + userProfile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - userProfile = NT.globals.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + userProfile = NT.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (userProfile === undefined) { diff --git a/Projects/Network/NT/Modules/Queries/Events.js b/Projects/Network/NT/Modules/Queries/Events.js index f36a6d121..49abb1779 100644 --- a/Projects/Network/NT/Modules/Queries/Events.js +++ b/Projects/Network/NT/Modules/Queries/Events.js @@ -59,8 +59,8 @@ exports.newNetworkModulesQueriesEvents = function newNetworkModulesQueriesEvents Any of the above happening, means that indeed it is related. */ - let emitterUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) - let targetUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) + let emitterUserProfile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) + let targetUserProfile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) let emitterBotProfile = emitterUserProfile.bots.get(eventReceived.emitterBotProfileId) let targetBotProfile = targetUserProfile.bots.get(eventReceived.targetBotProfileId) let emitterPost = emitterUserProfile.posts.get(eventReceived.emitterPostHash) diff --git a/Projects/Network/NT/Modules/Queries/UserProfileStats.js b/Projects/Network/NT/Modules/Queries/UserProfileStats.js index e093d03e2..dbae46ca1 100644 --- a/Projects/Network/NT/Modules/Queries/UserProfileStats.js +++ b/Projects/Network/NT/Modules/Queries/UserProfileStats.js @@ -18,9 +18,9 @@ exports.newNetworkModulesQueriesUserProfileStats = function newNetworkModulesQue Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.globals.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - thisObject.profile = NT.globals.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + thisObject.profile = NT.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (thisObject.profile === undefined) { diff --git a/Projects/Network/NT/Modules/Social-Graph/BotProfile.js b/Projects/Network/NT/Modules/Social-Graph/BotProfile.js index e7ce60b41..7718c9942 100644 --- a/Projects/Network/NT/Modules/Social-Graph/BotProfile.js +++ b/Projects/Network/NT/Modules/Social-Graph/BotProfile.js @@ -1,4 +1,4 @@ -exports.newBotProfile = function newBotProfile() { +exports.newNetworkModulesSocialGraphBotProfile = function newNetworkModulesSocialGraphBotProfile() { /* Users can have a Profile that can: * follow other bots profiles. @@ -80,7 +80,7 @@ exports.newBotProfile = function newBotProfile() { if (thisObject.posts.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') } else { - let post = NT.modules.POST.newPost() + let post = NT.modules.socialGraphPost.newNetworkModulesSocialGraphPost() post.initialize( emitterUserProfileId, targetUserProfileId, diff --git a/Projects/Network/NT/Modules/Social-Graph/Post.js b/Projects/Network/NT/Modules/Social-Graph/Post.js index 985bdd4a9..c34f006b3 100644 --- a/Projects/Network/NT/Modules/Social-Graph/Post.js +++ b/Projects/Network/NT/Modules/Social-Graph/Post.js @@ -1,4 +1,4 @@ -exports.newPost = function newPost() { +exports.newNetworkModulesSocialGraphPost = function newNetworkModulesSocialGraphPost() { /* Posts represent a collection of multimedia content sotored somewhere else and identified by that content hash. Posts might belong to: @@ -97,7 +97,7 @@ exports.newPost = function newPost() { /* Validate Target User Profile. */ - let targetUserProfile = NT.globals.memory.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + let targetUserProfile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } diff --git a/Projects/Network/NT/Modules/Social-Graph/UserProfile.js b/Projects/Network/NT/Modules/Social-Graph/UserProfile.js index 0144038cd..a4f86dfc0 100644 --- a/Projects/Network/NT/Modules/Social-Graph/UserProfile.js +++ b/Projects/Network/NT/Modules/Social-Graph/UserProfile.js @@ -1,4 +1,4 @@ -exports.newUserProfile = function newUserProfile() { +exports.newNetworkModulesSocialGraphUserProfile = function newNetworkModulesSocialGraphUserProfile() { /* Users can have a Profile that can: * follow other user profiles. @@ -84,7 +84,7 @@ exports.newUserProfile = function newUserProfile() { if (thisObject.posts.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') } else { - let post = NT.modules.POST.newPost() + let post = NT.modules.socialGraphPost.newNetworkModulesSocialGraphPost() post.initialize( emitterUserProfileId, targetUserProfileId, diff --git a/Projects/Network/NT/Utilities/QueriesValidations.js b/Projects/Network/NT/Utilities/QueriesValidations.js index 7441bfaf7..c88d7e891 100644 --- a/Projects/Network/NT/Utilities/QueriesValidations.js +++ b/Projects/Network/NT/Utilities/QueriesValidations.js @@ -15,7 +15,7 @@ exports.newNetworkUtilitiesQueriesValidations = function newNetworkUtilitiesQuer Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.globals.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = NT.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } if (thisObject.profile === undefined) {