aboutsummaryrefslogtreecommitdiff
path: root/internal/storage/store.go
blob: 59055b7e221b0a99b1add40042168ba3202460aa (plain) (blame)
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
package storage

import "github.com/Fuwn/plutia/internal/types"

type BlockHashEntry struct {
	BlockID uint64
	Hash    string
}

type OperationMutation struct {
	State types.StateV1
	Ref   *types.BlockRefV1
}

type Store interface {
	Close() error

	GetMode() (string, error)
	SetMode(mode string) error

	GetGlobalSeq() (uint64, error)
	SetGlobalSeq(seq uint64) error

	PutState(state types.StateV1) error
	GetState(did string) (types.StateV1, bool, error)
	ListStates() ([]types.StateV1, error)
	ForEachState(fn func(types.StateV1) error) error
	ApplyOperationsBatch(ops []OperationMutation, blockHashes []BlockHashEntry) error

	SetChainHead(did string, seq uint64) error
	GetChainHead(did string) (uint64, bool, error)
	AddDIDSequence(did string, seq uint64) error
	ListDIDSequences(did string) ([]uint64, error)

	PutOpSeqRef(seq uint64, ref types.BlockRefV1) error
	GetOpSeqRef(seq uint64) (types.BlockRefV1, bool, error)

	PutBlockHash(blockID uint64, hash string) error
	GetBlockHash(blockID uint64) (string, bool, error)
	ListBlockHashes() ([]string, error)
	ListBlockHashEntries() ([]BlockHashEntry, error)

	PutCheckpoint(cp types.CheckpointV1) error
	GetCheckpoint(sequence uint64) (types.CheckpointV1, bool, error)
	GetLatestCheckpoint() (types.CheckpointV1, bool, error)
}