forked from gcash/neutrino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
headerfs: define mockBlockHeaderStore
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package headerfs | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/btcsuite/btcd/blockchain" | ||
"github.com/btcsuite/btcd/chaincfg/chainhash" | ||
"github.com/btcsuite/btcd/wire" | ||
"github.com/btcsuite/btcwallet/waddrmgr" | ||
) | ||
|
||
// mockBlockHeaderStore is an implementation of the BlockHeaderStore backed by | ||
// a simple map. | ||
type mockBlockHeaderStore struct { | ||
headers map[chainhash.Hash]wire.BlockHeader | ||
} | ||
|
||
// A compile-time check to ensure the mockBlockHeaderStore adheres to the | ||
// BlockHeaderStore interface. | ||
var _ BlockHeaderStore = (*mockBlockHeaderStore)(nil) | ||
|
||
// NewMockBlockHeaderStore ... | ||
func NewMockBlockHeaderStore() BlockHeaderStore { | ||
return &mockBlockHeaderStore{ | ||
headers: make(map[chainhash.Hash]wire.BlockHeader), | ||
} | ||
} | ||
|
||
func (m *mockBlockHeaderStore) ChainTip() (*wire.BlockHeader, | ||
uint32, error) { | ||
return nil, 0, nil | ||
|
||
} | ||
|
||
func (m *mockBlockHeaderStore) LatestBlockLocator() ( | ||
blockchain.BlockLocator, error) { | ||
return nil, nil | ||
} | ||
|
||
func (m *mockBlockHeaderStore) FetchHeaderByHeight(height uint32) ( | ||
*wire.BlockHeader, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (m *mockBlockHeaderStore) FetchHeaderAncestors(uint32, | ||
*chainhash.Hash) ([]wire.BlockHeader, uint32, error) { | ||
|
||
return nil, 0, nil | ||
} | ||
|
||
func (m *mockBlockHeaderStore) HeightFromHash(*chainhash.Hash) (uint32, error) { | ||
return 0, nil | ||
|
||
} | ||
|
||
func (m *mockBlockHeaderStore) FetchHeader(h *chainhash.Hash) ( | ||
*wire.BlockHeader, uint32, error) { | ||
if header, ok := m.headers[*h]; ok { | ||
return &header, 0, nil | ||
} | ||
return nil, 0, fmt.Errorf("not found") | ||
} | ||
|
||
func (m *mockBlockHeaderStore) WriteHeaders(headers ...BlockHeader) error { | ||
for _, h := range headers { | ||
m.headers[h.BlockHash()] = *h.BlockHeader | ||
} | ||
return nil | ||
} | ||
|
||
func (m *mockBlockHeaderStore) RollbackLastBlock() (*waddrmgr.BlockStamp, | ||
error) { | ||
return nil, nil | ||
} |