forked from wealdtech/go-eth2-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
65 lines (56 loc) · 1.73 KB
/
store.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
// Copyright © 2019 Weald Technology Trading
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package wallet
import (
"errors"
"fmt"
filesystem "github.com/wealdtech/go-eth2-wallet-store-filesystem"
s3 "github.com/wealdtech/go-eth2-wallet-store-s3"
types "github.com/wealdtech/go-eth2-wallet-types"
)
var store types.Store
func init() {
// default store is filesystem
store = filesystem.New()
}
// SetStore sets a store to use given its name and optional passphrase.
// This does not allow access to all advanced features of stores. To access these create the stores yourself and set them with
// `UseStore()`.
func SetStore(name string, passphrase []byte) error {
var store types.Store
var err error
switch name {
case "s3":
store, err = s3.New(s3.WithPassphrase(passphrase))
case "filesystem":
store = filesystem.New(filesystem.WithPassphrase(passphrase))
default:
err = fmt.Errorf("unknown wallet store %q", name)
}
if err != nil {
return err
}
return UseStore(store)
}
// UseStore sets a store to use.
func UseStore(s types.Store) error {
if s == nil {
return errors.New("no store supplied")
}
store = s
return nil
}
// GetStore returns the name of the current store.
func GetStore() string {
return store.Name()
}