From 422f0a9791d585ebb495b7ea8244968bdde43d19 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 20 Dec 2015 21:46:41 -0600 Subject: [PATCH] revocation: split up methods to get current pre-image and hash --- revocation/shachain.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/revocation/shachain.go b/revocation/shachain.go index 35de18a3d..5ca55f79b 100644 --- a/revocation/shachain.go +++ b/revocation/shachain.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/btcsuite/btcd/wire" + "github.com/btcsuite/fastsha256" ) const ( @@ -135,11 +136,19 @@ func (h *HyperShaChain) AddNextHash(hash [32]byte) error { return nil } -// CurrentHash... -func (h *HyperShaChain) CurrentHash() (*wire.ShaHash, error) { - h.Lock() - defer h.Unlock() - return &h.lastHash, nil +// CurrentPreImage... +func (h *HyperShaChain) CurrentPreImage() *wire.ShaHash { + h.RLock() + defer h.RUnlock() + return &h.lastHash +} + +// CurrentRevocationHash... +// TODO(roasbeef): *wire.ShaHash vs [wire.HashSize]byte ? +func (h *HyperShaChain) CurrentRevocationHash() [wire.HashSize]byte { + h.RLock() + defer h.RUnlock() + return fastsha256.Sum256(h.lastHash[:]) } // LocatePreImage...