mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
namereg cleanup, tests
This commit is contained in:
@ -1,5 +1,40 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
MinNameRegistrationPeriod uint64 = 5
|
||||
|
||||
// cost for storing a name for a block is
|
||||
// CostPerBlock*CostPerByte*(len(data) + 32)
|
||||
NameCostPerByte uint64 = 1
|
||||
NameCostPerBlock uint64 = 1
|
||||
|
||||
MaxNameLength = 32
|
||||
MaxDataLength = 1 << 16
|
||||
|
||||
// Name should be alphanum, underscore, slash
|
||||
// Data should be anything permitted in JSON
|
||||
regexpAlphaNum = regexp.MustCompile("^[a-zA-Z0-9_/]*$")
|
||||
regexpJSON = regexp.MustCompile(`^[a-zA-Z0-9_/ \-"':,\n\t.{}()\[\]]*$`)
|
||||
)
|
||||
|
||||
// filter strings
|
||||
func validateNameRegEntryName(name string) bool {
|
||||
return regexpAlphaNum.Match([]byte(name))
|
||||
}
|
||||
|
||||
func validateNameRegEntryData(data string) bool {
|
||||
return regexpJSON.Match([]byte(data))
|
||||
}
|
||||
|
||||
// base cost is "effective" number of bytes
|
||||
func BaseEntryCost(name, data string) uint64 {
|
||||
return uint64(len(data) + 32)
|
||||
}
|
||||
|
||||
type NameRegEntry struct {
|
||||
Name string `json:"name"` // registered name for the entry
|
||||
Owner []byte `json:"owner"` // address that created the entry
|
||||
|
Reference in New Issue
Block a user