From 7c23cf13b394f88b4e6522d4fb4d02be50a799c3 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 5 May 2017 08:17:31 -0600 Subject: [PATCH] GetUtxo fixed. --- spvsvc/spvchain/rescan.go | 28 ++++++++++++++-------------- spvsvc/spvchain/sync_test.go | 22 ++++++++++------------ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/spvsvc/spvchain/rescan.go b/spvsvc/spvchain/rescan.go index fe7ef7a..966d211 100644 --- a/spvsvc/spvchain/rescan.go +++ b/spvsvc/spvchain/rescan.go @@ -563,20 +563,20 @@ func (s *ChainService) GetUtxo(options ...RescanOption) (*wire.TxOut, error) { Index], nil } } - // Otherwise, iterate backwards until we've gone too - // far. - curStamp.Height-- - if curStamp.Height < ro.startBlock.Height { - return nil, fmt.Errorf("Couldn't find "+ - "transaction %s", - ro.watchOutPoints[0].Hash) - } - header, err := s.GetBlockByHeight( - uint32(curStamp.Height)) - if err != nil { - return nil, err - } - curStamp.Hash = header.BlockHash() } + // Otherwise, iterate backwards until we've gone too + // far. + curStamp.Height-- + if curStamp.Height < ro.startBlock.Height { + return nil, fmt.Errorf("Couldn't find "+ + "transaction %s", + ro.watchOutPoints[0].Hash) + } + header, err := s.GetBlockByHeight( + uint32(curStamp.Height)) + if err != nil { + return nil, err + } + curStamp.Hash = header.BlockHash() } } diff --git a/spvsvc/spvchain/sync_test.go b/spvsvc/spvchain/sync_test.go index c800da0..faaa3f8 100644 --- a/spvsvc/spvchain/sync_test.go +++ b/spvsvc/spvchain/sync_test.go @@ -635,6 +635,16 @@ func TestSetup(t *testing.T) { } } + // Check and make sure the previous UTXO is now spent. + _, err = svc.GetUtxo( + spvchain.WatchOutPoints(ourOutPoint), + spvchain.StartBlock(&waddrmgr.BlockStamp{Height: 801}), + ) + if err.Error() != fmt.Sprintf("OutPoint %s has been spent", + ourOutPoint) { + t.Fatalf("UTXO %s not seen as spent: %s", ourOutPoint, err) + } + // Generate 5 blocks on h2 and wait for ChainService to sync to the // newly-best chain on h2. _, err = h2.Node.Generate(5) @@ -672,18 +682,6 @@ func TestSetup(t *testing.T) { t.Fatalf("Rescan event logs incorrect.\nWant: %s\nGot: %s\n", wantLog, gotLog) } - - // Check and make sure the previous UTXO is now spent. - // TODO: Uncomment this (right now it causes a deadlock.) - /*_, err = svc.GetUtxo( - spvchain.WatchOutPoints(ourOutPoint), - spvchain.StartBlock(&waddrmgr.BlockStamp{Height: 801}), - ) - if err.Error() != fmt.Sprintf("OutPoint %s has been spent", - ourOutPoint) { - t.Fatalf("UTXO %s not seen as spent: %s", ourOutPoint, err) - }*/ - } // csd does a connect-sync-disconnect between nodes in order to support