-
Notifications
You must be signed in to change notification settings - Fork 8
/
converter.go
38 lines (34 loc) · 979 Bytes
/
converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package vote
import (
"encoding/hex"
"time"
"github.com/bnb-chain/greenfield-challenger/db/model"
"github.com/cometbft/cometbft/votepool"
)
func DtoToEntity(v *model.Vote) (*votepool.Vote, error) {
pubKeyBts, err := hex.DecodeString(v.PubKey)
if err != nil {
return nil, err
}
sigBts, err := hex.DecodeString(v.Signature)
if err != nil {
return nil, err
}
res := votepool.Vote{}
res.EventType = votepool.EventType(v.EventType)
res.PubKey = append(res.PubKey, pubKeyBts...)
res.Signature = append(res.Signature, sigBts...)
res.EventHash = append(res.EventHash, v.EventHash...)
return &res, nil
}
func EntityToDto(from *votepool.Vote, challengeId uint64) *model.Vote {
v := model.Vote{
ChallengeId: challengeId,
PubKey: hex.EncodeToString(from.PubKey),
Signature: hex.EncodeToString(from.Signature[:]),
EventType: uint32(from.EventType),
EventHash: hex.EncodeToString(from.EventHash),
CreatedTime: time.Now().Unix(),
}
return &v
}