Created
February 11, 2022 08:48
-
-
Save ttt50966/c803bd1777f8252d74cfcec917784c5a to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
Author: Kuàn-ka | |
This is a LikeCoin chain script for monitoring node status. | |
Please dowonload the app below first | |
https://apps.apple.com/tw/app/scriptable/id1405459188 | |
background credit: @slothlife@liker.social | |
*/ | |
let address = args.widgetParameter; | |
if (address == null) {address = "cosmosvaloper1fdpmw3k73asq89gt0qvf9j97pgg2kapkk99yl2"} | |
url = "https://mainnet-node.like.co/cosmos/staking/v1beta1/validators" | |
let r = new Request(url) | |
let validators = await r.loadJSON() | |
name = "" | |
key = "" | |
active = "" | |
for(let i =0; i<validators["validators"].length;i++){ | |
if (validators["validators"][i]["operator_address"]==address){ | |
key = validators["validators"][i]["consensus_pubkey"]["key"] | |
name = validators["validators"][i]["description"]["moniker"] | |
if (validators["validators"][i]["status"] == "BOND_STATUS_BONDED") {active = "Active"} | |
if (validators["validators"][i]["status"] == "BOND_STATUS_UNBONDED") {active = "Inactive"} | |
if (validators["validators"][i]["jailed"] == true){active = "Jailed"} | |
} | |
} | |
voting_power = 0 | |
consen_addr = "" | |
total_voting_power = 0 | |
url2 = "https://mainnet-node.like.co/cosmos/base/tendermint/v1beta1/validatorsets/latest" | |
let r2 = new Request(url2) | |
let consensus = await r2.loadJSON() | |
for(let i = 0; i < consensus["validators"].length; i++){ | |
total_voting_power += Number(consensus["validators"][i]["voting_power"]) | |
if (consensus["validators"][i]["pub_key"]["key"] == key){ | |
voting_power = Number(consensus["validators"][i]["voting_power"]) | |
consen_addr = consensus["validators"][i]["address"] | |
} | |
} | |
block_height = consensus["block_height"] | |
miss_block_counter = "N/A" | |
url3 = "https://mainnet-node.like.co/cosmos/slashing/v1beta1/signing_infos/"+consen_addr | |
let r3 = new Request(url3) | |
let miss = await r3.loadJSON() | |
if (active == "Active"){miss_block_counter = miss["val_signing_info"]["missed_blocks_counter"]} | |
const width=125 | |
const h=7 | |
const w = new ListWidget() | |
let imgReq = new Request("https://cdn.discordapp.com/attachments/885853680589471796/936665382939398204/B663u29shnUAAAAASUVORK5CYII.png") | |
let img = await imgReq.loadImage() | |
w.backgroundImage = img | |
REFRESH_INTERVAL = 10 //mins | |
//w.backgroundColor=new Color("#222222") | |
var refreshDate = Date.now() + 1000*60*REFRESH_INTERVAL | |
w.refreshAfterDate = new Date(refreshDate) | |
w.addSpacer(16) | |
let provider = w.addText(" 鼠嗲達鼠") | |
provider.font = Font.mediumSystemFont(20) | |
provider.textColor = new Color("#FFFAFA") | |
w.addSpacer(8) | |
let provider1 = w.addText(" 🧀"+block_height) | |
provider1.font = Font.mediumSystemFont(18) | |
provider1.textColor = new Color("#222222") | |
let provider2 = w.addText(" " +name) | |
provider2.font = Font.mediumSystemFont(18) | |
provider2.textColor = new Color("#222222") | |
let provider21 = w.addText(" "+active) | |
provider21.font = Font.mediumSystemFont(16) | |
provider21.textColor = new Color("#222222") | |
let provider3 = w.addText(" Miss " + miss_block_counter) | |
provider3.font = Font.mediumSystemFont(16) | |
provider3.textColor = new Color("#222222") | |
let provider4 = w.addText(" Vote " + (voting_power/total_voting_power*100).toFixed(2).toString()+"%") | |
provider4.font = Font.mediumSystemFont(16) | |
provider4.textColor = new Color("#222222") | |
w.addSpacer(14) | |
Script.setWidget(w) | |
Script.complete() | |
w.presentSmall() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment