Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convey information about network confirmations when calling getUnspentUtxos #22

Open
bilthon opened this issue Oct 18, 2015 · 0 comments

Comments

@bilthon
Copy link

bilthon commented Oct 18, 2015

When querying for unspent transactions, one key information to be presented is how old it is. The getUnspentUtxos method from the Insight class returns an array of UnspentOutput objects.

The problem with this approach is that the important time information is capped from the raw HTTP response. Since the UnspentOutput object only have immutable fields the "timestamp" and "confirmation" attributes from the original response are left out when doing this:

unspent = _.map(unspent, UnspentOutput);

I see two ways to improve this method. We either add the "timestamp" and "confirmation" attributes to the UnspentOutput, or the getUnspentUtxos gets a new optional boolean parameter that when set to true will return the raw HTTP response. The former method will return a more complete version of the UsnpentOutput object. I don't see how this could break existing code. The latter will allow the caller to access these information without having to touch the UnspentOutput definition.

This would work like this:

Insight.prototype.getUnspentUtxos = function(addresses, raw, callback) {
  if(typeof(raw) == 'function'){
    callaback = raw
  }
  ...
  if(!raw || typeof(raw) == 'function')
    unspent = _.map(unspent, UnspentOutput);
}

This way we don't break anything that already uses this format of the API passing the callback as the second argument. And also provide a way to return the raw response if needed.

I'll be happy to submit a pull request with either modifications. But would like some opinions first.

Best regards
Nelson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant