-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
397 lines (353 loc) · 12.2 KB
/
provider.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
package provider
import (
"context"
"sync"
"github.com/xpladev/xpla.go/key"
"github.com/xpladev/xpla.go/types"
"github.com/xpladev/xpla/app/params"
cmclient "github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/gogo/protobuf/grpc"
)
// The standard form of XPLA client is interface type.
// XplaClient is endpoint in order to access xpla.go from external packages.
// If new modules are implemeted, external functions that are used to send tx or query state should be
// enrolled in XplaClient interface.
//
// e.g. - enroll bank module
//
// type TxMsgProvider interface {
// ...
// BankSend(types.BankSendMsg) XplaClient
// ...
// }
//
// type QueryMsgProvider interface {
// ...
// BankBalances(types.BankBalancesMsg) XplaClient
// DenomMetadata(...types.DenomMetadataMsg) XplaClient
// Total(...types.TotalMsg) XplaClient
// ...
// }
//
// The return type of these methods must be always the XplaClient because the client uses mehod chaining.
//
// e.g. - create and sign transaction
//
// txbytes, err := xplac.BankSend(bankSendMsg).CreateAndSignTx()
//
// e.g. - query
//
// res, err := xplac.BankBalances(bankBalancesMsg).Query()
type XplaClient interface {
WithProvider
GetProvider
TxProvider
QueryProvider
BroadcastProvider
InfoRequestProvider
TxMsgProvider
QueryMsgProvider
HelperProvider
}
// Optional parameters of client.xplaClient.
type Options struct {
PrivateKey key.PrivateKey
PublicKey key.PublicKey
AccountNumber string
Sequence string
BroadcastMode string
GasLimit string
GasPrice string
GasAdjustment string
FeeAmount string
SignMode signing.SignMode
FeeGranter sdk.AccAddress
TimeoutHeight string
LcdURL string
GrpcURL string
RpcURL string
EvmRpcURL string
Pagination types.Pagination
OutputDocument string
FromAddress sdk.AccAddress
}
// Methods set params of client.xplaClient.
type WithProvider interface {
UpdateXplacInCoreModule() XplaClient
WithOptions(Options) XplaClient
WithChainId(string) XplaClient
WithEncoding(params.EncodingConfig) XplaClient
WithContext(context.Context) XplaClient
WithPrivateKey(key.PrivateKey) XplaClient
WithPublicKey(key.PublicKey) XplaClient
WithAccountNumber(string) XplaClient
WithBroadcastMode(string) XplaClient
WithSequence(string) XplaClient
WithGasLimit(string) XplaClient
WithGasPrice(string) XplaClient
WithGasAdjustment(string) XplaClient
WithFeeAmount(string) XplaClient
WithSignMode(signing.SignMode) XplaClient
WithFeeGranter(sdk.AccAddress) XplaClient
WithTimeoutHeight(string) XplaClient
WithURL(string) XplaClient
WithGrpc(string) XplaClient
WithRpc(string) XplaClient
WithEvmRpc(string) XplaClient
WithPagination(types.Pagination) XplaClient
WithOutputDocument(string) XplaClient
WithFromAddress(sdk.AccAddress) XplaClient
WithModule(string) XplaClient
WithMsgType(string) XplaClient
WithMsg(interface{}) XplaClient
WithErr(error) XplaClient
}
// Methods get params of client.xplaClient.
type GetProvider interface {
GetChainId() string
GetPrivateKey() key.PrivateKey
GetPublicKey() key.PublicKey
GetEncoding() params.EncodingConfig
GetContext() context.Context
GetLcdURL() string
GetGrpcUrl() string
GetGrpcClient() grpc.ClientConn
GetRpc() string
GetEvmRpc() string
GetBroadcastMode() string
GetAccountNumber() string
GetSequence() string
GetGasLimit() string
GetGasPrice() string
GetGasAdjustment() string
GetFeeAmount() string
GetSignMode() signing.SignMode
GetFeeGranter() sdk.AccAddress
GetTimeoutHeight() string
GetPagination() *query.PageRequest
GetOutputDocument() string
GetFromAddress() sdk.AccAddress
GetHttpMutex() *sync.Mutex
GetModule() string
GetMsg() interface{}
GetMsgType() string
GetErr() error
}
// Methods handle transaction.
type TxProvider interface {
CreateAndSignTx() ([]byte, error)
CreateUnsignedTx() ([]byte, error)
SignTx(types.SignTxMsg) ([]byte, error)
MultiSign(types.TxMultiSignMsg) ([]byte, error)
EncodeTx(types.EncodeTxMsg) (string, error)
DecodeTx(types.DecodeTxMsg) (string, error)
ValidateSignatures(types.ValidateSignaturesMsg) (string, error)
}
// Method handles query functions.
type QueryProvider interface {
Query() (string, error)
}
// Methods handle functions of broadcasting.
type BroadcastProvider interface {
Broadcast([]byte) (*types.TxRes, error)
BroadcastBlock([]byte) (*types.TxRes, error)
BroadcastAsync([]byte) (*types.TxRes, error)
}
// Methods get information from XPLA chain.
type InfoRequestProvider interface {
LoadAccount(sdk.AccAddress) (authtypes.AccountI, error)
Simulate(cmclient.TxBuilder) (*sdktx.SimulateResponse, error)
}
// Methods are external functions of each module for sending transaction.
type TxMsgProvider interface {
// authz
AuthzGrant(types.AuthzGrantMsg) XplaClient
AuthzRevoke(types.AuthzRevokeMsg) XplaClient
AuthzExec(types.AuthzExecMsg) XplaClient
// bank
BankSend(types.BankSendMsg) XplaClient
// crisis
InvariantBroken(types.InvariantBrokenMsg) XplaClient
// distribution
FundCommunityPool(types.FundCommunityPoolMsg) XplaClient
CommunityPoolSpend(types.CommunityPoolSpendMsg) XplaClient
WithdrawRewards(types.WithdrawRewardsMsg) XplaClient
WithdrawAllRewards() XplaClient
SetWithdrawAddr(types.SetWithdrawAddrMsg) XplaClient
// evm
EvmSendCoin(types.SendCoinMsg) XplaClient
DeploySolidityContract(types.DeploySolContractMsg) XplaClient
InvokeSolidityContract(types.InvokeSolContractMsg) XplaClient
// feegrant
FeeGrant(types.FeeGrantMsg) XplaClient
RevokeFeeGrant(types.RevokeFeeGrantMsg) XplaClient
// gov
SubmitProposal(types.SubmitProposalMsg) XplaClient
GovDeposit(types.GovDepositMsg) XplaClient
Vote(types.VoteMsg) XplaClient
WeightedVote(types.WeightedVoteMsg) XplaClient
// params
ParamChange(types.ParamChangeMsg) XplaClient
// reward
FundFeeCollector(types.FundFeeCollectorMsg) XplaClient
// slashing
Unjail() XplaClient
// staking
CreateValidator(types.CreateValidatorMsg) XplaClient
EditValidator(types.EditValidatorMsg) XplaClient
Delegate(types.DelegateMsg) XplaClient
Unbond(types.UnbondMsg) XplaClient
Redelegate(types.RedelegateMsg) XplaClient
// upgrade
SoftwareUpgrade(types.SoftwareUpgradeMsg) XplaClient
CancelSoftwareUpgrade(types.CancelSoftwareUpgradeMsg) XplaClient
// volunteer
RegisterVolunteerValidator(types.RegisterVolunteerValidatorMsg) XplaClient
UnregisterVolunteerValidator(types.UnregisterVolunteerValidatorMsg) XplaClient
// wasm
StoreCode(types.StoreMsg) XplaClient
InstantiateContract(types.InstantiateMsg) XplaClient
ExecuteContract(types.ExecuteMsg) XplaClient
ClearContractAdmin(types.ClearContractAdminMsg) XplaClient
SetContractAdmin(types.SetContractAdminMsg) XplaClient
Migrate(types.MigrateMsg) XplaClient
}
// Methods are external functions of each module for querying.
type QueryMsgProvider interface {
// auth
AuthParams() XplaClient
AccAddress(types.QueryAccAddressMsg) XplaClient
Accounts() XplaClient
TxsByEvents(types.QueryTxsByEventsMsg) XplaClient
Tx(types.QueryTxMsg) XplaClient
// authz
QueryAuthzGrants(types.QueryAuthzGrantMsg) XplaClient
// bank
BankBalances(types.BankBalancesMsg) XplaClient
DenomMetadata(...types.DenomMetadataMsg) XplaClient
Total(...types.TotalMsg) XplaClient
// base
NodeInfo() XplaClient
Syncing() XplaClient
Block(...types.BlockMsg) XplaClient
ValidatorSet(...types.ValidatorSetMsg) XplaClient
// distribution
DistributionParams() XplaClient
ValidatorOutstandingRewards(types.ValidatorOutstandingRewardsMsg) XplaClient
DistCommission(types.QueryDistCommissionMsg) XplaClient
DistSlashes(types.QueryDistSlashesMsg) XplaClient
DistRewards(types.QueryDistRewardsMsg) XplaClient
CommunityPool() XplaClient
// evidence
QueryEvidence(...types.QueryEvidenceMsg) XplaClient
// evm
CallSolidityContract(types.CallSolContractMsg) XplaClient
GetTransactionByHash(types.GetTransactionByHashMsg) XplaClient
GetBlockByHashOrHeight(types.GetBlockByHashHeightMsg) XplaClient
AccountInfo(types.AccountInfoMsg) XplaClient
SuggestGasPrice() XplaClient
EthChainID() XplaClient
EthBlockNumber() XplaClient
Web3ClientVersion() XplaClient
Web3Sha3(types.Web3Sha3Msg) XplaClient
NetVersion() XplaClient
NetPeerCount() XplaClient
NetListening() XplaClient
EthProtocolVersion() XplaClient
EthSyncing() XplaClient
EthAccounts() XplaClient
EthGetBlockTransactionCount(types.EthGetBlockTransactionCountMsg) XplaClient
EstimateGas(types.InvokeSolContractMsg) XplaClient
EthGetTransactionByBlockHashAndIndex(types.GetTransactionByBlockHashAndIndexMsg) XplaClient
EthGetTransactionReceipt(types.GetTransactionReceiptMsg) XplaClient
EthNewFilter(types.EthNewFilterMsg) XplaClient
EthNewBlockFilter() XplaClient
EthNewPendingTransactionFilter() XplaClient
EthUninstallFilter(types.EthUninstallFilterMsg) XplaClient
EthGetFilterChanges(types.EthGetFilterChangesMsg) XplaClient
EthGetFilterLogs(types.EthGetFilterLogsMsg) XplaClient
EthGetLogs(types.EthGetLogsMsg) XplaClient
EthCoinbase() XplaClient
// feegrant
QueryFeeGrants(types.QueryFeeGrantMsg) XplaClient
// gov
QueryProposal(types.QueryProposalMsg) XplaClient
QueryProposals(types.QueryProposalsMsg) XplaClient
QueryDeposit(types.QueryDepositMsg) XplaClient
QueryVote(types.QueryVoteMsg) XplaClient
Tally(types.TallyMsg) XplaClient
GovParams(...types.GovParamsMsg) XplaClient
Proposer(types.ProposerMsg) XplaClient
// mint
MintParams() XplaClient
Inflation() XplaClient
AnnualProvisions() XplaClient
// ibc
IbcClientStates() XplaClient
IbcClientState(types.IbcClientStateMsg) XplaClient
IbcClientStatus(types.IbcClientStatusMsg) XplaClient
IbcClientConsensusStates(types.IbcClientConsensusStatesMsg) XplaClient
IbcClientConsensusStateHeights(types.IbcClientConsensusStateHeightsMsg) XplaClient
IbcClientConsensusState(types.IbcClientConsensusStateMsg) XplaClient
IbcClientHeader() XplaClient
IbcClientSelfConsensusState() XplaClient
IbcClientParams() XplaClient
IbcConnections(...types.IbcConnectionMsg) XplaClient
IbcClientConnections(types.IbcClientConnectionsMsg) XplaClient
IbcChannels(...types.IbcChannelMsg) XplaClient
IbcChannelConnections(types.IbcChannelConnectionsMsg) XplaClient
IbcChannelClientState(types.IbcChannelClientStateMsg) XplaClient
IbcChannelPacketCommitments(types.IbcChannelPacketCommitmentsMsg) XplaClient
IbcChannelPacketReceipt(types.IbcChannelPacketReceiptMsg) XplaClient
IbcChannelPacketAck(types.IbcChannelPacketAckMsg) XplaClient
IbcChannelUnreceivedPackets(types.IbcChannelUnreceivedPacketsMsg) XplaClient
IbcChannelUnreceivedAcks(types.IbcChannelUnreceivedAcksMsg) XplaClient
IbcChannelNextSequence(types.IbcChannelNextSequenceMsg) XplaClient
IbcDenomTraces(...types.IbcDenomTraceMsg) XplaClient
IbcDenomTrace(types.IbcDenomTraceMsg) XplaClient
IbcDenomHash(types.IbcDenomHashMsg) XplaClient
IbcEscrowAddress(types.IbcEscrowAddressMsg) XplaClient
IbcTransferParams() XplaClient
// params
QuerySubspace(types.SubspaceMsg) XplaClient
// reward
RewardParams() XplaClient
RewardPool() XplaClient
// slashing
SlashingParams() XplaClient
SigningInfos(...types.SigningInfoMsg) XplaClient
// staking
QueryValidators(...types.QueryValidatorMsg) XplaClient
QueryDelegation(types.QueryDelegationMsg) XplaClient
QueryUnbondingDelegation(types.QueryUnbondingDelegationMsg) XplaClient
QueryRedelegation(types.QueryRedelegationMsg) XplaClient
HistoricalInfo(types.HistoricalInfoMsg) XplaClient
StakingPool() XplaClient
StakingParams() XplaClient
// upgrade
UpgradeApplied(types.AppliedMsg) XplaClient
ModulesVersion(...types.QueryModulesVersionMsg) XplaClient
Plan() XplaClient
// volunteer
QueryVolunteerValidators() XplaClient
// wasm
QueryContract(types.QueryMsg) XplaClient
ListCode() XplaClient
ListContractByCode(types.ListContractByCodeMsg) XplaClient
Download(types.DownloadMsg) XplaClient
CodeInfo(types.CodeInfoMsg) XplaClient
ContractInfo(types.ContractInfoMsg) XplaClient
ContractStateAll(types.ContractStateAllMsg) XplaClient
ContractHistory(types.ContractHistoryMsg) XplaClient
Pinned() XplaClient
LibwasmvmVersion() XplaClient
}
// Method of helper.
type HelperProvider interface {
EncodedTxbytesToJsonTx([]byte) ([]byte, error)
}