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
|
return false
|
||||||
}
|
}
|
||||||
sender58, ok := v["sender"].(string)
|
sender, ok := v["sender"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error("Tx Handler: Unspecified sender.")
|
log.Error("Tx Handler: Unspecified sender.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
receiver58, ok := v["receiver"].(string)
|
receiver, ok := v["receiver"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error("Tx Handler: Unspecified receiver.")
|
log.Error("Tx Handler: Unspecified receiver.")
|
||||||
return false
|
return false
|
||||||
|
@ -429,8 +429,13 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
sender := btcutil.Base58Decode(sender58)
|
// TODO(jrick): btcd does not find the sender yet.
|
||||||
receiver := btcutil.Base58Decode(receiver58)
|
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() {
|
go func() {
|
||||||
t := &tx.RecvTx{
|
t := &tx.RecvTx{
|
||||||
|
@ -438,8 +443,8 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool
|
||||||
}
|
}
|
||||||
copy(t.TxHash[:], txhash[:])
|
copy(t.TxHash[:], txhash[:])
|
||||||
copy(t.BlockHash[:], blockhash[:])
|
copy(t.BlockHash[:], blockhash[:])
|
||||||
copy(t.SenderAddr[:], sender)
|
copy(t.SenderAddr[:], senderHash)
|
||||||
copy(t.ReceiverAddr[:], receiver)
|
copy(t.ReceiverAddr[:], receiverHash)
|
||||||
|
|
||||||
w.TxStore.Lock()
|
w.TxStore.Lock()
|
||||||
txs := w.TxStore.s
|
txs := w.TxStore.s
|
||||||
|
@ -457,7 +462,8 @@ func (w *BtcWallet) newBlockTxHandler(result interface{}, e *btcjson.Error) bool
|
||||||
}
|
}
|
||||||
copy(u.Out.Hash[:], txhash[:])
|
copy(u.Out.Hash[:], txhash[:])
|
||||||
u.Out.Index = uint32(index)
|
u.Out.Index = uint32(index)
|
||||||
copy(u.Addr[:], receiver)
|
|
||||||
|
copy(u.AddrHash[:], receiverHash)
|
||||||
copy(u.BlockHash[:], blockhash[:])
|
copy(u.BlockHash[:], blockhash[:])
|
||||||
|
|
||||||
w.UtxoStore.Lock()
|
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))
|
msgtx.AddTxIn(btcwire.NewTxIn((*btcwire.OutPoint)(&op.Out), nil))
|
||||||
}
|
}
|
||||||
for i, op := range outputs {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// Utxo is a type storing information about a single unspent
|
||||||
// transaction output.
|
// transaction output.
|
||||||
type Utxo struct {
|
type Utxo struct {
|
||||||
Addr [ripemd160.Size]byte
|
AddrHash [ripemd160.Size]byte
|
||||||
Out OutPoint
|
Out OutPoint
|
||||||
Subscript PkScript
|
Subscript PkScript
|
||||||
Amt uint64 // Measured in Satoshis
|
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
|
// ReadFrom satisifies the io.ReaderFrom interface. A Utxo is read
|
||||||
// from r with the format:
|
// 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.
|
// Each field is read little endian.
|
||||||
func (u *Utxo) ReadFrom(r io.Reader) (n int64, err error) {
|
func (u *Utxo) ReadFrom(r io.Reader) (n int64, err error) {
|
||||||
datas := []interface{}{
|
datas := []interface{}{
|
||||||
&u.Addr,
|
&u.AddrHash,
|
||||||
&u.Out,
|
&u.Out,
|
||||||
&u.Subscript,
|
&u.Subscript,
|
||||||
&u.Amt,
|
&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
|
// WriteTo satisifies the io.WriterTo interface. A Utxo is written to
|
||||||
// w in the format:
|
// 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.
|
// Each field is written little endian.
|
||||||
func (u *Utxo) WriteTo(w io.Writer) (n int64, err error) {
|
func (u *Utxo) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
datas := []interface{}{
|
datas := []interface{}{
|
||||||
&u.Addr,
|
&u.AddrHash,
|
||||||
&u.Out,
|
&u.Out,
|
||||||
&u.Subscript,
|
&u.Subscript,
|
||||||
&u.Amt,
|
&u.Amt,
|
||||||
|
|
|
@ -648,7 +648,7 @@ func (w *Wallet) NextUnusedAddress() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddressKey returns the private key for a payment address stored
|
// 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
|
// Bitcoin network than what this wallet uses, the address is not
|
||||||
// contained in the wallet, the address does not include a public and
|
// contained in the wallet, the address does not include a public and
|
||||||
// private key, or if the wallet is locked.
|
// private key, or if the wallet is locked.
|
||||||
|
|
Loading…
Reference in a new issue