-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.go
92 lines (82 loc) · 3.7 KB
/
query.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
/*
Copyright [2019] - [2021], PERSISTENCE TECHNOLOGIES PTE. LTD. and the persistenceBridge contributors
SPDX-License-Identifier: Apache-2.0
*/
package tendermint
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/relayer/relayer"
"github.com/persistenceOne/persistenceBridge/utilities/logging"
)
func AddressIsDelegatorToValidator(delegatorAddress, validatorAddress string, chain *relayer.Chain) bool {
_, err := QueryValidatorDelegator(delegatorAddress, validatorAddress, chain)
if err != nil {
return false
}
return true
}
func QueryValidatorDelegator(delegatorAddress, validatorAddress string, chain *relayer.Chain) (stakingTypes.Validator, error) {
stakingClient := stakingTypes.NewQueryClient(chain.CLIContext(0))
stakingRes, err := stakingClient.DelegatorValidator(context.Background(), &stakingTypes.QueryDelegatorValidatorRequest{
DelegatorAddr: delegatorAddress,
ValidatorAddr: validatorAddress,
})
if err != nil {
logging.Error("Delegator's validator not found, Error:", err)
return stakingTypes.Validator{}, err
}
return stakingRes.GetValidator(), err
}
func QueryDelegatorValidatorDelegations(delegatorAddress, validatorAddress string, chain *relayer.Chain) (stakingTypes.DelegationResponse, error) {
stakingClient := stakingTypes.NewQueryClient(chain.CLIContext(0))
stakingRes, err := stakingClient.Delegation(context.Background(), &stakingTypes.QueryDelegationRequest{
DelegatorAddr: delegatorAddress,
ValidatorAddr: validatorAddress,
})
if err != nil {
logging.Error("Delegator validator delegation not found, Error:", err)
return stakingTypes.DelegationResponse{}, err
}
return *stakingRes.DelegationResponse, err
}
func QueryDelegatorDelegations(delegatorAddress string, chain *relayer.Chain) (stakingTypes.DelegationResponses, error) {
stakingClient := stakingTypes.NewQueryClient(chain.CLIContext(0))
stakingRes, err := stakingClient.DelegatorDelegations(context.Background(), &stakingTypes.QueryDelegatorDelegationsRequest{
DelegatorAddr: delegatorAddress,
})
if err != nil {
logging.Info("Delegator delegations not found, Error:", err)
return nil, err
}
return stakingRes.DelegationResponses, err
}
func QueryValidator(validatorAddress sdk.ValAddress, chain *relayer.Chain) (stakingTypes.QueryValidatorResponse, error) {
stakingClient := stakingTypes.NewQueryClient(chain.CLIContext(0))
stakingResponse, err := stakingClient.Validator(context.Background(), &stakingTypes.QueryValidatorRequest{ValidatorAddr: validatorAddress.String()})
if err != nil {
logging.Error("Validator's staking response not found, Error:", err)
return stakingTypes.QueryValidatorResponse{}, err
}
return *stakingResponse, err
}
func QuerySlashingSigningInfo(consAddress sdk.ConsAddress, chain *relayer.Chain) (slashingTypes.QuerySigningInfoResponse, error) {
slashingClient := slashingTypes.NewQueryClient(chain.CLIContext(0))
slashingResponse, err := slashingClient.SigningInfo(context.Background(), &slashingTypes.QuerySigningInfoRequest{ConsAddress: consAddress.String()})
if err != nil {
logging.Error("Validator's signing info not found, Error:", err)
return slashingTypes.QuerySigningInfoResponse{}, err
}
return *slashingResponse, err
}
func QuerySlashingParams(chain *relayer.Chain) (slashingTypes.QueryParamsResponse, error) {
slashingClient := slashingTypes.NewQueryClient(chain.CLIContext(0))
slashingResponse, err := slashingClient.Params(context.Background(), &slashingTypes.QueryParamsRequest{})
if err != nil {
logging.Error("Params not found, Error:", err)
return slashingTypes.QueryParamsResponse{}, err
}
return *slashingResponse, err
}