github.com/RobustRoundRobin/quorum@v20.10.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 } 27 28 type Client struct { 29 HttpClient *http.Client 30 BaseURL string 31 } 32 33 func (c *Client) FullPath(path string) string { 34 return fmt.Sprintf("%s%s", c.BaseURL, path) 35 } 36 37 func (c *Client) Get(path string) (*http.Response, error) { 38 response, err := c.HttpClient.Get(c.FullPath(path)) 39 if err != nil { 40 return response, fmt.Errorf("unable to submit request (method:%s,path:%s). Cause: %v", "GET", path, err) 41 } 42 return response, err 43 } 44 45 type PrivacyFlagType uint64 46 47 const ( 48 PrivacyFlagStandardPrivate PrivacyFlagType = iota // 0 49 PrivacyFlagPartyProtection PrivacyFlagType = 1 << PrivacyFlagType(iota-1) // 1 50 PrivacyFlagStateValidation = iota | PrivacyFlagPartyProtection // 3 which includes PrivacyFlagPartyProtection 51 ) 52 53 func (f PrivacyFlagType) IsNotStandardPrivate() bool { 54 return !f.IsStandardPrivate() 55 } 56 57 func (f PrivacyFlagType) IsStandardPrivate() bool { 58 return f == PrivacyFlagStandardPrivate 59 } 60 61 func (f PrivacyFlagType) Has(other PrivacyFlagType) bool { 62 return other&f == other 63 } 64 65 func (f PrivacyFlagType) HasAll(others ...PrivacyFlagType) bool { 66 var all PrivacyFlagType 67 for _, flg := range others { 68 all = all | flg 69 } 70 return f.Has(all) 71 } 72 73 func (f PrivacyFlagType) Validate() error { 74 if f == PrivacyFlagStandardPrivate || f == PrivacyFlagPartyProtection || f == PrivacyFlagStateValidation { 75 return nil 76 } 77 return fmt.Errorf("invalid privacy flag") 78 } 79 80 type PrivateTransactionManagerFeature uint64 81 82 const ( 83 None PrivateTransactionManagerFeature = iota // 0 84 PrivacyEnhancements PrivateTransactionManagerFeature = 1 << PrivateTransactionManagerFeature(iota-1) // 1 85 ) 86 87 type FeatureSet struct { 88 features uint64 89 } 90 91 func NewFeatureSet(features ...PrivateTransactionManagerFeature) *FeatureSet { 92 var all uint64 = 0 93 for _, feature := range features { 94 all = all | uint64(feature) 95 } 96 return &FeatureSet{features: all} 97 } 98 99 func (p *FeatureSet) HasFeature(feature PrivateTransactionManagerFeature) bool { 100 return uint64(feature)&p.features != 0 101 }