-
Notifications
You must be signed in to change notification settings - Fork 6
/
query_get_session_request.go
39 lines (33 loc) · 1.49 KB
/
query_get_session_request.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sharedhelpers "github.com/pokt-network/poktroll/x/shared/helpers"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)
// NOTE: Please note that `QueryGetSessionRequest` is not a `sdk.Msg`, and is therefore not a message/request
// that will be signable or invoke a state transition. However, following a similar `ValidateBasic` pattern
// allows us to localize & reuse validation logic.
func NewQueryGetSessionRequest(appAddress, serviceId string, blockHeight int64) *QueryGetSessionRequest {
return &QueryGetSessionRequest{
ApplicationAddress: appAddress,
Service: &sharedtypes.Service{
Id: serviceId,
},
BlockHeight: blockHeight,
}
}
func (query *QueryGetSessionRequest) ValidateBasic() error {
// Validate the application address
if _, err := sdk.AccAddressFromBech32(query.ApplicationAddress); err != nil {
return ErrSessionInvalidAppAddress.Wrapf("invalid app address for session being retrieved %s; (%v)", query.ApplicationAddress, err)
}
// Validate the Service ID
if !sharedhelpers.IsValidService(query.Service) {
return ErrSessionInvalidService.Wrapf("invalid service for session being retrieved %s;", query.Service)
}
// Validate the height for which a session is being retrieved
if query.BlockHeight < 0 { // Note that `0` defaults to the latest height rather than genesis
return ErrSessionInvalidBlockHeight.Wrapf("invalid block height for session being retrieved %d;", query.BlockHeight)
}
return nil
}