|
6 | 6 | "database/sql" |
7 | 7 | "encoding/json" |
8 | 8 | "fmt" |
| 9 | + stringutils "github.com/DIMO-Network/shared/pkg/strings" |
9 | 10 | "io" |
10 | 11 | "math/big" |
11 | 12 | "net/http" |
@@ -163,7 +164,7 @@ func (e *deviceDefinitionOnChainService) GetManufacturer(ctx context.Context, ma |
163 | 164 | // GetDefinitionTableland gets dd from tableland with a select statement and returns tbl object |
164 | 165 | func (e *deviceDefinitionOnChainService) GetDefinitionTableland(ctx context.Context, manufacturerID *big.Int, ID string) (*models2.DeviceDefinitionTablelandModel, error) { |
165 | 166 | if manufacturerID == nil || manufacturerID.Uint64() == 0 { |
166 | | - return nil, fmt.Errorf("manufacturerID cannot be 0") |
| 167 | + return nil, fmt.Errorf("GetDefinitionTableland - manufacturerID cannot be 0") |
167 | 168 | } |
168 | 169 |
|
169 | 170 | tableName, err := e.getTablelandTableName(ctx, manufacturerID) |
@@ -341,20 +342,18 @@ func (e *deviceDefinitionOnChainService) Create(ctx context.Context, manufacture |
341 | 342 | auth.GasPrice = bumpedPrice |
342 | 343 | auth.From = fromAddress |
343 | 344 |
|
344 | | - queryInstance, err := contracts.NewRegistry(contractAddress, e.client) |
| 345 | + // call identity instead of the chain since more reliable |
| 346 | + manufacturer, err := e.identityAPI.GetManufacturer(stringutils.SlugString(manufacturerName)) |
345 | 347 | if err != nil { |
346 | 348 | e.logger.Err(err).Msgf("OnChainError - %s", dd.ID) |
347 | 349 | metrics.InternalError.With(prometheus.Labels{"method": TablelandErrors}).Inc() |
348 | | - return nil, fmt.Errorf("failed create NewRegistry: %w", err) |
| 350 | + return nil, fmt.Errorf("failed get manufacturer from identity: %w", err) |
349 | 351 | } |
350 | | - |
351 | | - // Validate if manufacturer exists |
352 | | - bigManufID, err := queryInstance.GetManufacturerIdByName(&bind.CallOpts{Context: ctx, Pending: true}, manufacturerName) |
353 | | - if err != nil { |
354 | | - e.logger.Err(err).Msgf("OnChainError - %s", dd.ID) |
355 | | - metrics.InternalError.With(prometheus.Labels{"method": TablelandErrors}).Inc() |
356 | | - return nil, fmt.Errorf("failed get GetManufacturerIdByName => %s: %w", manufacturerName, err) |
| 352 | + if manufacturer == nil { |
| 353 | + return nil, fmt.Errorf("manufacturer not found in identity") |
357 | 354 | } |
| 355 | + e.logger.Info().Msgf("manufacturer to create DD with: %+v", manufacturer) |
| 356 | + |
358 | 357 | instance, err := contracts.NewRegistryTransactor(contractAddress, e.client) |
359 | 358 | if err != nil { |
360 | 359 | e.logger.Err(err).Msgf("OnChainError - %s", dd.ID) |
@@ -383,6 +382,8 @@ func (e *deviceDefinitionOnChainService) Create(ctx context.Context, manufacture |
383 | 382 | deviceInputs.Metadata = string(jsonData) |
384 | 383 | } |
385 | 384 |
|
| 385 | + bigManufID := big.NewInt(int64(manufacturer.TokenID)) |
| 386 | + |
386 | 387 | // check for duplicate create |
387 | 388 | currentDeviceDefinition, err := e.GetDeviceDefinitionByID(ctx, bigManufID, deviceInputs.Id) |
388 | 389 | if err != nil { |
|
0 commit comments