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 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.
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:
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:
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