node/pkg/common: add GetAll accessor for GuardianSetState
Change-Id: I7ce71d356f9fc83cc751e98835cbae070deb8640
This commit is contained in:
parent
aa608b9396
commit
3dcf1f1998
|
@ -3,6 +3,7 @@ package common
|
|||
import (
|
||||
gossipv1 "github.com/certusone/wormhole/bridge/pkg/proto/gossip/v1"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -87,3 +88,18 @@ func (st *GuardianSetState) SetHeartBeat(addr common.Address, hb *gossipv1.Heart
|
|||
defer st.mu.Unlock()
|
||||
st.lastHeartbeat[addr] = hb
|
||||
}
|
||||
|
||||
// GetAll returns all stored heartbeats.
|
||||
func (st *GuardianSetState) GetAll() map[common.Address]*gossipv1.Heartbeat {
|
||||
st.mu.Lock()
|
||||
defer st.mu.Unlock()
|
||||
|
||||
ret := make(map[common.Address]*gossipv1.Heartbeat)
|
||||
|
||||
// Deep copy
|
||||
for k, v := range st.lastHeartbeat {
|
||||
ret[k] = proto.Clone(v).(*gossipv1.Heartbeat)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue