@@ -12,6 +12,45 @@ import (
12
12
"cosmossdk.io/core/transaction"
13
13
)
14
14
15
+ // AppManager is a coordinator for all things related to an application
16
+ // It is responsible for interacting with stf and store.
17
+ // Runtime/v2 is an extension of this interface.
18
+ type AppManager [T transaction.Tx ] interface {
19
+ // InitGenesis initializes the genesis state of the application.
20
+ InitGenesis (
21
+ ctx context.Context ,
22
+ blockRequest * server.BlockRequest [T ],
23
+ initGenesisJSON []byte ,
24
+ txDecoder transaction.Codec [T ],
25
+ ) (* server.BlockResponse , corestore.WriterMap , error )
26
+
27
+ // ExportGenesis exports the genesis state of the application.
28
+ ExportGenesis (ctx context.Context , version uint64 ) ([]byte , error )
29
+
30
+ // DeliverBlock executes a block of transactions.
31
+ DeliverBlock (
32
+ ctx context.Context ,
33
+ block * server.BlockRequest [T ],
34
+ ) (* server.BlockResponse , corestore.WriterMap , error )
35
+
36
+ // ValidateTx will validate the tx against the latest storage state. This means that
37
+ // only the stateful validation will be run, not the execution portion of the tx.
38
+ // If full execution is needed, Simulate must be used.
39
+ ValidateTx (ctx context.Context , tx T ) (server.TxResult , error )
40
+
41
+ // Simulate runs validation and execution flow of a Tx.
42
+ Simulate (ctx context.Context , tx T ) (server.TxResult , corestore.WriterMap , error )
43
+
44
+ // Query queries the application at the provided version.
45
+ // CONTRACT: Version must always be provided, if 0, get latest
46
+ Query (ctx context.Context , version uint64 , request transaction.Msg ) (transaction.Msg , error )
47
+
48
+ // QueryWithState executes a query with the provided state. This allows to process a query
49
+ // independently of the db state. For example, it can be used to process a query with temporary
50
+ // and uncommitted state
51
+ QueryWithState (ctx context.Context , state corestore.ReaderMap , request transaction.Msg ) (transaction.Msg , error )
52
+ }
53
+
15
54
// Store defines the underlying storage behavior needed by AppManager.
16
55
type Store interface {
17
56
// StateLatest returns a readonly view over the latest
@@ -24,8 +63,8 @@ type Store interface {
24
63
StateAt (version uint64 ) (corestore.ReaderMap , error )
25
64
}
26
65
27
- // AppManager is a coordinator for all things related to an application
28
- type AppManager [T transaction.Tx ] struct {
66
+ // appManager is a coordinator for all things related to an application
67
+ type appManager [T transaction.Tx ] struct {
29
68
// Gas limits for validating, querying, and simulating transactions.
30
69
config Config
31
70
// InitGenesis is a function that initializes the application state from a genesis file.
@@ -46,18 +85,18 @@ func New[T transaction.Tx](
46
85
stf StateTransitionFunction [T ],
47
86
initGenesisImpl InitGenesis ,
48
87
exportGenesisImpl ExportGenesis ,
49
- ) (* AppManager [T ], error ) {
50
- appManager := & AppManager [T ]{
51
- config : config ,
52
- db : db ,
53
- stf : stf ,
88
+ ) AppManager [T ] {
89
+ return & appManager [T ]{
90
+ config : config ,
91
+ db : db ,
92
+ stf : stf ,
93
+ initGenesis : initGenesisImpl ,
94
+ exportGenesis : exportGenesisImpl ,
54
95
}
55
-
56
- return appManager , nil
57
96
}
58
97
59
98
// InitGenesis initializes the genesis state of the application.
60
- func (a AppManager [T ]) InitGenesis (
99
+ func (a appManager [T ]) InitGenesis (
61
100
ctx context.Context ,
62
101
blockRequest * server.BlockRequest [T ],
63
102
initGenesisJSON []byte ,
@@ -102,15 +141,16 @@ func (a AppManager[T]) InitGenesis(
102
141
}
103
142
104
143
// ExportGenesis exports the genesis state of the application.
105
- func (a AppManager [T ]) ExportGenesis (ctx context.Context , version uint64 ) ([]byte , error ) {
144
+ func (a appManager [T ]) ExportGenesis (ctx context.Context , version uint64 ) ([]byte , error ) {
106
145
if a .exportGenesis == nil {
107
146
return nil , errors .New ("export genesis function not set" )
108
147
}
109
148
110
149
return a .exportGenesis (ctx , version )
111
150
}
112
151
113
- func (a AppManager [T ]) DeliverBlock (
152
+ // DeliverBlock executes a block of transactions.
153
+ func (a appManager [T ]) DeliverBlock (
114
154
ctx context.Context ,
115
155
block * server.BlockRequest [T ],
116
156
) (* server.BlockResponse , corestore.WriterMap , error ) {
@@ -134,7 +174,7 @@ func (a AppManager[T]) DeliverBlock(
134
174
// ValidateTx will validate the tx against the latest storage state. This means that
135
175
// only the stateful validation will be run, not the execution portion of the tx.
136
176
// If full execution is needed, Simulate must be used.
137
- func (a AppManager [T ]) ValidateTx (ctx context.Context , tx T ) (server.TxResult , error ) {
177
+ func (a appManager [T ]) ValidateTx (ctx context.Context , tx T ) (server.TxResult , error ) {
138
178
_ , latestState , err := a .db .StateLatest ()
139
179
if err != nil {
140
180
return server.TxResult {}, err
@@ -144,7 +184,7 @@ func (a AppManager[T]) ValidateTx(ctx context.Context, tx T) (server.TxResult, e
144
184
}
145
185
146
186
// Simulate runs validation and execution flow of a Tx.
147
- func (a AppManager [T ]) Simulate (ctx context.Context , tx T ) (server.TxResult , corestore.WriterMap , error ) {
187
+ func (a appManager [T ]) Simulate (ctx context.Context , tx T ) (server.TxResult , corestore.WriterMap , error ) {
148
188
_ , state , err := a .db .StateLatest ()
149
189
if err != nil {
150
190
return server.TxResult {}, nil , err
@@ -155,7 +195,7 @@ func (a AppManager[T]) Simulate(ctx context.Context, tx T) (server.TxResult, cor
155
195
156
196
// Query queries the application at the provided version.
157
197
// CONTRACT: Version must always be provided, if 0, get latest
158
- func (a AppManager [T ]) Query (ctx context.Context , version uint64 , request transaction.Msg ) (transaction.Msg , error ) {
198
+ func (a appManager [T ]) Query (ctx context.Context , version uint64 , request transaction.Msg ) (transaction.Msg , error ) {
159
199
// if version is provided attempt to do a height query.
160
200
if version != 0 {
161
201
queryState , err := a .db .StateAt (version )
@@ -176,6 +216,6 @@ func (a AppManager[T]) Query(ctx context.Context, version uint64, request transa
176
216
// QueryWithState executes a query with the provided state. This allows to process a query
177
217
// independently of the db state. For example, it can be used to process a query with temporary
178
218
// and uncommitted state
179
- func (a AppManager [T ]) QueryWithState (ctx context.Context , state corestore.ReaderMap , request transaction.Msg ) (transaction.Msg , error ) {
219
+ func (a appManager [T ]) QueryWithState (ctx context.Context , state corestore.ReaderMap , request transaction.Msg ) (transaction.Msg , error ) {
180
220
return a .stf .Query (ctx , state , a .config .QueryGasLimit , request )
181
221
}
0 commit comments