Save address with Utxo.

We want only one utxo file per wallet, so each serialized Utxo needs
to also contain the receiving address.
This commit is contained in:
Josh Rickmar 2013-09-04 09:32:14 -04:00
parent a1d3800feb
commit 0928361f22
2 changed files with 7 additions and 0 deletions

View file

@ -43,6 +43,7 @@ type UtxoStore struct {
} }
type Utxo struct { type Utxo struct {
Addr [ripemd160.Size]byte
TxHash btcwire.ShaHash TxHash btcwire.ShaHash
Amt int64 // Measured in Satoshis Amt int64 // Measured in Satoshis
Height int64 Height int64
@ -180,6 +181,7 @@ func (u *UtxoStore) WriteTo(w io.Writer) (n int64, err error) {
// 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.TxHash, &u.TxHash,
&u.Amt, &u.Amt,
&u.Height, &u.Height,
@ -203,6 +205,7 @@ func (u *Utxo) ReadFrom(r io.Reader) (n int64, err error) {
// 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.TxHash, &u.TxHash,
&u.Amt, &u.Amt,
&u.Height, &u.Height,

View file

@ -87,6 +87,10 @@ var (
func TestUtxoWriteRead(t *testing.T) { func TestUtxoWriteRead(t *testing.T) {
utxo1 := &Utxo{ utxo1 := &Utxo{
Addr: [ripemd160.Size]byte{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19,
},
TxHash: [btcwire.HashSize]byte{ TxHash: [btcwire.HashSize]byte{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,