github.com/corverroos/quorum@v21.1.0+incompatible/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 ) 10 11 var ( 12 ErrPrivateTxManagerNotinUse = errors.New("private transaction manager is not in use") 13 ErrPrivateTxManagerNotReady = errors.New("private transaction manager is not ready") 14 ErrPrivateTxManagerNotSupported = errors.New("private transaction manager does not support this operation") 15 ErrPrivateTxManagerDoesNotSupportPrivacyEnhancements = errors.New("private transaction manager does not support privacy enhancements") 16 ) 17 18 // Additional information for the private transaction that Private Transaction Manager carries 19 type ExtraMetadata struct { 20 // Hashes of affected Contracts 21 ACHashes common.EncryptedPayloadHashes 22 // Root Hash of a Merkle Trie containing all affected contract account in state objects 23 ACMerkleRoot common.Hash 24 // Privacy flag for contract: standardPrivate, partyProtection, psv 25 PrivacyFlag PrivacyFlagType 26 // Contract participants that are managed by the corresponding Tessera. 27 // Being used in Multi Tenancy 28 ManagedParties []string 29 // the sender of the transaction 30 Sender string 31 } 32 33 type Client struct { 34 HttpClient *http.Client 35 BaseURL string 36 } 37 38 func (c *Client) FullPath(path string) string { 39 return fmt.Sprintf("%s%s", c.BaseURL, path) 40 } 41 42 func (c *Client) Get(path string) (*http.Response, error) { 43 response, err := c.HttpClient.Get(c.FullPath(path)) 44 if err != nil { 45 return response, fmt.Errorf("unable to submit request (method:%s,path:%s). Cause: %v", "GET", path, err) 46 } 47 return response, err 48 } 49 50 type PrivacyFlagType uint64 51 52 const ( 53 PrivacyFlagStandardPrivate PrivacyFlagType = iota // 0 54 PrivacyFlagPartyProtection PrivacyFlagType = 1 << PrivacyFlagType(iota-1) // 1 55 PrivacyFlagStateValidation = iota | PrivacyFlagPartyProtection // 3 which includes PrivacyFlagPartyProtection 56 ) 57 58 func (f PrivacyFlagType) IsNotStandardPrivate() bool { 59 return !f.IsStandardPrivate() 60 } 61 62 func (f PrivacyFlagType) IsStandardPrivate() bool { 63 return f == PrivacyFlagStandardPrivate 64 } 65 66 func (f PrivacyFlagType) Has(other PrivacyFlagType) bool { 67 return other&f == other 68 } 69 70 func (f PrivacyFlagType) HasAll(others ...PrivacyFlagType) bool { 71 var all PrivacyFlagType 72 for _, flg := range others { 73 all = all | flg 74 } 75 return f.Has(all) 76 } 77 78 func (f PrivacyFlagType) Validate() error { 79 if f == PrivacyFlagStandardPrivate || f == PrivacyFlagPartyProtection || f == PrivacyFlagStateValidation { 80 return nil 81 } 82 return fmt.Errorf("invalid privacy flag") 83 } 84 85 type PrivateTransactionManagerFeature uint64 86 87 const ( 88 None PrivateTransactionManagerFeature = iota // 0 89 PrivacyEnhancements PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 1 90 MultiTenancy PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 2 91 ) 92 93 type FeatureSet struct { 94 features uint64 95 } 96 97 func NewFeatureSet(features ...PrivateTransactionManagerFeature) *FeatureSet { 98 var all uint64 = 0 99 for _, feature := range features { 100 all = all | uint64(feature) 101 } 102 return &FeatureSet{features: all} 103 } 104 105 func (p *FeatureSet) HasFeature(feature PrivateTransactionManagerFeature) bool { 106 return uint64(feature)&p.features != 0 107 }