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.

48 lines
1.2 KiB

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