/
set_halt_block.go
53 lines (45 loc) 路 1.37 KB
/
set_halt_block.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
package transaction
import (
"github.com/MinterTeam/minter-go-sdk/v2/wallet"
"github.com/ethereum/go-ethereum/rlp"
)
// SetHaltBlockData is a Data of Transaction for voting to stop the network on block.
// This transaction should be sent from OwnerAddress which is set in the "Declare candidacy transaction".
type SetHaltBlockData struct {
PubKey PublicKey
Height uint64
}
// NewSetHaltBlockData returns new SetHaltBlockData of Transaction for voting to stop the network on block.
func NewSetHaltBlockData() *SetHaltBlockData {
return &SetHaltBlockData{}
}
// SetPubKey sets public key.
func (d *SetHaltBlockData) SetPubKey(key string) (*SetHaltBlockData, error) {
pubKey, err := wallet.PublicKeyToHex(key)
if err != nil {
return d, err
}
copy(d.PubKey[:], pubKey)
return d, nil
}
// MustSetPubKey tries to set public key and panics on error.
func (d *SetHaltBlockData) MustSetPubKey(key string) *SetHaltBlockData {
_, err := d.SetPubKey(key)
if err != nil {
panic(err)
}
return d
}
// SetHeight sets height
func (d *SetHaltBlockData) SetHeight(height uint64) *SetHaltBlockData {
d.Height = height
return d
}
// Type returns Data type of the transaction.
func (d *SetHaltBlockData) Type() Type {
return TypeSetHaltBlock
}
// Encode returns the byte representation of a transaction Data.
func (d *SetHaltBlockData) Encode() ([]byte, error) {
return rlp.EncodeToBytes(d)
}