-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_value.go
82 lines (65 loc) · 1.8 KB
/
account_value.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
package digest
import (
"github.com/ProtoconNet/mitum-currency/v3/types"
"github.com/ProtoconNet/mitum2/base"
"github.com/ProtoconNet/mitum2/util/hint"
"github.com/pkg/errors"
"reflect"
)
var (
AccountValueHint = hint.MustNewHint("mitum-currency-account-value-v0.0.1")
)
type AccountValue struct {
hint.BaseHinter
ac types.Account
balance []types.Amount
height base.Height
contractAccountStatus types.ContractAccountStatus
}
func NewAccountValue(st base.State) (AccountValue, error) {
var ac types.Account
switch a, ok, err := IsAccountState(st); {
case err != nil:
return AccountValue{}, err
case !ok:
return AccountValue{}, errors.Errorf("Not state for currency.Account, %T", st.Value())
default:
ac = a
}
return AccountValue{
BaseHinter: hint.NewBaseHinter(AccountValueHint),
ac: ac,
height: st.Height(),
contractAccountStatus: types.NewContractAccountStatus(nil, nil),
}, nil
}
func (va AccountValue) Account() types.Account {
return va.ac
}
func (va AccountValue) Balance() []types.Amount {
return va.balance
}
func (va AccountValue) ContractAccountStatus() types.ContractAccountStatus {
return va.contractAccountStatus
}
func (va AccountValue) Height() base.Height {
return va.height
}
func (va AccountValue) SetHeight(height base.Height) AccountValue {
va.height = height
return va
}
func (va AccountValue) SetBalance(balance []types.Amount) AccountValue {
va.balance = balance
return va
}
func (va AccountValue) SetContractAccountStatus(status types.ContractAccountStatus) AccountValue {
va.contractAccountStatus = status
return va
}
func (va AccountValue) IsZeroValue() bool {
if reflect.DeepEqual(va, reflect.Zero(reflect.TypeOf(va)).Interface()) {
return true
}
return false
}