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

21
mock.go
View File

@ -1,7 +1,6 @@
package main
import (
"crypto/sha256"
"fmt"
"sync"
"sync/atomic"
@ -16,6 +15,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
)
@ -303,26 +303,29 @@ func (m *mockSecretKeyRing) ScalarMult(keyDesc keychain.KeyDescriptor,
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