-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore.go
80 lines (63 loc) · 2.95 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2019, 2020 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 types
import (
"context"
"github.com/google/uuid"
)
// Store is the interface for wallet stores. It is used to store and access data provided by wallets, both wallets themselves
// as well as keys inside the wallets.
type Store interface {
// Name provides the name of the store
Name() string
// StoreWallet stores wallet data. It will fail if it cannot store the data.
StoreWallet(walletID uuid.UUID, walletName string, data []byte) error
// RetrieveWallet retrieves wallet data for all wallets.
RetrieveWallets() <-chan []byte
// RetrieveWallet retrieves wallet data for a wallet with a given name.
// It will fail if it cannot retrieve the data.
RetrieveWallet(walletName string) ([]byte, error)
// RetrieveWalletByID retrieves wallet data for a wallet with a given ID.
// It will fail if it cannot retrieve the data.
RetrieveWalletByID(walletID uuid.UUID) ([]byte, error)
// StoreAccount stores account data. It will fail if it cannot store the data.
StoreAccount(walletID uuid.UUID, accountID uuid.UUID, data []byte) error
// RetrieveAccounts retrieves account information for all accounts.
RetrieveAccounts(walletID uuid.UUID) <-chan []byte
// RetrieveAccount retrieves account data for a wallet with a given ID.
// It will fail if it cannot retrieve the data.
RetrieveAccount(walletID uuid.UUID, accountID uuid.UUID) ([]byte, error)
// StoreAccountsIndex stores the index of accounts for a given wallet.
StoreAccountsIndex(walletID uuid.UUID, data []byte) error
// RetrieveAccountsIndex retrieves the index of accounts for a given wallet.
RetrieveAccountsIndex(walletID uuid.UUID) ([]byte, error)
}
// BatchStorer is an interface for storing account batches.
type BatchStorer interface {
// StoreBatch stores wallet batch data. It will fail if it cannot store the data.
StoreBatch(ctx context.Context, walletID uuid.UUID, walletName string, data []byte) error
}
// BatchRetriever is an interface for retrieving account batches.
type BatchRetriever interface {
// RetrieveBatch retrieves the batch of accounts for a given wallet.
RetrieveBatch(ctx context.Context, walletID uuid.UUID) ([]byte, error)
}
// StoreProvider is the interface provides a store.
type StoreProvider interface {
// Store returns the store.
Store() Store
}
// StoreLocationProvider provides the location of the store.
type StoreLocationProvider interface {
Location() string
}