Github Program impleme
This commit is contained in:
1 parent
a54de8bc93
commit
6c9c4511ac
13 files changed
+2007
-351
No files matched your search
+153
-1
@@ -773,7 +773,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> commitMessage = ' + commitMessage)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> token = ' + token)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> currentBranch = ' + currentBranch)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> contributionsBranch = ' + contributionsBranch)
|
||||
|
||||
@@ -1018,6 +1019,151 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
break
|
||||
|
||||
case 'Gov': {
|
||||
switch (requestParameters[2]) { // switch by command
|
||||
case 'getRepoInfo': {
|
||||
try {
|
||||
const GITHUB_API_WAITING_TIME = 1000
|
||||
const repository = unescape(requestParameters[3])
|
||||
const username = unescape(requestParameters[4])
|
||||
const token = unescape(requestParameters[5])
|
||||
let error
|
||||
let starsListArray = []
|
||||
|
||||
|
||||
getRepoInfo()
|
||||
|
||||
async function getRepoInfo() {
|
||||
|
||||
await doGithub()
|
||||
if (error !== undefined) {
|
||||
|
||||
let docs = {
|
||||
project: 'Governance',
|
||||
category: 'Topic',
|
||||
type: 'Gov Error - Get Repository Information',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
return
|
||||
}
|
||||
respondWithContent(JSON.stringify(starsListArray), httpResponse)
|
||||
}
|
||||
|
||||
async function doGithub() {
|
||||
|
||||
const { Octokit } = require("@octokit/rest")
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: token,
|
||||
userAgent: 'Superalgos Beta 10'
|
||||
})
|
||||
|
||||
const repo = repository
|
||||
const owner = 'Superalgos'
|
||||
const per_page = 100 // Max
|
||||
let page = 0
|
||||
let lastPage = false
|
||||
|
||||
while (lastPage === false) {
|
||||
try {
|
||||
page++
|
||||
await sleep(GITHUB_API_WAITING_TIME)
|
||||
let starsListResponse = await octokit.activity.listStargazersForRepo({
|
||||
owner,
|
||||
repo,
|
||||
per_page,
|
||||
page
|
||||
});
|
||||
|
||||
if (starsListResponse.data.length < 100) {
|
||||
lastPage = true
|
||||
}
|
||||
|
||||
for (let i = 0; i < starsListResponse.data.length; i++) {
|
||||
let star = starsListResponse.data[i]
|
||||
starsListArray.push(star.login)
|
||||
}
|
||||
|
||||
console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> Stars Page = ' + page)
|
||||
console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> Stars Received = ' + starsListResponse.data.length)
|
||||
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
if (err.stack.indexOf('last page') >= 0) {
|
||||
return
|
||||
} else {
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> commitMessage = ' + repository)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
error = err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> repository = ' + repository)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function respondWithDocsObject(docs, error) {
|
||||
|
||||
if (error.message !== undefined) {
|
||||
docs.placeholder.errorMessage = {
|
||||
style: 'Error',
|
||||
text: error.message
|
||||
}
|
||||
}
|
||||
if (error.stack !== undefined) {
|
||||
docs.placeholder.errorStack = {
|
||||
style: 'Javascript',
|
||||
text: error.stack
|
||||
}
|
||||
}
|
||||
if (error.code !== undefined) {
|
||||
docs.placeholder.errorCode = {
|
||||
style: 'Json',
|
||||
text: error.code
|
||||
}
|
||||
}
|
||||
|
||||
docs.placeholder.errorDetails = {
|
||||
style: 'Json',
|
||||
text: JSON.stringify(error, undefined, 4)
|
||||
}
|
||||
|
||||
let customResponse = {
|
||||
result: global.CUSTOM_FAIL_RESPONSE.result,
|
||||
docs: docs
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(customResponse), httpResponse)
|
||||
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'LegacyPlotter.js':
|
||||
{
|
||||
respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/LegacyPlotter.js', httpResponse)
|
||||
@@ -1962,4 +2108,10 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
return files.reduce((a, f) => a.concat(f), []);
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -27,12 +27,12 @@
|
||||
"id": "2e9dff69-e407-4ccb-9a42-e4a476e28d7c",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25404.12955404221,
|
||||
"y": 30290.214224224663
|
||||
"x": 25378.919432488667,
|
||||
"y": 30284.045346726893
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25364.971696376197,
|
||||
"y": 30587.647682636805
|
||||
"x": 25352.77270966437,
|
||||
"y": 30582.903756154417
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -57,12 +57,12 @@
|
||||
"id": "af1984a3-465b-48ed-9944-c101a8ed376c",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25514.971696376197,
|
||||
"y": 30327.840061501473
|
||||
"x": 25491.297293634878,
|
||||
"y": 30316.80050620095
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25364.971696376197,
|
||||
"y": 30587.647682636805
|
||||
"x": 25352.77270966437,
|
||||
"y": 30582.903756154417
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -81,8 +81,8 @@
|
||||
"id": "9f94d0e0-ddf7-4e04-8a3c-9485c09e079d",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25364.971696376197,
|
||||
"y": 30587.647682636805
|
||||
"x": 25352.77270966437,
|
||||
"y": 30582.903756154417
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -118,12 +118,12 @@
|
||||
"id": "c41497c5-7440-4ebd-aabb-fbc3d022136b",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25612.29870102263,
|
||||
"y": 30392.871886898894
|
||||
"x": 25569.788428094842,
|
||||
"y": 30363.105873343502
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25462.29870102263,
|
||||
"y": 30652.679508034227
|
||||
"x": 25443.00294957263,
|
||||
"y": 30634.998209454498
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -148,12 +148,12 @@
|
||||
"id": "6625953a-6026-4686-9091-2796fd08b9a7",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25700.304703110003,
|
||||
"y": 30470.05107933161
|
||||
"x": 25664.186150615667,
|
||||
"y": 30432.321147169798
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25462.29870102263,
|
||||
"y": 30652.679508034227
|
||||
"x": 25443.00294957263,
|
||||
"y": 30634.998209454498
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -172,8 +172,8 @@
|
||||
"id": "174e7d3b-fe3c-4fb1-825c-4ea488d82171",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25462.29870102263,
|
||||
"y": 30652.679508034227
|
||||
"x": 25443.00294957263,
|
||||
"y": 30634.998209454498
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -209,12 +209,12 @@
|
||||
"id": "53ddcc36-f693-4193-8284-999a88f1c944",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25765.336528507425,
|
||||
"y": 30567.37808397805
|
||||
"x": 25722.106322157964,
|
||||
"y": 30502.679508034227
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25527.330526420054,
|
||||
"y": 30750.006512680666
|
||||
"x": 25509.974287802,
|
||||
"y": 30714.81154239019
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -239,12 +239,12 @@
|
||||
"id": "ff1e4a84-3363-4348-ad15-31a34898fa82",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25817.108274306775,
|
||||
"y": 30672.36079914991
|
||||
"x": 25787.138147555386,
|
||||
"y": 30600.006512680666
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25527.330526420054,
|
||||
"y": 30750.006512680666
|
||||
"x": 25509.974287802,
|
||||
"y": 30714.81154239019
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -263,8 +263,8 @@
|
||||
"id": "8b3714a0-3bf2-491e-8ffc-9c4286446382",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25527.330526420054,
|
||||
"y": 30750.006512680666
|
||||
"x": 25509.974287802,
|
||||
"y": 30714.81154239019
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -293,8 +293,8 @@
|
||||
"id": "5bd09ac2-6c9f-4a7d-a547-c05a8a1e98e2",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25550.166666666668,
|
||||
"y": 30864.81154239019
|
||||
"x": 25545.60899257033,
|
||||
"y": 30812.71708909011
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -330,12 +330,12 @@
|
||||
"id": "9eb846a4-effb-4380-9487-1a82011b0488",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25804.49438617344,
|
||||
"y": 31094.42160180924
|
||||
"x": 25841.051318473994,
|
||||
"y": 30969.00044899035
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25527.330526420054,
|
||||
"y": 30979.616572099716
|
||||
"x": 25545.60899257033,
|
||||
"y": 30916.90599569027
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -354,8 +354,8 @@
|
||||
"id": "80d4f08f-bb7f-48a2-9cef-be12befcac2e",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25527.330526420054,
|
||||
"y": 30979.616572099716
|
||||
"x": 25545.60899257033,
|
||||
"y": 30916.90599569027
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -391,12 +391,12 @@
|
||||
"id": "d2cf4c65-b4bd-4fa8-b0da-f73a38b8419a",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25674.430735378595,
|
||||
"y": 31289.07561110212
|
||||
"x": 25769.781908937333,
|
||||
"y": 31164.81154239019
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25462.29870102263,
|
||||
"y": 31076.943576746155
|
||||
"x": 25509.974287802,
|
||||
"y": 31014.81154239019
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -415,8 +415,8 @@
|
||||
"id": "68e3f570-4156-4be6-8881-c526a06f85d0",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25462.29870102263,
|
||||
"y": 31076.943576746155
|
||||
"x": 25509.974287802,
|
||||
"y": 31014.81154239019
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -452,12 +452,12 @@
|
||||
"id": "24e62dd3-4d7b-4eba-b401-493c155d85d0",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25479.776726085725,
|
||||
"y": 31419.139261896962
|
||||
"x": 25635.839232478593,
|
||||
"y": 31324.438208261578
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25364.971696376197,
|
||||
"y": 31141.975402143577
|
||||
"x": 25443.00294957263,
|
||||
"y": 31094.624875325884
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -476,8 +476,69 @@
|
||||
"id": "f09429a2-3f6c-4210-bb73-0c8efd254c82",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25364.971696376197,
|
||||
"y": 31141.975402143577
|
||||
"x": 25443.00294957263,
|
||||
"y": 31094.624875325884
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
"y": 30864.81154239019
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {
|
||||
"isRunning": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Pool Class",
|
||||
"name": "Github Prgoram",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"poolClasses": [],
|
||||
"pools": [
|
||||
{
|
||||
"type": "Pool",
|
||||
"name": "Github Rewards",
|
||||
"config": "{\n \"codeName\": \"Github-Rewards\"\n}",
|
||||
"project": "Governance",
|
||||
"poolClasses": [],
|
||||
"pools": [],
|
||||
"id": "8829c80f-028b-4315-85a1-82ad502f0687",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25455.37875266207,
|
||||
"y": 31428.627114861738
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25352.77270966437,
|
||||
"y": 31146.719328625964
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {
|
||||
"isRunning": false
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": "e4daed5d-1c83-4f64-a504-3aef7d73e688",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25352.77270966437,
|
||||
"y": 31146.719328625964
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25250.166666666668,
|
||||
@@ -511,7 +572,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": true,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
@@ -1649,7 +1710,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"isCollapsed": true,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"type": "Github Program",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Configure",
|
||||
"actionFunction": "uiObject.configEditor.activate",
|
||||
"label": "Configure",
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"actionProject": "Foundations",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "tokensAwarded",
|
||||
"actionFunction": "payload.executeAction",
|
||||
"label": "Add Tokens Awarded",
|
||||
"relatedUiObject": "Tokens Awarded"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"actionProject": "Foundations",
|
||||
"askConfirmation": true,
|
||||
"confirmationLabel": "Confirm to Delete",
|
||||
"label": "Delete",
|
||||
"iconPathOn": "delete-entity",
|
||||
"iconPathOff": "delete-entity",
|
||||
"actionFunction": "payload.executeAction"
|
||||
}
|
||||
],
|
||||
"editors": {
|
||||
"config": true
|
||||
},
|
||||
"initialValues": {
|
||||
"config": "{}"
|
||||
},
|
||||
"attachingRules": {
|
||||
"compatibleTypes": "->Token Power Switch->"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"level": 1,
|
||||
"propertyNameAtParent": "githubProgram",
|
||||
"childrenNodesProperties": [
|
||||
{
|
||||
"name": "tokensAwarded",
|
||||
"type": "node",
|
||||
"childType": "Tokens Awarded",
|
||||
"autoAdd": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -78,6 +78,15 @@
|
||||
"label": "Add Delegation Program",
|
||||
"relatedUiObject": "Delegation Program"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"actionProject": "Foundations",
|
||||
"actionFunction": "payload.executeAction",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "githubProgram",
|
||||
"label": "Add Github Program",
|
||||
"relatedUiObject": "Github Program"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"actionProject": "Foundations",
|
||||
@@ -149,6 +158,12 @@
|
||||
"type": "node",
|
||||
"childType": "Delegation Program",
|
||||
"autoAdd": false
|
||||
},
|
||||
{
|
||||
"name": "githubProgram",
|
||||
"type": "node",
|
||||
"childType": "Github Program",
|
||||
"autoAdd": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
"addLeftIcons": true,
|
||||
"level": 2,
|
||||
"attachingRules": {
|
||||
"compatibleTypes": "->Referral Program->Mentorship Program->Support Program->Claims Program->Staking Program->"
|
||||
"compatibleTypes": "->Referral Program->Mentorship Program->Support Program->Claims Program->Staking Program->Github Program->"
|
||||
},
|
||||
"propertyNameAtParent": "tokensAwarded"
|
||||
}
|
||||
@@ -98,11 +98,18 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
userProfiles
|
||||
)
|
||||
/*
|
||||
Run the Github Program
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.githubProgram.calculate(
|
||||
pools,
|
||||
userProfiles
|
||||
)
|
||||
/*
|
||||
After all the programs were ran, we can calculate the tokens mining
|
||||
calculation each profile.
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.tokenMining.calculate(
|
||||
userProfiles
|
||||
)
|
||||
userProfiles
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
function newGovernanceFunctionLibraryGithubProgram() {
|
||||
let thisObject = {
|
||||
calculate: calculate
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function calculate(
|
||||
pools,
|
||||
userProfiles
|
||||
) {
|
||||
let programPoolTokenReward
|
||||
/*
|
||||
In order to be able to calculate the share of the Program Pool for each User Profile,
|
||||
we need to accumulate all the Github Power that each User Profile at their Program
|
||||
node has, because with that Power is that each Program node gets a share of the pool.
|
||||
*/
|
||||
let accumulatedProgramPower = 0
|
||||
|
||||
/* Scan Pools Until finding the Mentoship-Program Pool */
|
||||
for (let i = 0; i < pools.length; i++) {
|
||||
let poolsNode = pools[i]
|
||||
programPoolTokenReward = UI.projects.governance.utilities.pools.findPool(poolsNode, "Github-Rewards")
|
||||
}
|
||||
if (programPoolTokenReward === undefined || programPoolTokenReward === 0) { return }
|
||||
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program")
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
|
||||
resetProgram(program)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program")
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
|
||||
validateProgram(program, userProfile)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program")
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
if (program.payload.githubProgram.isActive === false) { continue }
|
||||
|
||||
distributeProgram(program)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program")
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
if (program.payload.githubProgram.isActive === false) { continue }
|
||||
|
||||
calculateProgram(program)
|
||||
}
|
||||
|
||||
function resetProgram(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.githubProgram === undefined) {
|
||||
node.payload.githubProgram = {
|
||||
count: 0,
|
||||
percentage: 0,
|
||||
outgoingPower: 0,
|
||||
ownPower: 0,
|
||||
incomingPower: 0,
|
||||
awarded: {
|
||||
tokens: 0,
|
||||
percentage: 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
node.payload.githubProgram.count = 0
|
||||
node.payload.githubProgram.percentage = 0
|
||||
node.payload.githubProgram.outgoingPower = 0
|
||||
node.payload.githubProgram.ownPower = 0
|
||||
node.payload.githubProgram.incomingPower = 0
|
||||
node.payload.githubProgram.awarded = {
|
||||
tokens: 0,
|
||||
percentage: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validateProgram(node, userProfile) {
|
||||
/*
|
||||
This program is not going to run unless the Profile has Tokens, and for
|
||||
that users needs to execute the setup procedure of signing their Github
|
||||
username with their private key.
|
||||
*/
|
||||
if (
|
||||
userProfile.payload.blockchainTokens === undefined
|
||||
) {
|
||||
node.payload.githubProgram.isActive = false
|
||||
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.")
|
||||
return
|
||||
}
|
||||
/*
|
||||
Next thing to do is to validate if the github user profile has a star at the Superalgos repository.
|
||||
*/
|
||||
let profileSignature = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'signature')
|
||||
if (
|
||||
profileSignature === undefined
|
||||
) {
|
||||
node.payload.githubProgram.isActive = false
|
||||
userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, and produce a signature of your Github Username.")
|
||||
return
|
||||
}
|
||||
let githubUsername = profileSignature.message
|
||||
node.payload.githubProgram.hasStar = UI.projects.governance.spaces.userProfileSpace.githubStars.get(githubUsername)
|
||||
|
||||
if (node.payload.githubProgram.hasStar === true) {
|
||||
node.payload.githubProgram.isActive = true
|
||||
} else {
|
||||
node.payload.githubProgram.isActive = false
|
||||
}
|
||||
}
|
||||
|
||||
function distributeProgram(programNode) {
|
||||
if (programNode === undefined || programNode.payload === undefined) { return }
|
||||
/*
|
||||
Here we will convert Token Power into Github Power.
|
||||
As per system rules Github Powar = tokensPower
|
||||
*/
|
||||
let programPower = programNode.payload.tokenPower
|
||||
programNode.payload.githubProgram.ownPower = programPower
|
||||
|
||||
accumulatedProgramPower = accumulatedProgramPower + programPower
|
||||
}
|
||||
|
||||
function calculateProgram(programNode) {
|
||||
/*
|
||||
Here we will calculate which share of the Program Pool this user will get in tokens.
|
||||
To do that, we use the ownPower, to see which proportion of the accumulatedProgramPower
|
||||
represents.
|
||||
*/
|
||||
if (programNode.payload === undefined) { return }
|
||||
/*
|
||||
If the accumulatedProgramPower is not grater the amount of tokens at the Program Pool, then
|
||||
this user will get the exact amount of tokens from the pool as incomingPower he has.
|
||||
|
||||
If the accumulatedProgramPower is grater the amount of tokens at the Program Pool, then
|
||||
the amount ot tokens to be received is a proportional to the share of incomingPower in accumulatedProgramPower.
|
||||
*/
|
||||
let totalPowerRewardRatio = accumulatedProgramPower / programPoolTokenReward
|
||||
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
|
||||
|
||||
if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) {
|
||||
programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.")
|
||||
return
|
||||
}
|
||||
programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio
|
||||
|
||||
drawProgram(programNode)
|
||||
}
|
||||
|
||||
function drawProgram(node) {
|
||||
if (node.payload !== undefined) {
|
||||
|
||||
const ownPowerText = parseFloat(node.payload.githubProgram.ownPower.toFixed(0)).toLocaleString('en')
|
||||
|
||||
node.payload.uiObject.statusAngleOffset = 0
|
||||
node.payload.uiObject.statusAtAngle = false
|
||||
|
||||
node.payload.uiObject.setStatus(ownPowerText + ' Github Power')
|
||||
}
|
||||
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
|
||||
|
||||
const tokensAwardedText = parseFloat(node.payload.githubProgram.awarded.tokens.toFixed(0)).toLocaleString('en')
|
||||
|
||||
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
|
||||
node.tokensAwarded.payload.uiObject.valueAtAngle = false
|
||||
|
||||
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,16 @@ function newGovernanceFunctionLibraryTokenMining() {
|
||||
|
||||
calculateProgram(userProfile, program, "delegationProgram")
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program")
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
|
||||
calculateProgram(userProfile, program, "githubProgram")
|
||||
}
|
||||
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
@@ -49,7 +49,8 @@ function newGovernanceFunctionLibraryTokenPower() {
|
||||
node.type === 'Voting Program' ||
|
||||
node.type === 'Claims Program' ||
|
||||
node.type === 'Staking Program' ||
|
||||
node.type === 'Delegation Program'
|
||||
node.type === 'Delegation Program' ||
|
||||
node.type === 'Github Program'
|
||||
) { return }
|
||||
/*
|
||||
We will reset token power of children.
|
||||
@@ -149,7 +150,8 @@ function newGovernanceFunctionLibraryTokenPower() {
|
||||
node.type === 'Voting Program' ||
|
||||
node.type === 'Claims Program' ||
|
||||
node.type === 'Staking Program' ||
|
||||
node.type === 'Delegation Program'
|
||||
node.type === 'Delegation Program' ||
|
||||
node.type === 'Github Program'
|
||||
) { return }
|
||||
/*
|
||||
We will redistribute token power among children.
|
||||
|
||||
@@ -2,6 +2,7 @@ function newGovernanceUserProfileSpace() {
|
||||
const MODULE_NAME = 'User Profile Space'
|
||||
|
||||
let thisObject = {
|
||||
githubStars: undefined,
|
||||
container: undefined,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
@@ -17,13 +18,66 @@ function newGovernanceUserProfileSpace() {
|
||||
let waitingForResponses = 0
|
||||
let timer = 0
|
||||
|
||||
thisObject.githubStars = new Map()
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize() {
|
||||
/*
|
||||
Here we will get a list of all github usernames who have a star or fork and are watching the
|
||||
Superalgos Repository. This will later be used to know which user profiles are participating
|
||||
at the Github Program.
|
||||
*/
|
||||
|
||||
/* Find the Username and Password */
|
||||
let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs')
|
||||
if (apisNode === undefined) {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
UI.projects.education.spaces.docsSpace.sidePanelTab.open()
|
||||
return
|
||||
}
|
||||
if (apisNode.githubAPI === undefined) {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
UI.projects.education.spaces.docsSpace.sidePanelTab.open()
|
||||
return
|
||||
}
|
||||
|
||||
let config = JSON.parse(apisNode.githubAPI.config)
|
||||
if (config.username === undefined || config.username === "") {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
UI.projects.education.spaces.docsSpace.sidePanelTab.open()
|
||||
return
|
||||
}
|
||||
if (config.token === undefined || config.token === "") {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
UI.projects.education.spaces.docsSpace.sidePanelTab.open()
|
||||
return
|
||||
}
|
||||
|
||||
httpRequest(
|
||||
undefined,
|
||||
'Gov/getRepoInfo/' +
|
||||
'Superalgos' + '/' +
|
||||
config.username + '/' +
|
||||
config.token
|
||||
, onGithubStarsResponse)
|
||||
|
||||
return
|
||||
|
||||
function onGithubStarsResponse(err, githubStarsArray) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
githubStarsArray = JSON.parse(githubStarsArray)
|
||||
|
||||
for (let i = 0; i < githubStarsArray.length; i++) {
|
||||
githubUsername = githubStarsArray[i]
|
||||
thisObject.githubStars.set(githubUsername, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function finalize() {
|
||||
thisObject.githubStars = undefined
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
}
|
||||
|
||||
@@ -1051,6 +1051,11 @@
|
||||
"name": "Profile Constructor",
|
||||
"propertyName": "profileConstructor",
|
||||
"functionName": "newGovernanceFunctionLibraryProfileConstructor"
|
||||
},
|
||||
{
|
||||
"name": "Github Program",
|
||||
"propertyName": "githubProgram",
|
||||
"functionName": "newGovernanceFunctionLibraryGithubProgram"
|
||||
}
|
||||
],
|
||||
"utilities": [
|
||||
|
||||
Reference in new issue
Block a user