-
Notifications
You must be signed in to change notification settings - Fork 67
/
set_info.go
39 lines (34 loc) · 1.02 KB
/
set_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package miner
import (
"fmt"
"net/http"
"github.com/application-research/estuary/model"
"github.com/application-research/estuary/util"
"github.com/filecoin-project/go-address"
"golang.org/x/xerrors"
"gorm.io/gorm"
)
type MinerSetInfoParams struct {
Name string `json:"name"`
}
func (mm *MinerManager) SetMinerInfo(m address.Address, params MinerSetInfoParams, u *util.User) error {
var sm model.StorageMiner
if err := mm.db.First(&sm, "address = ?", m.String()).Error; err != nil {
if xerrors.Is(err, gorm.ErrRecordNotFound) {
return &util.HttpError{
Code: http.StatusNotFound,
Reason: util.ERR_RECORD_NOT_FOUND,
Details: fmt.Sprintf("miner: %s was not found", m),
}
}
return err
}
if !(u.Perm >= util.PermLevelAdmin || sm.Owner == u.ID) {
return &util.HttpError{
Code: http.StatusUnauthorized,
Reason: util.ERR_MINER_NOT_OWNED,
Details: "user does not own this miner",
}
}
return mm.db.Model(model.StorageMiner{}).Where("address = ?", m.String()).Update("name", params.Name).Error
}