@@ -10,7 +10,7 @@ import (
10
10
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
11
11
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
12
12
"github.com/tendermint/tendermint/crypto/tmhash"
13
- yaml "gopkg.in/yaml.v2"
13
+ "gopkg.in/yaml.v2"
14
14
15
15
connectiontypes "github.com/cosmos/ibc-go/v2/modules/core/03-connection/types"
16
16
)
@@ -66,40 +66,44 @@ func NewInterchainAccount(ba *authtypes.BaseAccount, accountOwner string) *Inter
66
66
}
67
67
68
68
// SetPubKey - Implements AccountI
69
- func (InterchainAccount ) SetPubKey (pubKey crypto.PubKey ) error {
70
- return fmt . Errorf ( "not supported for interchain accounts " )
69
+ func (ia InterchainAccount ) SetPubKey (pubKey crypto.PubKey ) error {
70
+ return sdkerrors . Wrap ( ErrUnsupported , "cannot set public key for interchain account " )
71
71
}
72
72
73
73
// SetSequence - Implements AccountI
74
- func (InterchainAccount ) SetSequence (seq uint64 ) error {
75
- return fmt . Errorf ( "not supported for interchain accounts " )
74
+ func (ia InterchainAccount ) SetSequence (seq uint64 ) error {
75
+ return sdkerrors . Wrap ( ErrUnsupported , "cannot set sequence number for interchain account " )
76
76
}
77
77
78
78
func (ia InterchainAccount ) Validate () error {
79
+ if strings .TrimSpace (ia .AccountOwner ) == "" {
80
+ return sdkerrors .Wrap (ErrInvalidAccountAddress , "AccountOwner cannot be empty" )
81
+ }
82
+
79
83
return ia .BaseAccount .Validate ()
80
84
}
81
85
82
- type ibcAccountPretty struct {
86
+ type InterchainAccountPretty struct {
83
87
Address sdk.AccAddress `json:"address" yaml:"address"`
84
88
PubKey string `json:"public_key" yaml:"public_key"`
85
89
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
86
90
Sequence uint64 `json:"sequence" yaml:"sequence"`
87
- AccountOwner string `json:"address " yaml:"account_owner"`
91
+ AccountOwner string `json:"account_owner " yaml:"account_owner"`
88
92
}
89
93
90
94
func (ia InterchainAccount ) String () string {
91
95
out , _ := ia .MarshalYAML ()
92
- return out .( string )
96
+ return string ( out )
93
97
}
94
98
95
- // MarshalYAML returns the YAML representation of a InterchainAccount.
96
- func (ia InterchainAccount ) MarshalYAML () (interface {} , error ) {
99
+ // MarshalYAML returns the YAML representation of an InterchainAccount
100
+ func (ia InterchainAccount ) MarshalYAML () ([] byte , error ) {
97
101
accAddr , err := sdk .AccAddressFromBech32 (ia .Address )
98
102
if err != nil {
99
103
return nil , err
100
104
}
101
105
102
- bs , err := yaml .Marshal (ibcAccountPretty {
106
+ bz , err := yaml .Marshal (InterchainAccountPretty {
103
107
Address : accAddr ,
104
108
PubKey : "" ,
105
109
AccountNumber : ia .AccountNumber ,
@@ -111,28 +115,34 @@ func (ia InterchainAccount) MarshalYAML() (interface{}, error) {
111
115
return nil , err
112
116
}
113
117
114
- return string ( bs ) , nil
118
+ return bz , nil
115
119
}
116
120
117
- // MarshalJSON returns the JSON representation of a InterchainAccount.
121
+ // MarshalJSON returns the JSON representation of an InterchainAccount.
118
122
func (ia InterchainAccount ) MarshalJSON () ([]byte , error ) {
119
123
accAddr , err := sdk .AccAddressFromBech32 (ia .Address )
120
124
if err != nil {
121
125
return nil , err
122
126
}
123
127
124
- return json .Marshal (ibcAccountPretty {
128
+ bz , err := json .Marshal (InterchainAccountPretty {
125
129
Address : accAddr ,
126
130
PubKey : "" ,
127
131
AccountNumber : ia .AccountNumber ,
128
132
Sequence : ia .Sequence ,
129
133
AccountOwner : ia .AccountOwner ,
130
134
})
135
+
136
+ if err != nil {
137
+ return nil , err
138
+ }
139
+
140
+ return bz , nil
131
141
}
132
142
133
143
// UnmarshalJSON unmarshals raw JSON bytes into a ModuleAccount.
134
144
func (ia * InterchainAccount ) UnmarshalJSON (bz []byte ) error {
135
- var alias ibcAccountPretty
145
+ var alias InterchainAccountPretty
136
146
if err := json .Unmarshal (bz , & alias ); err != nil {
137
147
return err
138
148
}
0 commit comments