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