/
currency_policy.go
48 lines (38 loc) · 1.18 KB
/
currency_policy.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
package types
import (
"github.com/ProtoconNet/mitum-currency/v3/common"
"github.com/ProtoconNet/mitum2/util"
"github.com/ProtoconNet/mitum2/util/hint"
)
var (
CurrencyPolicyHint = hint.MustNewHint("mitum-currency-currency-policy-v0.0.1")
)
type CurrencyPolicy struct {
hint.BaseHinter
newAccountMinBalance common.Big
feeer Feeer
}
func NewCurrencyPolicy(newAccountMinBalance common.Big, feeer Feeer) CurrencyPolicy {
return CurrencyPolicy{
BaseHinter: hint.NewBaseHinter(CurrencyPolicyHint),
newAccountMinBalance: newAccountMinBalance, feeer: feeer,
}
}
func (po CurrencyPolicy) Bytes() []byte {
return util.ConcatBytesSlice(po.newAccountMinBalance.Bytes(), po.feeer.Bytes())
}
func (po CurrencyPolicy) IsValid([]byte) error {
if !po.newAccountMinBalance.OverNil() {
return util.ErrInvalid.Errorf("NewAccountMinBalance under zero")
}
if err := util.CheckIsValiders(nil, false, po.BaseHinter, po.feeer); err != nil {
return util.ErrInvalid.Errorf("invalid currency policy: %v", err)
}
return nil
}
func (po CurrencyPolicy) NewAccountMinBalance() common.Big {
return po.newAccountMinBalance
}
func (po CurrencyPolicy) Feeer() Feeer {
return po.feeer
}