-
Notifications
You must be signed in to change notification settings - Fork 126
/
types.go
69 lines (59 loc) · 1.65 KB
/
types.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
package types
import (
"fmt"
"github.com/pkg/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewSuper constructs a super
func NewSuper(description string, accountType AccountType, address, addedBy sdk.AccAddress) Super {
return Super{
Description: description,
AccountType: accountType,
Address: address.String(),
AddedBy: addedBy.String(),
}
}
// Equal returns if the guardian is equal to specified guardian
func (g Super) Equal(super Super) bool {
return g.Address == super.Address &&
g.AddedBy == super.AddedBy &&
g.Description == super.Description &&
g.AccountType == super.AccountType
}
// AccountTypeFromString converts string to AccountType byte, Returns ff if invalid.
func AccountTypeFromString(str string) (AccountType, error) {
switch str {
case "Genesis":
return Genesis, nil
case "Ordinary":
return Ordinary, nil
default:
return AccountType(0xff), errors.Errorf("'%s' is not a valid account type", str)
}
}
// ValidAccountType returns true if the AccountType option is valid and false otherwise.
func ValidAccountType(option AccountType) bool {
if option == Genesis ||
option == Ordinary {
return true
}
return false
}
// Marshal needed for protobuf compatibility.
func (at AccountType) Marshal() ([]byte, error) {
return []byte{byte(at)}, nil
}
// Unmarshal needed for protobuf compatibility.
func (at *AccountType) Unmarshal(data []byte) error {
*at = AccountType(data[0])
return nil
}
// Format implements the fmt.Formatter interface.
func (at AccountType) Format(s fmt.State, verb rune) {
switch verb {
case 's':
s.Write([]byte(at.String()))
default:
s.Write([]byte(fmt.Sprintf("%v", byte(at))))
}
}