-
Notifications
You must be signed in to change notification settings - Fork 7
/
utxo_repository.go
85 lines (78 loc) · 3.44 KB
/
utxo_repository.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
package domain
import (
"context"
)
const (
UtxoAdded UtxoEventType = iota
UtxoConfirmed
UtxoLocked
UtxoUnlocked
UtxoSpent
UtxoConfirmedSpend
)
var (
utxoTypeString = map[UtxoEventType]string{
UtxoAdded: "UtxoAdded",
UtxoConfirmed: "UtxoConfirmed",
UtxoLocked: "UtxoLocked",
UtxoUnlocked: "UtxoUnlocked",
UtxoSpent: "UtxoSpent",
UtxoConfirmedSpend: "UtxoConfirmedSpend",
}
)
type UtxoEventType int
func (t UtxoEventType) String() string {
return utxoTypeString[t]
}
// UtxoEvent holds info about an event occured within the repository.
type UtxoEvent struct {
EventType UtxoEventType
Utxos []UtxoInfo
}
// UtxoRepository is the abstraction for any kind of database intended to
// persist Utxos.
type UtxoRepository interface {
// AddUtxos adds the provided utxos to the repository by preventing
// duplicates.
// Generates a UtxoAdded event if successfull.
AddUtxos(ctx context.Context, utxos []*Utxo) (int, error)
// GetUtxosByKey returns the utxos identified by the given keys.
GetUtxosByKey(ctx context.Context, utxoKeys []UtxoKey) ([]*Utxo, error)
// GetAllUtxos returns the entire UTXO set, included those locked or
// already spent.
GetAllUtxos(ctx context.Context) ([]*Utxo, error)
// GetSpendableUtxos returns all unlocked utxo UTXOs.
GetSpendableUtxos(ctx context.Context) ([]*Utxo, error)
// GetAllUtxosForAccount returns the list of all utxos for the given
// account.
GetAllUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error)
// GetSpendableUtxosForAccount returns the list of spendable utxos for the
// given account. The list incldues only confirmed and unlocked utxos.
GetSpendableUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error)
// GetLockedUtxosForAccount returns the list of all currently locked utxos
// for the given account.
GetLockedUtxosForAccount(ctx context.Context, account string) ([]*Utxo, error)
// GetBalanceForAccount returns the confirmed, unconfirmed and locked
// balances per each asset for the given account.
GetBalanceForAccount(ctx context.Context, account string) (map[string]*Balance, error)
// SpendUtxos updates the status of the given list of utxos to "spent" by the given txid.
// Generates a UtxoSpent event if successfull.
SpendUtxos(ctx context.Context, utxoKeys []UtxoKey, txid string) (int, error)
// ConfirmSpendUtxos updates the status of the given list of utxos to "confirmed spend".
// Generates a UtxoConfirmedSpend event if successfull.
ConfirmSpendUtxos(ctx context.Context, utxoKeys []UtxoKey, status UtxoStatus) (int, error)
// ConfirmUtxos updates the status of the given list of utxos to "confirmed".
// Generates a UtxoConfirmed event if successfull.
ConfirmUtxos(ctx context.Context, utxoKeys []UtxoKey, status UtxoStatus) (int, error)
// LockUtxos updates the status of the given list of utxos to "locked".
// Generates a UtxoLocked event if successfull.
LockUtxos(ctx context.Context, utxoKeys []UtxoKey, timestamp, expiryTimestamp int64) (int, error)
// UnlockUtxos updates the status of the given list of utxos to "unlocked".
// Generates a UtxoUnlocked event if successfull.
UnlockUtxos(ctx context.Context, utxoKeys []UtxoKey) (int, error)
// DeleteUtxosForAccount deletes every utxo associated to the given account
// from the repository.
DeleteUtxosForAccount(ctx context.Context, accountName string) error
// GetEventChannel returns the channel of UtxoEvents.
GetEventChannel() chan UtxoEvent
}