From e11f3065d372b979a42b9b4e45d89bb4e1ffb38e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 9 Jan 2024 06:58:03 -0500 Subject: [PATCH] feat: implement saveNodeVotes --- service/p2p.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/service/p2p.go b/service/p2p.go index 1731471..e04c4d2 100644 --- a/service/p2p.go +++ b/service/p2p.go @@ -11,6 +11,7 @@ import ( "git.lumeweb.com/LumeWeb/libs5-go/protocol/base" "git.lumeweb.com/LumeWeb/libs5-go/protocol/signed" "git.lumeweb.com/LumeWeb/libs5-go/structs" + "git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/libs5-go/utils" "github.com/vmihailenco/msgpack/v5" bolt "go.etcd.io/bbolt" @@ -300,6 +301,25 @@ func (p *P2PImpl) readNodeVotes(nodeId *encoding.NodeId) (interfaces.NodeVotes, return score, nil } +func (p *P2PImpl) saveNodeVotes(nodeId *encoding.NodeId) (interfaces.NodeVotes, error) { + votes, err := p.readNodeVotes(nodeId) + if err != nil { + return nil, err + } + + data, err := msgpack.Marshal(votes) + if err != nil { + return nil, err + } + + err = p.nodesBucket.Put(nodeId.Raw(), data) + if err != nil { + return nil, err + } + + return votes, nil +} + func (p *P2PImpl) GetNodeScore(nodeId *encoding.NodeId) (float64, error) { if nodeId.Equals(p.localNodeID) { return 1, nil