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