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.

102 lines
2.4 KiB

  1. package types
  2. import (
  3. "github.com/tendermint/tendermint/wire"
  4. )
  5. //---------------------------------------------------------------------------------------------------
  6. // PermissionsTx.PermArgs interface and argument encoding
  7. // Arguments are a registered interface in the PermissionsTx,
  8. // so binary handles the arguments and each permission function gets a type-byte
  9. // PermFlag() maps the type-byte to the permission
  10. // The account sending the PermissionsTx must have this PermFlag set
  11. type PermArgs interface {
  12. PermFlag() PermFlag
  13. }
  14. const (
  15. PermArgsTypeHasBase = byte(0x01)
  16. PermArgsTypeSetBase = byte(0x02)
  17. PermArgsTypeUnsetBase = byte(0x03)
  18. PermArgsTypeSetGlobal = byte(0x04)
  19. PermArgsTypeHasRole = byte(0x05)
  20. PermArgsTypeAddRole = byte(0x06)
  21. PermArgsTypeRmRole = byte(0x07)
  22. )
  23. // for wire.readReflect
  24. var _ = wire.RegisterInterface(
  25. struct{ PermArgs }{},
  26. wire.ConcreteType{&HasBaseArgs{}, PermArgsTypeHasBase},
  27. wire.ConcreteType{&SetBaseArgs{}, PermArgsTypeSetBase},
  28. wire.ConcreteType{&UnsetBaseArgs{}, PermArgsTypeUnsetBase},
  29. wire.ConcreteType{&SetGlobalArgs{}, PermArgsTypeSetGlobal},
  30. wire.ConcreteType{&HasRoleArgs{}, PermArgsTypeHasRole},
  31. wire.ConcreteType{&AddRoleArgs{}, PermArgsTypeAddRole},
  32. wire.ConcreteType{&RmRoleArgs{}, PermArgsTypeRmRole},
  33. )
  34. type HasBaseArgs struct {
  35. Address []byte `json:"address"`
  36. Permission PermFlag `json:"permission"`
  37. }
  38. func (*HasBaseArgs) PermFlag() PermFlag {
  39. return HasBase
  40. }
  41. type SetBaseArgs struct {
  42. Address []byte `json:"address"`
  43. Permission PermFlag `json:"permission"`
  44. Value bool `json:"value"`
  45. }
  46. func (*SetBaseArgs) PermFlag() PermFlag {
  47. return SetBase
  48. }
  49. type UnsetBaseArgs struct {
  50. Address []byte `json:"address"`
  51. Permission PermFlag `json:"permission"`
  52. }
  53. func (*UnsetBaseArgs) PermFlag() PermFlag {
  54. return UnsetBase
  55. }
  56. type SetGlobalArgs struct {
  57. Permission PermFlag `json:"permission"`
  58. Value bool `json:"value"`
  59. }
  60. func (*SetGlobalArgs) PermFlag() PermFlag {
  61. return SetGlobal
  62. }
  63. type HasRoleArgs struct {
  64. Address []byte `json:"address"`
  65. Role string `json:"role"`
  66. }
  67. func (*HasRoleArgs) PermFlag() PermFlag {
  68. return HasRole
  69. }
  70. type AddRoleArgs struct {
  71. Address []byte `json:"address"`
  72. Role string `json:"role"`
  73. }
  74. func (*AddRoleArgs) PermFlag() PermFlag {
  75. return AddRole
  76. }
  77. type RmRoleArgs struct {
  78. Address []byte `json:"address"`
  79. Role string `json:"role"`
  80. }
  81. func (*RmRoleArgs) PermFlag() PermFlag {
  82. return RmRole
  83. }