Use btcjson result type for listunspent.

This commit is contained in:
Josh Rickmar 2014-04-08 22:35:39 -05:00
parent a1b731f69e
commit 6216012aac

View file

@ -20,6 +20,7 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/conformal/btcjson"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwallet/tx" "github.com/conformal/btcwallet/tx"
"github.com/conformal/btcwallet/wallet" "github.com/conformal/btcwallet/wallet"
@ -803,7 +804,7 @@ func (am *AccountManager) GetTransaction(txsha *btcwire.ShaHash) []accountTx {
// a transaction on locally known wallets. If we know nothing about a // a transaction on locally known wallets. If we know nothing about a
// transaction an empty array will be returned. // transaction an empty array will be returned.
func (am *AccountManager) ListUnspent(minconf, maxconf int, func (am *AccountManager) ListUnspent(minconf, maxconf int,
addresses map[string]bool) ([]map[string]interface{}, error) { addresses map[string]bool) ([]*btcjson.ListUnSpentResult, error) {
bs, err := GetCurBlock() bs, err := GetCurBlock()
if err != nil { if err != nil {
@ -812,7 +813,7 @@ func (am *AccountManager) ListUnspent(minconf, maxconf int,
filter := len(addresses) != 0 filter := len(addresses) != 0
infos := []map[string]interface{}{} var results []*btcjson.ListUnSpentResult
for _, a := range am.AllAccounts() { for _, a := range am.AllAccounts() {
for _, rtx := range a.TxStore.UnspentOutputs() { for _, rtx := range a.TxStore.UnspentOutputs() {
confs := confirms(rtx.Height(), bs.Height) confs := confirms(rtx.Height(), bs.Height)
@ -833,27 +834,27 @@ func (am *AccountManager) ListUnspent(minconf, maxconf int,
} }
include: include:
outpoint := rtx.OutPoint() outpoint := rtx.OutPoint()
info := map[string]interface{}{ result := &btcjson.ListUnSpentResult{
"txid": outpoint.Hash.String(), TxId: outpoint.Hash.String(),
"vout": float64(outpoint.Index), Vout: float64(outpoint.Index),
"account": a.Name(), Account: a.Name(),
"scriptPubKey": hex.EncodeToString(rtx.PkScript()), ScriptPubKey: hex.EncodeToString(rtx.PkScript()),
"amount": float64(rtx.Value()) / 1e8, Amount: float64(rtx.Value()) / 1e8,
"confirmations": float64(confs), Confirmations: float64(confs),
} }
// BUG: this should be a JSON array so that all // BUG: this should be a JSON array so that all
// addresses can be included, or removed (and the // addresses can be included, or removed (and the
// caller extracts addresses from the pkScript). // caller extracts addresses from the pkScript).
if len(addrs) > 0 { if len(addrs) > 0 {
info["address"] = addrs[0].EncodeAddress() result.Address = addrs[0].EncodeAddress()
} }
infos = append(infos, info) results = append(results, result)
} }
} }
return infos, nil return results, nil
} }
// RescanActiveAddresses begins a rescan for all active addresses for // RescanActiveAddresses begins a rescan for all active addresses for