Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (107 sloc) 4.13 KB
package types
import (
"bytes"
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
)
// DefaultParamspace defines the default auth module parameter subspace
const DefaultParamspace = ModuleName
// Default parameter values
const (
DefaultMaxMemoCharacters uint64 = 256
DefaultTxSigLimit uint64 = 7
DefaultTxSizeCostPerByte uint64 = 10
DefaultSigVerifyCostED25519 uint64 = 590
DefaultSigVerifyCostSecp256k1 uint64 = 1000
)
// Parameter keys
var (
KeyMaxMemoCharacters = []byte("MaxMemoCharacters")
KeyTxSigLimit = []byte("TxSigLimit")
KeyTxSizeCostPerByte = []byte("TxSizeCostPerByte")
KeySigVerifyCostED25519 = []byte("SigVerifyCostED25519")
KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
)
var _ subspace.ParamSet = &Params{}
// Params defines the parameters for the auth module.
type Params struct {
MaxMemoCharacters uint64 `json:"max_memo_characters" yaml:"max_memo_characters"`
TxSigLimit uint64 `json:"tx_sig_limit" yaml:"tx_sig_limit"`
TxSizeCostPerByte uint64 `json:"tx_size_cost_per_byte" yaml:"tx_size_cost_per_byte"`
SigVerifyCostED25519 uint64 `json:"sig_verify_cost_ed25519" yaml:"sig_verify_cost_ed25519"`
SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1" yaml:"sig_verify_cost_secp256k1"`
}
// NewParams creates a new Params object
func NewParams(maxMemoCharacters, txSigLimit, txSizeCostPerByte,
sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64) Params {
return Params{
MaxMemoCharacters: maxMemoCharacters,
TxSigLimit: txSigLimit,
TxSizeCostPerByte: txSizeCostPerByte,
SigVerifyCostED25519: sigVerifyCostED25519,
SigVerifyCostSecp256k1: sigVerifyCostSecp256k1,
}
}
// ParamKeyTable for auth module
func ParamKeyTable() subspace.KeyTable {
return subspace.NewKeyTable().RegisterParamSet(&Params{})
}
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of auth module's parameters.
// nolint
func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
return subspace.ParamSetPairs{
{KeyMaxMemoCharacters, &p.MaxMemoCharacters},
{KeyTxSigLimit, &p.TxSigLimit},
{KeyTxSizeCostPerByte, &p.TxSizeCostPerByte},
{KeySigVerifyCostED25519, &p.SigVerifyCostED25519},
{KeySigVerifyCostSecp256k1, &p.SigVerifyCostSecp256k1},
}
}
// Equal returns a boolean determining if two Params types are identical.
func (p Params) Equal(p2 Params) bool {
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p)
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2)
return bytes.Equal(bz1, bz2)
}
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return Params{
MaxMemoCharacters: DefaultMaxMemoCharacters,
TxSigLimit: DefaultTxSigLimit,
TxSizeCostPerByte: DefaultTxSizeCostPerByte,
SigVerifyCostED25519: DefaultSigVerifyCostED25519,
SigVerifyCostSecp256k1: DefaultSigVerifyCostSecp256k1,
}
}
// String implements the stringer interface.
func (p Params) String() string {
var sb strings.Builder
sb.WriteString("Params: \n")
sb.WriteString(fmt.Sprintf("MaxMemoCharacters: %d\n", p.MaxMemoCharacters))
sb.WriteString(fmt.Sprintf("TxSigLimit: %d\n", p.TxSigLimit))
sb.WriteString(fmt.Sprintf("TxSizeCostPerByte: %d\n", p.TxSizeCostPerByte))
sb.WriteString(fmt.Sprintf("SigVerifyCostED25519: %d\n", p.SigVerifyCostED25519))
sb.WriteString(fmt.Sprintf("SigVerifyCostSecp256k1: %d\n", p.SigVerifyCostSecp256k1))
return sb.String()
}
// Validate checks that the parameters have valid values.
func (p Params) Validate() error {
if p.TxSigLimit == 0 {
return fmt.Errorf("invalid tx signature limit: %d", p.TxSigLimit)
}
if p.SigVerifyCostED25519 == 0 {
return fmt.Errorf("invalid ED25519 signature verification cost: %d", p.SigVerifyCostED25519)
}
if p.SigVerifyCostSecp256k1 == 0 {
return fmt.Errorf("invalid SECK256k1 signature verification cost: %d", p.SigVerifyCostSecp256k1)
}
if p.MaxMemoCharacters == 0 {
return fmt.Errorf("invalid max memo characters: %d", p.MaxMemoCharacters)
}
if p.TxSizeCostPerByte == 0 {
return fmt.Errorf("invalid tx size cost per byte: %d", p.TxSizeCostPerByte)
}
return nil
}
You can’t perform that action at this time.