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.

55 lines
1.4 KiB

10 years ago
10 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. NameByteCostMultiplier int64 = 1
  12. NameBlockCostMultiplier int64 = 1
  13. MaxNameLength = 64
  14. MaxDataLength = 1 << 16
  15. // Name should be file system lik
  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 NameBaseCost(name, data string) int64 {
  29. return int64(len(data) + 32)
  30. }
  31. func NameCostPerBlock(baseCost int64) int64 {
  32. return NameBlockCostMultiplier * NameByteCostMultiplier * baseCost
  33. }
  34. type NameRegEntry struct {
  35. Name string `json:"name"` // registered name for the entry
  36. Owner []byte `json:"owner"` // address that created the entry
  37. Data string `json:"data"` // data to store under this name
  38. Expires int `json:"expires"` // block at which this entry expires
  39. }
  40. func (entry *NameRegEntry) Copy() *NameRegEntry {
  41. entryCopy := *entry
  42. return &entryCopy
  43. }