Bash Shell Script To View Quick Stats On Balance And Tickets

Discussion in 'User Projects' started by ZiggyZoomber, Apr 10, 2016.

Tags:
  1. 2017/12/15 - Decred v1.1.2 released! → Release Notes  → Downloads
  1. ZiggyZoomber

    ZiggyZoomber New Member

    Feb 8, 2016
    2
    7
    Cyberspace
    #1 ZiggyZoomber, Apr 10, 2016
    Last edited: Jun 5, 2016
    Hey, I tossed together a little bash shells script that displays your wallet balance and ticket info and figured others might find it handy to use as well.

    getbalance.jpg

    I keep it in the same folder as dcrctl and called it "getbalance.sh"

    Code:
    #!/bin/bash
    # Balance (All, Spendable Locked)
    all=$(./dcrctl --wallet getbalance default 0 all)
    spend=$(./dcrctl --wallet getbalance default 0 spendable)
    lock=$(./dcrctl --wallet getbalance default 0 locked)
    echo -e "\e[1mDecred | Rethink Digital Currency.\e[0m"
    echo -e "\e[92mBalance \e[33m=> \e[32mTotal: $all, Spendable: $spend, Locked: $lock"
    # Tickets (Voted, Missed, Revoked, Live, Immature)
    json=$(./dcrctl --wallet getstakeinfo)
    voted=$(echo "$json" | jq '.voted')
    missed=$(echo "$json" | jq '.missed')
    revoked=$(echo "$json" | jq '.revoked')
    live=$(echo "$json" | jq '.live')
    immature=$(echo "$json" | jq '.immature')
    ticketprice=$(echo "$json" | jq '.difficulty')
    echo -e "\e[96mTickets \e[33m=> \e[36mVoted: $voted, Missed: $missed, Revoked: $revoked, Live: $live, Immature: $immature"
    echo -e "           \e[36mCurrent Ticket Price: $ticketprice"
    # Wallet Info
    json=$(./dcrctl --wallet walletinfo)
    stake=$(echo "$json" | jq '.stakemining')
    unlocked=$(echo "$json" | jq '.unlocked')
    ticketmax=$(echo "$json" | jq '.ticketmaxprice')
    echo -e "\e[95mStatus  \e[33m=> \e[35mPoS Enabled: $stake, Wallet Unlocked: $unlocked, Ticket Max Price: $ticketmax\n\e[0m"
    
    
    *NOTES:
    1) You will need to install a program called jq (https://stedolan.github.io/jq/) which is used to parse out some of the ticket info.
    2) This assumes you have setup a dcrctl.conf with rpc user and pass

    UPDATES:
    2016.06.05 - I added additional information about tickets and status of PoS and Wallet.
     
    chappjc, 418Sec, David and 4 others like this.
  2. root

    root Member

    Feb 3, 2016
    381
    76
  3. Lee Sharp

    Lee Sharp Sr. Member

    Dec 28, 2015
    308
    217
    Male
    Independent Consultant
    Houston, Texas
    This should be in user projects. Nice work!
     
  4. 418Sec

    418Sec Member
    Advocate (Twitter)

    Jan 3, 2016
    122
    65
    Male
    Good work! This will be useful to some people and projects! :)
     
  5. dave

    dave New Member

    Jan 11, 2016
    27
    10
    I have been using jq with windows (in conjunction with autohotkey and a bat file) to generate my report to google drive every 15 minutes


    ----------My Balance----------
    All: 642.10318476
    Locked: 593.22170743
    Spendable: 32.32594846
    Pending: 16.555529

    ----------My Tickets----------
    Live: 87
    Immature: 0
    Mempool: 0
    Avg Cost: 6.818640

    Voted: 178
    Missed: 1
    Subsidy: 329.402053

    ----------All Tickets---------
    Live: 43106
    Staked: 411078.21523679
    Avg Cost: 9.536450
    Cur Cost: 31.09293709
    Mempool: 0


    04/12/16 08:40 AM
     
  6. 418Sec

    418Sec Member
    Advocate (Twitter)

    Jan 3, 2016
    122
    65
    Male
    That's handy... Share the code if you may.
     
  7. dave

    dave New Member

    Jan 11, 2016
    27
    10
    ok...but im doing this in a VERY hackish way.......the goal was to make it look good on my phone (see screenshot)
    1. autohotkey script runs every 15 minutes,
    2. the batch file gets the data using jq to parse some elements (this could be done in autohotkey as well but it was already done as a batch file and i was too lazy to move it)
    3. autohotkey does the calculation, formatting, and saves to google drive

    Required
    jq (https://stedolan.github.io/jq/)
    autohotkey (https://autohotkey.com/download/)


    in batch file "getbalance.bat"
    ---------------------------------------------------------------------------
    C:\Decred\dcrctl.exe --wallet getbalance "default" 0 all > "C:\Decred\temp\all.tmp"
    C:\Decred\dcrctl.exe --wallet getbalance > "C:\Decred\temp\bal.tmp"
    C:\Decred\dcrctl.exe --wallet getbalance "default" 0 locked > "C:\Decred\temp\lock.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo > "C:\Decred\temp\stakeinfo.tmp"
    C:\Decred\dcrctl.exe --wallet getticketpoolvalue > "C:\Decred\temp\stakesize.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .poolsize > "C:\Decred\temp\poolsize.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .difficulty > "C:\Decred\temp\difficulty.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .allmempooltix > "C:\Decred\temp\allmempooltix.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .ownmempooltix > "C:\Decred\temp\ownmempooltix.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .immature > "C:\Decred\temp\immature.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .live > "C:\Decred\temp\live.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .voted > "C:\Decred\temp\voted.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .totalsubsidy > "C:\Decred\temp\totalsubsidy.tmp"
    C:\Decred\dcrctl.exe --wallet getstakeinfo|jq-win64 .missed > "C:\Decred\temp\missed.tmp"
    ---------------------------------------------------------------------------

    in autohotkey file "drive.ahk"

    AutoTrim, On
    Loop
    {
    runwait, "C:\Decred\getbalance.bat",,hide

    FileRead, allDCR,C:\Decred\temp\all.tmp
    FileRead, lockDCR,C:\Decred\temp\lock.tmp
    FileRead, balDCR,C:\Decred\temp\bal.tmp


    FileRead, AllStakeVar,C:\Decred\temp\stakesize.tmp
    FileRead, AllPoolVar,C:\Decred\temp\poolsize.tmp
    fileread, difficulty,C:\Decred\temp\difficulty.tmp
    fileread, allmempooltix,C:\Decred\temp\allmempooltix.tmp
    fileread, ownmempooltix,C:\Decred\temp\ownmempooltix.tmp
    fileread, immature,C:\Decred\temp\immature.tmp
    fileread, live,C:\Decred\temp\live.tmp
    fileread, voted,C:\Decred\temp\voted.tmp
    fileread, totalsubsidy,C:\Decred\temp\totalsubsidy.tmp
    fileread, missed,C:\Decred\temp\missed.tmp


    AllPoolVar:=eval(AllPoolVar)
    AllStakeVar:=eval(AllStakeVar)
    difficulty:=eval(difficulty)
    allmempooltix:=eval(allmempooltix)
    ownmempooltix:=eval(ownmempooltix)
    immature:=eval(immature)
    live:=eval(live)
    voted:=eval(voted)
    totalsubsidy:=eval(totalsubsidy)
    missed:=eval(missed)
    allDCR:=eval(allDCR)
    lockDCR:=eval(lockDCR)
    balDCR:=eval(balDCR)

    AvgAllPoolTix:=AllStakeVar/AllPoolVar
    pendingDCR:=allDCR-balDCR-lockDCR
    AvgMyPoolTix:=lockDCR/(live+immature)
    FormatTime, Time,, MM/dd/yy hh:mm tt
    ;msgbox, %AvgAllPoolTix%
    filedelete, C:\Google Drive\decred\report.txt
    FileAppend,
    (
    ----------My Balance----------
    All: %allDCR%
    Locked: %lockDCR%
    Spendable: %balDCR%
    Pending: %pendingDCR%

    ----------My Tickets----------
    Live: %live%
    Immature: %immature%
    Mempool: %ownmempooltix%
    Avg Cost: %AvgMyPoolTix%

    Voted: %voted%
    Missed: %missed%
    Subsidy: %totalsubsidy%

    ----------All Tickets---------
    Live: %AllPoolVar%
    Staked: %AllStakeVar%
    Avg Cost: %AvgAllPoolTix%
    Cur Cost: %difficulty%
    Mempool: %allmempooltix%


    %time%

    ), C:\Google Drive\decred\report.txt

    filedelete, C:\Decred\temp\*.tmp
    Sleep, 900000
    }

    Return



    Eval(x)
    {
    StringReplace, x, x, `n,, All
    StringReplace, x, x, `r,, All
    StringReplace, x, x, %A_SPACE%,, All
    Return x
    }
     

    Attached Files:

    418Sec likes this.

Share This Page