@@ -126,14 +126,46 @@ func getRateFromOracle(oracle *oneinchoracle.OneinchOracle, token []byte, ret *t
126126 return nil
127127}
128128
129- func parseAddressBalance (tokens []common.Address , address string , balances []* big.Int ) []* types.Eth1AddressBalance {
129+ func parseAddressBalance (tokens []common.Address , address string , balances []* big.Int ) ([]* types.Eth1AddressBalance , error ) {
130+ if len (tokens ) == 0 || len (balances ) == 0 {
131+ return nil , fmt .Errorf ("tokens or balances slice is empty" )
132+ }
133+ if len (tokens ) != len (balances ) {
134+ return nil , fmt .Errorf ("tokens and balances slices have mismatched lengths" )
135+ }
136+
137+ if address == "" {
138+ return nil , fmt .Errorf ("address is empty" )
139+ }
140+ addrBytes := common .FromHex (address )
141+ if len (addrBytes ) == 0 {
142+ return nil , fmt .Errorf ("invalid address format" )
143+ }
144+
130145 res := make ([]* types.Eth1AddressBalance , len (tokens ))
131- for tokenIdx := range tokens {
146+ for tokenIdx , token := range tokens {
147+ if token == (common.Address {}) {
148+ return nil , fmt .Errorf ("token at index %d is empty" , tokenIdx )
149+ }
150+ tokenBytes := token .Bytes ()
151+ if len (tokenBytes ) == 0 {
152+ return nil , fmt .Errorf ("invalid token format at index %d" , tokenIdx )
153+ }
154+
155+ if balances [tokenIdx ] == nil {
156+ return nil , fmt .Errorf ("balance at index %d is nil" , tokenIdx )
157+ }
158+ balanceBytes := balances [tokenIdx ].Bytes ()
159+ if len (balanceBytes ) == 0 {
160+ return nil , fmt .Errorf ("invalid balance format at index %d" , tokenIdx )
161+ }
162+
132163 res [tokenIdx ] = & types.Eth1AddressBalance {
133- Address : common . FromHex ( address ) ,
134- Token : common . FromHex ( string ( tokens [ tokenIdx ]. Bytes ())) ,
135- Balance : balances [ tokenIdx ]. Bytes () ,
164+ Address : addrBytes ,
165+ Token : tokenBytes ,
166+ Balance : balanceBytes ,
136167 }
137168 }
138- return res
169+
170+ return res , nil
139171}
0 commit comments