/
keys_controller.go
33 lines (29 loc) · 1.12 KB
/
keys_controller.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
package web
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/smartcontractkit/chainlink/core/services"
"github.com/smartcontractkit/chainlink/core/store/models"
"github.com/smartcontractkit/chainlink/core/store/presenters"
)
// KeysController manages account keys
type KeysController struct {
App services.Application
}
// Create adds a new account
// Example:
// "<application>/keys"
func (kc *KeysController) Create(c *gin.Context) {
request := models.CreateKeyRequest{}
if err := c.ShouldBindJSON(&request); err != nil {
jsonAPIError(c, http.StatusUnprocessableEntity, err)
} else if err := kc.App.GetStore().KeyStore.Unlock(request.CurrentPassword); err != nil {
jsonAPIError(c, http.StatusUnauthorized, err)
} else if account, err := kc.App.GetStore().KeyStore.NewAccount(request.CurrentPassword); err != nil {
jsonAPIError(c, http.StatusInternalServerError, err)
} else if err := kc.App.GetStore().SyncDiskKeyStoreToDB(); err != nil {
jsonAPIError(c, http.StatusInternalServerError, err)
} else {
jsonAPIResponseWithStatus(c, presenters.NewAccount{Account: &account}, "account", http.StatusCreated)
}
}