Skip to content

[Feature Request] Expand API to get stakes #161

@uaktags

Description

@uaktags

One thing I always loved about another, closed source, explorer was that they had an API to list the stakes a certain Address has via API. They went even further by allowing to do "since block height XXX". I've coded my own implementation, but wondering if there's a better idea for how to do it.

function find_stakes(address, block, cb) {
  Tx.find({vin:[], 'vout.addresses': address, blockindex: {$gt: block}}, function(err, txes){
    if(txes) {
      return cb(txes);
    } else {
      return cb(null);
    }
  });
}

So we're searching 'txes' for where there's no vin (no input), but the vout is the address being searched. For the blockheight, we're doing $gt (greater than) against the passed block. This seems to get me my desired result.
An example of usage is: http://<ipaddress>:3001/ext/getstakes/<XPADDRESS>/height/<BlockHeight>

[{"_id":"5ab157a00f4a6d8e1a646d7e","txid":"19344c5c44e7e9923bb934318ccfc4cf6ec8e307c2bd5192793b38c75d9b341d","blockhash":"5fd34ace448890caa226517a0b77ddce6881a9fbf7dbb89637c97e74b862dccc","__v":0,"blockindex":2154161,"timestamp":1521307364,"total":23576214684900,"vout":[{"addresses":"XCBCB5opdMg5YckkWtMmvv7nfioTe432n7","amount":23576214684900}],"vin":[]}]

Incredibly slow, but exactly what I was looking for. Are there any suggestions anyone has? If this is as good as it gets, then should I just do a pullrequest for the feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions