|
7 | 7 | "math/big" |
8 | 8 | "reflect" |
9 | 9 | "strings" |
| 10 | + "time" |
10 | 11 |
|
11 | 12 | "golang.org/x/text/cases" |
12 | 13 | "golang.org/x/text/language" |
@@ -231,6 +232,11 @@ func traverseFields( |
231 | 232 | // then continue as normal |
232 | 233 | } |
233 | 234 |
|
| 235 | + // If its a nil pointer, do not include in types |
| 236 | + if fieldType.Kind() == reflect.Ptr && field.IsNil() { |
| 237 | + continue |
| 238 | + } |
| 239 | + |
234 | 240 | for { |
235 | 241 | if fieldType.Kind() == reflect.Ptr { |
236 | 242 | fieldType = fieldType.Elem() |
@@ -295,6 +301,11 @@ func traverseFields( |
295 | 301 |
|
296 | 302 | ethTyp := typToEth(fieldType) |
297 | 303 | if len(ethTyp) > 0 { |
| 304 | + // Support array of uint64 |
| 305 | + if isCollection && fieldType.Kind() != reflect.Slice && fieldType.Kind() != reflect.Array { |
| 306 | + ethTyp += "[]" |
| 307 | + } |
| 308 | + |
298 | 309 | if prefix == typeDefPrefix { |
299 | 310 | typeMap[rootType] = append(typeMap[rootType], apitypes.Type{ |
300 | 311 | Name: fieldName, |
@@ -381,6 +392,7 @@ var ( |
381 | 392 | bigIntType = reflect.TypeOf(big.Int{}) |
382 | 393 | cosmIntType = reflect.TypeOf(sdk.Int{}) |
383 | 394 | cosmosAnyType = reflect.TypeOf(&codectypes.Any{}) |
| 395 | + timeType = reflect.TypeOf(time.Time{}) |
384 | 396 | ) |
385 | 397 |
|
386 | 398 | // typToEth supports only basic types and arrays of basic types. |
@@ -425,13 +437,15 @@ func typToEth(typ reflect.Type) string { |
425 | 437 | } |
426 | 438 | case reflect.Ptr: |
427 | 439 | if typ.Elem().ConvertibleTo(bigIntType) || |
| 440 | + typ.Elem().ConvertibleTo(timeType) || |
428 | 441 | typ.Elem().ConvertibleTo(cosmIntType) { |
429 | 442 | return str |
430 | 443 | } |
431 | 444 | case reflect.Struct: |
432 | 445 | if typ.ConvertibleTo(hashType) || |
433 | 446 | typ.ConvertibleTo(addressType) || |
434 | 447 | typ.ConvertibleTo(bigIntType) || |
| 448 | + typ.ConvertibleTo(timeType) || |
435 | 449 | typ.ConvertibleTo(cosmIntType) { |
436 | 450 | return str |
437 | 451 | } |
|
0 commit comments