@@ -14,11 +14,23 @@ type WalletBalanceData struct {
1414 Balances []* iotajsonrpc.Balance `json:"balances"`
1515}
1616
17+ // WalletBalanceErrorData represents the data structure for wallet balance error cases
18+ type WalletBalanceErrorData struct {
19+ AddressIndex uint32 `json:"addressIndex"`
20+ Address string `json:"address"`
21+ Error string `json:"error"`
22+ }
23+
1724// WalletBalanceOutput represents the output of wallet balance commands
1825type WalletBalanceOutput struct {
1926 BaseOutput [WalletBalanceData ]
2027}
2128
29+ // WalletBalanceErrorOutput represents the output for wallet balance errors
30+ type WalletBalanceErrorOutput struct {
31+ BaseOutput [WalletBalanceErrorData ]
32+ }
33+
2234// NewWalletBalanceOutput creates a new wallet balance output
2335func NewWalletBalanceOutput (addressIndex uint32 , address string , balances []* iotajsonrpc.Balance , success bool ) * WalletBalanceOutput {
2436 status := "success"
@@ -43,14 +55,14 @@ func NewWalletBalanceSuccess(addressIndex uint32, address string, balances []*io
4355}
4456
4557// NewWalletBalanceError creates an error wallet balance output
46- func NewWalletBalanceError (addressIndex uint32 , address string ) * WalletBalanceOutput {
47- data := WalletBalanceData {
58+ func NewWalletBalanceError (addressIndex uint32 , address string , errorMsg string ) * WalletBalanceErrorOutput {
59+ data := WalletBalanceErrorData {
4860 AddressIndex : addressIndex ,
4961 Address : address ,
50- Balances : [] * iotajsonrpc. Balance {} ,
62+ Error : errorMsg ,
5163 }
5264
53- return & WalletBalanceOutput {
65+ return & WalletBalanceErrorOutput {
5466 BaseOutput : NewBaseOutput ("wallet_balance" , "error" , data ),
5567 }
5668}
@@ -125,3 +137,58 @@ func (wbo *WalletBalanceOutput) GetBalanceForCoinType(coinType string) (string,
125137func (wbo * WalletBalanceOutput ) IsSuccess () bool {
126138 return wbo .Status == "success"
127139}
140+
141+ // ToTable returns the wallet balance error output as table rows
142+ func (wbeo * WalletBalanceErrorOutput ) ToTable () [][]string {
143+ rows := [][]string {
144+ {"Address Index" , "Address" },
145+ {strconv .FormatUint (uint64 (wbeo .Data .AddressIndex ), 10 ), wbeo .Data .Address },
146+ }
147+
148+ // Add empty row for spacing
149+ rows = append (rows , []string {"" , "" })
150+
151+ // Add error information
152+ rows = append (rows , []string {"Error" , wbeo .Data .Error })
153+
154+ return rows
155+ }
156+
157+ // Validate validates the wallet balance error output
158+ func (wbeo * WalletBalanceErrorOutput ) Validate () error {
159+ // Validate base output
160+ if err := wbeo .BaseOutput .Validate (); err != nil {
161+ return err
162+ }
163+
164+ // Validate wallet balance error-specific fields
165+ if wbeo .Data .Address == "" {
166+ return fmt .Errorf ("address cannot be empty for wallet balance error output" )
167+ }
168+
169+ if wbeo .Data .Error == "" {
170+ return fmt .Errorf ("error message cannot be empty for wallet balance error output" )
171+ }
172+
173+ return nil
174+ }
175+
176+ // GetAddress returns the wallet address
177+ func (wbeo * WalletBalanceErrorOutput ) GetAddress () string {
178+ return wbeo .Data .Address
179+ }
180+
181+ // GetAddressIndex returns the address index
182+ func (wbeo * WalletBalanceErrorOutput ) GetAddressIndex () uint32 {
183+ return wbeo .Data .AddressIndex
184+ }
185+
186+ // GetError returns the error message
187+ func (wbeo * WalletBalanceErrorOutput ) GetError () string {
188+ return wbeo .Data .Error
189+ }
190+
191+ // IsSuccess returns false since this is an error output
192+ func (wbeo * WalletBalanceErrorOutput ) IsSuccess () bool {
193+ return false
194+ }
0 commit comments