From 50073b32c1b652f1b431245fb376adaf878bb612 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 10 Oct 2013 18:44:44 -0400 Subject: [PATCH] Save correct addresses for new utxos --- cmd.go | 20 +++++++++++++------- createtx.go | 2 +- tx/tx.go | 10 +++++----- wallet/wallet.go | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cmd.go b/cmd.go index ea0bde3..1745d73 100644 --- a/cmd.go +++ b/cmd.go @@ -375,12 +375,12 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool } return false } - sender58, ok := v["sender"].(string) + sender, ok := v["sender"].(string) if !ok { log.Error("Tx Handler: Unspecified sender.") return false } - receiver58, ok := v["receiver"].(string) + receiver, ok := v["receiver"].(string) if !ok { log.Error("Tx Handler: Unspecified receiver.") return false @@ -429,8 +429,13 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool return false } - sender := btcutil.Base58Decode(sender58) - receiver := btcutil.Base58Decode(receiver58) + // TODO(jrick): btcd does not find the sender yet. + senderHash, _, _ := btcutil.DecodeAddress(sender) + receiverHash, _, err := btcutil.DecodeAddress(receiver) + if err != nil { + log.Error("Tx Handler: receiver address can not be decoded: " + err.Error()) + return false + } go func() { t := &tx.RecvTx{ @@ -438,8 +443,8 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool } copy(t.TxHash[:], txhash[:]) copy(t.BlockHash[:], blockhash[:]) - copy(t.SenderAddr[:], sender) - copy(t.ReceiverAddr[:], receiver) + copy(t.SenderAddr[:], senderHash) + copy(t.ReceiverAddr[:], receiverHash) w.TxStore.Lock() txs := w.TxStore.s @@ -457,7 +462,8 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool } copy(u.Out.Hash[:], txhash[:]) u.Out.Index = uint32(index) - copy(u.Addr[:], receiver) + + copy(u.AddrHash[:], receiverHash) copy(u.BlockHash[:], blockhash[:]) w.UtxoStore.Lock() diff --git a/createtx.go b/createtx.go index 8638e0a..398e326 100644 --- a/createtx.go +++ b/createtx.go @@ -169,7 +169,7 @@ func (w *BtcWallet) txToPairs(pairs map[string]uint64, fee uint64, minconf int) msgtx.AddTxIn(btcwire.NewTxIn((*btcwire.OutPoint)(&op.Out), nil)) } for i, op := range outputs { - addrstr, err := btcutil.EncodeAddress(op.Addr[:], w.Wallet.Net()) + addrstr, err := btcutil.EncodeAddress(op.AddrHash[:], w.Wallet.Net()) if err != nil { return nil, err } diff --git a/tx/tx.go b/tx/tx.go index d59c0e8..a7564cd 100644 --- a/tx/tx.go +++ b/tx/tx.go @@ -39,7 +39,7 @@ type UtxoStore []*Utxo // Utxo is a type storing information about a single unspent // transaction output. type Utxo struct { - Addr [ripemd160.Size]byte + AddrHash [ripemd160.Size]byte Out OutPoint Subscript PkScript Amt uint64 // Measured in Satoshis @@ -183,12 +183,12 @@ func (u *UtxoStore) Rollback(height int64, hash *btcwire.ShaHash) (modified bool // ReadFrom satisifies the io.ReaderFrom interface. A Utxo is read // from r with the format: // -// [Addr (20 bytes), Out (36 bytes), Subscript (varies), Amt (8 bytes), Height (8 bytes), BlockHash (32 bytes)] +// [AddrHash (20 bytes), Out (36 bytes), Subscript (varies), Amt (8 bytes), Height (8 bytes), BlockHash (32 bytes)] // // Each field is read little endian. func (u *Utxo) ReadFrom(r io.Reader) (n int64, err error) { datas := []interface{}{ - &u.Addr, + &u.AddrHash, &u.Out, &u.Subscript, &u.Amt, @@ -213,12 +213,12 @@ func (u *Utxo) ReadFrom(r io.Reader) (n int64, err error) { // WriteTo satisifies the io.WriterTo interface. A Utxo is written to // w in the format: // -// [Addr (20 bytes), Out (36 bytes), Subscript (varies), Amt (8 bytes), Height (8 bytes), BlockHash (32 bytes)] +// [AddrHash (20 bytes), Out (36 bytes), Subscript (varies), Amt (8 bytes), Height (8 bytes), BlockHash (32 bytes)] // // Each field is written little endian. func (u *Utxo) WriteTo(w io.Writer) (n int64, err error) { datas := []interface{}{ - &u.Addr, + &u.AddrHash, &u.Out, &u.Subscript, &u.Amt, diff --git a/wallet/wallet.go b/wallet/wallet.go index f9f45dc..1e756d9 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -648,7 +648,7 @@ func (w *Wallet) NextUnusedAddress() (string, error) { } // GetAddressKey returns the private key for a payment address stored -// in a wallet. This can fail if the payment address for a different +// in a wallet. This can fail if the payment address is for a different // Bitcoin network than what this wallet uses, the address is not // contained in the wallet, the address does not include a public and // private key, or if the wallet is locked.