feat: implement saveNodeVotes

This commit is contained in:
Derrick Hammer 2024-01-09 06:58:03 -05:00
parent 266f9ada0e
commit e11f3065d3
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 20 additions and 0 deletions

View File

@ -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