Closed dcousens closed 9 years ago
Ping @kyledrake, @jprichardson, @weilu and any others to chime in their input.
tl;dr we're not a bitcoin node.
Wallet.__processTx
attempts to give us some of that functionality, but fails without a way to chain transaction history properly; which is something entirely on the user to feed us properly.
We could fake it using various approaches, but [I feel] we should only handle unspents and do that well.
If the user wants to be fancy with their own processTx
, they can go ahead and process the unspents themselves.
If this proposal was developed and merged when do you expect the next release to be? I would really like to use it!
A 1.x.y
compatible release is in the works, but its up to @weilu and others as to when/if this gets merged and tagged.
When is the expected release to be?
I think we could get a 1.0.3
release soon, within the next 24 hrs if @weilu is around for review. But otherwise a clean 2.0.0
release may be a while yet. No ETA.
@dcousens my primary use case for processPendingTx
currently is when a user creates & sends a transaction, I can reflect that immediately on balance, unspent & history, instead of waiting for a blockchain API to pick it up. Moving forward, to update wallet balance, unspent and history, I expect relevant transactions will be pushed from blockchain API to client where only processPendingTx
and processConfirmedTx
will be used for handling them. In other words, setUnspent
is meant for one time use upon wallet initialization, subsequently processPendingTx
and processConfirmedTx
should be used.
And yes, transactions are expected to be fed in exact the same order they appear on blockchain. I don't think that should come in surprise to any dev? Missing tx is a concern but imho that's a server/client communication/sync issue that's out of the scope and control for bitcoinjs-lib.
All that being said, I'm open to solutions that address the common use cases and simplifies the wallet logic.
@weilu I think the basics are obvious, but the assumption you've made is that the blockchain API is giving you transactions/unspents in exact chronological order. This is most certainly not the case, and can't be relied on either.
I also feel that it'd be nice to move unspent management to an abstraction other than Wallet
.
Right now, its responsibilities are:
At most, I feel the top two are relevant, where as the last should be done by a different abstraction.
The 'out of place' nature of createTransaction
in Wallet
is indicative enough of this, since, at least in colloquial terms, since when does a Wallet
"create" a transaction.
Wallet
has been removed in 2.0.0
in favour of https://www.npmjs.org/package/bip32-wallet or https://www.npmjs.org/package/cb-wallet.
Both approximately mimic the original Wallet
API, with the former using the original unspents style of UTXO management and the latter using transaction chains.
@weilu correct me if I'm wrong.
edit: We should probably update the README to point to these (and other) implementations.
Copied from https://github.com/bitcoinjs/bitcoinjs-lib/pull/258 for discussion.
This kind of sucks, but I think we'll see
2.0.0
sooner than we'd like, simply because this was part of the library I just didn't have time to get around to until now (in terms of my involvement).