-
Notifications
You must be signed in to change notification settings - Fork 328
/
putpollresult.go
76 lines (61 loc) · 2.27 KB
/
putpollresult.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2019 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
package action
import (
"github.com/iotexproject/iotex-proto/golang/iotextypes"
"google.golang.org/protobuf/proto"
"github.com/iotexproject/iotex-core/v2/pkg/util/byteutil"
"github.com/iotexproject/iotex-core/v2/state"
)
// PutPollResult represents put the poll result from gravity chain.
type PutPollResult struct {
height uint64
candidates state.CandidateList
}
// NewPutPollResult instantiates a putting poll result action struct.
func NewPutPollResult(
height uint64,
candidates state.CandidateList,
) *PutPollResult {
return &PutPollResult{
height: height,
candidates: candidates,
}
}
// LoadProto converts a proto message into put block action.
func (r *PutPollResult) LoadProto(putPollResultPb *iotextypes.PutPollResult) error {
if putPollResultPb == nil {
return ErrNilProto
}
if r == nil {
return ErrNilAction
}
*r = PutPollResult{}
r.height = putPollResultPb.Height
return r.candidates.LoadProto(putPollResultPb.Candidates)
}
func (act *PutPollResult) FillAction(core *iotextypes.ActionCore) {
core.Action = &iotextypes.ActionCore_PutPollResult{PutPollResult: act.Proto()}
}
// Proto converts put poll result action into a proto message.
func (r *PutPollResult) Proto() *iotextypes.PutPollResult {
return &iotextypes.PutPollResult{
Height: r.height,
Candidates: r.candidates.Proto(),
}
}
// Height returns put poll result height.
func (r *PutPollResult) Height() uint64 { return r.height }
// Candidates returns the list of candidates.
func (r *PutPollResult) Candidates() state.CandidateList { return r.candidates }
// Serialize returns the byte representation of put poll result action.
func (r *PutPollResult) Serialize() []byte {
return byteutil.Must(proto.Marshal(r.Proto()))
}
// IntrinsicGas returns the intrinsic gas of a put poll result action
func (r *PutPollResult) IntrinsicGas() (uint64, error) {
return 0, nil
}
func (r *PutPollResult) SanityCheck() error { return nil }