This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rules.go
81 lines (63 loc) · 1.57 KB
/
rules.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
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/hypersdk/chain"
)
var _ chain.Rules = (*Rules)(nil)
type Rules struct {
chainID ids.ID
g *Genesis
}
// TODO: use upgradeBytes
func (g *Genesis) Rules(chainID ids.ID, _ int64) *Rules {
return &Rules{chainID, g}
}
func (r *Rules) GetChainID() ids.ID {
return r.chainID
}
func (r *Rules) GetMaxBlockTxs() int {
return r.g.MaxBlockTxs
}
func (r *Rules) GetValidityWindow() int64 {
return r.g.ValidityWindow
}
func (r *Rules) GetMaxBlockUnits() uint64 {
return r.g.MaxBlockUnits
}
func (r *Rules) GetBaseUnits() uint64 {
return r.g.BaseUnits
}
func (r *Rules) GetMinUnitPrice() uint64 {
return r.g.MinUnitPrice
}
func (r *Rules) GetUnitPriceChangeDenominator() uint64 {
return r.g.UnitPriceChangeDenominator
}
func (r *Rules) GetWindowTargetUnits() uint64 {
return r.g.WindowTargetUnits
}
func (r *Rules) GetMinBlockCost() uint64 {
return r.g.MinBlockCost
}
func (r *Rules) GetBlockCostChangeDenominator() uint64 {
return r.g.BlockCostChangeDenominator
}
func (r *Rules) GetWindowTargetBlocks() uint64 {
return r.g.WindowTargetBlocks
}
func (r *Rules) FetchCustom(f string) (any, bool) {
switch f { //nolint:gocritic
case StateLockupField:
return r.g.StateLockup, true
}
return nil, false
}
func GetStateLockup(r chain.Rules) (uint64, error) {
rstateLockup, ok := r.FetchCustom(StateLockupField)
if !ok {
return 0, ErrStateLockupMissing
}
return rstateLockup.(uint64), nil
}