Superalgos Network, first modules
This commit is contained in:
1 parent
d96d91049d
commit
383b9f1368
6 files changed
+227
-70
No files matched your search
+90
-20
@@ -1,36 +1,106 @@
|
|||||||
exports.newEvent = function newEvent() {
|
exports.newEvent = function newEvent() {
|
||||||
|
|
||||||
let thisObject = {
|
let thisObject = {
|
||||||
id: undefined,
|
eventId: undefined,
|
||||||
githubUsername: undefined,
|
eventType: undefined,
|
||||||
blockchainAccount: undefined,
|
emitterUserProfile: undefined,
|
||||||
following: undefined,
|
targetUserProfile: undefined,
|
||||||
followers: undefined,
|
asset: undefined,
|
||||||
followingCount: undefined,
|
timestamp: undefined,
|
||||||
followersCount: undefined,
|
|
||||||
tradeCopying: undefined,
|
|
||||||
tradeCopiers: undefined,
|
|
||||||
tradeCopyingCount: undefined,
|
|
||||||
tradeCopiersCount: undefined,
|
|
||||||
ranking: undefined,
|
|
||||||
joined: undefined,
|
|
||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
finalize: finalize
|
finalize: finalize
|
||||||
}
|
}
|
||||||
|
|
||||||
thisObject.following = new Map()
|
const EVENT_TYPES = {
|
||||||
thisObject.followers = new Map()
|
NEW_MULTI_MEDIA_POST: 10,
|
||||||
|
REPLY_TO_MULTI_MEDIA_POST: 11,
|
||||||
thisObject.tradeCopying = new Map()
|
REPOST_MULTI_MEDIA: 12,
|
||||||
thisObject.tradeCopiersCount = new Map()
|
QUOTE_REPOST_MULTI_MEDIA: 13,
|
||||||
|
FOLLOW_MULTI_MEDIA_POSTS: 14,
|
||||||
|
UNFOLLOW_MULTIMEDIA_POSTS: 15,
|
||||||
|
NEW_TRADE_POST: 20,
|
||||||
|
REPLY_TO_TRADE_POST: 21,
|
||||||
|
RE_POST_TRADE: 22,
|
||||||
|
QUOTE_REPOST_TRADE: 23,
|
||||||
|
FOLLOW_TRADE_POSTS: 24,
|
||||||
|
UNFOLLOW_TRADE_POSTS: 25,
|
||||||
|
REACTION_LIKE: 100,
|
||||||
|
REACTION_LOVE: 101,
|
||||||
|
REACTION_HAHA: 102,
|
||||||
|
REACTION_WOW: 103,
|
||||||
|
REACTION_SAD: 104,
|
||||||
|
REACTION_ANGRY: 105,
|
||||||
|
REACTION_HUG: 106
|
||||||
|
}
|
||||||
|
|
||||||
return thisObject
|
return thisObject
|
||||||
|
|
||||||
function finalize() {
|
function finalize() {
|
||||||
|
thisObject.emitterUserProfile = undefined
|
||||||
|
thisObject.targetUserProfile = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize() {
|
function initialize(eventMessage) {
|
||||||
|
/*
|
||||||
|
We expect here a JSON string with the following properties:
|
||||||
|
|
||||||
|
{
|
||||||
|
"eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
|
"eventType": 10,
|
||||||
|
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
|
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
|
"emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
|
"targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
|
"asset": "BTC",
|
||||||
|
"timestamp": 124234234234
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
let event = JSON.parse(eventMessage)
|
||||||
|
|
||||||
|
thisObject.emitterUserProfile = NT.memory.USER_PROFILES.get(event.emitterUserProfileId)
|
||||||
|
if (thisObject.emitterUserProfile === undefined) {
|
||||||
|
/* The message is ignored */
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
thisObject.targetUserProfile = NT.memory.USER_PROFILES.get(event.targetUserProfileId)
|
||||||
|
if (thisObject.targetUserProfile === undefined) {
|
||||||
|
/* The message is ignored when it does not have a target user profile and is required*/
|
||||||
|
if (
|
||||||
|
event.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST &&
|
||||||
|
event.eventType !== EVENT_TYPES.NEW_TRADE_POST
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
thisObject.eventId = event.eventId
|
||||||
|
thisObject.eventType = event.eventType
|
||||||
|
thisObject.asset = event.asset
|
||||||
|
thisObject.timestamp = event.timestamp
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case (
|
||||||
|
event.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA ||
|
||||||
|
event.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA ||
|
||||||
|
event.eventType === EVENT_TYPES.NEW_TRADE_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.RE_POST_TRADE ||
|
||||||
|
event.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE
|
||||||
|
): {
|
||||||
|
let post = NT.modules.POST.newPost()
|
||||||
|
post.initialize(
|
||||||
|
event.emitterPostHash,
|
||||||
|
event.targetPostHash,
|
||||||
|
thisObject.eventType,
|
||||||
|
thisObject.emitterUserProfile,
|
||||||
|
thisObject.asset,
|
||||||
|
thisObject.timestamp
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-28
@@ -1,28 +1,10 @@
|
|||||||
[
|
{
|
||||||
{
|
"eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
"type": "post",
|
"eventType": 10,
|
||||||
"timestamp": 12343242342,
|
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
"userProfile": "Luis-Fernando-Molina",
|
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
"asset": "BTC",
|
||||||
},
|
"timestamp": 124234234234,
|
||||||
{
|
"postHash": "dasdhqJKGdadjlasgjaGSHAJGSDjhagsg",
|
||||||
"type": "reply",
|
"postId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db"
|
||||||
"timestamp": 12343242342,
|
}
|
||||||
"userProfile": "Luis-Fernando-Molina",
|
|
||||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed",
|
|
||||||
"relatedEvent": "daawerewdhkasdSdGHGjdsasd"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "trade",
|
|
||||||
"timestamp": 12343242342,
|
|
||||||
"userProfile": "Luis-Fernando-Molina",
|
|
||||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "reaction",
|
|
||||||
"timestamp": 12343242342,
|
|
||||||
"userProfile": "Luis-Fernando-Molina",
|
|
||||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
+16
-4
@@ -1,7 +1,19 @@
|
|||||||
|
|
||||||
|
|
||||||
let usersProfiles = new Map() // Here we will store the user profiles and their statistics.
|
global.NT = {
|
||||||
let timeline = [] // A time ordered list of Posts and Trades.
|
memory: {
|
||||||
let events = new Map()
|
USER_PROFILES: new Map(), // Here we will store the user profiles and their statistics.
|
||||||
let hashGraph = {}
|
POSTS: new Map(), // This are all the posts we are keeping track of.
|
||||||
|
EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once.
|
||||||
|
TIMELINE: [] // A time ordered list of Posts and Trades.
|
||||||
|
},
|
||||||
|
modules: {
|
||||||
|
EVENT: require('./event.js'),
|
||||||
|
POST: require('./post.js')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
We will add this event to the timeline
|
||||||
|
*/
|
||||||
|
NT.memory.TIMELINE.push()
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
exports.newPost = function newPost() {
|
||||||
|
|
||||||
|
let thisObject = {
|
||||||
|
postHash: undefined,
|
||||||
|
postType: undefined,
|
||||||
|
userProfile: undefined,
|
||||||
|
asset: undefined,
|
||||||
|
timestamp: undefined,
|
||||||
|
replies: undefined,
|
||||||
|
targetPost: undefined,
|
||||||
|
initialize: initialize,
|
||||||
|
finalize: finalize
|
||||||
|
}
|
||||||
|
|
||||||
|
const POST_TYPES = {
|
||||||
|
NEW_MULTI_MEDIA_POST: 10,
|
||||||
|
REPLY_TO_MULTI_MEDIA_POST: 11,
|
||||||
|
REPOST_MULTI_MEDIA: 12,
|
||||||
|
QUOTE_REPOST_MULTI_MEDIA: 13,
|
||||||
|
NEW_TRADE_POST: 20,
|
||||||
|
REPLY_TO_TRADE_POST: 21,
|
||||||
|
RE_POST_TRADE: 22,
|
||||||
|
QUOTE_REPOST_TRADE: 23
|
||||||
|
}
|
||||||
|
|
||||||
|
return thisObject
|
||||||
|
|
||||||
|
function finalize() {
|
||||||
|
thisObject.postHash = undefined
|
||||||
|
thisObject.postType = undefined
|
||||||
|
thisObject.userProfile = undefined
|
||||||
|
thisObject.asset = undefined
|
||||||
|
thisObject.timestamp = undefined
|
||||||
|
thisObject.replies = undefined
|
||||||
|
thisObject.targetPost = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize(
|
||||||
|
emitterPostHash,
|
||||||
|
targetPostHash,
|
||||||
|
postType,
|
||||||
|
userProfile,
|
||||||
|
asset,
|
||||||
|
timestamp
|
||||||
|
) {
|
||||||
|
|
||||||
|
thisObject.emitterPostHash = emitterPostHash
|
||||||
|
thisObject.targetPostHash = targetPostHash
|
||||||
|
thisObject.postType = postType
|
||||||
|
thisObject.userProfile = userProfile
|
||||||
|
thisObject.asset = asset
|
||||||
|
thisObject.timestamp = timestamp
|
||||||
|
/*
|
||||||
|
Let's find the Target Post
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
event.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA ||
|
||||||
|
event.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA ||
|
||||||
|
event.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.RE_POST_TRADE ||
|
||||||
|
event.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE
|
||||||
|
) {
|
||||||
|
thisObject.targetPost = NT.memory.POSTS.get(thisObject.targetPostHash)
|
||||||
|
|
||||||
|
if (thisObject.targetPost === undefined) {
|
||||||
|
throw ('Target Post Not Found.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Let's add this post to the replies of the Target Post
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
event.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
|
||||||
|
event.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST
|
||||||
|
) {
|
||||||
|
thisObject.targetPost.replies.push(thisObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
-16
@@ -1,29 +1,25 @@
|
|||||||
exports.newUserProfile = function newUserProfile() {
|
exports.newUserProfile = function newUserProfile() {
|
||||||
|
|
||||||
let thisObject = {
|
let thisObject = {
|
||||||
id: undefined,
|
userProfieId: undefined,
|
||||||
githubUsername: undefined,
|
githubUsername: undefined,
|
||||||
blockchainAccount: undefined,
|
blockchainAccount: undefined,
|
||||||
following: undefined,
|
postFollowing: undefined,
|
||||||
followers: undefined,
|
postFollowers: undefined,
|
||||||
followingCount: undefined,
|
tradeFollowing: undefined,
|
||||||
followersCount: undefined,
|
tradeFollowers: undefined,
|
||||||
tradeCopying: undefined,
|
|
||||||
tradeCopiers: undefined,
|
|
||||||
tradeCopyingCount: undefined,
|
|
||||||
tradeCopiersCount: undefined,
|
|
||||||
ranking: undefined,
|
ranking: undefined,
|
||||||
joined: undefined,
|
events: undefined,
|
||||||
|
postFollowingCount: undefined,
|
||||||
|
postFollowersCount: undefined,
|
||||||
|
tradeFollowingCount: undefined,
|
||||||
|
tradeFollowersCount: undefined,
|
||||||
|
eventsCount: undefined,
|
||||||
|
postsCount: undefined,
|
||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
finalize: finalize
|
finalize: finalize
|
||||||
}
|
}
|
||||||
|
|
||||||
thisObject.following = new Map()
|
|
||||||
thisObject.followers = new Map()
|
|
||||||
|
|
||||||
thisObject.tradeCopying = new Map()
|
|
||||||
thisObject.tradeCopiersCount = new Map()
|
|
||||||
|
|
||||||
return thisObject
|
return thisObject
|
||||||
|
|
||||||
function finalize() {
|
function finalize() {
|
||||||
@@ -32,5 +28,20 @@ exports.newUserProfile = function newUserProfile() {
|
|||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
|
|
||||||
|
thisObject.postFollowing = new Map()
|
||||||
|
thisObject.postFollowers = new Map()
|
||||||
|
|
||||||
|
thisObject.tradeFollowing = new Map()
|
||||||
|
thisObject.tradeFollowers = new Map()
|
||||||
|
|
||||||
|
thisObject.events = []
|
||||||
|
|
||||||
|
thisObject.postFollowingCount = 0
|
||||||
|
thisObject.postFollowersCount = 0
|
||||||
|
thisObject.tradeFollowingCount = 0
|
||||||
|
thisObject.tradeFollowersCount = 0
|
||||||
|
thisObject.eventsCount = 0
|
||||||
|
thisObject.postsCount = 0
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12827,7 +12827,9 @@
|
|||||||
"referenceParentCombinedNodePath": [
|
"referenceParentCombinedNodePath": [
|
||||||
[
|
[
|
||||||
"Smidy13",
|
"Smidy13",
|
||||||
"User Profile"
|
"User Profile",
|
||||||
|
"Governance",
|
||||||
|
"4b5eca40-4d97-454d-91f3-8627a98ef682"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -13078,7 +13080,7 @@
|
|||||||
"floatingObject": {
|
"floatingObject": {
|
||||||
"isPinned": false,
|
"isPinned": false,
|
||||||
"isFrozen": false,
|
"isFrozen": false,
|
||||||
"isCollapsed": true,
|
"isCollapsed": false,
|
||||||
"angleToParent": 1,
|
"angleToParent": 1,
|
||||||
"distanceToParent": 3,
|
"distanceToParent": 3,
|
||||||
"arrangementStyle": 0
|
"arrangementStyle": 0
|
||||||
|
|||||||
Reference in new issue
Block a user