common.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package engine
  2. import (
  3. "errors"
  4. "fmt"
  5. "net/http"
  6. "github.com/ethereum/go-ethereum/common"
  7. "github.com/ethereum/go-ethereum/rlp"
  8. )
  9. const (
  10. PrivacyGroupResident = "RESIDENT"
  11. PrivacyGroupLegacy = "LEGACY"
  12. PrivacyGroupPantheon = "PANTHEON"
  13. )
  14. var (
  15. ErrPrivateTxManagerNotinUse = errors.New("private transaction manager is not in use")
  16. ErrPrivateTxManagerNotReady = errors.New("private transaction manager is not ready")
  17. ErrPrivateTxManagerNotSupported = errors.New("private transaction manager does not support this operation")
  18. ErrPrivateTxManagerDoesNotSupportPrivacyEnhancements = errors.New("private transaction manager does not support privacy enhancements")
  19. ErrPrivateTxManagerDoesNotSupportMandatoryRecipients = errors.New("private transaction manager does not support mandatory recipients")
  20. )
  21. type PrivacyGroup struct {
  22. Type string `json:"type"`
  23. Name string `json:"name"`
  24. PrivacyGroupId string `json:"privacyGroupId"`
  25. Description string `json:"description"`
  26. From string `json:"from"`
  27. Members []string `json:"members"`
  28. }
  29. // Additional information for the private transaction that Private Transaction Manager carries
  30. type ExtraMetadata struct {
  31. // Hashes of affected Contracts
  32. ACHashes common.EncryptedPayloadHashes
  33. // Root Hash of a Merkle Trie containing all affected contract account in state objects
  34. ACMerkleRoot common.Hash
  35. // Privacy flag for contract: standardPrivate, partyProtection, psv
  36. PrivacyFlag PrivacyFlagType
  37. // Contract participants that are managed by the corresponding Tessera.
  38. // Being used in Multi Tenancy
  39. ManagedParties []string
  40. // The sender of the transaction
  41. Sender string
  42. // Recipients that are mandated to be included
  43. MandatoryRecipients []string
  44. }
  45. type QuorumPayloadExtra struct {
  46. Payload string
  47. ExtraMetaData *ExtraMetadata
  48. IsSender bool
  49. }
  50. type Client struct {
  51. HttpClient *http.Client
  52. BaseURL string
  53. }
  54. func (c *Client) FullPath(path string) string {
  55. return fmt.Sprintf("%s%s", c.BaseURL, path)
  56. }
  57. func (c *Client) Get(path string) (*http.Response, error) {
  58. response, err := c.HttpClient.Get(c.FullPath(path))
  59. if err != nil {
  60. return response, fmt.Errorf("unable to submit request (method:%s,path:%s). Cause: %v", "GET", path, err)
  61. }
  62. return response, err
  63. }
  64. type PrivacyFlagType uint64
  65. const (
  66. PrivacyFlagStandardPrivate PrivacyFlagType = iota
  67. PrivacyFlagPartyProtection
  68. PrivacyFlagMandatoryRecipients
  69. PrivacyFlagStateValidation
  70. )
  71. func (f PrivacyFlagType) IsNotStandardPrivate() bool {
  72. return !f.IsStandardPrivate()
  73. }
  74. func (f PrivacyFlagType) IsStandardPrivate() bool {
  75. return f == PrivacyFlagStandardPrivate
  76. }
  77. func (f PrivacyFlagType) Has(other PrivacyFlagType) bool {
  78. return other&f == other
  79. }
  80. func (f PrivacyFlagType) HasAll(others ...PrivacyFlagType) bool {
  81. var all PrivacyFlagType
  82. for _, flg := range others {
  83. all = all | flg
  84. }
  85. return f.Has(all)
  86. }
  87. func (f PrivacyFlagType) Validate() error {
  88. if f == PrivacyFlagStandardPrivate || f == PrivacyFlagPartyProtection || f == PrivacyFlagMandatoryRecipients || f == PrivacyFlagStateValidation {
  89. return nil
  90. }
  91. return fmt.Errorf("invalid privacy flag")
  92. }
  93. type PrivateTransactionManagerFeature uint64
  94. const (
  95. None PrivateTransactionManagerFeature = iota // 0
  96. PrivacyEnhancements PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 1
  97. MultiTenancy PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 2
  98. MultiplePrivateStates PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 4
  99. MandatoryRecipients PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 8
  100. )
  101. type FeatureSet struct {
  102. features uint64
  103. }
  104. func NewFeatureSet(features ...PrivateTransactionManagerFeature) *FeatureSet {
  105. var all uint64 = 0
  106. for _, feature := range features {
  107. all = all | uint64(feature)
  108. }
  109. return &FeatureSet{features: all}
  110. }
  111. func (p *FeatureSet) HasFeature(feature PrivateTransactionManagerFeature) bool {
  112. return uint64(feature)&p.features != 0
  113. }
  114. type ExtraMetaDataRLP ExtraMetadata
  115. func (emd *ExtraMetadata) DecodeRLP(stream *rlp.Stream) error {
  116. // initialize the ACHashes map before passing it into the rlp decoder
  117. emd.ACHashes = make(map[common.EncryptedPayloadHash]struct{})
  118. emdRLP := (*ExtraMetaDataRLP)(emd)
  119. if err := stream.Decode(emdRLP); err != nil {
  120. return err
  121. }
  122. return nil
  123. }