Skip to content

Instantly share code, notes, and snippets.

@karek314

karek314/lisk_lip.php

Last active Apr 1, 2019
Embed
What would you like to do?
Simple polling script based on Lisk blockchain, to poll LIP support
<?php
require_once('../../../../lisk-php/main.php');
$m = new Memcached();
$m->addServer('localhost', 11211);
$server = getCurrentServer($m);
$lips_approval_base_address="4205629L";
echo "<br><center>Welcome to very simple website to poll the current delegates attitude to LIP to restrict votes number to 1 and remain 101 top delegates.</center><br>
LIP: <a href='https://research.lisk.io/t/change-to-one-vote-per-account' target='_blank'>https://research.lisk.io/t/change-to-one-vote-per-account</a><br><br>
Better idea proposed by ThePool.io delegate: <a href='https://research.lisk.io/t/change-to-one-vote-per-account/18/22' target='_blank'>https://research.lisk.io/t/change-to-one-vote-per-account/18/22</a><br><br>
As forging delegate on mainnet, please send any value transaction (smallest 0.00000001) to address <b><a href='https://explorer.lisk.io/address/".$lips_approval_base_address."' target='_blank'>".$lips_approval_base_address."</a></b> with text in data field<br>
<b>lip-change_to_one_vote_per_account.md:NOT_AGREE</b> - I do not agree with the change, I want LiskHQ to take community feedback seriously and solve DPOS issues the right way. (At least 90% chances of not running code with this change)<br>
<b>lip-change_to_one_vote_per_account.md:WILL_SUPPORT</b> - I will run this code and support this change<br>
<b>lip-change_to_one_vote_per_account.md:MAYBE</b> - I might run this code if majority of delegates will run it, but I'm not really happy with it<br>
<br><br>
Example transaction: <a href='https://explorer.lisk.io/tx/18270818122034197982' target='_blank'>https://explorer.lisk.io/tx/18270818122034197982</a><br>
If as delegate you want to change your decision, make new transaction, this scripts pulls latest one as valid.<br> Reasons behind particular decision might be disclosed in <a href='https://research.lisk.io/t/change-to-one-vote-per-account' target='_blank'>this topic</a><br>
<br>If you are standby delegate in rank range of 101-202 you can signal your opinion as well.<br>
Results appear below, live data, reloaded from Lisk blockchain on request.
<br>";
$delegates = GetDelegatesList($server)["data"];
$maybe_count = 0;
$support_count = 0;
$no_support_count = 0;
$no_decision_count = 0;
foreach ($delegates as $key => $value) {
$name = $value["username"];
$address = $value["account"]["address"];
$rank = $value["rank"];
$url = $server."api/transactions/".'?recipientId='.$lips_approval_base_address.'&senderId='.$address.'&sort=timestamp:desc';
$tx = MainFunction("GET",$url,false,false,true,5)["data"];
if (count($tx)==0){
echo "<br>[".$rank."]->".$name."->".$address."-><font color='blue'>NOT DECIDED</font>";
$no_decision_count++;
} else {
$decision=$tx[0]["asset"]["data"];
if (strpos($decision, ':') !== false) {
$decision=explode(':', $decision)[1];
if ($decision == "WILL_NOT_SUPPORT" || $decision == "NOT_AGREE") {
$decision='<font color="red">'.$decision."</font>";
echo "<br>[".$rank."]->".$name."->".$address."->".$decision;
$no_support_count++;
} else if ($decision == "WILL_SUPPORT") {
$decision='<font color="green">'.$decision."</font>";
echo "<br>[".$rank."]->".$name."->".$address."->".$decision;
$support_count++;
} else if ($decision == "MAYBE") {
$decision='<font color="orange">'.$decision."</font>";
echo "<br>[".$rank."]->".$name."->".$address."->".$decision;
$maybe_count++;
} else {
echo "<br>[".$rank."]->".$name."->".$address."-><font color='blue'>Incompatible transaction data</font>";
$no_decision_count++;
}
} else {
$no_decision_count++;
echo "<br>[".$rank."]->".$name."->".$address."-><font color='blue'>Incompatible transaction data</font>";
}
}
}
echo "<br><br>Current results:<br>";
echo "SUPPORTED BY: ".$support_count."<br>";
echo "NOT SUPPORTED BY: ".$no_support_count."<br>";
echo "MAYBE SUPPORTED BY: ".$maybe_count."<br>";
echo "NO DECISION YET: ".$no_decision_count."<br><br><br>";
echo "Statistics purpose: standby delegates opinion<br>Essentially, consensus breaking change, directly is decision to be made by lisk forging delegates, only. This decision however, will be judged by their voters in the long run.<br>";
$standby_delegates = GetDelegatesList($server, $limit=101, $orderBy="rate", $offset=101, $orderType="asc")["data"];
$standby_delegates2 = GetDelegatesList($server, $limit=101, $orderBy="rate", $offset=202, $orderType="asc")["data"];
$standby_delegates = array_merge($standby_delegates,$standby_delegates2);
$maybe_count = 0;
$support_count = 0;
$no_support_count = 0;
$no_decision_count = 0;
foreach ($standby_delegates as $key => $value) {
$name = $value["username"];
$address = $value["account"]["address"];
$rank = $value["rank"];
$url = $server."api/transactions/".'?recipientId='.$lips_approval_base_address.'&senderId='.$address.'&sort=timestamp:desc';
$tx = MainFunction("GET",$url,false,false,true,5)["data"];
if (count($tx)==0){
echo "<br>[".$rank."]->".$name."->".$address."-><font color='blue'>NOT DECIDED</font>";
$no_decision_count++;
} else {
$decision=$tx[0]["asset"]["data"];
if (strpos($decision, ':') !== false) {
$decision=explode(':', $decision)[1];
if ($decision == "WILL_NOT_SUPPORT" || $decision == "NOT_AGREE") {
$decision='<font color="red">'.$decision."</font>";
echo "<br>[".$rank."]->".$name."->".$address."->".$decision;
$no_support_count++;
} else if ($decision == "WILL_SUPPORT") {
$decision='<font color="green">'.$decision."</font>";
echo "<br>[".$rank."]->".$name."->".$address."->".$decision;
$support_count++;
} else if ($decision == "MAYBE") {
$decision='<font color="orange">'.$decision."</font>";
echo "<br>[".$rank."]->".$name."->".$address."->".$decision;
$maybe_count++;
} else {
echo "<br>[".$rank."]->".$name."->".$address."-><font color='blue'>Incompatible transaction data</font>";
$no_decision_count++;
}
} else {
$no_decision_count++;
echo "<br>[".$rank."]->".$name."->".$address."-><font color='blue'>Incompatible transaction data</font>";
}
}
}
echo "<br><br>202 first standby delegates results:<br>";
echo "SUPPORTED BY: ".$support_count."<br>";
echo "NOT SUPPORTED BY: ".$no_support_count."<br>";
echo "MAYBE SUPPORTED BY: ".$maybe_count."<br>";
echo "NO DECISION YET: ".$no_decision_count."<br>";
echo "<br><br>This is opensource code, based on lisk-php, available <a href='https://gist.github.com/karek314/9873e5f8b389e65d628463be3cfbbf6f' target='_blank'>here</a>";
function getCurrentServer($m){
$lisk_host = $m->get('lisk_host');
$lisk_port = $m->get('lisk_port');
$lisk_protocol = $m->get('lisk_protocol');
$server = $lisk_protocol."://";
if ($lisk_port == 80 || $lisk_port == 443) {
$server .= $lisk_host."/";
} else {
$server .= $lisk_host.":".$lisk_port."/";
}
return $server;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.