-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclaim_bos.pl
65 lines (60 loc) · 2.41 KB
/
claim_bos.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strict;
use Time::Piece;
# Author: Eugene Luzgin @ EOS Tribe
my $producer = "YOUR-PRODUCER-NAME"; #<-- CHANGE THIS
my $wallet_pswd = "YOUR-WALLET-PASSWORD"; #<-- CHANGE THIS
my $datadir = "/home/eostribe/bos-mainnet"; #<-- CHANGE THIS
my $unlock_cmd = $datadir."/cleos.sh wallet unlock --password ".$wallet_pswd;
my $prodstats_cmd = $datadir."/cleos.sh get table eosio eosio producers -l 10000 | grep -A 7 ".$producer;
my $claim_cmd = $datadir."/cleos.sh system claimrewards $producer -p $producer > $datadir/claim.log";
my $balance_cmd = $datadir."/cleos.sh get currency balance eosio.token $producer > $datadir/balance.log";
my $time_diff_24h = 86400;
my @prodstats = `$prodstats_cmd`;
my $last_claim_time = 0;
foreach my $stat (@prodstats) {
if($stat=~m/"last_claim_time": "(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)\.\d\d\d"/) {
my $tp = Time::Piece->strptime($1, "%Y-%m-%dT%H:%M:%S");
$last_claim_time = $tp->epoch;;
}
}
my $current_time = time();
if($last_claim_time > 0) {
my $diff_time = $current_time - $last_claim_time;
#print $last_claim_time."->".$current_time.": ".$diff_time. "\n";
# 24h period passed - call unlock wallet and claim:
if($diff_time > $time_diff_24h) {
#Unlock wallet:
`$unlock_cmd`;
#Claim rewards:
`$claim_cmd`;
my $block_pay;
my $vote_pay;
# Read Log:
open CLOG, "$datadir/claim.log";
while (my $row = <CLOG>) {
# {"from":"eosio.bpay","to":"bostribeprod","quantity":"62.4918 BOS","memo":"producer block pay"}
if($row=~m/"from":"eosio.bpay","to":"$producer","quantity":"(\d+\.\d+) BOS","memo":"producer block pay"/) {
$block_pay = $1;
}
# {"from":"eosio.vpay","to":"bostribeprod","quantity":"312.6348 BOS","memo":"producer vote pay"}
if($row=~m/"from":"eosio.vpay","to":"$producer","quantity":"(\d+\.\d+) BOS","memo":"producer vote pay"/) {
$vote_pay = $1;
}
}
close CLOG;
# Get new Balance:
`$balance_cmd`;
# Read Log:
open BLOG, "$datadir/balance.log";
my $balance_amt = <BLOG>;
close BLOG;
my $notice = "BOS Claimed: $block_pay [block], $vote_pay [vote] \nNew Balance: $balance_amt";
print $notice;
# Backup logs with timestamp:
if(!-d "$datadir/claimlogs") {
`mkdir $datadir/claimlogs`;
}
`cp $datadir/claim.log $datadir/claimlogs/claim-$current_time.log`;
`cp $datadir/balance.log $datadir/claimlogs/balance-$current_time.log`;
}
}