You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

10 years ago
9 years ago
10 years ago
10 years ago
  1. package types
  2. import (
  3. "regexp"
  4. )
  5. var (
  6. MinNameRegistrationPeriod int = 5
  7. // NOTE: base costs and validity checks are here so clients
  8. // can use them without importing state
  9. // cost for storing a name for a block is
  10. // CostPerBlock*CostPerByte*(len(data) + 32)
  11. NameCostPerByte int64 = 1
  12. NameCostPerBlock int64 = 1
  13. MaxNameLength = 32
  14. MaxDataLength = 1 << 16
  15. // Name should be alphanum, underscore, slash
  16. // Data should be anything permitted in JSON
  17. regexpAlphaNum = regexp.MustCompile("^[a-zA-Z0-9._/]*$")
  18. regexpJSON = regexp.MustCompile(`^[a-zA-Z0-9_/ \-"':,\n\t.{}()\[\]]*$`)
  19. )
  20. // filter strings
  21. func validateNameRegEntryName(name string) bool {
  22. return regexpAlphaNum.Match([]byte(name))
  23. }
  24. func validateNameRegEntryData(data string) bool {
  25. return regexpJSON.Match([]byte(data))
  26. }
  27. // base cost is "effective" number of bytes
  28. func BaseEntryCost(name, data string) int64 {
  29. return int64(len(data) + 32)
  30. }
  31. type NameRegEntry struct {
  32. Name string `json:"name"` // registered name for the entry
  33. Owner []byte `json:"owner"` // address that created the entry
  34. Data string `json:"data"` // data to store under this name
  35. Expires int `json:"expires"` // block at which this entry expires
  36. }
  37. func (entry *NameRegEntry) Copy() *NameRegEntry {
  38. entryCopy := *entry
  39. return &entryCopy
  40. }