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() {
|
||||
|
||||
let thisObject = {
|
||||
id: undefined,
|
||||
githubUsername: undefined,
|
||||
blockchainAccount: undefined,
|
||||
following: undefined,
|
||||
followers: undefined,
|
||||
followingCount: undefined,
|
||||
followersCount: undefined,
|
||||
tradeCopying: undefined,
|
||||
tradeCopiers: undefined,
|
||||
tradeCopyingCount: undefined,
|
||||
tradeCopiersCount: undefined,
|
||||
ranking: undefined,
|
||||
joined: undefined,
|
||||
eventId: undefined,
|
||||
eventType: undefined,
|
||||
emitterUserProfile: undefined,
|
||||
targetUserProfile: undefined,
|
||||
asset: undefined,
|
||||
timestamp: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
thisObject.following = new Map()
|
||||
thisObject.followers = new Map()
|
||||
|
||||
thisObject.tradeCopying = new Map()
|
||||
thisObject.tradeCopiersCount = new Map()
|
||||
const EVENT_TYPES = {
|
||||
NEW_MULTI_MEDIA_POST: 10,
|
||||
REPLY_TO_MULTI_MEDIA_POST: 11,
|
||||
REPOST_MULTI_MEDIA: 12,
|
||||
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
|
||||
|
||||
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 @@
|
||||
[
|
||||
{
|
||||
"type": "post",
|
||||
"timestamp": 12343242342,
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"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"
|
||||
}
|
||||
]
|
||||
|
||||
{
|
||||
"eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"eventType": 10,
|
||||
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"asset": "BTC",
|
||||
"timestamp": 124234234234,
|
||||
"postHash": "dasdhqJKGdadjlasgjaGSHAJGSDjhagsg",
|
||||
"postId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db"
|
||||
}
|
||||
+16
-4
@@ -1,7 +1,19 @@
|
||||
|
||||
|
||||
let usersProfiles = new Map() // Here we will store the user profiles and their statistics.
|
||||
let timeline = [] // A time ordered list of Posts and Trades.
|
||||
let events = new Map()
|
||||
let hashGraph = {}
|
||||
global.NT = {
|
||||
memory: {
|
||||
USER_PROFILES: new Map(), // Here we will store the user profiles and their statistics.
|
||||
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() {
|
||||
|
||||
let thisObject = {
|
||||
id: undefined,
|
||||
userProfieId: undefined,
|
||||
githubUsername: undefined,
|
||||
blockchainAccount: undefined,
|
||||
following: undefined,
|
||||
followers: undefined,
|
||||
followingCount: undefined,
|
||||
followersCount: undefined,
|
||||
tradeCopying: undefined,
|
||||
tradeCopiers: undefined,
|
||||
tradeCopyingCount: undefined,
|
||||
tradeCopiersCount: undefined,
|
||||
postFollowing: undefined,
|
||||
postFollowers: undefined,
|
||||
tradeFollowing: undefined,
|
||||
tradeFollowers: undefined,
|
||||
ranking: undefined,
|
||||
joined: undefined,
|
||||
events: undefined,
|
||||
postFollowingCount: undefined,
|
||||
postFollowersCount: undefined,
|
||||
tradeFollowingCount: undefined,
|
||||
tradeFollowersCount: undefined,
|
||||
eventsCount: undefined,
|
||||
postsCount: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
thisObject.following = new Map()
|
||||
thisObject.followers = new Map()
|
||||
|
||||
thisObject.tradeCopying = new Map()
|
||||
thisObject.tradeCopiersCount = new Map()
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
@@ -32,5 +28,20 @@ exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
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": [
|
||||
[
|
||||
"Smidy13",
|
||||
"User Profile"
|
||||
"User Profile",
|
||||
"Governance",
|
||||
"4b5eca40-4d97-454d-91f3-8627a98ef682"
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -13078,7 +13080,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": true,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
|
||||
Reference in new issue
Block a user