Pode parecer um tanto desonesto fazer isso, por parecer compra de votos e tudo mais, mas acredito que eu deva devolver um voto de apreço pelo conteúdo de quem me deu voto de confiança como testemunha.
Estou pensando em fazer mais scripts desses, mas utilizando outros critérios para distribuir votos positivos, como comentários nas minhas postagens ou apreço de longa data por conteúdo em uma lista fixa. Mas definitivamente pretendo fazer um para dar votos pequenos todos que postarem conteúdo em Língua Portuguêsa.
E desculpem se pareceu muito inconsistente em algumas partes, mas eu não vi necessidade de reimplementar a assinatra de transações quando tenho o cli_wallet instalado. E estava com pressa para terminar.
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ob_implicit_flush(true);
$exe_command = 'cli_wallet -s ws://localhost:*****';
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", "php://stdout", "w"),
2 => array("file", "php://stdout", "w")
);
$process = proc_open($exe_command, $descriptorspec, $pipes);
$voters = listVoters();
function nextBlock($sum = 0) {
$myfile = fopen("./block.txt", "r+") or die("Unable to open file!");
$block = fread($myfile, filesize("./block.txt"));
if ($sum == 0) {
fclose($myfile);
return $block;
}
if (is_numeric($block)) {
$block = $block + $sum;
} else {
}
fseek($myfile, 0);
fwrite($myfile, $block);
fclose($myfile);
return $block;
}
function listVoters() {
$url = 'http://localhost:*****';
$c = "";
$first = true;
$voters = array();
$data = array(
"id" => 1,
"jsonrpc" => "2.0",
"method" => "database_api.list_witness_votes",
"params" => array(
"start" => array(
"fernandosoder",
$c
),
"limit" => 1000,
"order" => "by_witness_account"
)
);
for (;;) {
$data['params']['start'][1] = $c;
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string)
)
);
$result = curl_exec($ch);
$res = json_decode($result);
$last = "";
foreach ($res->result->votes as $key => $vote) {
if ($key != 0 || $first) {
if (end($voters) > $vote->account) {
return $voters;
}
if (!in_array($vote->account, $voters) && $vote->account != $data['params']['start'][0]) {
array_push($voters, $vote->account);
}
$c = $vote->account;
}
}
curl_close($ch);
$first = false;
}
}
function getBlock() {
$url = 'http://localhost:*****';
$data = array(
"id" => 1,
"jsonrpc" => "2.0",
"method" => "block_api.get_block",
"params" => array()
);
$data['params'] = array("block_num" => nextBlock());
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string)
)
);
$result = curl_exec($ch);
$res = json_decode($result);
curl_close($ch);
return $res;
}
if (is_resource($process)) {
fputs($pipes[0], "unlock ************\n");
for (;;) {
$block = getBlock()->result->block;
if (isset($block)) {
foreach ($block->transactions as $transaction) {
foreach ($transaction->operations as $operation) {
if ($operation->type == "comment_operation") {
if (in_array($operation->value->author, $voters)) {
$com = 'vote fernandosoder ' . $operation->value->author . ' ' . $operation->value->permlink . ' 100 true';
fputs($pipes[0], $com . "\n");
sleep(4);
}
}
}
}
nextBlock(1);
} else {
$voters = listVoters();
sleep(30);
}
}
}
exit();
Se você tiver um voto sobrando...