github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/state/state.go (about) 1 package state 2 3 import ( 4 "context" 5 6 "github.com/cosmos/cosmos-sdk/x/staking/types" 7 8 "github.com/celestiaorg/celestia-node/blob" 9 "github.com/celestiaorg/celestia-node/state" 10 ) 11 12 var _ Module = (*API)(nil) 13 14 // Module represents the behaviors necessary for a user to 15 // query for state-related information and submit transactions/ 16 // messages to the Celestia network. 17 // 18 //go:generate mockgen -destination=mocks/api.go -package=mocks . Module 19 //nolint:dupl 20 type Module interface { 21 22 // AccountAddress retrieves the address of the node's account/signer 23 AccountAddress(ctx context.Context) (state.Address, error) 24 // Balance retrieves the Celestia coin balance for the node's account/signer 25 // and verifies it against the corresponding block's AppHash. 26 Balance(ctx context.Context) (*state.Balance, error) 27 // BalanceForAddress retrieves the Celestia coin balance for the given address and verifies 28 // the returned balance against the corresponding block's AppHash. 29 // 30 // NOTE: the balance returned is the balance reported by the block right before 31 // the node's current head (head-1). This is due to the fact that for block N, the block's 32 // `AppHash` is the result of applying the previous block's transaction list. 33 BalanceForAddress(ctx context.Context, addr state.Address) (*state.Balance, error) 34 35 // Transfer sends the given amount of coins from default wallet of the node to the given account 36 // address. 37 Transfer( 38 ctx context.Context, to state.AccAddress, amount, fee state.Int, gasLimit uint64, 39 ) (*state.TxResponse, error) 40 // SubmitTx submits the given transaction/message to the 41 // Celestia network and blocks until the tx is included in 42 // a block. 43 SubmitTx(ctx context.Context, tx state.Tx) (*state.TxResponse, error) 44 // SubmitPayForBlob builds, signs and submits a PayForBlob transaction. 45 SubmitPayForBlob( 46 ctx context.Context, 47 fee state.Int, 48 gasLim uint64, 49 blobs []*blob.Blob, 50 ) (*state.TxResponse, error) 51 52 // CancelUnbondingDelegation cancels a user's pending undelegation from a validator. 53 CancelUnbondingDelegation( 54 ctx context.Context, 55 valAddr state.ValAddress, 56 amount, 57 height, 58 fee state.Int, 59 gasLim uint64, 60 ) (*state.TxResponse, error) 61 // BeginRedelegate sends a user's delegated tokens to a new validator for redelegation. 62 BeginRedelegate( 63 ctx context.Context, 64 srcValAddr, 65 dstValAddr state.ValAddress, 66 amount, 67 fee state.Int, 68 gasLim uint64, 69 ) (*state.TxResponse, error) 70 // Undelegate undelegates a user's delegated tokens, unbonding them from the current validator. 71 Undelegate( 72 ctx context.Context, 73 delAddr state.ValAddress, 74 amount, fee state.Int, 75 gasLim uint64, 76 ) (*state.TxResponse, error) 77 // Delegate sends a user's liquid tokens to a validator for delegation. 78 Delegate( 79 ctx context.Context, 80 delAddr state.ValAddress, 81 amount, fee state.Int, 82 gasLim uint64, 83 ) (*state.TxResponse, error) 84 85 // QueryDelegation retrieves the delegation information between a delegator and a validator. 86 QueryDelegation(ctx context.Context, valAddr state.ValAddress) (*types.QueryDelegationResponse, error) 87 // QueryUnbonding retrieves the unbonding status between a delegator and a validator. 88 QueryUnbonding(ctx context.Context, valAddr state.ValAddress) (*types.QueryUnbondingDelegationResponse, error) 89 // QueryRedelegations retrieves the status of the redelegations between a delegator and a validator. 90 QueryRedelegations( 91 ctx context.Context, 92 srcValAddr, 93 dstValAddr state.ValAddress, 94 ) (*types.QueryRedelegationsResponse, error) 95 } 96 97 // API is a wrapper around Module for the RPC. 98 // TODO(@distractedm1nd): These structs need to be autogenerated. 99 // 100 //nolint:dupl 101 type API struct { 102 Internal struct { 103 AccountAddress func(ctx context.Context) (state.Address, error) `perm:"read"` 104 Balance func(ctx context.Context) (*state.Balance, error) `perm:"read"` 105 BalanceForAddress func(ctx context.Context, addr state.Address) (*state.Balance, error) `perm:"read"` 106 Transfer func( 107 ctx context.Context, 108 to state.AccAddress, 109 amount, 110 fee state.Int, 111 gasLimit uint64, 112 ) (*state.TxResponse, error) `perm:"write"` 113 SubmitTx func(ctx context.Context, tx state.Tx) (*state.TxResponse, error) `perm:"read"` 114 SubmitPayForBlob func( 115 ctx context.Context, 116 fee state.Int, 117 gasLim uint64, 118 blobs []*blob.Blob, 119 ) (*state.TxResponse, error) `perm:"write"` 120 CancelUnbondingDelegation func( 121 ctx context.Context, 122 valAddr state.ValAddress, 123 amount, 124 height, 125 fee state.Int, 126 gasLim uint64, 127 ) (*state.TxResponse, error) `perm:"write"` 128 BeginRedelegate func( 129 ctx context.Context, 130 srcValAddr, 131 dstValAddr state.ValAddress, 132 amount, 133 fee state.Int, 134 gasLim uint64, 135 ) (*state.TxResponse, error) `perm:"write"` 136 Undelegate func( 137 ctx context.Context, 138 delAddr state.ValAddress, 139 amount, 140 fee state.Int, 141 gasLim uint64, 142 ) (*state.TxResponse, error) `perm:"write"` 143 Delegate func( 144 ctx context.Context, 145 delAddr state.ValAddress, 146 amount, 147 fee state.Int, 148 gasLim uint64, 149 ) (*state.TxResponse, error) `perm:"write"` 150 QueryDelegation func( 151 ctx context.Context, 152 valAddr state.ValAddress, 153 ) (*types.QueryDelegationResponse, error) `perm:"read"` 154 QueryUnbonding func( 155 ctx context.Context, 156 valAddr state.ValAddress, 157 ) (*types.QueryUnbondingDelegationResponse, error) `perm:"read"` 158 QueryRedelegations func( 159 ctx context.Context, 160 srcValAddr, 161 dstValAddr state.ValAddress, 162 ) (*types.QueryRedelegationsResponse, error) `perm:"read"` 163 } 164 } 165 166 func (api *API) AccountAddress(ctx context.Context) (state.Address, error) { 167 return api.Internal.AccountAddress(ctx) 168 } 169 170 func (api *API) BalanceForAddress(ctx context.Context, addr state.Address) (*state.Balance, error) { 171 return api.Internal.BalanceForAddress(ctx, addr) 172 } 173 174 func (api *API) Transfer( 175 ctx context.Context, 176 to state.AccAddress, 177 amount, 178 fee state.Int, 179 gasLimit uint64, 180 ) (*state.TxResponse, error) { 181 return api.Internal.Transfer(ctx, to, amount, fee, gasLimit) 182 } 183 184 func (api *API) SubmitTx(ctx context.Context, tx state.Tx) (*state.TxResponse, error) { 185 return api.Internal.SubmitTx(ctx, tx) 186 } 187 188 func (api *API) SubmitPayForBlob( 189 ctx context.Context, 190 fee state.Int, 191 gasLim uint64, 192 blobs []*blob.Blob, 193 ) (*state.TxResponse, error) { 194 return api.Internal.SubmitPayForBlob(ctx, fee, gasLim, blobs) 195 } 196 197 func (api *API) CancelUnbondingDelegation( 198 ctx context.Context, 199 valAddr state.ValAddress, 200 amount, 201 height, 202 fee state.Int, 203 gasLim uint64, 204 ) (*state.TxResponse, error) { 205 return api.Internal.CancelUnbondingDelegation(ctx, valAddr, amount, height, fee, gasLim) 206 } 207 208 func (api *API) BeginRedelegate( 209 ctx context.Context, 210 srcValAddr, dstValAddr state.ValAddress, 211 amount, 212 fee state.Int, 213 gasLim uint64, 214 ) (*state.TxResponse, error) { 215 return api.Internal.BeginRedelegate(ctx, srcValAddr, dstValAddr, amount, fee, gasLim) 216 } 217 218 func (api *API) Undelegate( 219 ctx context.Context, 220 delAddr state.ValAddress, 221 amount, 222 fee state.Int, 223 gasLim uint64, 224 ) (*state.TxResponse, error) { 225 return api.Internal.Undelegate(ctx, delAddr, amount, fee, gasLim) 226 } 227 228 func (api *API) Delegate( 229 ctx context.Context, 230 delAddr state.ValAddress, 231 amount, 232 fee state.Int, 233 gasLim uint64, 234 ) (*state.TxResponse, error) { 235 return api.Internal.Delegate(ctx, delAddr, amount, fee, gasLim) 236 } 237 238 func (api *API) QueryDelegation(ctx context.Context, valAddr state.ValAddress) (*types.QueryDelegationResponse, error) { 239 return api.Internal.QueryDelegation(ctx, valAddr) 240 } 241 242 func (api *API) QueryUnbonding( 243 ctx context.Context, 244 valAddr state.ValAddress, 245 ) (*types.QueryUnbondingDelegationResponse, error) { 246 return api.Internal.QueryUnbonding(ctx, valAddr) 247 } 248 249 func (api *API) QueryRedelegations( 250 ctx context.Context, 251 srcValAddr, dstValAddr state.ValAddress, 252 ) (*types.QueryRedelegationsResponse, error) { 253 return api.Internal.QueryRedelegations(ctx, srcValAddr, dstValAddr) 254 } 255 256 func (api *API) Balance(ctx context.Context) (*state.Balance, error) { 257 return api.Internal.Balance(ctx) 258 }