-
Notifications
You must be signed in to change notification settings - Fork 105
/
set-password.go
59 lines (48 loc) · 1.51 KB
/
set-password.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package wallet
import (
"errors"
"net/url"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/gorilla/mux"
"github.com/rocket-pool/node-manager-core/api/server"
"github.com/rocket-pool/node-manager-core/api/types"
"github.com/rocket-pool/node-manager-core/utils/input"
)
// ===============
// === Factory ===
// ===============
type walletSetPasswordContextFactory struct {
handler *WalletHandler
}
func (f *walletSetPasswordContextFactory) Create(args url.Values) (*walletSetPasswordContext, error) {
c := &walletSetPasswordContext{
handler: f.handler,
}
inputErrs := []error{
server.ValidateArg("password", args, input.ValidateNodePassword, &c.password),
server.ValidateArg("save", args, input.ValidateBool, &c.save),
}
return c, errors.Join(inputErrs...)
}
func (f *walletSetPasswordContextFactory) RegisterRoute(router *mux.Router) {
server.RegisterQuerylessGet[*walletSetPasswordContext, types.SuccessData](
router, "set-password", f, f.handler.logger.Logger, f.handler.serviceProvider.ServiceProvider,
)
}
// ===============
// === Context ===
// ===============
type walletSetPasswordContext struct {
handler *WalletHandler
password string
save bool
}
func (c *walletSetPasswordContext) PrepareData(data *types.SuccessData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
sp := c.handler.serviceProvider
w := sp.GetWallet()
err := w.SetPassword(c.password, c.save)
if err != nil {
return types.ResponseStatus_Error, err
}
return types.ResponseStatus_Success, err
}