Created
November 3, 2017 19:27
-
-
Save sleepdefic1t/3f6c6ab512897d210805e5acc999ba25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update() { | |
SpreadsheetApp.getActiveSheet().getRange("F6").setValue(Math.random()); | |
} | |
function getHeight(rand) { | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/blocks/getHeight"); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return json.height; | |
} | |
} catch (err) { | |
return err.message; | |
} | |
} | |
function fetchReceivedTransactions(address,offset) { | |
var transactions = {}; | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/transactions?recipientId="+address+"&offset="+offset+"&limit=50"); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return json.transactions; | |
} | |
} catch (err) { | |
return -1; | |
} | |
} | |
function totalVotes(address, rand) { | |
var transactions = {}; | |
var count = 0; | |
//get transactions | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/transactions?recipientId="+address+"&limit=0"); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
transactions = json.transactions; | |
count = json.count; | |
} | |
} catch (err) { | |
return -1; | |
} | |
//extract unique voters | |
var voters = []; | |
for(i = 0; i< count; i++){ | |
if (i%50 === 0) { | |
var trans = fetchReceivedTransactions(address,i) | |
for (j=0; j< trans.length; j++) { | |
if(voters.indexOf(transactions[j].senderId) === -1){ | |
voters.push(transactions[j].senderId); | |
} | |
} | |
} | |
} | |
//calculate total | |
var totalVotes = 0; | |
for(i = 0; i< voters.length; i++){ | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/accounts?address="+voters[i]); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
if(json.account.address != "AUexKjGtgsSpVzPLs6jNMM6vJ6znEVTQWK") { // bittrex | |
totalVotes = totalVotes + parseFloat(json.account.balance)/100000000; | |
} | |
} | |
} catch (err) { | |
return -1; | |
} | |
} | |
return totalVotes; | |
} | |
function getDelegateRank(username, rand) { | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/delegates/get?username="+username); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return parseInt(json.delegate.rate); | |
} | |
} catch (err) { | |
return -1; | |
} | |
} | |
function getDelegateVotes(username, rand) { | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/delegates/get?username="+username); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return parseFloat(json.delegate.vote)/100000000 | |
} | |
} catch (err) { | |
return -1; | |
} | |
} | |
function getArkBalance(address, rand) { | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/accounts?address="+address); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return parseFloat(json.account.balance)/100000000; | |
} | |
} catch (err) { | |
return -1; | |
} | |
} | |
function publicKey(username, rand) { | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/delegates/get?username="+username); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return json.delegate.publicKey; | |
} | |
} catch (err) { | |
return "Error"; | |
} | |
} | |
function voterCount(publicKey, rand) { | |
try { | |
var response = UrlFetchApp.fetch("https://api.arkcoin.net/api/delegates/voters?publicKey="+publicKey); | |
if(response.getResponseCode() === 200) { | |
var json = JSON.parse(response.getContentText()); | |
return json.accounts.length; | |
} | |
} catch (err) { | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment