Skip to content

Commit 9ab5e51

Browse files
authored
Return manuf and model on decode, cleanup code from before (#281)
* return manuf and model on decode, cleanup code from before * add manufacturer, some more comments, change to use legacy ksuid * fixes and comments for later * add styles definitionid, db changes * continue removing old ksuid and change fkeys * deprecate stuff, fix compilation, pending fix tests * fix name changes, add definition_trxs * store transactions * delete more integration features code, update tests, lint errors * track all on-chain trxs * remove unused routes * remove more * swagger updates * drop device definitions, consequences look do-able * decode VIN refactored & re-worked * remove unused grpc calls, migrate more calls to use tableland for dd * remove more unused stuff * delete more old code, migrate stuff * more * keep resolinvg issues * change get device style to use on chain dd * refactor and move over more funcs to use on-chain stuff * implement custom tableland query * query by make year and range impl * continue changing dependencies to use on chain * re-implement sync search with tbland * re implement add_vin * move presentation objects to avoid import cycles * move more stuff around for iport cycles * fix import cylce, refactor * linter and swag * fixes to get tests passing, db index * fix remaining tests * lint, tests, refactor
1 parent 1fe103f commit 9ab5e51

127 files changed

Lines changed: 4848 additions & 15611 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121

2222
- name: golangci-lint
23-
uses: golangci/golangci-lint-action@v6
23+
uses: golangci/golangci-lint-action@v7
2424
with:
2525
version: latest
2626
only-new-issues: false

.golangci.yml

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,52 @@
1-
run:
2-
timeout: 5m
1+
version: "2"
32
linters:
43
enable:
54
- prealloc
65
- revive
7-
- goimports
8-
- errcheck
9-
- gosimple
10-
- govet
11-
- ineffassign
12-
- staticcheck
13-
- typecheck
14-
- unused
15-
- zerologlint
166
- tagliatelle
17-
7+
- zerologlint
8+
settings:
9+
tagliatelle:
10+
case:
11+
rules:
12+
json: camel
13+
yaml: upperSnake
14+
use-field-name: true
15+
exclusions:
16+
generated: lax
17+
presets:
18+
- comments
19+
- common-false-positives
20+
- legacy
21+
- std-error-handling
22+
rules:
23+
- linters:
24+
- revive
25+
- tagliatelle
26+
path: internal/infrastructure/gateways/datgroup_api_service.go
27+
paths:
28+
- pkg/grpc
29+
- third_party$
30+
- builtin$
31+
- examples$
1832
issues:
1933
fix: true
20-
exclude-dirs:
21-
- pkg/grpc
22-
exclude-rules:
23-
- path: 'internal/infrastructure/gateways/datgroup_api_service.go'
24-
linters:
25-
- tagliatelle
26-
- revive
27-
28-
output:
29-
print-issued-lines: true
30-
31-
linters-settings:
32-
gci:
33-
# Section configuration to compare against.
34-
# Section names are case-insensitive and may contain parameters in ().
35-
# The default order of sections is `standard > default > custom > blank > dot`,
36-
# If `custom-order` is `true`, it follows the order of `sections` option.
37-
# Default: ["standard", "default"]
38-
sections:
39-
- standard # Standard section: captures all standard packages.
40-
- default # Default section: contains all imports that could not be matched to another section type.
41-
- prefix(github.com/DIMO-Network/device-definitions-api) # Custom section: groups all imports with the specified Prefix.
42-
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
43-
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
44-
# Skip generated files.
45-
# Default: true
46-
skip-generated: true
47-
# Enable custom order of sections.
48-
# If `true`, make the section order the same as the order of `sections`.
49-
# Default: false
50-
custom-order: false
51-
tagliatelle:
52-
# Check the struck tag name case.
53-
case:
54-
# Use the struct field name to check the name of the struct tag.
55-
# Default: false
56-
use-field-name: true
57-
rules:
58-
# Any struct tag type can be used.
59-
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `upperSnake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`.
60-
json: camel
61-
yaml: upperSnake
34+
formatters:
35+
enable:
36+
- goimports
37+
settings:
38+
gci:
39+
sections:
40+
- standard
41+
- default
42+
- prefix(github.com/DIMO-Network/device-definitions-api)
43+
- blank
44+
- dot
45+
custom-order: false
46+
exclusions:
47+
generated: lax
48+
paths:
49+
- pkg/grpc
50+
- third_party$
51+
- builtin$
52+
- examples$

cmd/device-definitions-api/add_vin.go

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ import (
66
"database/sql"
77
"flag"
88
"fmt"
9+
"math/big"
910
"os"
1011
"strconv"
1112
"strings"
1213
"time"
1314

15+
"github.com/DIMO-Network/device-definitions-api/internal/core/common"
16+
"github.com/DIMO-Network/device-definitions-api/internal/infrastructure/gateways"
17+
"github.com/DIMO-Network/device-definitions-api/internal/infrastructure/sender"
18+
"github.com/ethereum/go-ethereum/ethclient"
19+
20+
"github.com/volatiletech/sqlboiler/v4/queries/qm"
21+
1422
"github.com/DIMO-Network/device-definitions-api/internal/config"
1523
"github.com/DIMO-Network/device-definitions-api/internal/infrastructure/db/models"
1624
"github.com/DIMO-Network/shared"
@@ -25,6 +33,8 @@ import (
2533
type addVINCmd struct {
2634
logger zerolog.Logger
2735
settings config.Settings
36+
37+
sender sender.Sender
2838
}
2939

3040
func (*addVINCmd) Name() string { return "addvin" }
@@ -52,6 +62,17 @@ func (p *addVINCmd) Execute(ctx context.Context, _ *flag.FlagSet, _ ...interface
5262
pdb := db.NewDbConnectionFromSettings(ctx, &p.settings.DB, true)
5363
pdb.WaitForDB(p.logger)
5464

65+
ethClient, err := ethclient.Dial(p.settings.EthereumRPCURL.String())
66+
if err != nil {
67+
p.logger.Fatal().Err(err).Msg("Failed to create Ethereum client.")
68+
}
69+
70+
chainID, err := ethClient.ChainID(ctx)
71+
if err != nil {
72+
p.logger.Fatal().Err(err).Msg("Couldn't retrieve chain id.")
73+
}
74+
onChainSvc := gateways.NewDeviceDefinitionOnChainService(&p.settings, &p.logger, ethClient, chainID, p.sender, pdb.DBS)
75+
5576
vinDecodeNumber, err := models.FindVinNumber(ctx, pdb.DBS().Reader, vin)
5677
if err != nil && !errors.Is(err, sql.ErrNoRows) {
5778
p.logger.Fatal().Err(err).Send()
@@ -62,21 +83,21 @@ func (p *addVINCmd) Execute(ctx context.Context, _ *flag.FlagSet, _ ...interface
6283
return subcommands.ExitSuccess
6384
}
6485
processedVIN := shared.VIN(vin)
65-
wmi, err := models.Wmis(models.WmiWhere.Wmi.EQ(processedVIN.Wmi())).One(ctx, pdb.DBS().Reader)
86+
wmi, err := models.Wmis(models.WmiWhere.Wmi.EQ(processedVIN.Wmi()), qm.Load(models.WmiRels.DeviceMake)).One(ctx, pdb.DBS().Reader)
6687
if err != nil {
6788
fmt.Println("could not find WMI for vin")
6889
return subcommands.ExitFailure
6990
}
7091
vinNumber := models.VinNumber{
71-
Vin: vin,
72-
Wmi: processedVIN.Wmi(),
73-
VDS: processedVIN.VDS(),
74-
CheckDigit: processedVIN.CheckDigit(),
75-
SerialNumber: processedVIN.SerialNumber(),
76-
Vis: processedVIN.VIS(),
77-
DeviceMakeID: wmi.DeviceMakeID,
78-
DecodeProvider: null.StringFrom("manual"),
79-
Year: processedVIN.Year(),
92+
Vin: vin,
93+
Wmi: processedVIN.Wmi(),
94+
VDS: processedVIN.VDS(),
95+
CheckDigit: processedVIN.CheckDigit(),
96+
SerialNumber: processedVIN.SerialNumber(),
97+
Vis: processedVIN.VIS(),
98+
ManufacturerName: wmi.R.DeviceMake.Name,
99+
DecodeProvider: null.StringFrom("manual"),
100+
Year: processedVIN.Year(),
80101
}
81102
if vinNumber.Year == 0 || vinNumber.Year < 2008 || vinNumber.Year > time.Now().Year() {
82103
year, err := cmdLineInput("enter model year")
@@ -97,14 +118,19 @@ func (p *addVINCmd) Execute(ctx context.Context, _ *flag.FlagSet, _ ...interface
97118
return subcommands.ExitFailure
98119
}
99120

100-
deviceDefinition, err := models.DeviceDefinitions(models.DeviceDefinitionWhere.Model.EQ(model),
101-
models.DeviceDefinitionWhere.DeviceMakeID.EQ(vinNumber.DeviceMakeID),
102-
models.DeviceDefinitionWhere.Year.EQ(int16(vinNumber.Year))).One(ctx, pdb.DBS().Reader)
121+
manufacturer, err := onChainSvc.GetManufacturer(ctx, wmi.R.DeviceMake.NameSlug, pdb.DBS().Reader)
122+
if err != nil {
123+
fmt.Println(err.Error())
124+
return subcommands.ExitFailure
125+
}
126+
definitionID := common.DeviceDefinitionSlug(wmi.R.DeviceMake.NameSlug, shared.SlugString(model), int16(vinNumber.Year))
127+
deviceDefinition, err := onChainSvc.GetDefinitionTableland(ctx, big.NewInt(int64(manufacturer.TokenID)), definitionID)
128+
103129
if err != nil {
104130
fmt.Println(err.Error() + " " + model + " " + strconv.Itoa(vinNumber.Year))
105131
return subcommands.ExitFailure
106132
}
107-
vinNumber.DefinitionID = deviceDefinition.NameSlug
133+
vinNumber.DefinitionID = deviceDefinition.ID
108134

109135
err = vinNumber.Insert(ctx, pdb.DBS().Writer, boil.Infer())
110136
if err != nil {

0 commit comments

Comments
 (0)