summaryrefslogtreecommitdiff
path: root/ledger/store/trackerdb/generickv/writer.go
blob: 8975c97c6e2c09aab09c5589c038d4aa39f2052d (plain)
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
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package generickv

import (
	"context"
	"github.com/algorand/go-algorand/config"
	"github.com/algorand/go-algorand/data/basics"
	"github.com/algorand/go-algorand/ledger/store/trackerdb"
	"github.com/algorand/go-algorand/protocol"
	"testing"
)

type writer struct {
	// TODO: the need for the store here is quite broken
	//       this is due to exposing RunMigrations and AccountsInit on the writers
	//       the internals of this methods completly ignore the "writer" and recreate a transaction
	store trackerdb.Store
	KvWrite
	KvRead
}

// MakeWriter returns a trackerdb.Writer for a KV
func MakeWriter(store trackerdb.Store, kvw KvWrite, kvr KvRead) trackerdb.Writer {
	return &writer{store, kvw, kvr}
}

// MakeAccountsOptimizedWriter implements trackerdb.Writer
func (w *writer) MakeAccountsOptimizedWriter(hasAccounts bool, hasResources bool, hasKvPairs bool, hasCreatables bool) (trackerdb.AccountsWriter, error) {
	return MakeAccountsWriter(w, w), nil
}

// MakeAccountsWriter implements trackerdb.Writer
func (w *writer) MakeAccountsWriter() (trackerdb.AccountsWriterExt, error) {
	return MakeAccountsWriter(w, w), nil
}

// MakeOnlineAccountsOptimizedWriter implements trackerdb.Writer
func (w *writer) MakeOnlineAccountsOptimizedWriter(hasAccounts bool) (trackerdb.OnlineAccountsWriter, error) {
	return MakeOnlineAccountsWriter(w), nil
}

// MakeSpVerificationCtxWriter implements trackerdb.Writer
func (w *writer) MakeSpVerificationCtxWriter() trackerdb.SpVerificationCtxWriter {
	return MakeStateproofWriter(w)
}

// Testing implements trackerdb.Writer
func (w *writer) Testing() trackerdb.WriterTestExt {
	return &writerForTesting{w.store, w, w}
}

type writerForTesting struct {
	trackerdb.Store
	KvWrite
	KvRead
}

// AccountsInitLightTest implements trackerdb.WriterTestExt
func (w *writerForTesting) AccountsInitLightTest(tb testing.TB, initAccounts map[basics.Address]basics.AccountData, proto config.ConsensusParams) (newDatabase bool, err error) {
	panic("unimplemented")
}

// AccountsInitTest implements trackerdb.WriterTestExt
func (w *writerForTesting) AccountsInitTest(tb testing.TB, initAccounts map[basics.Address]basics.AccountData, proto protocol.ConsensusVersion) (newDatabase bool) {
	return AccountsInitTest(tb, w, initAccounts, proto)
}

// AccountsUpdateSchemaTest implements trackerdb.WriterTestExt
func (w *writerForTesting) AccountsUpdateSchemaTest(ctx context.Context) (err error) {
	panic("unimplemented")
}

// ModifyAcctBaseTest implements trackerdb.WriterTestExt
func (w *writerForTesting) ModifyAcctBaseTest() error {
	panic("unimplemented")
}