-
Notifications
You must be signed in to change notification settings - Fork 46
/
min_fee.go
39 lines (32 loc) · 880 Bytes
/
min_fee.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 (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewMinFee allows to build a MinFee instance based on the given message type and fee amount
func NewMinFee(messageType string, amount sdk.Coins) MinFee {
return MinFee{
MessageType: messageType,
Amount: amount,
}
}
// Validate checks if minimum fee represents a valid instance
func (mf MinFee) Validate() error {
if !strings.HasPrefix(mf.MessageType, "/") {
return fmt.Errorf("invalid message type")
}
if !mf.Amount.IsValid() {
return fmt.Errorf("invalid minimum fee amount")
}
return nil
}
// ContainsMinFee returns true iff the given min fee slice contains a min fee for the given message type
func ContainsMinFee(minFees []MinFee, msgType string) bool {
for _, minFee := range minFees {
if minFee.MessageType == msgType {
return true
}
}
return false
}