cnct+lnwl+hswc: use lntypes.Preimage for witness beacon

This commit is contained in:
Conner Fromknecht
2019-02-19 17:06:00 -08:00
parent 2d8bc99d9e
commit 29f07a58cb
16 changed files with 126 additions and 114 deletions

View File

@@ -32,26 +32,31 @@ import (
type mockPreimageCache struct {
sync.Mutex
preimageMap map[[32]byte][]byte
preimageMap map[lntypes.Hash]lntypes.Preimage
}
func (m *mockPreimageCache) LookupPreimage(hash []byte) ([]byte, bool) {
func newMockPreimageCache() *mockPreimageCache {
return &mockPreimageCache{
preimageMap: make(map[lntypes.Hash]lntypes.Preimage),
}
}
func (m *mockPreimageCache) LookupPreimage(
hash lntypes.Hash) (lntypes.Preimage, bool) {
m.Lock()
defer m.Unlock()
var h [32]byte
copy(h[:], hash)
p, ok := m.preimageMap[h]
p, ok := m.preimageMap[hash]
return p, ok
}
func (m *mockPreimageCache) AddPreimages(preimages ...[]byte) error {
func (m *mockPreimageCache) AddPreimages(preimages ...lntypes.Preimage) error {
m.Lock()
defer m.Unlock()
for _, preimage := range preimages {
m.preimageMap[sha256.Sum256(preimage)] = preimage
m.preimageMap[preimage.Hash()] = preimage
}
return nil