2019-06-05 16:26:17 -07:00
|
|
|
package types
|
2018-12-20 11:09:43 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params/subspace"
|
2018-12-20 11:09:43 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// DefaultParamspace defines the default auth module parameter subspace
|
2019-05-16 08:25:32 -07:00
|
|
|
const DefaultParamspace = ModuleName
|
2018-12-20 11:09:43 -08:00
|
|
|
|
|
|
|
// Default parameter values
|
|
|
|
const (
|
2019-02-04 15:35:12 -08:00
|
|
|
DefaultMaxMemoCharacters uint64 = 256
|
|
|
|
DefaultTxSigLimit uint64 = 7
|
|
|
|
DefaultTxSizeCostPerByte uint64 = 10
|
|
|
|
DefaultSigVerifyCostED25519 uint64 = 590
|
|
|
|
DefaultSigVerifyCostSecp256k1 uint64 = 1000
|
2018-12-20 11:09:43 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Parameter keys
|
|
|
|
var (
|
|
|
|
KeyMaxMemoCharacters = []byte("MaxMemoCharacters")
|
|
|
|
KeyTxSigLimit = []byte("TxSigLimit")
|
2019-02-04 15:35:12 -08:00
|
|
|
KeyTxSizeCostPerByte = []byte("TxSizeCostPerByte")
|
2018-12-20 11:09:43 -08:00
|
|
|
KeySigVerifyCostED25519 = []byte("SigVerifyCostED25519")
|
|
|
|
KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
|
|
|
|
)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
var _ subspace.ParamSet = &Params{}
|
2018-12-20 11:09:43 -08:00
|
|
|
|
|
|
|
// Params defines the parameters for the auth module.
|
|
|
|
type Params struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
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"`
|
2018-12-20 11:09:43 -08:00
|
|
|
}
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:35:19 -08:00
|
|
|
// ParamKeyTable for auth module
|
2019-06-05 16:26:17 -07:00
|
|
|
func ParamKeyTable() subspace.KeyTable {
|
|
|
|
return subspace.NewKeyTable().RegisterParamSet(&Params{})
|
2018-12-20 11:09:43 -08:00
|
|
|
}
|
|
|
|
|
2019-02-04 18:13:04 -08:00
|
|
|
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
|
2018-12-20 11:09:43 -08:00
|
|
|
// pairs of auth module's parameters.
|
|
|
|
// nolint
|
2019-04-30 09:31:38 -07:00
|
|
|
func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
|
|
|
|
return subspace.ParamSetPairs{
|
2018-12-20 11:09:43 -08:00
|
|
|
{KeyMaxMemoCharacters, &p.MaxMemoCharacters},
|
|
|
|
{KeyTxSigLimit, &p.TxSigLimit},
|
2019-02-04 15:35:12 -08:00
|
|
|
{KeyTxSizeCostPerByte, &p.TxSizeCostPerByte},
|
2018-12-20 11:09:43 -08:00
|
|
|
{KeySigVerifyCostED25519, &p.SigVerifyCostED25519},
|
|
|
|
{KeySigVerifyCostSecp256k1, &p.SigVerifyCostSecp256k1},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Equal returns a boolean determining if two Params types are identical.
|
|
|
|
func (p Params) Equal(p2 Params) bool {
|
2019-06-05 16:26:17 -07:00
|
|
|
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p)
|
|
|
|
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2)
|
2018-12-20 11:09:43 -08:00
|
|
|
return bytes.Equal(bz1, bz2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultParams returns a default set of parameters.
|
|
|
|
func DefaultParams() Params {
|
|
|
|
return Params{
|
|
|
|
MaxMemoCharacters: DefaultMaxMemoCharacters,
|
|
|
|
TxSigLimit: DefaultTxSigLimit,
|
2019-02-04 15:35:12 -08:00
|
|
|
TxSizeCostPerByte: DefaultTxSizeCostPerByte,
|
2018-12-20 11:09:43 -08:00
|
|
|
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))
|
2019-02-04 15:35:12 -08:00
|
|
|
sb.WriteString(fmt.Sprintf("TxSizeCostPerByte: %d\n", p.TxSizeCostPerByte))
|
2018-12-20 11:09:43 -08:00
|
|
|
sb.WriteString(fmt.Sprintf("SigVerifyCostED25519: %d\n", p.SigVerifyCostED25519))
|
|
|
|
sb.WriteString(fmt.Sprintf("SigVerifyCostSecp256k1: %d\n", p.SigVerifyCostSecp256k1))
|
|
|
|
return sb.String()
|
|
|
|
}
|
2019-09-12 12:22:25 -07:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|