Upstream sync
This commit is contained in:
@@ -18,6 +18,10 @@ import (
|
||||
"gitlab.com/pactual1/backend/shared"
|
||||
)
|
||||
|
||||
const (
|
||||
ContractDistanceThresholdKm = float64(10)
|
||||
)
|
||||
|
||||
func SaveDeviceInfo(c *gin.Context) {
|
||||
var deviceInfo models.DeviceInfo
|
||||
rawData, _ := c.GetRawData()
|
||||
@@ -48,7 +52,7 @@ func SaveDeviceInfo(c *gin.Context) {
|
||||
deviceInfoBytes, _ := json.Marshal(deviceInfo)
|
||||
if deviceContract.BlockchainSecret == "" {
|
||||
deviceContract.BlockchainSecret = shared.GenerateRandomString(BlockchainSecretLength)
|
||||
_, _, err := contract.UpdateContract(deviceContract)
|
||||
deviceContract, _, err = contract.UpdateContract(deviceContract)
|
||||
if err != nil {
|
||||
log.Printf("SaveDeviceInfo Update Contract error: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not update contract secret"})
|
||||
@@ -68,6 +72,16 @@ func SaveDeviceInfo(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not save device info in blockchain"})
|
||||
return
|
||||
}
|
||||
|
||||
if shared.DistanceKm(deviceInfo.Lat, deviceInfo.Lon, deviceContract.EndLat, deviceContract.EndLon) <= ContractDistanceThresholdKm {
|
||||
deviceContract.Status = models.ContractStatusExecuted
|
||||
_, _, err := contract.UpdateContract(deviceContract)
|
||||
if err != nil {
|
||||
log.Printf("SaveDeviceInfo Update Contract error: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not update contract status"})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user