mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-02 19:44:03 +02:00
cnct+lnwl+hswc: use lntypes.Preimage for witness beacon
This commit is contained in:
21
mock.go
21
mock.go
@ -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
|
||||
|
Reference in New Issue
Block a user