Save correct addresses for new utxos
This commit is contained in:
parent
1ecc74c37d
commit
50073b32c1
4 changed files with 20 additions and 14 deletions
20
cmd.go
20
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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
10
tx/tx.go
10
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,
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue