How to get the full history of a HIVE account (JS)

in #hive3 years ago (edited)

This is how I get the full account history of a given HIVE account with dhive

Not included are virtual ops, as that's a different call entirely.
I had solved this before, but this time my solution is kind of neat, so I wanted to share, in case someone else did not find that trivial.

<script src="https://unpkg.com/@hiveio/dhive@latest/dist/dhive.js"></script>
<script>
let account = 'bittrex-richie';
let client = new dhive.Client(["https://api.hive.blog"]);

class AccountData {
    constructor(account, client) {
        this.account = account
        this.client = client             
        this.operations = []
    }
    load(start = -1, limit = 1000) {
        return new Promise(resolve => {                            
            this.client.database.getAccountHistory(
                account = this.account, 
                start = start, 
                limit = limit
        )
            .then((operations) => {                    
                for (var operation of operations.reverse()) {   
                    this.operations.push(operation)
                } 
                if (start == -1) {
                    start = operation[0] - 1
                } 
                else {
                    start = start - limit
                }
                if (start <= 0){                        
                    resolve()
                    return
                }
                if (limit >= start) {
                    limit = start
                }
                this.load(start, limit).then(resolve)                    
            })
        })
    }
}   
var ada = new AccountData(account, client);
ada.load().then(() => {        
    for (operation of ada.operations) {
        console.log(operation)
    }
})
</script>
Sort:  

Ich versteh nur Bahnhof.

Hört sich dennoch gut an... :o)

!BEER

Oder man probiert https://hivetasks.com/ aus...

bringt einem ja nich viel, wenn man was programmieren will.

Daß ich da nicht von selbst drauf gekommen bin.... mit meinen nur noch ganz dunkel irgendwo in einer vesteckten Ecke meines Hirns vorhandenen C64 Basic Kenntnissen. ;-) ;-)

I'm looking for somebody to feed me the numbers to reproduce this report and @statsmonkey.

I don't know what code to do that is worth, but I'm willing to pay for it.

I got this week off. Next week I have to work full time again.
If you want this done quickly, contact me now.

Sorry, got sidetracked by work.

Got Discord?

Yes, #8249.

we got to share a server.
https://discord.gg/Y2WDKcNN


Hey @felixxx, here is a little bit of BEER from @indextrader24 for you. Enjoy it!

Learn how to earn FREE BEER each day by staking your BEER.