-
Notifications
You must be signed in to change notification settings - Fork 92
/
EntryIncreaseServerCount.go
112 lines (90 loc) · 2.47 KB
/
EntryIncreaseServerCount.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package adminBlock
import (
"fmt"
"os"
"github.com/FactomProject/factomd/common/constants"
"github.com/FactomProject/factomd/common/interfaces"
"github.com/FactomProject/factomd/common/primitives"
)
// DB Signature Entry -------------------------
type IncreaseServerCount struct {
AdminIDType uint32 `json:"adminidtype"`
Amount byte `json:"amount"`
}
var _ interfaces.IABEntry = (*IncreaseServerCount)(nil)
var _ interfaces.BinaryMarshallable = (*IncreaseServerCount)(nil)
// Create a new DB Signature Entry
func NewIncreaseSererCount(num byte) (e *IncreaseServerCount) {
e = new(IncreaseServerCount)
e.Amount = num
return
}
func (c *IncreaseServerCount) UpdateState(state interfaces.IState) error {
return nil
}
func (e *IncreaseServerCount) Type() byte {
return constants.TYPE_ADD_SERVER_COUNT
}
func (e *IncreaseServerCount) MarshalBinary() (rval []byte, err error) {
defer func(pe *error) {
if *pe != nil {
fmt.Fprintf(os.Stderr, "IncreaseServerCount.MarshalBinary err:%v", *pe)
}
}(&err)
var buf primitives.Buffer
e.AdminIDType = uint32(e.Type())
err = buf.PushByte(e.Type())
if err != nil {
return nil, err
}
err = buf.PushByte(e.Amount)
if err != nil {
return nil, err
}
return buf.DeepCopyBytes(), nil
}
func (e *IncreaseServerCount) UnmarshalBinaryData(data []byte) ([]byte, error) {
buf := primitives.NewBuffer(data)
b, err := buf.PopByte()
if err != nil {
return nil, err
}
if b != e.Type() {
return nil, fmt.Errorf("Invalid Entry type")
}
e.Amount, err = buf.PopByte()
if err != nil {
return nil, err
}
return buf.DeepCopyBytes(), nil
}
func (e *IncreaseServerCount) UnmarshalBinary(data []byte) (err error) {
_, err = e.UnmarshalBinaryData(data)
return
}
func (e *IncreaseServerCount) JSONByte() ([]byte, error) {
e.AdminIDType = uint32(e.Type())
return primitives.EncodeJSON(e)
}
func (e *IncreaseServerCount) JSONString() (string, error) {
e.AdminIDType = uint32(e.Type())
return primitives.EncodeJSONString(e)
}
func (e *IncreaseServerCount) String() string {
str := fmt.Sprintf(" E: %35s -- by %d", "Increase Server Count", e.Amount)
return str
}
func (e *IncreaseServerCount) IsInterpretable() bool {
return false
}
func (e *IncreaseServerCount) Interpret() string {
return ""
}
func (e *IncreaseServerCount) Hash() (rval interfaces.IHash) {
defer func() { rval = primitives.CheckNil(rval, "IncreaseServerCount.Hash") }()
bin, err := e.MarshalBinary()
if err != nil {
panic(err)
}
return primitives.Sha(bin)
}