-
Notifications
You must be signed in to change notification settings - Fork 15
/
block_state.go
46 lines (38 loc) · 1.22 KB
/
block_state.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
package types
import (
"github.com/eosspark/eos-go/common"
"github.com/eosspark/eos-go/crypto"
"reflect"
)
type BlockState struct {
BlockHeaderState `multiIndex:"inline"`
SignedBlock *SignedBlock `multiIndex:"inline"`
Validated bool `json:"validated"`
InCurrentChain bool `json:"in_current_chain"`
Trxs []*TransactionMetadata
}
func NewBlockState(cur *BlockHeaderState) *BlockState {
return &BlockState{*cur, &SignedBlock{},
false, false, make([]*TransactionMetadata, 0)}
}
func NewBlockState2(prev *BlockHeaderState, when BlockTimeStamp) *BlockState {
bs := &BlockState{
BlockHeaderState: *prev.GenerateNext(when),
SignedBlock: &SignedBlock{},
}
bs.SignedBlock.SignedBlockHeader = bs.Header
return bs
}
func NewBlockState3(prev *BlockHeaderState, b *SignedBlock, trust bool) *BlockState {
return &BlockState{
BlockHeaderState: *prev.Next(b.SignedBlockHeader, trust),
SignedBlock: b,
}
}
//for treeset
var BlockIdTypes = reflect.TypeOf(common.BlockIdType(crypto.NewSha256Nil()))
//for treeset
var BlockNumType = reflect.TypeOf(uint32(0))
func (b *BlockState) IsEmpty() bool {
return b.SignedBlock.IsEmpty() && !b.Validated && !b.InCurrentChain && len(b.Trxs) == 0
}