-
Notifications
You must be signed in to change notification settings - Fork 6
/
timelimit.go
129 lines (106 loc) · 3.29 KB
/
timelimit.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package actions
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/hacash/core/fields"
"github.com/hacash/core/interfaces"
"github.com/hacash/core/interfacev2"
)
type Action_29_SubmitTimeLimit struct {
StartHeight fields.BlockHeight
EndHeight fields.BlockHeight
// data ptr
belong_trs interfaces.Transaction
}
func (elm *Action_29_SubmitTimeLimit) Kind() uint16 {
return 29
}
// json api
func (elm *Action_29_SubmitTimeLimit) Describe() map[string]interface{} {
var data = map[string]interface{}{}
return data
}
func (elm *Action_29_SubmitTimeLimit) Serialize() ([]byte, error) {
var kindByte = make([]byte, 2)
binary.BigEndian.PutUint16(kindByte, elm.Kind())
var h1, _ = elm.StartHeight.Serialize()
var h2, _ = elm.EndHeight.Serialize()
var buffer bytes.Buffer
buffer.Write(kindByte)
buffer.Write(h1)
buffer.Write(h2)
return buffer.Bytes(), nil
}
func (elm *Action_29_SubmitTimeLimit) Parse(buf []byte, seek uint32) (uint32, error) {
var e error
seek, e = elm.StartHeight.Parse(buf, seek)
if e != nil {
return 0, e
}
seek, e = elm.EndHeight.Parse(buf, seek)
if e != nil {
return 0, e
}
return seek, nil
}
func (elm *Action_29_SubmitTimeLimit) Size() uint32 {
return 2 + elm.StartHeight.Size() + elm.EndHeight.Size()
}
func (*Action_29_SubmitTimeLimit) RequestSignAddresses() []fields.Address {
return []fields.Address{} // not sign
}
func (act *Action_29_SubmitTimeLimit) WriteInChainState(state interfaces.ChainStateOperation) error {
if act.belong_trs == nil {
panic("Action belong to transaction not be nil !")
}
curblockhei := state.GetPendingBlockHeight()
// start check
if act.StartHeight > 0 {
if curblockhei < uint64(act.StartHeight) {
return fmt.Errorf("The transaction cannot be submitted if the current block height is less than %d", act.StartHeight)
}
}
// end check
if act.EndHeight > 0 {
if curblockhei > uint64(act.EndHeight) {
return fmt.Errorf("The transaction cannot be submitted if the current block height is more than %d", act.EndHeight)
}
}
// submit time check ok pass
return nil
}
func (act *Action_29_SubmitTimeLimit) WriteinChainState(state interfacev2.ChainStateOperation) error {
if act.belong_trs == nil {
panic("Action belong to transaction not be nil !")
}
curblockhei := state.GetPendingBlockHeight()
// start check
if act.StartHeight > 0 {
if curblockhei < uint64(act.StartHeight) {
return fmt.Errorf("The transaction cannot be submitted if the current block height is less than %d", act.StartHeight)
}
}
// end check
if act.EndHeight > 0 {
if curblockhei > uint64(act.EndHeight) {
return fmt.Errorf("The transaction cannot be submitted if the current block height is more than %d", act.EndHeight)
}
}
// submit time check ok pass
return nil
}
func (act *Action_29_SubmitTimeLimit) RecoverChainState(state interfacev2.ChainStateOperation) error {
panic("RecoverChainState() removed !")
}
// Set belongs to long_ trs
func (act *Action_29_SubmitTimeLimit) SetBelongTransaction(trs interfacev2.Transaction) {
act.belong_trs = trs.(interfaces.Transaction)
}
func (act *Action_29_SubmitTimeLimit) SetBelongTrs(trs interfaces.Transaction) {
act.belong_trs = trs
}
// burning fees // 是否销毁本笔交易的 90% 的交易费用
func (act *Action_29_SubmitTimeLimit) IsBurning90PersentTxFees() bool {
return false
}