forked from Consensys/quorum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reloadableimpl.go
105 lines (90 loc) · 2.62 KB
/
reloadableimpl.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package account
import (
"context"
"time"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/log"
)
type DispenseFunc func() (Service, error)
type ReloadableService struct {
DispenseFunc DispenseFunc
}
func (am *ReloadableService) Status(ctx context.Context) (string, error) {
s, err := am.DispenseFunc()
if err != nil {
return "", err
}
return s.Status(ctx)
}
func (am *ReloadableService) Open(ctx context.Context, passphrase string) error {
s, err := am.DispenseFunc()
if err != nil {
return err
}
return s.Open(ctx, passphrase)
}
func (am *ReloadableService) Close(ctx context.Context) error {
s, err := am.DispenseFunc()
if err != nil {
return err
}
return s.Close(ctx)
}
func (am *ReloadableService) Accounts(ctx context.Context) []accounts.Account {
s, err := am.DispenseFunc()
if err != nil {
log.Error("unable to dispense account plugin", "err", err)
return []accounts.Account{}
}
return s.Accounts(ctx)
}
func (am *ReloadableService) Contains(ctx context.Context, account accounts.Account) bool {
s, err := am.DispenseFunc()
if err != nil {
log.Error("unable to dispense account plugin", "err", err)
return false
}
return s.Contains(ctx, account)
}
func (am *ReloadableService) Sign(ctx context.Context, account accounts.Account, toSign []byte) ([]byte, error) {
s, err := am.DispenseFunc()
if err != nil {
return nil, err
}
return s.Sign(ctx, account, toSign)
}
func (am *ReloadableService) UnlockAndSign(ctx context.Context, account accounts.Account, toSign []byte, passphrase string) ([]byte, error) {
s, err := am.DispenseFunc()
if err != nil {
return nil, err
}
return s.UnlockAndSign(ctx, account, toSign, passphrase)
}
func (am *ReloadableService) TimedUnlock(ctx context.Context, account accounts.Account, password string, duration time.Duration) error {
s, err := am.DispenseFunc()
if err != nil {
return err
}
return s.TimedUnlock(ctx, account, password, duration)
}
func (am *ReloadableService) Lock(ctx context.Context, account accounts.Account) error {
s, err := am.DispenseFunc()
if err != nil {
return err
}
return s.Lock(ctx, account)
}
func (am *ReloadableService) NewAccount(ctx context.Context, newAccountConfig interface{}) (accounts.Account, error) {
s, err := am.DispenseFunc()
if err != nil {
return accounts.Account{}, err
}
return s.NewAccount(ctx, newAccountConfig)
}
func (am *ReloadableService) ImportRawKey(ctx context.Context, rawKey string, newAccountConfig interface{}) (accounts.Account, error) {
s, err := am.DispenseFunc()
if err != nil {
return accounts.Account{}, err
}
return s.ImportRawKey(ctx, rawKey, newAccountConfig)
}