-
Notifications
You must be signed in to change notification settings - Fork 887
/
state.go
257 lines (235 loc) · 7.85 KB
/
state.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package state
import (
"context"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/celestiaorg/celestia-node/blob"
"github.com/celestiaorg/celestia-node/state"
)
var _ Module = (*API)(nil)
// Module represents the behaviors necessary for a user to
// query for state-related information and submit transactions/
// messages to the Celestia network.
//
//go:generate mockgen -destination=mocks/api.go -package=mocks . Module
//nolint:dupl
type Module interface {
// AccountAddress retrieves the address of the node's account/signer
AccountAddress(ctx context.Context) (state.Address, error)
// Balance retrieves the Celestia coin balance for the node's account/signer
// and verifies it against the corresponding block's AppHash.
Balance(ctx context.Context) (*state.Balance, error)
// BalanceForAddress retrieves the Celestia coin balance for the given address and verifies
// the returned balance against the corresponding block's AppHash.
//
// NOTE: the balance returned is the balance reported by the block right before
// the node's current head (head-1). This is due to the fact that for block N, the block's
// `AppHash` is the result of applying the previous block's transaction list.
BalanceForAddress(ctx context.Context, addr state.Address) (*state.Balance, error)
// Transfer sends the given amount of coins from default wallet of the node to the given account
// address.
Transfer(
ctx context.Context, to state.AccAddress, amount, fee state.Int, gasLimit uint64,
) (*state.TxResponse, error)
// SubmitTx submits the given transaction/message to the
// Celestia network and blocks until the tx is included in
// a block.
SubmitTx(ctx context.Context, tx state.Tx) (*state.TxResponse, error)
// SubmitPayForBlob builds, signs and submits a PayForBlob transaction.
SubmitPayForBlob(
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs []*blob.Blob,
) (*state.TxResponse, error)
// CancelUnbondingDelegation cancels a user's pending undelegation from a validator.
CancelUnbondingDelegation(
ctx context.Context,
valAddr state.ValAddress,
amount,
height,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error)
// BeginRedelegate sends a user's delegated tokens to a new validator for redelegation.
BeginRedelegate(
ctx context.Context,
srcValAddr,
dstValAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error)
// Undelegate undelegates a user's delegated tokens, unbonding them from the current validator.
Undelegate(
ctx context.Context,
delAddr state.ValAddress,
amount, fee state.Int,
gasLim uint64,
) (*state.TxResponse, error)
// Delegate sends a user's liquid tokens to a validator for delegation.
Delegate(
ctx context.Context,
delAddr state.ValAddress,
amount, fee state.Int,
gasLim uint64,
) (*state.TxResponse, error)
// QueryDelegation retrieves the delegation information between a delegator and a validator.
QueryDelegation(ctx context.Context, valAddr state.ValAddress) (*types.QueryDelegationResponse, error)
// QueryUnbonding retrieves the unbonding status between a delegator and a validator.
QueryUnbonding(ctx context.Context, valAddr state.ValAddress) (*types.QueryUnbondingDelegationResponse, error)
// QueryRedelegations retrieves the status of the redelegations between a delegator and a validator.
QueryRedelegations(
ctx context.Context,
srcValAddr,
dstValAddr state.ValAddress,
) (*types.QueryRedelegationsResponse, error)
}
// API is a wrapper around Module for the RPC.
// TODO(@distractedm1nd): These structs need to be autogenerated.
//
//nolint:dupl
type API struct {
Internal struct {
AccountAddress func(ctx context.Context) (state.Address, error) `perm:"read"`
Balance func(ctx context.Context) (*state.Balance, error) `perm:"read"`
BalanceForAddress func(ctx context.Context, addr state.Address) (*state.Balance, error) `perm:"read"`
Transfer func(
ctx context.Context,
to state.AccAddress,
amount,
fee state.Int,
gasLimit uint64,
) (*state.TxResponse, error) `perm:"write"`
SubmitTx func(ctx context.Context, tx state.Tx) (*state.TxResponse, error) `perm:"read"`
SubmitPayForBlob func(
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs []*blob.Blob,
) (*state.TxResponse, error) `perm:"write"`
CancelUnbondingDelegation func(
ctx context.Context,
valAddr state.ValAddress,
amount,
height,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) `perm:"write"`
BeginRedelegate func(
ctx context.Context,
srcValAddr,
dstValAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) `perm:"write"`
Undelegate func(
ctx context.Context,
delAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) `perm:"write"`
Delegate func(
ctx context.Context,
delAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) `perm:"write"`
QueryDelegation func(
ctx context.Context,
valAddr state.ValAddress,
) (*types.QueryDelegationResponse, error) `perm:"read"`
QueryUnbonding func(
ctx context.Context,
valAddr state.ValAddress,
) (*types.QueryUnbondingDelegationResponse, error) `perm:"read"`
QueryRedelegations func(
ctx context.Context,
srcValAddr,
dstValAddr state.ValAddress,
) (*types.QueryRedelegationsResponse, error) `perm:"read"`
}
}
func (api *API) AccountAddress(ctx context.Context) (state.Address, error) {
return api.Internal.AccountAddress(ctx)
}
func (api *API) BalanceForAddress(ctx context.Context, addr state.Address) (*state.Balance, error) {
return api.Internal.BalanceForAddress(ctx, addr)
}
func (api *API) Transfer(
ctx context.Context,
to state.AccAddress,
amount,
fee state.Int,
gasLimit uint64,
) (*state.TxResponse, error) {
return api.Internal.Transfer(ctx, to, amount, fee, gasLimit)
}
func (api *API) SubmitTx(ctx context.Context, tx state.Tx) (*state.TxResponse, error) {
return api.Internal.SubmitTx(ctx, tx)
}
func (api *API) SubmitPayForBlob(
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs []*blob.Blob,
) (*state.TxResponse, error) {
return api.Internal.SubmitPayForBlob(ctx, fee, gasLim, blobs)
}
func (api *API) CancelUnbondingDelegation(
ctx context.Context,
valAddr state.ValAddress,
amount,
height,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) {
return api.Internal.CancelUnbondingDelegation(ctx, valAddr, amount, height, fee, gasLim)
}
func (api *API) BeginRedelegate(
ctx context.Context,
srcValAddr, dstValAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) {
return api.Internal.BeginRedelegate(ctx, srcValAddr, dstValAddr, amount, fee, gasLim)
}
func (api *API) Undelegate(
ctx context.Context,
delAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) {
return api.Internal.Undelegate(ctx, delAddr, amount, fee, gasLim)
}
func (api *API) Delegate(
ctx context.Context,
delAddr state.ValAddress,
amount,
fee state.Int,
gasLim uint64,
) (*state.TxResponse, error) {
return api.Internal.Delegate(ctx, delAddr, amount, fee, gasLim)
}
func (api *API) QueryDelegation(ctx context.Context, valAddr state.ValAddress) (*types.QueryDelegationResponse, error) {
return api.Internal.QueryDelegation(ctx, valAddr)
}
func (api *API) QueryUnbonding(
ctx context.Context,
valAddr state.ValAddress,
) (*types.QueryUnbondingDelegationResponse, error) {
return api.Internal.QueryUnbonding(ctx, valAddr)
}
func (api *API) QueryRedelegations(
ctx context.Context,
srcValAddr, dstValAddr state.ValAddress,
) (*types.QueryRedelegationsResponse, error) {
return api.Internal.QueryRedelegations(ctx, srcValAddr, dstValAddr)
}
func (api *API) Balance(ctx context.Context) (*state.Balance, error) {
return api.Internal.Balance(ctx)
}