From b3bc7ca28962fb5dc19ab69987f1b0b10ded2a3b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 10:46:15 +0100 Subject: [PATCH 01/11] Update ClientInterface.js --- .../NT/Modules/ClientInterface.js | 152 ++++++++++++++---- 1 file changed, 120 insertions(+), 32 deletions(-) diff --git a/Projects/Social-Trading/NT/Modules/ClientInterface.js b/Projects/Social-Trading/NT/Modules/ClientInterface.js index bd429b878..0da1aa0d4 100644 --- a/Projects/Social-Trading/NT/Modules/ClientInterface.js +++ b/Projects/Social-Trading/NT/Modules/ClientInterface.js @@ -1,15 +1,16 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModulesClientInterface() { /* This module represents the Interface the Network Node have - with Network Clients connected to it. There are two things + with Network Clients connected to it. There are 3 things Network Clients can do with this Network Node: - * Send an Event that happened at the Network Client to the Network. * Make a Query to the Network Node for info needed at the Network Client. + * Send an Event that happened at the Network Client to the Network. + * Send a Signal that needs to be distributed. This interface is one layer above the communication protocol interface where actual messages are received through, like for instance the - websockets interface. + websockets interface or http interface. */ let thisObject = { messageReceived: messageReceived, @@ -47,7 +48,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule return response } - if (messageHeader.requestType !== 'Event' && messageHeader.requestType !== 'Query') { + if (messageHeader.requestType !== 'Event' && messageHeader.requestType !== 'Query' && messageHeader.requestType !== 'Signal') { let response = { result: 'Error', message: 'Client Interface requestType Not Supported.' @@ -56,15 +57,99 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule } switch (messageHeader.requestType) { + case 'Query': { + return await queryReceived(messageHeader.queryMessage, userProfile) + } case 'Event': { return await eventReceived(messageHeader.eventMessage, userProfile) } - case 'Query': { - return await queryReceived(messageHeader.queryMessage, userProfile) + case 'Signal': { + return await signalReceived(messageHeader.eventMessage, userProfile) } } } + async function queryReceived(queryMessage, userProfile) { + /* + We expect here a JSON string with some or all of the following properties: + + { + "queryType": 10, + "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "emitterUserProfileHandle": "Luis-Fernando-Molina", + "targetUserProfileHandle": "Luis-Fernando-Molina", + "emitterBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetBBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "timestamp": 124234234234, + "botAsset": "BTC", + "botExchange": "Binance", + "botEnabled": true, + "initialIndex": 35, + "amountRequested": 50, + "direction": "Past" + } + */ + + let queryReceived + try { + queryReceived = JSON.parse(queryMessage) + } catch (err) { + let response = { + result: 'Error', + message: 'Client Interface queryMessage Not Correct JSON Format.' + } + return response + } + /* + At the Client Interface, queries need to be emitted by the same userProfile that is + connected at the Network Node. + */ + if (queryReceived.emitterUserProfileId !== userProfile.userProfileId) { + let response = { + result: 'Error', + message: 'Client Interface emitterUserProfileId !== userProfileId Connected to Network Node.' + } + return response + } + /* + Here we will process the query. This does not change the state of the Social Graph. + */ + try { + let query = NT.projects.socialTrading.modules.query.newSocialTradingModulesQuery() + query.initialize(queryReceived) + + // console.log((new Date()).toISOString(), '- Client Interface', '- Query Message Received', queryMessage) + + let response = { + result: 'Ok', + message: 'Client Interface Query Processed.', + data: query.execute() + } + + // console.log((new Date()).toISOString(), '- Client Interface', '- Query Response Sent', JSON.stringify(response)) + + return response + + } catch (err) { + /* + Any exception that happens while trying to execute the query. + */ + if (err.stack !== undefined) { + console.log('[ERROR] Client Interface -> err.stack = ' + err.stack) + } + let errorMessage = err.message + if (errorMessage === undefined) { errorMessage = err } + let response = { + result: 'Error', + message: 'Client Interface ' + errorMessage + } + return response + } + } + async function eventReceived(eventMessage, userProfile) { /* We expect here a JSON string with some or all of the following properties: @@ -160,16 +245,15 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule } } - async function queryReceived(queryMessage, userProfile) { + async function signalReceived(signalMessage, userProfile) { /* We expect here a JSON string with some or all of the following properties: { - "queryType": 10, + "signalId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "signalType": 10, "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "emitterUserProfileHandle": "Luis-Fernando-Molina", - "targetUserProfileHandle": "Luis-Fernando-Molina", "emitterBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "targetBBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", @@ -177,56 +261,60 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule "timestamp": 124234234234, "botAsset": "BTC", "botExchange": "Binance", - "botEnabled": true, - "initialIndex": 35, - "amountRequested": 50, - "direction": "Past" + "botEnabled": true } */ - let queryReceived + let signalReceived try { - queryReceived = JSON.parse(queryMessage) + signalReceived = JSON.parse(signalMessage) } catch (err) { let response = { result: 'Error', - message: 'Client Interface queryMessage Not Correct JSON Format.' + message: 'Client Interface signalMessage Not Correct JSON Format.' } return response } /* - At the Client Interface, queries need to be emitted by the same userProfile that is - connected at the Network Node. + We will not accept signals that don't have an signalId. */ - if (queryReceived.emitterUserProfileId !== userProfile.userProfileId) { + if (signalReceived.signalId === undefined) { let response = { result: 'Error', - message: 'Client Interface emitterUserProfileId !== userProfileId Connected to Network Node.' + message: 'signalId Not Provided.' } return response } /* - Here we will process the query. This does not change the state of the Social Graph. + We will not accept signals that have already been processed. + */ + + if (NT.projects.network.globals.memory.maps.SIGNALS.get(signalReceived.signalId) !== undefined) { + let response = { + result: 'Error', + message: 'Client Interface Signal Already Exists.' + } + return response + } + /* + Here we will process the signal and change the state of the Social Graph. */ try { - let query = NT.projects.socialTrading.modules.query.newSocialTradingModulesQuery() - query.initialize(queryReceived) - - // console.log((new Date()).toISOString(), '- Client Interface', '- Query Message Received', queryMessage) + let signal = NT.projects.socialTrading.modules.signal.newSocialTradingModulesSignal() + signal.initialize(signalReceived) + NT.projects.network.globals.memory.maps.SIGNALS.set(signalReceived.eventId, signal) + NT.projects.network.globals.memory.arrays.SIGNALS.push(signal) let response = { result: 'Ok', - message: 'Client Interface Query Processed.', - data: query.execute() + message: 'Client Interface Signal Processed.' } - - // console.log((new Date()).toISOString(), '- Client Interface', '- Query Response Sent', JSON.stringify(response)) - return response } catch (err) { /* - Any exception that happens while trying to execute the query. + Any exception that happens while trying to change the state of the Social Graph, + will be returned to the caller without doing anything else here. */ if (err.stack !== undefined) { console.log('[ERROR] Client Interface -> err.stack = ' + err.stack) From 2fa5dde807f1815caca5f40c0844e1ef64b3c11d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 10:53:26 +0100 Subject: [PATCH 02/11] Update Memory.js --- Projects/Network/NT/Globals/Memory.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Projects/Network/NT/Globals/Memory.js b/Projects/Network/NT/Globals/Memory.js index 560d7ad6f..1d8692cee 100644 --- a/Projects/Network/NT/Globals/Memory.js +++ b/Projects/Network/NT/Globals/Memory.js @@ -4,12 +4,14 @@ exports.newNetworkGlobalsMemory = function () { */ let thisObject = { maps: { - EVENTS: new Map() // This is the registry of all events received that prevents processing them more than once. + EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once. + SIGNALS: new Map() // This is the registry of all signals received that prevents processing them more than once. }, arrays: { NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node ordered by Ranking. NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node ordered by Ranking. - EVENTS: [] // This is the registry of all events in order that prevents ordering them more than once. + EVENTS: [], // This is the registry of all events in order that prevents ordering them more than once. + SIGNALS: [] // This is the registry of all signals in order that prevents ordering them more than once. } } From 0eb8a16c60147b79d19772385a47d9e75c737383 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 11:10:28 +0100 Subject: [PATCH 03/11] Signal.js --- Projects/ProjectsSchema.json | 6 + Projects/Social-Trading/NT/Modules/Event.js | 5 +- Projects/Social-Trading/NT/Modules/Signal.js | 403 +++++++++++++++++++ 3 files changed, 411 insertions(+), 3 deletions(-) create mode 100644 Projects/Social-Trading/NT/Modules/Signal.js diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index e2eb56473..d2d21442c 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1528,6 +1528,12 @@ "functionName": "newSocialTradingModulesEvent", "fileName": "Event.js" }, + { + "name": "Signal", + "propertyName": "signal", + "functionName": "newSocialTradingModulesSignal", + "fileName": "Signal.js" + }, { "name": "Client Interface", "propertyName": "clientInterface", diff --git a/Projects/Social-Trading/NT/Modules/Event.js b/Projects/Social-Trading/NT/Modules/Event.js index 9902cbf0e..764e77c8b 100644 --- a/Projects/Social-Trading/NT/Modules/Event.js +++ b/Projects/Social-Trading/NT/Modules/Event.js @@ -1,8 +1,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { /* - An Event is anything that happens system wide that - needs to be delivered to relevant entities via - the Superalgos Network. + An Event is an action taken by users that triggers a + change at the social graph. An Event (in contrast to a Query) produces a change on the state of the social graph. diff --git a/Projects/Social-Trading/NT/Modules/Signal.js b/Projects/Social-Trading/NT/Modules/Signal.js new file mode 100644 index 000000000..df2f6c2f0 --- /dev/null +++ b/Projects/Social-Trading/NT/Modules/Signal.js @@ -0,0 +1,403 @@ +exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() { + /* + An Signal is an action taken by users that triggers a + change at the social graph. + + An Signal (in contrast to a Query) produces a change + on the state of the social graph. + */ + let thisObject = { + /* Unique Key */ + signalId: undefined, + /* Referenced Entities Unique Keys */ + emitterUserProfileId: undefined, + targetUserProfileId: undefined, + emitterBotProfileId: undefined, + targetBotProfileId: undefined, + emitterPostHash: undefined, + targetPostHash: undefined, + /* Signal Unique Properties */ + signalType: undefined, + timestamp: undefined, + /* Bot Related Properties */ + botAsset: undefined, + botExchange: undefined, + botEnabled: undefined, + /* Framework Functions */ + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize(signalReceived) { + /* + Store the message properties into this object properties. + */ + thisObject.signalId = signalReceived.signalId + thisObject.emitterUserProfileId = signalReceived.emitterUserProfileId + thisObject.targetUserProfileId = signalReceived.targetUserProfileId + thisObject.emitterBotProfileId = signalReceived.emitterBotProfileId + thisObject.targetBotProfileId = signalReceived.targetBotProfileId + thisObject.emitterPostHash = signalReceived.emitterPostHash + thisObject.targetPostHash = signalReceived.targetPostHash + thisObject.signalType = signalReceived.signalType + thisObject.timestamp = signalReceived.timestamp + thisObject.botAsset = signalReceived.botAsset + thisObject.botExchange = signalReceived.botExchange + thisObject.botEnabled = signalReceived.botEnabled + /* + Local Variables + */ + let emitterUserProfile + let targetUserProfile + let emitterBotProfile + let targetBotProfile + /* + Validate Emitter User Profile. + */ + if (thisObject.emitterUserProfileId === undefined) { + throw ('Emitter User Profile Id Not Provided.') + } + emitterUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) + if (emitterUserProfile === undefined) { + throw ('Emitter User Profile Not Found.') + } + /* + Validate Target User Profile. + */ + if (thisObject.targetUserProfileId !== undefined) { + targetUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + if (targetUserProfile === undefined) { + throw ('Target User Profile Not Found.') + } + } + /* + Validate Emitter Bot Profile. + */ + if (thisObject.emitterBotProfileId !== undefined) { + emitterBotProfile = emitterUserProfile.bots.get(thisObject.emitterBotProfileId) + if (emitterBotProfile === undefined) { + throw ('Emitter Bot Profile Not Found.') + } + } + /* + Validate Target Bot Profile. + */ + if (thisObject.targetBotProfileId !== undefined) { + targetBotProfile = emitterUserProfile.bots.get(thisObject.targetBotProfileId) + if (targetBotProfile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } + + if (postingSignals()) { + signalCounters() + return + } + if (followingSignals()) { + signalCounters() + return + } + if (reactionSignals()) { + signalCounters() + return + } + if (botSignals()) { + signalCounters() + return + } + + function postingSignals() { + /* + Is is related to Posting? + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_BOT_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_BOT_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_BOT_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_BOT_POST + ) { + /* + New User Post + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_USER_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_USER_POST + ) { + emitterUserProfile.addPost( + thisObject.emitterUserProfileId, + thisObject.targetUserProfileId, + thisObject.emitterPostHash, + thisObject.targetPostHash, + thisObject.signalType - 10, + thisObject.timestamp + ) + return true + } + /* + New Bot Post + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_BOT_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_BOT_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_BOT_POST || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_BOT_POST + ) { + if (emitterBotProfile === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + emitterBotProfile.addPost( + thisObject.emitterUserProfileId, + thisObject.targetUserProfileId, + thisObject.emitterBotProfileId, + thisObject.targetBotProfileId, + thisObject.emitterPostHash, + thisObject.targetPostHash, + thisObject.signalType - 20, + thisObject.timestamp + ) + return true + } + /* + Remove User Post + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_USER_POST + ) { + emitterUserProfile.removePost( + thisObject.emitterPostHash + ) + return true + } + /* + Remove Bot Post + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_BOT_POST + ) { + if (emitterBotProfile === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + emitterBotProfile.removePost( + thisObject.emitterPostHash + ) + return true + } + } + } + + function followingSignals() { + /* + Is is a following? + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.FOLLOW_USER_PROFILE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_USER_PROFILE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.FOLLOW_BOT_PROFILE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_BOT_PROFILE + ) { + switch (thisObject.signalType) { + case SA.projects.socialTrading.globals.signalTypes.FOLLOW_USER_PROFILE: { + + if (thisObject.emitterUserProfileId === undefined) { + throw ('Emitter User Profile Id Not Provided.') + } + + if (thisObject.targetUserProfileId === undefined) { + throw ('Target User Profile Id Not Provided.') + } + + emitterUserProfile.addFollowing( + thisObject.targetUserProfileId + ) + targetUserProfile.addFollower( + thisObject.emitterUserProfileId + ) + break + } + case SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_USER_PROFILE: { + + if (thisObject.emitterUserProfileId === undefined) { + throw ('Emitter User Profile Id Not Provided.') + } + + if (thisObject.targetUserProfileId === undefined) { + throw ('Target User Profile Id Not Provided.') + } + + emitterUserProfile.removeFollowing( + thisObject.targetUserProfileId + ) + targetUserProfile.removeFollower( + thisObject.emitterUserProfileId + ) + break + } + case SA.projects.socialTrading.globals.signalTypes.FOLLOW_BOT_PROFILE: { + + if (thisObject.emitterBotProfileId === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + if (thisObject.targetBotProfileId === undefined) { + throw ('Target Bot Profile Id Not Provided.') + } + + emitterBotProfile.addFollowing( + thisObject.targetUserProfileId, + thisObject.targetBotProfileId + ) + targetBotProfile.addFollower( + thisObject.emitterUserProfileId, + thisObject.emitterBotProfileId + ) + break + } + case SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_BOT_PROFILE: { + + if (thisObject.emitterBotProfileId === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + if (thisObject.targetBotProfileId === undefined) { + throw ('Target Bot Profile Id Not Provided.') + } + + emitterBotProfile.removeFollowing( + thisObject.targetBotProfileId + ) + targetBotProfile.removeFollower( + thisObject.emitterBotProfileId + ) + break + } + } + return true + } + } + + function reactionSignals() { + /* + Is is a Reaction? + */ + let targetPost + + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_LIKE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_LOVE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_HAHA || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_WOW || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_SAD || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_ANGRY || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_CARE + ) { + + if (targetBotProfile !== undefined) { + targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) + } else { + targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) + } + + if (targetPost === undefined) { + throw ('Target Post Not Found') + } + + targetPost.addReaction(thisObject.signalType - 100) + return true + } + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_LIKE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_LOVE || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_HAHA || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_WOW || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_SAD || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_ANGRY || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_CARE + ) { + + if (targetBotProfile !== undefined) { + targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) + } else { + targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) + } + + if (targetPost === undefined) { + throw ('Target Post Not Found') + } + + targetPost.removeReaction(thisObject.signalType - 200) + return true + } + } + + function botSignals() { + /* + Is is a Bot? + */ + if ( + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_BOT || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_BOT || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ENABLE_BOT || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.DISABLE_BOT + ) { + switch (thisObject.signalType) { + case SA.projects.socialTrading.globals.signalTypes.ADD_BOT: { + emitterUserProfile.addBot( + thisObject.emitterUserProfileId, + thisObject.emitterBotProfileId, + thisObject.botAsset, + thisObject.botExchange, + thisObject.botEnabled + ) + break + } + case SA.projects.socialTrading.globals.signalTypes.REMOVE_BOT: { + emitterUserProfile.removeBot( + thisObject.emitterBotProfileId + ) + break + } + case SA.projects.socialTrading.globals.signalTypes.ENABLE_BOT: { + emitterUserProfile.enableBot( + thisObject.emitterBotProfileId + ) + break + } + case SA.projects.socialTrading.globals.signalTypes.DISABLE_BOT: { + emitterUserProfile.disableBot( + thisObject.emitterBotProfileId + ) + break + } + } + return true + } + } + + function signalCounters() { + emitterUserProfile.emitterSignalsCount++ + if (targetUserProfile !== undefined) { + targetUserProfile.targetSignalsCount++ + } + if (emitterBotProfile !== undefined) { + emitterUserProfile.emitterSignalsCount++ + } + if (targetBotProfile !== undefined) { + targetBotProfile.targetSignalsCount++ + } + } + } +} \ No newline at end of file From e39ec7b282a5f36d34df86364b07a68443e738fd Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 11:19:02 +0100 Subject: [PATCH 04/11] typo --- Projects/Social-Trading/NT/Modules/Event.js | 8 ++++---- Projects/Social-Trading/NT/Modules/Signal.js | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Projects/Social-Trading/NT/Modules/Event.js b/Projects/Social-Trading/NT/Modules/Event.js index 764e77c8b..91f9b814b 100644 --- a/Projects/Social-Trading/NT/Modules/Event.js +++ b/Projects/Social-Trading/NT/Modules/Event.js @@ -114,7 +114,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { function postingEvents() { /* - Is is related to Posting? + Is it related to Posting? */ if ( thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.NEW_USER_POST || @@ -201,7 +201,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { function followingEvents() { /* - Is is a following? + Is it a following? */ if ( thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE || @@ -291,7 +291,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { function reactionEvents() { /* - Is is a Reaction? + Is it a Reaction? */ let targetPost @@ -345,7 +345,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { function botEvents() { /* - Is is a Bot? + Is it a Bot? */ if ( thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_BOT || diff --git a/Projects/Social-Trading/NT/Modules/Signal.js b/Projects/Social-Trading/NT/Modules/Signal.js index df2f6c2f0..d2d296094 100644 --- a/Projects/Social-Trading/NT/Modules/Signal.js +++ b/Projects/Social-Trading/NT/Modules/Signal.js @@ -1,10 +1,12 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() { /* - An Signal is an action taken by users that triggers a - change at the social graph. + A Signal is an action taken by a bot that needs to be + delivered to all the followers of that bot respecting + the rule to deliver it fist to the bots belonging to + users with the highers ranking. - An Signal (in contrast to a Query) produces a change - on the state of the social graph. + An Signal is attached to the Social Graph as a new post + from the Bot producing the signal. */ let thisObject = { /* Unique Key */ @@ -114,7 +116,7 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() function postingSignals() { /* - Is is related to Posting? + Is it related to Posting? */ if ( thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_USER_POST || @@ -201,7 +203,7 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() function followingSignals() { /* - Is is a following? + Is it a following? */ if ( thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.FOLLOW_USER_PROFILE || @@ -291,7 +293,7 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() function reactionSignals() { /* - Is is a Reaction? + Is it a Reaction? */ let targetPost @@ -345,7 +347,7 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() function botSignals() { /* - Is is a Bot? + Is it a Bot? */ if ( thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_BOT || From ace0f17ca86daa21bf7c8ae1551f3f5313a5cace Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 11:47:46 +0100 Subject: [PATCH 05/11] Signals Js --- Projects/ProjectsSchema.json | 6 + Projects/Social-Trading/NT/Modules/Signal.js | 300 ++---------------- .../Social-Trading/SA/Globals/SignalTypes.js | 12 + 3 files changed, 41 insertions(+), 277 deletions(-) create mode 100644 Projects/Social-Trading/SA/Globals/SignalTypes.js diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index d2d21442c..3b41c6d7b 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1601,6 +1601,12 @@ "propertyName": "eventTypes", "functionName": "newSocialTradingGlobalsEventTypes", "fileName": "EventTypes.js" + }, + { + "name": "Signal Types", + "propertyName": "eventTypes", + "functionName": "newSocialTradingGlobalsSignalTypes", + "fileName": "SignalTypes.js" } ] }, diff --git a/Projects/Social-Trading/NT/Modules/Signal.js b/Projects/Social-Trading/NT/Modules/Signal.js index d2d296094..1e9dbc537 100644 --- a/Projects/Social-Trading/NT/Modules/Signal.js +++ b/Projects/Social-Trading/NT/Modules/Signal.js @@ -20,6 +20,7 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() targetPostHash: undefined, /* Signal Unique Properties */ signalType: undefined, + signalData: undefined, timestamp: undefined, /* Bot Related Properties */ botAsset: undefined, @@ -48,6 +49,7 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() thisObject.emitterPostHash = signalReceived.emitterPostHash thisObject.targetPostHash = signalReceived.targetPostHash thisObject.signalType = signalReceived.signalType + thisObject.signalData = signalReceived.signalData thisObject.timestamp = signalReceived.timestamp thisObject.botAsset = signalReceived.botAsset thisObject.botExchange = signalReceived.botExchange @@ -97,298 +99,42 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() } } - if (postingSignals()) { + if (tradingSignals()) { signalCounters() - return - } - if (followingSignals()) { - signalCounters() - return - } - if (reactionSignals()) { - signalCounters() - return - } - if (botSignals()) { - signalCounters() - return + return } - function postingSignals() { + function tradingSignals() { /* - Is it related to Posting? + Is it related to Trading? */ if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_BOT_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_BOT_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_BOT_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_BOT_POST + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.TRIGGER_ON || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.TRIGGER_OFF || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.TAKE_POSITION || + thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.CLOSE_POSITION ) { /* - New User Post + We will create a new Bot Post with the Signal info attached to it. */ - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_USER_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_USER_POST - ) { - emitterUserProfile.addPost( - thisObject.emitterUserProfileId, - thisObject.targetUserProfileId, - thisObject.emitterPostHash, - thisObject.targetPostHash, - thisObject.signalType - 10, - thisObject.timestamp - ) - return true + if (emitterBotProfile === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') } - /* - New Bot Post - */ - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.NEW_BOT_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPLY_TO_BOT_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REPOST_BOT_POST || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.QUOTE_REPOST_BOT_POST - ) { - if (emitterBotProfile === undefined) { - throw ('Emitter Bot Profile Id Not Provided.') - } - emitterBotProfile.addPost( - thisObject.emitterUserProfileId, - thisObject.targetUserProfileId, - thisObject.emitterBotProfileId, - thisObject.targetBotProfileId, - thisObject.emitterPostHash, - thisObject.targetPostHash, - thisObject.signalType - 20, - thisObject.timestamp - ) - return true - } - /* - Remove User Post - */ - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_USER_POST - ) { - emitterUserProfile.removePost( - thisObject.emitterPostHash - ) - return true - } - /* - Remove Bot Post - */ - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_BOT_POST - ) { - if (emitterBotProfile === undefined) { - throw ('Emitter Bot Profile Id Not Provided.') - } - - emitterBotProfile.removePost( - thisObject.emitterPostHash - ) - return true - } - } - } - - function followingSignals() { - /* - Is it a following? - */ - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.FOLLOW_USER_PROFILE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_USER_PROFILE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.FOLLOW_BOT_PROFILE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_BOT_PROFILE - ) { - switch (thisObject.signalType) { - case SA.projects.socialTrading.globals.signalTypes.FOLLOW_USER_PROFILE: { - - if (thisObject.emitterUserProfileId === undefined) { - throw ('Emitter User Profile Id Not Provided.') - } - - if (thisObject.targetUserProfileId === undefined) { - throw ('Target User Profile Id Not Provided.') - } - - emitterUserProfile.addFollowing( - thisObject.targetUserProfileId - ) - targetUserProfile.addFollower( - thisObject.emitterUserProfileId - ) - break - } - case SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_USER_PROFILE: { - - if (thisObject.emitterUserProfileId === undefined) { - throw ('Emitter User Profile Id Not Provided.') - } - - if (thisObject.targetUserProfileId === undefined) { - throw ('Target User Profile Id Not Provided.') - } - - emitterUserProfile.removeFollowing( - thisObject.targetUserProfileId - ) - targetUserProfile.removeFollower( - thisObject.emitterUserProfileId - ) - break - } - case SA.projects.socialTrading.globals.signalTypes.FOLLOW_BOT_PROFILE: { - - if (thisObject.emitterBotProfileId === undefined) { - throw ('Emitter Bot Profile Id Not Provided.') - } - - if (thisObject.targetBotProfileId === undefined) { - throw ('Target Bot Profile Id Not Provided.') - } - - emitterBotProfile.addFollowing( - thisObject.targetUserProfileId, - thisObject.targetBotProfileId - ) - targetBotProfile.addFollower( - thisObject.emitterUserProfileId, - thisObject.emitterBotProfileId - ) - break - } - case SA.projects.socialTrading.globals.signalTypes.UNFOLLOW_BOT_PROFILE: { - - if (thisObject.emitterBotProfileId === undefined) { - throw ('Emitter Bot Profile Id Not Provided.') - } - - if (thisObject.targetBotProfileId === undefined) { - throw ('Target Bot Profile Id Not Provided.') - } - - emitterBotProfile.removeFollowing( - thisObject.targetBotProfileId - ) - targetBotProfile.removeFollower( - thisObject.emitterBotProfileId - ) - break - } - } + emitterBotProfile.addPost( + thisObject.emitterUserProfileId, + thisObject.targetUserProfileId, + thisObject.emitterBotProfileId, + thisObject.targetBotProfileId, + thisObject.emitterPostHash, + thisObject.targetPostHash, + thisObject.signalType - 20, + thisObject.timestamp + ) return true } } - function reactionSignals() { - /* - Is it a Reaction? - */ - let targetPost - - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_LIKE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_LOVE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_HAHA || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_WOW || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_SAD || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_ANGRY || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_REACTION_CARE - ) { - - if (targetBotProfile !== undefined) { - targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) - } else { - targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) - } - - if (targetPost === undefined) { - throw ('Target Post Not Found') - } - - targetPost.addReaction(thisObject.signalType - 100) - return true - } - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_LIKE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_LOVE || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_HAHA || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_WOW || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_SAD || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_ANGRY || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_REACTION_CARE - ) { - - if (targetBotProfile !== undefined) { - targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) - } else { - targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) - } - - if (targetPost === undefined) { - throw ('Target Post Not Found') - } - - targetPost.removeReaction(thisObject.signalType - 200) - return true - } - } - - function botSignals() { - /* - Is it a Bot? - */ - if ( - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ADD_BOT || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.REMOVE_BOT || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.ENABLE_BOT || - thisObject.signalType === SA.projects.socialTrading.globals.signalTypes.DISABLE_BOT - ) { - switch (thisObject.signalType) { - case SA.projects.socialTrading.globals.signalTypes.ADD_BOT: { - emitterUserProfile.addBot( - thisObject.emitterUserProfileId, - thisObject.emitterBotProfileId, - thisObject.botAsset, - thisObject.botExchange, - thisObject.botEnabled - ) - break - } - case SA.projects.socialTrading.globals.signalTypes.REMOVE_BOT: { - emitterUserProfile.removeBot( - thisObject.emitterBotProfileId - ) - break - } - case SA.projects.socialTrading.globals.signalTypes.ENABLE_BOT: { - emitterUserProfile.enableBot( - thisObject.emitterBotProfileId - ) - break - } - case SA.projects.socialTrading.globals.signalTypes.DISABLE_BOT: { - emitterUserProfile.disableBot( - thisObject.emitterBotProfileId - ) - break - } - } - return true - } - } - function signalCounters() { emitterUserProfile.emitterSignalsCount++ if (targetUserProfile !== undefined) { diff --git a/Projects/Social-Trading/SA/Globals/SignalTypes.js b/Projects/Social-Trading/SA/Globals/SignalTypes.js new file mode 100644 index 000000000..a97750de1 --- /dev/null +++ b/Projects/Social-Trading/SA/Globals/SignalTypes.js @@ -0,0 +1,12 @@ +exports.newSocialTradingGlobalsSignalTypes = function () { + + let thisObject = { + /* Trading Signals */ + TRIGGER_ON: 10, + TRIGGER_OFF: 11, + TAKE_POSITION: 12, + CLOSE_POSITION: 13 + } + + return thisObject +} \ No newline at end of file From e54be502c9be2e0dfe41506ee400dae009419af9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 12:05:40 +0100 Subject: [PATCH 06/11] Post and Reaction Types --- Projects/ProjectsSchema.json | 12 ++++++ .../Social-Trading/SA/Globals/PostTypes.js | 12 ++++++ .../SA/Globals/ReactionTypes.js | 15 +++++++ .../SA/Modules/Social-Graph/Post.js | 41 ++++++------------- 4 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 Projects/Social-Trading/SA/Globals/PostTypes.js create mode 100644 Projects/Social-Trading/SA/Globals/ReactionTypes.js diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 3b41c6d7b..3fd1d2c7d 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1607,6 +1607,18 @@ "propertyName": "eventTypes", "functionName": "newSocialTradingGlobalsSignalTypes", "fileName": "SignalTypes.js" + }, + { + "name": "Post Types", + "propertyName": "postTypes", + "functionName": "newSocialTradingGlobalsPostTypes", + "fileName": "PostTypes.js" + }, + { + "name": "Reaction Types", + "propertyName": "reactionTypes", + "functionName": "newSocialTradingGlobalsReactionTypes", + "fileName": "ReactionTypes.js" } ] }, diff --git a/Projects/Social-Trading/SA/Globals/PostTypes.js b/Projects/Social-Trading/SA/Globals/PostTypes.js new file mode 100644 index 000000000..19135688d --- /dev/null +++ b/Projects/Social-Trading/SA/Globals/PostTypes.js @@ -0,0 +1,12 @@ +exports.newSocialTradingGlobalsPostTypes = function () { + + let thisObject = { + /* Post Types */ + NEW_POST: 0, + REPLY_TO_POST: 1, + REPOST_: 2, + QUOTE_REPOST_: 3 + } + + return thisObject +} \ No newline at end of file diff --git a/Projects/Social-Trading/SA/Globals/ReactionTypes.js b/Projects/Social-Trading/SA/Globals/ReactionTypes.js new file mode 100644 index 000000000..44c4b9c03 --- /dev/null +++ b/Projects/Social-Trading/SA/Globals/ReactionTypes.js @@ -0,0 +1,15 @@ +exports.newSocialTradingGlobalsReactionTypes = function () { + + let thisObject = { + /* Reaction Types */ + REACTION_LIKE: 0, + REACTION_LOVE: 1, + REACTION_HAHA: 2, + REACTION_WOW: 3, + REACTION_SAD: 4, + REACTION_ANGRY: 5, + REACTION_CARE: 6 + } + + return thisObject +} \ No newline at end of file diff --git a/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js b/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js index f3678cc62..eac354289 100644 --- a/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js +++ b/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js @@ -1,6 +1,6 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModulesSocialGraphPost() { /* - Posts represent a collection of multimedia content sorted somewhere else + Posts represent a collection of multimedia content stored somewhere else and identified by that content hash. Posts might belong to: * a User Profile. * a Bot Profile. @@ -34,33 +34,16 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule finalize: finalize } - const POST_TYPES = { - NEW_POST: 0, - REPLY_TO_POST: 1, - REPOST_: 2, - QUOTE_REPOST_: 3 - } - - const REACTION_TYPES = { - REACTION_LIKE: 0, - REACTION_LOVE: 1, - REACTION_HAHA: 2, - REACTION_WOW: 3, - REACTION_SAD: 4, - REACTION_ANGRY: 5, - REACTION_CARE: 6 - } - thisObject.replies = new Map() thisObject.reactions = new Map() - thisObject.reactions.set(REACTION_TYPES.REACTION_LIKE, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_LOVE, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_HAHA, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_WOW, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_SAD, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_ANGRY, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_CARE, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_LIKE, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_LOVE, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_HAHA, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_WOW, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_SAD, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_ANGRY, 0) + thisObject.reactions.set(SA.projects.socialTrading.globals.reactionTypes.REACTION_CARE, 0) return thisObject @@ -92,9 +75,9 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule Let's find the Target Post */ if ( - thisObject.postType === POST_TYPES.REPLY_TO_POST || - thisObject.postType === POST_TYPES.REPOST_ || - thisObject.postType === POST_TYPES.QUOTE_REPOST_ + thisObject.postType === SA.projects.socialTrading.globals.postTypes.REPLY_TO_POST || + thisObject.postType === SA.projects.socialTrading.globals.postTypes.REPOST_ || + thisObject.postType === SA.projects.socialTrading.globals.postTypes.QUOTE_REPOST_ ) { /* Validate Target User Profile. @@ -113,7 +96,7 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule Let's add this post to the replies of the Target Post */ if ( - thisObject.postType === POST_TYPES.REPLY_TO_POST + thisObject.postType === SA.projects.socialTrading.globals.postTypes.REPLY_TO_POST ) { targetPost.replies.set(thisObject.targetPostHash, thisObject.targetPostHash) } From 9fab335a303bd98d00ffd2c44a2cc72e321017f4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 12:14:42 +0100 Subject: [PATCH 07/11] Storing Signal Data at the Social Graph --- Projects/Social-Trading/NT/Modules/Signal.js | 6 ++++-- Projects/Social-Trading/SA/Globals/PostTypes.js | 5 +++-- .../SA/Modules/Social-Graph/BotProfile.js | 8 ++++++-- .../Social-Trading/SA/Modules/Social-Graph/Post.js | 13 ++++++++++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Projects/Social-Trading/NT/Modules/Signal.js b/Projects/Social-Trading/NT/Modules/Signal.js index 1e9dbc537..80278e153 100644 --- a/Projects/Social-Trading/NT/Modules/Signal.js +++ b/Projects/Social-Trading/NT/Modules/Signal.js @@ -128,8 +128,10 @@ exports.newSocialTradingModulesSignal = function newSocialTradingModulesSignal() thisObject.targetBotProfileId, thisObject.emitterPostHash, thisObject.targetPostHash, - thisObject.signalType - 20, - thisObject.timestamp + SA.projects.socialTrading.globals.postTypes.SIGNAL_POST, + thisObject.timestamp, + thisObject.signalType, + thisObject.signalData ) return true } diff --git a/Projects/Social-Trading/SA/Globals/PostTypes.js b/Projects/Social-Trading/SA/Globals/PostTypes.js index 19135688d..8146c04c3 100644 --- a/Projects/Social-Trading/SA/Globals/PostTypes.js +++ b/Projects/Social-Trading/SA/Globals/PostTypes.js @@ -4,8 +4,9 @@ exports.newSocialTradingGlobalsPostTypes = function () { /* Post Types */ NEW_POST: 0, REPLY_TO_POST: 1, - REPOST_: 2, - QUOTE_REPOST_: 3 + REPOST: 2, + QUOTE_REPOST: 3, + SIGNAL_POST: 4 } return thisObject diff --git a/Projects/Social-Trading/SA/Modules/Social-Graph/BotProfile.js b/Projects/Social-Trading/SA/Modules/Social-Graph/BotProfile.js index 886bcd53d..eee366470 100644 --- a/Projects/Social-Trading/SA/Modules/Social-Graph/BotProfile.js +++ b/Projects/Social-Trading/SA/Modules/Social-Graph/BotProfile.js @@ -75,7 +75,9 @@ exports.newSocialTradingModulesSocialGraphBotProfile = function newSocialTrading emitterPostHash, targetPostHash, postType, - timestamp + timestamp, + signalType, + signalData ) { if (thisObject.posts.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') @@ -89,7 +91,9 @@ exports.newSocialTradingModulesSocialGraphBotProfile = function newSocialTrading emitterPostHash, targetPostHash, postType, - timestamp + timestamp, + signalType, + signalData ) thisObject.posts.set(emitterPostHash, post) diff --git a/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js b/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js index eac354289..ecd515087 100644 --- a/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js +++ b/Projects/Social-Trading/SA/Modules/Social-Graph/Post.js @@ -23,6 +23,9 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule /* Post Unique Properties */ postType: undefined, timestamp: undefined, + /* Signal Related Properties */ + signalType: undefined, + signalData: undefined, /* Maps */ replies: undefined, reactions: undefined, @@ -60,7 +63,9 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule emitterPostHash, targetPostHash, postType, - timestamp + timestamp, + signalType, + signalData ) { thisObject.emitterUserProfileId = emitterUserProfileId @@ -71,13 +76,15 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule thisObject.targetPostHash = targetPostHash thisObject.postType = postType thisObject.timestamp = timestamp + thisObject.signalType = signalType + thisObject.signalData = signalData /* Let's find the Target Post */ if ( thisObject.postType === SA.projects.socialTrading.globals.postTypes.REPLY_TO_POST || - thisObject.postType === SA.projects.socialTrading.globals.postTypes.REPOST_ || - thisObject.postType === SA.projects.socialTrading.globals.postTypes.QUOTE_REPOST_ + thisObject.postType === SA.projects.socialTrading.globals.postTypes.REPOST || + thisObject.postType === SA.projects.socialTrading.globals.postTypes.QUOTE_REPOST ) { /* Validate Target User Profile. From e91e135ef71a44a6b76f60343c7366d320e7b92c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 12:19:51 +0100 Subject: [PATCH 08/11] Post queries --- Projects/Social-Trading/NT/Modules/Queries/PostReplies.js | 2 ++ Projects/Social-Trading/NT/Modules/Queries/ProfilePosts.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Projects/Social-Trading/NT/Modules/Queries/PostReplies.js b/Projects/Social-Trading/NT/Modules/Queries/PostReplies.js index d9af6ea72..cb29d0d9b 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/PostReplies.js +++ b/Projects/Social-Trading/NT/Modules/Queries/PostReplies.js @@ -72,6 +72,8 @@ exports.newSocialTradingModulesQueriesPostReplies = function newSocialTradingMod targetPostHash: post.targetPostHash, postType: post.postType, timestamp: post.timestamp, + signalType: post.signalType, + signalData: post.signalData, repliesCount: post.replies.size, reactions: Array.from(post.reactions) } diff --git a/Projects/Social-Trading/NT/Modules/Queries/ProfilePosts.js b/Projects/Social-Trading/NT/Modules/Queries/ProfilePosts.js index a1971be61..68c52ac33 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/ProfilePosts.js +++ b/Projects/Social-Trading/NT/Modules/Queries/ProfilePosts.js @@ -67,6 +67,8 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi targetPostHash: post.targetPostHash, postType: post.postType, timestamp: post.timestamp, + signalType: post.signalType, + signalData: post.signalData, repliesCount: post.replies.size, reactions: Array.from(post.reactions) } From 6495cd77de79eb1a2695367cc61ac8f97af3fc77 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 13 Nov 2021 14:50:24 +0100 Subject: [PATCH 09/11] httpInterface at Node implemented --- Environment.js | 1 + Network/NetwokNode.js | 7 +++ .../User-Profiles/Luis-Fernando-Molina.json | 6 +-- .../Schemas/App-Schema/p2p-network-node.json | 2 +- Projects/Network/NT/Modules/HttpInterface.js | 52 +++++++++++++++++++ Projects/ProjectsSchema.json | 8 ++- .../NT/Modules/ClientInterface.js | 4 +- 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 Projects/Network/NT/Modules/HttpInterface.js diff --git a/Environment.js b/Environment.js index a599d095e..78846c598 100644 --- a/Environment.js +++ b/Environment.js @@ -17,6 +17,7 @@ exports.newEnvironment = function () { DESKTOP_WEB_SOCKETS_INTERFACE_HOST: 'localhost', PLATFORM_HTTP_INTERFACE_PORT: 34248, DESKTOP_HTTP_INTERFACE_PORT: 33248, + NETWORK_HTTP_INTERFACE_PORT: 31248, PATH_TO_DATA_STORAGE: path.join(basePath, './Platform/My-Data-Storage'), PATH_TO_PROJECTS: path.join(basePath, './Projects'), PATH_TO_LOG_FILES: path.join(basePath, './Platform/My-Log-Files'), diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index 4bd5f705c..c4301e112 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -6,6 +6,7 @@ exports.newNetworkNode = function newNetworkNode() { p2pNetworkPeers: undefined, p2pNetworkNode: undefined, webSocketsInterface: undefined, + httpInterface: undefined, socialGraphService: undefined, storage: undefined, run: run @@ -65,6 +66,12 @@ exports.newNetworkNode = function newNetworkNode() { thisObject.webSocketsInterface = NT.projects.network.modules.webSocketsInterface.newNetworkModulesWebSocketsInterface() thisObject.webSocketsInterface.initialize() console.log('Network Node Web Sockets Interface ........................................... Listening at port ' + JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webSocketsPort) + /* + Other Network Nodes and Client Apps will communicate with this Network Node via it's HTTP Interface. + */ + thisObject.webSocketsInterface = NT.projects.network.modules.webHttpInterface.newNetworkModulesHttpInterface() + thisObject.webSocketsInterface.initialize() + console.log('Network Node Http Interface .................................................. Listening at port ' + JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webPort) } } } diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 14668a46b..a60755b4f 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -17236,7 +17236,7 @@ "signingAccountChild": { "type": "P2P Network Node", "name": "P2P Network Node # 1", - "config": "{\n \"codeName\": \"P2P-Network-Node-1\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18042\"\n}", + "config": "{\n \"codeName\": \"P2P-Network-Node-1\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18042\",\n \"webPort\": \"31248\"\n}", "project": "Governance", "id": "bb0f0417-9dfb-47a3-941f-dcfa82fbaea1", "savedPayload": { @@ -17292,7 +17292,7 @@ "signingAccountChild": { "type": "P2P Network Node", "name": "P2P Network Node # 2", - "config": "{\n \"codeName\": \"P2P-Network-Node-2\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18043\"\n}", + "config": "{\n \"codeName\": \"P2P-Network-Node-2\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18043\",\n \"webPort\": \"31248\"\n}", "project": "Governance", "id": "76fa8a24-9ab4-4eaf-82f2-458ba557b204", "savedPayload": { @@ -17348,7 +17348,7 @@ "signingAccountChild": { "type": "P2P Network Node", "name": "P2P Network Node # 3", - "config": "{\n \"codeName\": \"P2P-Network-Node-3\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18044\"\n}", + "config": "{\n \"codeName\": \"P2P-Network-Node-3\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18044\",\n \"webPort\": \"31248\"\n}", "project": "Governance", "id": "297e57c2-3c1a-4170-b710-d2705804205b", "savedPayload": { diff --git a/Projects/Governance/Schemas/App-Schema/p2p-network-node.json b/Projects/Governance/Schemas/App-Schema/p2p-network-node.json index ae7aeb2d4..17f1a4838 100644 --- a/Projects/Governance/Schemas/App-Schema/p2p-network-node.json +++ b/Projects/Governance/Schemas/App-Schema/p2p-network-node.json @@ -25,7 +25,7 @@ "config": true }, "initialValues": { - "config": "{ \n\"codeName\": \"localhost\", \n\"host\": \"localhost\", \n\"webSocketsPort\": \"18042\"\n}" + "config": "{ \n\"codeName\": \"localhost\", \n\"host\": \"localhost\", \n\"webPort\": \"31248\", \n\"webSocketsPort\": \"18042\"\n}" }, "addLeftIcons": true, "level": 1, diff --git a/Projects/Network/NT/Modules/HttpInterface.js b/Projects/Network/NT/Modules/HttpInterface.js new file mode 100644 index 000000000..aed274b25 --- /dev/null +++ b/Projects/Network/NT/Modules/HttpInterface.js @@ -0,0 +1,52 @@ +exports.newNetworkModulesHttpInterface = function newNetworkModulesHttpInterface() { + /* + This module represent the HTTP API of the + NNetwork Node. All HTTP request are processed + by this module. + */ + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + } + + function initialize() { + let port = JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webPort + /* + We will create an HTTP Server and leave it running forever. + */ + SA.nodeModules.http.createServer(onHttpRequest).listen(port) + } + + function onHttpRequest(httpRequest, httpResponse) { + try { + let requestPathAndParameters = httpRequest.url.split('?') // Remove version information + let requestPath = requestPathAndParameters[0].split('/') + let endpointOrFile = requestPath[1] + + switch (endpointOrFile) { + case 'Signal': + { + let message = requestPath[2] + let response = await thisObject.clientInterface.messageReceived(message) + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(response), httpResponse) + } + break + case 'Stats': + { + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify([]), httpResponse) + } + break + default: + { + } + } + } catch (err) { + console.log(err.stack) + } + } +} diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 3fd1d2c7d..ca78a8f61 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1389,6 +1389,12 @@ "propertyName": "webSocketsInterface", "functionName": "newNetworkModulesWebSocketsInterface", "fileName": "WebSocketsInterface.js" + }, + { + "name": "Http Interface", + "propertyName": "httpInterface", + "functionName": "newNetworkModulesHttpInterface", + "fileName": "HttpInterface.js" } ], "utilities": [] @@ -1629,7 +1635,7 @@ "name": "Http Interface", "propertyName": "httpInterface", "functionName": "newDesktopModulesHttpInterface", - "fileName": "httpInterface.js" + "fileName": "HttpInterface.js" }, { "name": "Web Sockets Interface", diff --git a/Projects/Social-Trading/NT/Modules/ClientInterface.js b/Projects/Social-Trading/NT/Modules/ClientInterface.js index 0da1aa0d4..e99344c1a 100644 --- a/Projects/Social-Trading/NT/Modules/ClientInterface.js +++ b/Projects/Social-Trading/NT/Modules/ClientInterface.js @@ -64,7 +64,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule return await eventReceived(messageHeader.eventMessage, userProfile) } case 'Signal': { - return await signalReceived(messageHeader.eventMessage, userProfile) + return await signalReceived(messageHeader.eventMessage) } } } @@ -245,7 +245,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule } } - async function signalReceived(signalMessage, userProfile) { + async function signalReceived(signalMessage) { /* We expect here a JSON string with some or all of the following properties: From 8d2c9d2646538c45d8a357ba47c513025fce3872 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 14 Nov 2021 13:53:29 +0100 Subject: [PATCH 10/11] Governance System, bug fixes for web3 calls. --- Platform/Client/web3Server.js | 15 +++++++++------ .../WebServer/Images/sa-v10-logo-horiz-dark.png | Bin 0 -> 4631 bytes .../Foundations/UI/Spaces/Top-Space/TopSpace.js | 2 +- .../UI/Spaces/User-Profile-Space/UserProfile.js | 14 ++++++++++++-- Projects/Network/NT/Modules/HttpInterface.js | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 Platform/WebServer/Images/sa-v10-logo-horiz-dark.png diff --git a/Platform/Client/web3Server.js b/Platform/Client/web3Server.js index 0e4624bf5..c156b7e14 100644 --- a/Platform/Client/web3Server.js +++ b/Platform/Client/web3Server.js @@ -90,7 +90,7 @@ exports.newWeb3Server = function newWeb3Server() { let balance - let ABI = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"listAddress","type":"address"},{"name":"isBlackListed","type":"bool"}],"name":"blackListAddress","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint256"},{"name":"_supply","type":"uint256"},{"name":"tokenOwner","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"burner","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"blackListed","type":"address"},{"indexed":false,"name":"value","type":"bool"}],"name":"Blacklist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}] + let ABI = [{ "constant": true, "inputs": [], "name": "name", "outputs": [{ "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_spender", "type": "address" }, { "name": "_value", "type": "uint256" }], "name": "approve", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "totalSupply", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_from", "type": "address" }, { "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" }], "name": "transferFrom", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "decimals", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "unpause", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [{ "name": "account", "type": "address" }, { "name": "amount", "type": "uint256" }], "name": "mint", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [{ "name": "_value", "type": "uint256" }], "name": "burn", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "paused", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_spender", "type": "address" }, { "name": "_subtractedValue", "type": "uint256" }], "name": "decreaseApproval", "outputs": [{ "name": "success", "type": "bool" }], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [{ "name": "_owner", "type": "address" }], "name": "balanceOf", "outputs": [{ "name": "balance", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "listAddress", "type": "address" }, { "name": "isBlackListed", "type": "bool" }], "name": "blackListAddress", "outputs": [{ "name": "success", "type": "bool" }], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [], "name": "pause", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "owner", "outputs": [{ "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "symbol", "outputs": [{ "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" }], "name": "transfer", "outputs": [{ "name": "", "type": "bool" }], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [{ "name": "_spender", "type": "address" }, { "name": "_addedValue", "type": "uint256" }], "name": "increaseApproval", "outputs": [{ "name": "success", "type": "bool" }], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [{ "name": "_owner", "type": "address" }, { "name": "_spender", "type": "address" }], "name": "allowance", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "name": "newOwner", "type": "address" }], "name": "transferOwnership", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "name": "_name", "type": "string" }, { "name": "_symbol", "type": "string" }, { "name": "_decimals", "type": "uint256" }, { "name": "_supply", "type": "uint256" }, { "name": "tokenOwner", "type": "address" }], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "from", "type": "address" }, { "indexed": true, "name": "to", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }], "name": "Mint", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "burner", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }], "name": "Burn", "type": "event" }, { "anonymous": false, "inputs": [], "name": "Pause", "type": "event" }, { "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "previousOwner", "type": "address" }, { "indexed": true, "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "blackListed", "type": "address" }, { "indexed": false, "name": "value", "type": "bool" }], "name": "Blacklist", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "owner", "type": "address" }, { "indexed": true, "name": "spender", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }], "name": "Approval", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "from", "type": "address" }, { "indexed": true, "name": "to", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }], "name": "Transfer", "type": "event" }] const contractInst = new web3.eth.Contract(ABI, contractAddress) @@ -101,8 +101,11 @@ exports.newWeb3Server = function newWeb3Server() { await getBalance() - return balance - + return { + walletAddress: walletAddress, + balance: balance, + result: 'Ok' + } } async function getWalletBalances(host, port, interface, walletDefinition) { @@ -326,7 +329,7 @@ exports.newWeb3Server = function newWeb3Server() { async function sendTokens(number, userProfile, fromAddress, toAddress, tokenAmount) { try { - + tokenAmount = Math.trunc(tokenAmount / 1000000000000000000) console.log('') @@ -384,12 +387,12 @@ exports.newWeb3Server = function newWeb3Server() { console.log('Transaction:', rawTransaction) let result - + result = await web3.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex')) .catch(err => { console.log('[ERROR] sendSignedTransaction -> err =' + JSON.stringify(err)) }) - + console.log('Result:', result) return result } catch (err) { diff --git a/Platform/WebServer/Images/sa-v10-logo-horiz-dark.png b/Platform/WebServer/Images/sa-v10-logo-horiz-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..2eab06ccc1481e6758d32a119e1f80cd10cb9efc GIT binary patch literal 4631 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 Date: Sun, 14 Nov 2021 14:01:34 +0100 Subject: [PATCH 11/11] Network node bug fix --- Network/NetwokNode.js | 4 ++-- NetworkRoot.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index c4301e112..64dcaaa88 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -69,8 +69,8 @@ exports.newNetworkNode = function newNetworkNode() { /* Other Network Nodes and Client Apps will communicate with this Network Node via it's HTTP Interface. */ - thisObject.webSocketsInterface = NT.projects.network.modules.webHttpInterface.newNetworkModulesHttpInterface() - thisObject.webSocketsInterface.initialize() + thisObject.httpInterface = NT.projects.network.modules.httpInterface.newNetworkModulesHttpInterface() + thisObject.httpInterface.initialize() console.log('Network Node Http Interface .................................................. Listening at port ' + JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webPort) } } diff --git a/NetworkRoot.js b/NetworkRoot.js index a09e3cd62..eab6a7d4e 100644 --- a/NetworkRoot.js +++ b/NetworkRoot.js @@ -47,6 +47,7 @@ exports.newNetworkRoot = function newNetworkRoot() { fs: require('fs'), path: require('path'), util: require('util'), + http: require('http'), nodeFetch: require('node-fetch'), web3: require('web3'), ws: require('ws'),