Skip to content

Commit

Permalink
SI-2471-burn-vehicle (#292)
Browse files Browse the repository at this point in the history
* wip

* burn vehicle endpoints

* rename mint_request_id to transaction_request_id

* new col name

* add burn req id column to vehicle nft table

* undo

* handle vehicle node burn event

* make error check less specific for TestGetDeviceByUnitID_Should_Be_NotFound

* handle burn in contract event processor

* burn post req as tx; spelling

* change to make nats test pass

* undo struct rename

* add test for DeleteUserDevice

* clean up

* Update internal/services/autopi_api_service_test.go

Co-authored-by: Kevin Joiner <[email protected]>

* Update internal/controllers/user_devices_controller.go

Co-authored-by: Kevin Joiner <[email protected]>

* Update internal/controllers/user_integrations_controller.go

Co-authored-by: Kevin Joiner <[email protected]>

* Update internal/controllers/user_devices_controller.go

Co-authored-by: Kevin Joiner <[email protected]>

* Update internal/controllers/user_devices_controller.go

Co-authored-by: Kevin Joiner <[email protected]>

* condense checks into single func

* put vehicle burn under token endpoint; web2 delete

* update swagger

* tidy

* clean up

* make logging consistent

* fixing errors

* simplify auth middleware

* swagger

---------

Co-authored-by: Kevin Joiner <[email protected]>
  • Loading branch information
Allyson-English and KevinJoiner authored Mar 26, 2024
1 parent 7d24070 commit 8392367
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 414 deletions.
14 changes: 9 additions & 5 deletions cmd/devices-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,

vehicleAddr := common.HexToAddress(settings.VehicleNFTAddress)

// vehicle token actions
vPriv.Get("/commands/burn", userDeviceController.GetBurnDevice)
vPriv.Post("/commands/burn", userDeviceController.PostBurnDevice)

// vehicle command privileges
vPriv.Get("/status", privTokenWare.OneOf(vehicleAddr,
[]privileges.Privilege{privileges.VehicleNonLocationData, privileges.VehicleCurrentLocation, privileges.VehicleAllTimeLocation}), nftController.GetVehicleStatus)
Expand Down Expand Up @@ -308,11 +312,11 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,
udOwner.Post("/integrations/:integrationID", userDeviceController.RegisterDeviceIntegration)
udOwner.Post("/commands/refresh", userDeviceController.RefreshUserDeviceStatus)

// token owner actions
udOwnerByTokenMw := owner.VehicleToken(pdb, &logger)
udOwnerByToken := v1Auth.Group("/user/devices/:tokenID", udOwnerByTokenMw)
udOwnerByToken.Get("/commands/burn", userDeviceController.GetBurnDevice)
udOwnerByToken.Post("/commands/burn", userDeviceController.PostBurnDevice)
// Vehicle owner routes.
vehicleOwnerMw := owner.VehicleToken(pdb, usersClient, &logger)
vOwner := v1Auth.Group("/user/vehicle/:tokenID", vehicleOwnerMw)
vOwner.Get("/commands/burn", userDeviceController.GetBurnDevice)
vOwner.Post("/commands/burn", userDeviceController.PostBurnDevice)

if settings.SyntheticDevicesEnabled {
syntheticController := controllers.NewSyntheticDevicesController(settings, pdb.DBS, &logger, ddSvc, usersClient, wallet, registryClient)
Expand Down
186 changes: 90 additions & 96 deletions docs/docs.go

Large diffs are not rendered by default.

184 changes: 89 additions & 95 deletions docs/swagger.json

Large diffs are not rendered by default.

142 changes: 69 additions & 73 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ definitions:
externalId:
type: string
signature:
description: |-
AftermarketDeviceSignature is the 65-byte, hex-encoded Ethereum signature of
the pairing payload by the device. Only needed if the vehicle owner and aftermarket
device owner are not the same.
items:
type: integer
type: array
Expand Down Expand Up @@ -956,10 +960,6 @@ definitions:
externalId:
type: string
signature:
description: |-
AftermarketDeviceSignature is the 65-byte, hex-encoded Ethereum signature of
the pairing payload by the device. Only needed if the vehicle owner and aftermarket
device owner are not the same.
items:
type: integer
type: array
Expand Down Expand Up @@ -1918,7 +1918,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.AutoPiDeviceInfo'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.AutoPiDeviceInfo'
security:
- BearerAuth: []
tags:
Expand Down Expand Up @@ -1956,7 +1956,7 @@ paths:
name: claimRequest
required: true
schema:
$ref: '#/definitions/internal_controllers.AutoPiClaimRequest'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.AutoPiClaimRequest'
produces:
- application/json
responses:
Expand Down Expand Up @@ -2307,58 +2307,19 @@ paths:
name: user_device
required: true
schema:
$ref: '#/definitions/internal_controllers.RegisterUserDevice'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.RegisterUserDevice'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/internal_controllers.RegisterUserDeviceResponse'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.RegisterUserDeviceResponse'
security:
- ApiKeyAuth: []
- BearerAuth: []
tags:
- user-devices
/user/devices/:tokenID/commands/burn:
get:
description: Returns the data the user must sign in order to burn the device.
parameters:
- description: token id
in: path
name: tokenID
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/apitypes.TypedData'
security:
- BearerAuth: []
tags:
- user-devices
post:
description: Sends a burn device request to the blockchain
parameters:
- description: token id
in: path
name: tokenID
required: true
type: integer
- description: Signature and Token ID
in: body
name: burnRequest
required: true
schema:
$ref: '#/definitions/internal_controllers.BurnRequest'
responses:
"200":
description: OK
security:
- BearerAuth: []
tags:
- user-devices
/user/devices/:userDeviceID/aftermarket/commands/cloud-repair:
post:
description: Re-apply AutoPi cloud actions in an attempt to get the device transmitting
Expand Down Expand Up @@ -2416,7 +2377,7 @@ paths:
name: userSignature
required: true
schema:
$ref: '#/definitions/internal_controllers.AutoPiPairRequest'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.AutoPiPairRequest'
produces:
- application/json
responses: {}
Expand Down Expand Up @@ -2455,7 +2416,7 @@ paths:
name: userSignature
required: true
schema:
$ref: '#/definitions/internal_controllers.AutoPiPairRequest'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.AutoPiPairRequest'
produces:
- application/json
responses: {}
Expand All @@ -2472,7 +2433,7 @@ paths:
name: userDeviceIntegrationRegistration
required: true
schema:
$ref: '#/definitions/internal_controllers.RegisterDeviceIntegrationRequest'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.RegisterDeviceIntegrationRequest'
responses:
"204":
description: No Content
Expand Down Expand Up @@ -2527,7 +2488,7 @@ paths:
name: mintRequest
required: true
schema:
$ref: '#/definitions/internal_controllers.MintRequest'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.MintRequest'
responses:
"200":
description: OK
Expand Down Expand Up @@ -2582,7 +2543,7 @@ paths:
name: name
required: true
schema:
$ref: '#/definitions/internal_controllers.UpdateCountryCodeReq'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.UpdateCountryCodeReq'
produces:
- application/json
responses:
Expand Down Expand Up @@ -2678,7 +2639,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.GetUserDeviceIntegrationResponse'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.GetUserDeviceIntegrationResponse'
security:
- BearerAuth: []
tags:
Expand Down Expand Up @@ -2709,7 +2670,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.CommandRequestStatusResp'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.CommandRequestStatusResp'
summary: Get the status of a submitted command.
tags:
- device
Expand Down Expand Up @@ -2758,7 +2719,7 @@ paths:
name: signed
required: true
schema:
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.BurnSyntheticDeviceRequest'
$ref: '#/definitions/internal_controllers.BurnSyntheticDeviceRequest'
produces:
- application/json
responses:
Expand Down Expand Up @@ -2789,7 +2750,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.CommandResponse'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.CommandResponse'
summary: Lock the device's doors
tags:
- device
Expand All @@ -2816,7 +2777,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.CommandResponse'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.CommandResponse'
summary: Unlock the device's doors
tags:
- device
Expand Down Expand Up @@ -2844,7 +2805,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.CommandResponse'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.CommandResponse'
summary: Open the device's front trunk
tags:
- device
Expand Down Expand Up @@ -2895,7 +2856,7 @@ paths:
name: signed
required: true
schema:
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.MintSyntheticDeviceRequest'
$ref: '#/definitions/internal_controllers.MintSyntheticDeviceRequest'
produces:
- application/json
responses:
Expand Down Expand Up @@ -2925,7 +2886,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.CommandResponse'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.CommandResponse'
summary: Open the device's rear trunk
tags:
- device
Expand All @@ -2942,7 +2903,7 @@ paths:
name: name
required: true
schema:
$ref: '#/definitions/internal_controllers.UpdateNameReq'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.UpdateNameReq'
- description: user id
in: path
name: user_device_id
Expand All @@ -2966,7 +2927,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.DeviceOffer'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.DeviceOffer'
security:
- BearerAuth: []
tags:
Expand All @@ -2986,7 +2947,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.DeviceRange'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.DeviceRange'
security:
- BearerAuth: []
tags:
Expand Down Expand Up @@ -3029,7 +2990,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.DeviceValuation'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.DeviceValuation'
security:
- BearerAuth: []
tags:
Expand All @@ -3045,7 +3006,7 @@ paths:
name: vin
required: true
schema:
$ref: '#/definitions/internal_controllers.UpdateVINReq'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.UpdateVINReq'
- description: user id
in: path
name: userDeviceID
Expand Down Expand Up @@ -3074,7 +3035,7 @@ paths:
name: nftIamges
required: true
schema:
$ref: '#/definitions/internal_controllers.NFTImageData'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.NFTImageData'
responses:
"204":
description: No Content
Expand All @@ -3095,18 +3056,18 @@ paths:
name: user_device
required: true
schema:
$ref: '#/definitions/internal_controllers.RegisterUserDeviceSmartcar'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.RegisterUserDeviceSmartcar'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.UserDeviceFull'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.UserDeviceFull'
"201":
description: Created
schema:
$ref: '#/definitions/internal_controllers.UserDeviceFull'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.UserDeviceFull'
"400":
description: validation failure
"409":
Expand All @@ -3132,14 +3093,14 @@ paths:
name: user_device
required: true
schema:
$ref: '#/definitions/internal_controllers.RegisterUserDeviceVIN'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.RegisterUserDeviceVIN'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/internal_controllers.UserDeviceFull'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.UserDeviceFull'
"400":
description: validation failure
"424":
Expand All @@ -3160,7 +3121,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.MyDevicesResp'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.MyDevicesResp'
security:
- BearerAuth: []
tags:
Expand All @@ -3174,7 +3135,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.MyDevicesResp'
$ref: '#/definitions/github.com_DIMO-Network_devices-api_internal_controllers.MyDevicesResp'
security:
- BearerAuth: []
tags:
Expand Down Expand Up @@ -3263,6 +3224,41 @@ paths:
- BearerAuth: []
tags:
- geofence
/user/vehicle/{tokenID}/commands/burn:
get:
description: Returns the data the user must sign in order to burn the device.
parameters:
- description: token id
in: path
name: tokenID
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/apitypes.TypedData'
security:
- BearerAuth: []
post:
description: Sends a burn device request to the blockchain
parameters:
- description: token id
in: path
name: tokenID
required: true
type: integer
- description: Signature and Token ID
in: body
name: burnRequest
required: true
schema:
$ref: '#/definitions/internal_controllers.BurnRequest'
responses:
"200":
description: OK
security:
- BearerAuth: []
/vehicle/{tokenID}/commands/doors/lock:
post:
description: Lock the device's doors.
Expand Down
Loading

0 comments on commit 8392367

Please sign in to comment.