From c0e990fb3f83e79da078eef00a1b4678cc3cc68a Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 13 Jun 2014 13:28:50 -0500 Subject: [PATCH] Only use P2PKH outputs as sendfrom/many inputs. Closes #89. --- createtx.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/createtx.go b/createtx.go index 492b3d6..9d1796a 100644 --- a/createtx.go +++ b/createtx.go @@ -184,6 +184,17 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount, if err != nil { return nil, err } + // Filter out unspendable outputs, that is, remove those that (at this + // time) are not P2PKH outputs. Other inputs must be manually included + // in transactions and sent (for example, using createrawtransaction, + // signrawtransaction, and sendrawtransaction). + eligible := make([]*txstore.Credit, 0, len(unspent)) + for i := range unspent { + switch btcscript.GetScriptClass(unspent[i].TxOut().PkScript) { + case btcscript.PubKeyHashTy: + eligible = append(eligible, unspent[i]) + } + } var selectedInputs []*txstore.Credit // These are nil/zeroed until a change address is needed, and reused @@ -196,9 +207,9 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount, for { msgtx = txNoInputs.Copy() - // Select unspent outputs to be used in transaction based on the amount + // Select eligible outputs to be used in transaction based on the amount // neededing to sent, and the current fee estimation. - inputs, btcin, err := selectInputs(unspent, amt+fee, minconf) + inputs, btcin, err := selectInputs(eligible, amt+fee, minconf) if err != nil { return nil, err }