-
Notifications
You must be signed in to change notification settings - Fork 105
/
masquerade.go
58 lines (48 loc) · 1.47 KB
/
masquerade.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
package wallet
import (
"errors"
"net/url"
_ "time/tzdata"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"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 walletMasqueradeContextFactory struct {
handler *WalletHandler
}
func (f *walletMasqueradeContextFactory) Create(args url.Values) (*walletMasqueradeContext, error) {
c := &walletMasqueradeContext{
handler: f.handler,
}
inputErrs := []error{
server.ValidateArg("address", args, input.ValidateAddress, &c.address),
}
return c, errors.Join(inputErrs...)
}
func (f *walletMasqueradeContextFactory) RegisterRoute(router *mux.Router) {
server.RegisterQuerylessGet[*walletMasqueradeContext, types.SuccessData](
router, "masquerade", f, f.handler.logger.Logger, f.handler.serviceProvider.ServiceProvider,
)
}
// ===============
// === Context ===
// ===============
type walletMasqueradeContext struct {
handler *WalletHandler
address common.Address
}
func (c *walletMasqueradeContext) PrepareData(data *types.SuccessData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
sp := c.handler.serviceProvider
w := sp.GetWallet()
err := w.MasqueradeAsAddress(c.address)
if err != nil {
return types.ResponseStatus_Error, err
}
return types.ResponseStatus_Success, nil
}