tendermint/types/names.go

56 lines
1.4 KiB
Go
Raw Normal View History

2015-05-22 13:53:10 -07:00
package types
2015-05-24 11:41:42 -07:00
import (
"regexp"
)
var (
MinNameRegistrationPeriod int = 5
2015-05-24 11:41:42 -07:00
2015-07-30 14:34:38 -07:00
// NOTE: base costs and validity checks are here so clients
// can use them without importing state
2015-05-24 11:41:42 -07:00
// cost for storing a name for a block is
// CostPerBlock*CostPerByte*(len(data) + 32)
NameByteCostMultiplier int64 = 1
NameBlockCostMultiplier int64 = 1
2015-05-24 11:41:42 -07:00
MaxNameLength = 64
2015-05-24 11:41:42 -07:00
MaxDataLength = 1 << 16
// Name should be file system lik
2015-05-24 11:41:42 -07:00
// Data should be anything permitted in JSON
regexpAlphaNum = regexp.MustCompile("^[a-zA-Z0-9._/-@]*$")
regexpJSON = regexp.MustCompile(`^[a-zA-Z0-9_/ \-+"':,\n\t.{}()\[\]]*$`)
2015-05-24 11:41:42 -07:00
)
// 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 NameBaseCost(name, data string) int64 {
return int64(len(data) + 32)
2015-05-24 11:41:42 -07:00
}
func NameCostPerBlock(baseCost int64) int64 {
return NameBlockCostMultiplier * NameByteCostMultiplier * baseCost
}
2015-05-22 13:53:10 -07:00
type NameRegEntry struct {
Name string `json:"name"` // registered name for the entry
Owner []byte `json:"owner"` // address that created the entry
Data string `json:"data"` // data to store under this name
Expires int `json:"expires"` // block at which this entry expires
}
func (entry *NameRegEntry) Copy() *NameRegEntry {
entryCopy := *entry
return &entryCopy
2015-05-22 13:53:10 -07:00
}