namereg cleanup, tests

This commit is contained in:
Ethan Buchman
2015-05-24 14:41:42 -04:00
parent 02aedaaefb
commit 77ff09e173
5 changed files with 242 additions and 41 deletions

View File

@ -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